01: /*
02: * Created on Jun 19, 2004
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07: package org.xdev.base.descriptor.xml;
08:
09: import java.io.File;
10:
11: import java.util.List;
12: import java.util.HashMap;
13:
14: import org.jdom.*;
15: import org.jdom.input.SAXBuilder;
16:
17: import org.xdev.base.core.compiler.type.AbstractType;
18: import org.xdev.base.core.manager.PluginManager;
19: import org.xdev.base.descriptor.AbstractMetaDataDescriptor;
20: import org.xdev.base.descriptor.xml.parser.AbstractTypeParser;
21:
22: public class XmlDocumentDescriptor extends AbstractMetaDataDescriptor {
23:
24: /**
25: * @param id
26: * @param properties
27: */
28: public XmlDocumentDescriptor(String id, HashMap properties) {
29:
30: super (id, properties);
31: // TODO Auto-generated constructor stub
32: }
33:
34: /* (non-Javadoc)
35: * @see org.xdev.base.descriptor.AbstractMetaDataDescriptor#parseDescriptions(java.io.File)
36: */
37: protected AbstractType[] parseDescriptions(File file)
38: throws Exception {
39:
40: PluginManager manager = PluginManager.getInstance();
41:
42: Document doc = new SAXBuilder().build(file);
43:
44: Element root = doc.getRootElement();
45:
46: List children = root.getChildren();
47:
48: int size = children.size();
49:
50: AbstractType[] types = new AbstractType[size];
51:
52: Element type = null;
53:
54: Namespace typeNs = null;
55:
56: Class typeParserClass = null;
57:
58: AbstractTypeParser typeParserObj = null;
59:
60: Class[] validators = null;
61:
62: List validatorElms = null;
63:
64: Element validatorElm = null;
65:
66: for (int i = 0; i < size; i++) {
67:
68: type = (Element) children.get(i);
69:
70: typeNs = type.getNamespace();
71:
72: typeParserClass = manager.loadClass(typeNs.getURI());
73:
74: typeParserObj = (AbstractTypeParser) typeParserClass
75: .newInstance();
76:
77: types[i] = typeParserObj.parse(type);
78: }
79:
80: return types;
81: }
82:
83: }
|