1 6 7 package org.jfox.ioc.deploy; 8 9 import java.util.ArrayList ; 10 import java.util.Iterator ; 11 import java.util.List ; 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 ; 17 import org.w3c.dom.Element ; 18 import org.w3c.dom.Node ; 19 20 23 24 public class ComponentModuleDescriptor implements Descriptor { 25 26 private List components = new ArrayList (); 27 private String description; 28 private int priority = ComponentMeta.DEFAULT_PRIORITY; 30 31 private List <String > publicClassList = new ArrayList <String >(); 32 33 public ComponentModuleDescriptor(Document document) throws ComponentDescriptionException { 34 this.processXML(document.getDocumentElement()); 35 } 36 37 43 public void processXML(Node node) throws ComponentDescriptionException { 44 setDescription(XMLUtils.getChildNodeValueOf(node, "description")); 45 setPriority(XMLUtils.getChildNodeValueOf(node, "priority")); 46 47 50 Node publicClassesElement = XMLUtils.getChildNodeOf(node, "public-classes"); 51 if(publicClassesElement != null) { 52 Iterator pubClasses = XMLUtils.getElementsByTagName((Element ) publicClassesElement, "class"); 53 while(pubClasses.hasNext()) { 54 Element pubClass = (Element ) pubClasses.next(); 55 String pubClassName = XMLUtils.getValueOf(pubClass); 56 addPublicClassName(pubClassName); 57 } 58 } 59 60 Iterator components = XMLUtils.getElementsByTagName((Element ) node, "component"); 61 while(components.hasNext()) { 62 Element component = (Element ) components.next(); 63 ComponentDescriptor componentDesc = new ComponentDescriptor(this); 64 componentDesc.processXML(component); 65 addComponent(componentDesc); 66 } 67 } 68 69 public String getDescription() { 70 return description; 71 } 72 73 public void setDescription(String description) { 74 this.description = description; 75 } 76 77 public int getPriority() { 78 return priority; 79 } 80 81 public void setPriority(String priority) { 82 try { 83 this.priority = Integer.parseInt(priority); 84 } 85 catch(Exception 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 className) { 99 publicClassList.add(className); 100 } 101 102 public String [] getPublicClasses() { 103 return publicClassList.toArray(new String [publicClassList.size()]); 104 } 105 106 public static void main(String [] args) { 107 108 } 109 } 110 111 | Popular Tags |