KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > deploy > ComponentModuleDescriptor


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.ioc.deploy;
8
9 import java.util.ArrayList JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.List JavaDoc;
12
13 import org.jfox.ioc.ComponentMeta;
14 import org.jfox.ioc.deployment.Descriptor;
15 import org.jfox.ioc.util.XMLUtils;
16 import org.w3c.dom.Document JavaDoc;
17 import org.w3c.dom.Element JavaDoc;
18 import org.w3c.dom.Node JavaDoc;
19
20 /**
21  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
22  */

23
24 public class ComponentModuleDescriptor implements Descriptor {
25
26     private List JavaDoc components = new ArrayList JavaDoc();
27     private String JavaDoc description;
28     // default priority
29
private int priority = ComponentMeta.DEFAULT_PRIORITY;
30
31     private List JavaDoc<String JavaDoc> publicClassList = new ArrayList JavaDoc<String JavaDoc>();
32
33     public ComponentModuleDescriptor(Document JavaDoc document) throws ComponentDescriptionException {
34         this.processXML(document.getDocumentElement());
35     }
36
37     /**
38      * node is the Document element
39      *
40      * @param node
41      * @throws ComponentDescriptionException
42      */

43     public void processXML(Node JavaDoc node) throws ComponentDescriptionException {
44         setDescription(XMLUtils.getChildNodeValueOf(node, "description"));
45         setPriority(XMLUtils.getChildNodeValueOf(node, "priority"));
46
47         /**
48          * public classes 需要被预先装载,以提交到 ClassLoader 的共享区
49          */

50         Node JavaDoc publicClassesElement = XMLUtils.getChildNodeOf(node, "public-classes");
51         if(publicClassesElement != null) {
52             Iterator JavaDoc pubClasses = XMLUtils.getElementsByTagName((Element JavaDoc) publicClassesElement, "class");
53             while(pubClasses.hasNext()) {
54                 Element JavaDoc pubClass = (Element JavaDoc) pubClasses.next();
55                 String JavaDoc pubClassName = XMLUtils.getValueOf(pubClass);
56                 addPublicClassName(pubClassName);
57             }
58         }
59
60         Iterator JavaDoc components = XMLUtils.getElementsByTagName((Element JavaDoc) node, "component");
61         while(components.hasNext()) {
62             Element JavaDoc component = (Element JavaDoc) components.next();
63             ComponentDescriptor componentDesc = new ComponentDescriptor(this);
64             componentDesc.processXML(component);
65             addComponent(componentDesc);
66         }
67     }
68
69     public String JavaDoc getDescription() {
70         return description;
71     }
72
73     public void setDescription(String JavaDoc description) {
74         this.description = description;
75     }
76
77     public int getPriority() {
78         return priority;
79     }
80
81     public void setPriority(String JavaDoc priority) {
82         try {
83             this.priority = Integer.parseInt(priority);
84         }
85         catch(Exception JavaDoc e) {
86             e.printStackTrace();
87         }
88     }
89
90     void addComponent(ComponentDescriptor component) {
91         components.add(component);
92     }
93
94     public ComponentDescriptor[] getComponentDescriptors() {
95         return (ComponentDescriptor[]) components.toArray(new ComponentDescriptor[components.size()]);
96     }
97
98     public void addPublicClassName(String JavaDoc className) {
99         publicClassList.add(className);
100     }
101
102     public String JavaDoc[] getPublicClasses() {
103         return publicClassList.toArray(new String JavaDoc[publicClassList.size()]);
104     }
105
106     public static void main(String JavaDoc[] args) {
107
108     }
109 }
110
111
Popular Tags