123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- package com.sysmodel.datamodel.xmlmodel.impl;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Iterator;
- import java.util.List;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import com.sysmodel.datamodel.xmlmanager.XMLLoader;
- import com.sysmodel.datamodel.xmlmanager.XMLSave;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.Reference;
- import com.sysmodel.datamodel.xmlmodel.able.MdpAttribute;
- import com.sysmodel.datamodel.xmlmodel.able.MdpClass;
- import com.sysmodel.datamodel.xmlmodel.able.MdpConstant;
- import com.sysmodel.datamodel.xmlmodel.able.MdpDataSource;
- import com.sysmodel.datamodel.xmlmodel.able.MdpModule;
- import com.sysmodel.datamodel.xmlmodel.able.Relation;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- import com.sysmodel.datamodel.xmlmodel.able.Template;
- public class SysModelImpl implements SysModel{
- private static Log log = LogFactory.getLog(SysModelImpl.class);
- private String author;
- private String version;
- private String unitcode;
- private String unitname;
- private ArrayList<MdpModuleImpl> mdpModules = new ArrayList<MdpModuleImpl>();
- private ArrayList<MdpDataSourceImpl> mdpDataSources = new ArrayList<MdpDataSourceImpl>();
- private ArrayList<MdpConstantImpl> mdpConstants = new ArrayList<MdpConstantImpl>();
- private ArrayList<MdpClassImpl> mdpClasses = new ArrayList<MdpClassImpl>();
- private ArrayList<TemplateImpl> templates = new ArrayList<TemplateImpl>();
- private ArrayList<RelationImpl> listRelations = new ArrayList<RelationImpl>();
- private static SysModelImpl sysmodel = null;
- public static String fileLoadPath = null;
- private SysModelImpl() {
- author = "nbs";
- version = "1.0";
- }
- /**
- * 获得应用单位编码
- *
- * @return
- */
- public String getUnitCode() {
- return unitcode;
- }
- public void setUnitcode(String unitcode) {
- this.unitcode = unitcode;
- }
- public String getAuthor() {
- return author;
- }
- public void setAuthor(String author) {
- this.author = author;
- }
- public String getVersion() {
- return version;
- }
- public void setVersion(String version) {
- this.version = version;
- }
- public ArrayList<MdpModuleImpl> getMdpModules() {
- return mdpModules;
- }
- public void setmdpModules(ArrayList<MdpModuleImpl> mdpModules) {
- this.mdpModules = mdpModules;
- }
- public ArrayList<MdpDataSourceImpl> getMdpDataSources() {
- return mdpDataSources;
- }
- public void setMdpDataSources(ArrayList<MdpDataSourceImpl> mdpDataSources) {
- this.mdpDataSources = mdpDataSources;
- }
- public ArrayList<TemplateImpl> getTemplates() {
- return templates;
- }
- public void setTemplates(ArrayList<TemplateImpl> templates) {
- this.templates = templates;
- }
- public ArrayList<MdpConstantImpl> getMdpConstants() {
- return mdpConstants;
- }
- public void setMdpConstants(ArrayList<MdpConstantImpl> mdpConstants) {
- this.mdpConstants = mdpConstants;
- }
- public ArrayList<MdpClassImpl> getMdpClasses() {
- return mdpClasses;
- }
- public void setMdpClasses(ArrayList<MdpClassImpl> mdpClasses) {
- this.mdpClasses = mdpClasses;
- }
- public ArrayList<RelationImpl> getRelations() {
- return listRelations;
- }
- public void addRelations(List<RelationImpl> relations) {
- this.listRelations.addAll(relations);
- }
- public void setRelations(ArrayList<RelationImpl> relations) {
- this.listRelations = relations;
- }
- public Template getTemplateByName(String templateName) {
- if (templateName == null)
- return null;
- for (int i = 0; i < templates.size(); i++) {
- TemplateImpl temp = (TemplateImpl) templates.get(i);
- if (temp.getName().equals(templateName))
- return temp;
- }
- return null;
- }
- public static SysModelImpl getInstance() {
- return sysmodel;
- }
- public static SysModelImpl getInstance(File[] files) {
- if (sysmodel == null)
- sysmodel = new SysModelImpl();
- else
- sysmodel.clear();
- if (null != files && 0 != files.length) {
- com.sysmodel.configLoader.XMLLoader loader = new com.sysmodel.configLoader.XMLLoader();
- if (loader.loadXML(files))
- log.info("文件加载成功");
- }
- return sysmodel;
- }
- public static SysModelImpl getInstance(String fullpath) {
- if (sysmodel == null) {
- sysmodel = new SysModelImpl();
- } else
- sysmodel.clear();
- if (!fullpath.equals("")) {
- fileLoadPath = fullpath;
- XMLLoader loader = new XMLLoader();
- if (loader.loadFromXML(fullpath)) {
- log.info("load success : " + fullpath);
- }
- } else
- log.info("full path is empty");
- return sysmodel;
- }
- public boolean saveSysModelToXML() {
- XMLSave loader = new XMLSave();
- return loader.saveToXMLFile(fileLoadPath);
- }
- public MdpModule getMdpModuleByCode(String code) {
- for (int i = 0; i < mdpModules.size(); i++) {
- MdpModuleImpl modSource = (MdpModuleImpl) mdpModules.get(i);
- if (modSource.getCode().equals(code))
- return modSource;
- }
- return null;
- }
- public MdpDataSource getDataSourceByCode(int sourcecode) {
- for (int i = 0; i < mdpDataSources.size(); i++) {
- MdpDataSourceImpl dataSource = (MdpDataSourceImpl) mdpDataSources.get(i);
- if (dataSource.getDataSourceid() == sourcecode)
- return dataSource;
- }
- return null;
- }
- public MdpAttribute getMdpAttributeByName(int classid, String attributeName) {
- if (getMdpClassByClassID(classid) == null) {
- log.info("classid :" + classid + " 的表不存在");
- return null;
- } else {
- return getMdpClassByClassID(classid).getMdpAttributeByName(attributeName);
- }
- }
- public MdpClass getMdpClassByClassID(int classid) {
- for (int i = 0; i < mdpClasses.size(); i++) {
- MdpClass mdpClass = (MdpClass) mdpClasses.get(i);
- if (mdpClass.getClassid() == classid)
- return mdpClass;
- }
- return null;
- }
- public ArrayList<MdpClass> getMdpClassByType(String type) {
- ArrayList<MdpClass> al = new ArrayList<MdpClass>();
- for (int i = 0; i < mdpClasses.size(); i++) {
- MdpClass mdpClass = (MdpClass) mdpClasses.get(i);
- if (mdpClass.getType().equals(type)) {
- al.add(mdpClass);
- }
- }
- return al;
- }
- public ArrayList<MdpClass> getAllChildMdpClassByType(String type) {
- ArrayList<MdpClass> al = new ArrayList<MdpClass>();
- for (int i = 0; i < mdpClasses.size(); i++) {
- MdpClass mdpClass = (MdpClass) mdpClasses.get(i);
- if (mdpClass.getType().startsWith(type)) {
- al.add(mdpClass);
- }
- }
- return al;
- }
- public MdpConstant getMdpConstantByName(String codeName) {
- for (int i = 0; i < mdpConstants.size(); i++) {
- MdpConstant constant = (MdpConstant) mdpConstants.get(i);
- if (constant.getCodeName().equals(codeName))
- return constant;
- }
- return null;
- }
- public ArrayList<MdpConstantImpl> getMdpConstantByType(String type) {
- ArrayList<MdpConstantImpl> list = new ArrayList<MdpConstantImpl>();
- for (int i = 0; i < mdpConstants.size(); i++) {
- MdpConstantImpl MdpConstant = (MdpConstantImpl) mdpConstants.get(i);
- if (MdpConstant.getType().equals(type)) {
- list.add(MdpConstant);
- }
- }
- return list;
- }
- public String getMdpConstantDisplayString(String codeName, String uniqueCode) {
- MdpConstant constant = getMdpConstantByName(codeName);
- if (constant != null) {
- if (constant.isTree() && uniqueCode.length() > 4) {
- if (uniqueCode.substring(0, uniqueCode.length() - 2).equals("1200")) {
- return constant.getMdpConstantDisplayString(uniqueCode);
- } else {
- return constant.getMdpConstantDisplayString(uniqueCode.substring(0,
- uniqueCode.length() - 2))
- + constant.getMdpConstantDisplayString(uniqueCode);
- }
- } else
- return constant.getMdpConstantDisplayString(uniqueCode);
- }
- return "";
- }
- public boolean isChildTable(int classid) {
- for (int i = 0; i < listRelations.size(); i++) {
- Relation relation = (Relation) listRelations.get(i);
- if (relation.getGuestClassid() == classid
- && relation.getType() == Relation.REALTION_MASTER)
- return true;
- }
- return false;
- }
- public ArrayList<MdpAttribute> getReferenceConstantMdpAttribute(MdpClass mdpClass,
- String codeName) {
- ArrayList<MdpAttribute> arraylist = new ArrayList<MdpAttribute>();
- List<MdpAttributeImpl> attributes = mdpClass.getAllMdpAttributes();
- Iterator<MdpAttributeImpl> it = attributes.iterator();
- while (it.hasNext()) {
- MdpAttribute temp = (MdpAttribute) it.next();
- if (temp.getReferenceType() == Reference.REF_CONSTANT
- && temp.getReference().getReferenceTable().equals(codeName))
- arraylist.add(temp);
- }
- return arraylist;
- }
- public String getCalendarDayTime() {
- Calendar calendar = Calendar.getInstance();
- java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
- return df.format(calendar.getTime());
- }
- public String getFileLoadFolder() {
- return fileLoadPath.replaceAll("DataModel.xml", "");
- }
- public ArrayList<MdpClass> getMdpClassByDataSource(int dataSource) {
- SysModel sysmodel = ModelFactory.getSysmodel();
- ArrayList<MdpClassImpl> mdpClassList = sysmodel.getMdpClasses();
- ArrayList<MdpClass> tables = new ArrayList<MdpClass>();
- for (int i = 0; i < mdpClassList.size(); i++) {
- MdpClass mdpClass = (MdpClass) mdpClassList.get(i);
- if (mdpClass.getDataSource() == dataSource) {
- tables.add(mdpClass);
- }
- }
- return tables;
- }
- public ArrayList<MdpConstant> getMdpConstantByDataSource(int dataSource) {
- SysModel sysmodel = ModelFactory.getSysmodel();
- ArrayList<MdpConstantImpl> MdpConstantList = sysmodel.getMdpConstants();
- ArrayList<MdpConstant> mdpConstants = new ArrayList<MdpConstant>();
- for (int i = 0; i < MdpConstantList.size(); i++) {
- MdpConstant mdpConstant = (MdpConstant) MdpConstantList.get(i);
- if (mdpConstant.getDataSource() == dataSource) {
- mdpConstants.add(mdpConstant);
- }
- }
- return mdpConstants;
- }
- private void clear() {
- mdpModules.clear();
- mdpDataSources.clear();
- templates.clear();
- mdpConstants.clear();
- mdpClasses.clear();
- }
- public ArrayList<MdpModuleImpl> getMdpModulesByPcode(String pCode) {
- ArrayList<MdpModuleImpl> result = new ArrayList<MdpModuleImpl>();
- for (int i = 0; i < mdpModules.size(); i++) {
- MdpModuleImpl modSource = (MdpModuleImpl) mdpModules.get(i);
- // log.info("modSource.getPcode() = " + modSource.getPcode());
- if (modSource.getPcode().equals(pCode))
- result.add(modSource);
- }
- return result;
- }
- public String getUnitname() {
- return unitname;
- }
- public void setUnitname(String unitname) {
- this.unitname = unitname;
- }
- }
|