e4f86e797bf4683507b2ff55dec710e08d67f963.svn-base 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. package com.sysmodel.datamodel.xmlmodel.impl;
  2. import java.io.File;
  3. import java.util.ArrayList;
  4. import java.util.Calendar;
  5. import java.util.Iterator;
  6. import java.util.List;
  7. import org.apache.commons.logging.Log;
  8. import org.apache.commons.logging.LogFactory;
  9. import com.sysmodel.datamodel.xmlmanager.XMLLoader;
  10. import com.sysmodel.datamodel.xmlmanager.XMLSave;
  11. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  12. import com.sysmodel.datamodel.xmlmodel.Reference;
  13. import com.sysmodel.datamodel.xmlmodel.able.MdpAttribute;
  14. import com.sysmodel.datamodel.xmlmodel.able.MdpClass;
  15. import com.sysmodel.datamodel.xmlmodel.able.MdpConstant;
  16. import com.sysmodel.datamodel.xmlmodel.able.MdpDataSource;
  17. import com.sysmodel.datamodel.xmlmodel.able.MdpModule;
  18. import com.sysmodel.datamodel.xmlmodel.able.Relation;
  19. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  20. import com.sysmodel.datamodel.xmlmodel.able.Template;
  21. public class SysModelImpl implements SysModel{
  22. private static Log log = LogFactory.getLog(SysModelImpl.class);
  23. private String author;
  24. private String version;
  25. private String unitcode;
  26. private String unitname;
  27. private ArrayList<MdpModuleImpl> mdpModules = new ArrayList<MdpModuleImpl>();
  28. private ArrayList<MdpDataSourceImpl> mdpDataSources = new ArrayList<MdpDataSourceImpl>();
  29. private ArrayList<MdpConstantImpl> mdpConstants = new ArrayList<MdpConstantImpl>();
  30. private ArrayList<MdpClassImpl> mdpClasses = new ArrayList<MdpClassImpl>();
  31. private ArrayList<TemplateImpl> templates = new ArrayList<TemplateImpl>();
  32. private ArrayList<RelationImpl> listRelations = new ArrayList<RelationImpl>();
  33. private static SysModelImpl sysmodel = null;
  34. public static String fileLoadPath = null;
  35. private SysModelImpl() {
  36. author = "nbs";
  37. version = "1.0";
  38. }
  39. /**
  40. * 获得应用单位编码
  41. *
  42. * @return
  43. */
  44. public String getUnitCode() {
  45. return unitcode;
  46. }
  47. public void setUnitcode(String unitcode) {
  48. this.unitcode = unitcode;
  49. }
  50. public String getAuthor() {
  51. return author;
  52. }
  53. public void setAuthor(String author) {
  54. this.author = author;
  55. }
  56. public String getVersion() {
  57. return version;
  58. }
  59. public void setVersion(String version) {
  60. this.version = version;
  61. }
  62. public ArrayList<MdpModuleImpl> getMdpModules() {
  63. return mdpModules;
  64. }
  65. public void setmdpModules(ArrayList<MdpModuleImpl> mdpModules) {
  66. this.mdpModules = mdpModules;
  67. }
  68. public ArrayList<MdpDataSourceImpl> getMdpDataSources() {
  69. return mdpDataSources;
  70. }
  71. public void setMdpDataSources(ArrayList<MdpDataSourceImpl> mdpDataSources) {
  72. this.mdpDataSources = mdpDataSources;
  73. }
  74. public ArrayList<TemplateImpl> getTemplates() {
  75. return templates;
  76. }
  77. public void setTemplates(ArrayList<TemplateImpl> templates) {
  78. this.templates = templates;
  79. }
  80. public ArrayList<MdpConstantImpl> getMdpConstants() {
  81. return mdpConstants;
  82. }
  83. public void setMdpConstants(ArrayList<MdpConstantImpl> mdpConstants) {
  84. this.mdpConstants = mdpConstants;
  85. }
  86. public ArrayList<MdpClassImpl> getMdpClasses() {
  87. return mdpClasses;
  88. }
  89. public void setMdpClasses(ArrayList<MdpClassImpl> mdpClasses) {
  90. this.mdpClasses = mdpClasses;
  91. }
  92. public ArrayList<RelationImpl> getRelations() {
  93. return listRelations;
  94. }
  95. public void addRelations(List<RelationImpl> relations) {
  96. this.listRelations.addAll(relations);
  97. }
  98. public void setRelations(ArrayList<RelationImpl> relations) {
  99. this.listRelations = relations;
  100. }
  101. public Template getTemplateByName(String templateName) {
  102. if (templateName == null)
  103. return null;
  104. for (int i = 0; i < templates.size(); i++) {
  105. TemplateImpl temp = (TemplateImpl) templates.get(i);
  106. if (temp.getName().equals(templateName))
  107. return temp;
  108. }
  109. return null;
  110. }
  111. public static SysModelImpl getInstance() {
  112. return sysmodel;
  113. }
  114. public static SysModelImpl getInstance(File[] files) {
  115. if (sysmodel == null)
  116. sysmodel = new SysModelImpl();
  117. else
  118. sysmodel.clear();
  119. if (null != files && 0 != files.length) {
  120. com.sysmodel.configLoader.XMLLoader loader = new com.sysmodel.configLoader.XMLLoader();
  121. if (loader.loadXML(files))
  122. log.info("文件加载成功");
  123. }
  124. return sysmodel;
  125. }
  126. public static SysModelImpl getInstance(String fullpath) {
  127. if (sysmodel == null) {
  128. sysmodel = new SysModelImpl();
  129. } else
  130. sysmodel.clear();
  131. if (!fullpath.equals("")) {
  132. fileLoadPath = fullpath;
  133. XMLLoader loader = new XMLLoader();
  134. if (loader.loadFromXML(fullpath)) {
  135. log.info("load success : " + fullpath);
  136. }
  137. } else
  138. log.info("full path is empty");
  139. return sysmodel;
  140. }
  141. public boolean saveSysModelToXML() {
  142. XMLSave loader = new XMLSave();
  143. return loader.saveToXMLFile(fileLoadPath);
  144. }
  145. public MdpModule getMdpModuleByCode(String code) {
  146. for (int i = 0; i < mdpModules.size(); i++) {
  147. MdpModuleImpl modSource = (MdpModuleImpl) mdpModules.get(i);
  148. if (modSource.getCode().equals(code))
  149. return modSource;
  150. }
  151. return null;
  152. }
  153. public MdpDataSource getDataSourceByCode(int sourcecode) {
  154. for (int i = 0; i < mdpDataSources.size(); i++) {
  155. MdpDataSourceImpl dataSource = (MdpDataSourceImpl) mdpDataSources.get(i);
  156. if (dataSource.getDataSourceid() == sourcecode)
  157. return dataSource;
  158. }
  159. return null;
  160. }
  161. public MdpAttribute getMdpAttributeByName(int classid, String attributeName) {
  162. if (getMdpClassByClassID(classid) == null) {
  163. log.info("classid :" + classid + " 的表不存在");
  164. return null;
  165. } else {
  166. return getMdpClassByClassID(classid).getMdpAttributeByName(attributeName);
  167. }
  168. }
  169. public MdpClass getMdpClassByClassID(int classid) {
  170. for (int i = 0; i < mdpClasses.size(); i++) {
  171. MdpClass mdpClass = (MdpClass) mdpClasses.get(i);
  172. if (mdpClass.getClassid() == classid)
  173. return mdpClass;
  174. }
  175. return null;
  176. }
  177. public ArrayList<MdpClass> getMdpClassByType(String type) {
  178. ArrayList<MdpClass> al = new ArrayList<MdpClass>();
  179. for (int i = 0; i < mdpClasses.size(); i++) {
  180. MdpClass mdpClass = (MdpClass) mdpClasses.get(i);
  181. if (mdpClass.getType().equals(type)) {
  182. al.add(mdpClass);
  183. }
  184. }
  185. return al;
  186. }
  187. public ArrayList<MdpClass> getAllChildMdpClassByType(String type) {
  188. ArrayList<MdpClass> al = new ArrayList<MdpClass>();
  189. for (int i = 0; i < mdpClasses.size(); i++) {
  190. MdpClass mdpClass = (MdpClass) mdpClasses.get(i);
  191. if (mdpClass.getType().startsWith(type)) {
  192. al.add(mdpClass);
  193. }
  194. }
  195. return al;
  196. }
  197. public MdpConstant getMdpConstantByName(String codeName) {
  198. for (int i = 0; i < mdpConstants.size(); i++) {
  199. MdpConstant constant = (MdpConstant) mdpConstants.get(i);
  200. if (constant.getCodeName().equals(codeName))
  201. return constant;
  202. }
  203. return null;
  204. }
  205. public ArrayList<MdpConstantImpl> getMdpConstantByType(String type) {
  206. ArrayList<MdpConstantImpl> list = new ArrayList<MdpConstantImpl>();
  207. for (int i = 0; i < mdpConstants.size(); i++) {
  208. MdpConstantImpl MdpConstant = (MdpConstantImpl) mdpConstants.get(i);
  209. if (MdpConstant.getType().equals(type)) {
  210. list.add(MdpConstant);
  211. }
  212. }
  213. return list;
  214. }
  215. public String getMdpConstantDisplayString(String codeName, String uniqueCode) {
  216. MdpConstant constant = getMdpConstantByName(codeName);
  217. if (constant != null) {
  218. if (constant.isTree() && uniqueCode.length() > 4) {
  219. if (uniqueCode.substring(0, uniqueCode.length() - 2).equals("1200")) {
  220. return constant.getMdpConstantDisplayString(uniqueCode);
  221. } else {
  222. return constant.getMdpConstantDisplayString(uniqueCode.substring(0,
  223. uniqueCode.length() - 2))
  224. + constant.getMdpConstantDisplayString(uniqueCode);
  225. }
  226. } else
  227. return constant.getMdpConstantDisplayString(uniqueCode);
  228. }
  229. return "";
  230. }
  231. public boolean isChildTable(int classid) {
  232. for (int i = 0; i < listRelations.size(); i++) {
  233. Relation relation = (Relation) listRelations.get(i);
  234. if (relation.getGuestClassid() == classid
  235. && relation.getType() == Relation.REALTION_MASTER)
  236. return true;
  237. }
  238. return false;
  239. }
  240. public ArrayList<MdpAttribute> getReferenceConstantMdpAttribute(MdpClass mdpClass,
  241. String codeName) {
  242. ArrayList<MdpAttribute> arraylist = new ArrayList<MdpAttribute>();
  243. List<MdpAttributeImpl> attributes = mdpClass.getAllMdpAttributes();
  244. Iterator<MdpAttributeImpl> it = attributes.iterator();
  245. while (it.hasNext()) {
  246. MdpAttribute temp = (MdpAttribute) it.next();
  247. if (temp.getReferenceType() == Reference.REF_CONSTANT
  248. && temp.getReference().getReferenceTable().equals(codeName))
  249. arraylist.add(temp);
  250. }
  251. return arraylist;
  252. }
  253. public String getCalendarDayTime() {
  254. Calendar calendar = Calendar.getInstance();
  255. java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
  256. return df.format(calendar.getTime());
  257. }
  258. public String getFileLoadFolder() {
  259. return fileLoadPath.replaceAll("DataModel.xml", "");
  260. }
  261. public ArrayList<MdpClass> getMdpClassByDataSource(int dataSource) {
  262. SysModel sysmodel = ModelFactory.getSysmodel();
  263. ArrayList<MdpClassImpl> mdpClassList = sysmodel.getMdpClasses();
  264. ArrayList<MdpClass> tables = new ArrayList<MdpClass>();
  265. for (int i = 0; i < mdpClassList.size(); i++) {
  266. MdpClass mdpClass = (MdpClass) mdpClassList.get(i);
  267. if (mdpClass.getDataSource() == dataSource) {
  268. tables.add(mdpClass);
  269. }
  270. }
  271. return tables;
  272. }
  273. public ArrayList<MdpConstant> getMdpConstantByDataSource(int dataSource) {
  274. SysModel sysmodel = ModelFactory.getSysmodel();
  275. ArrayList<MdpConstantImpl> MdpConstantList = sysmodel.getMdpConstants();
  276. ArrayList<MdpConstant> mdpConstants = new ArrayList<MdpConstant>();
  277. for (int i = 0; i < MdpConstantList.size(); i++) {
  278. MdpConstant mdpConstant = (MdpConstant) MdpConstantList.get(i);
  279. if (mdpConstant.getDataSource() == dataSource) {
  280. mdpConstants.add(mdpConstant);
  281. }
  282. }
  283. return mdpConstants;
  284. }
  285. private void clear() {
  286. mdpModules.clear();
  287. mdpDataSources.clear();
  288. templates.clear();
  289. mdpConstants.clear();
  290. mdpClasses.clear();
  291. }
  292. public ArrayList<MdpModuleImpl> getMdpModulesByPcode(String pCode) {
  293. ArrayList<MdpModuleImpl> result = new ArrayList<MdpModuleImpl>();
  294. for (int i = 0; i < mdpModules.size(); i++) {
  295. MdpModuleImpl modSource = (MdpModuleImpl) mdpModules.get(i);
  296. // log.info("modSource.getPcode() = " + modSource.getPcode());
  297. if (modSource.getPcode().equals(pCode))
  298. result.add(modSource);
  299. }
  300. return result;
  301. }
  302. public String getUnitname() {
  303. return unitname;
  304. }
  305. public void setUnitname(String unitname) {
  306. this.unitname = unitname;
  307. }
  308. }