001: /*
002: * Created on Oct 30, 2004
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Style - Code Templates
006: */
007: package org.xdev.base.schema;
008:
009: import java.util.HashMap;
010: import java.util.List;
011:
012: import org.apache.log4j.Level;
013: import org.jdom.Document;
014: import org.jdom.Element;
015: import org.jdom.input.SAXBuilder;
016: import org.xdev.base.core.BASE;
017: import org.xdev.base.core.compiler.AXCompiler;
018: import org.xdev.base.core.object.Configuration;
019: import org.xdev.base.log.LoggerWriter;
020:
021: /**
022: * @author Administrator
023: *
024: * TODO To change the template for this generated type comment go to
025: * Window - Preferences - Java - Code Style - Code Templates
026: */
027: public class ComponentSchemaManager {
028:
029: private static ComponentSchemaManager manager = null;
030:
031: private HashMap schemaMap = new HashMap();
032:
033: private ComponentSchemaManager() {
034: super ();
035: // TODO Auto-generated constructor stub
036: }
037:
038: public static ComponentSchemaManager getInstance() {
039:
040: if (manager == null) {
041:
042: manager = new ComponentSchemaManager();
043:
044: manager.init();
045: }
046:
047: return manager;
048: }
049:
050: protected void init() {
051:
052: try {
053: SAXBuilder builder = new SAXBuilder();
054:
055: Document doc = builder.build(BASE.getFile(
056: "/component-schema.xml", this .getClass()));
057:
058: Element root = doc.getRootElement();
059:
060: List schemaList = root.getChildren("schema");
061:
062: int size = schemaList.size();
063:
064: AbstractComponentSchema schema = null;
065:
066: Class schemaType = null;
067: Class componentType = null;
068:
069: String schemaId = null;
070:
071: Element schemaElm = null;
072:
073: for (int i = 0; i < size; i++) {
074:
075: schemaId = schemaElm.getAttributeValue("id");
076:
077: schemaType = AXCompiler.loadClass(schemaElm
078: .getAttributeValue("type"));
079: componentType = AXCompiler.loadClass(schemaElm
080: .getAttributeValue("component"));
081:
082: schema = (AbstractComponentSchema) schemaType
083: .getConstructor(
084: new Class[] { String.class,
085: HashMap.class, Class.class })
086: .newInstance(
087: new Object[] {
088: schemaId,
089: AXCompiler
090: .getInstance()
091: .compileProperties(
092: schemaElm, null),
093: componentType });
094:
095: schemaMap.put(schema.getComponentType(), schema);
096: }
097: } catch (Exception ex) {
098:
099: LoggerWriter.log(BASE.getValueFromObject(ex),
100: Level.ERROR_INT, this .getClass());
101: }
102: }
103:
104: public AbstractComponentSchema getSchema(Configuration config) {
105:
106: return (AbstractComponentSchema) this.schemaMap.get(config
107: .getClass());
108: }
109:
110: }
|