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.Element ; 17 import org.w3c.dom.Node ; 18 19 22 23 public class ComponentDescriptor implements Descriptor { 24 private String desc; 25 private String implementation; 26 private String name = ""; 27 private boolean singleton = ComponentMeta.DEFAULT_SINGLETON; 28 private boolean typeSingleton = ComponentMeta.DEFAULT_TYPE_SINGLETON; 29 private ConstructorDescriptor constructor; 30 private List properties = new ArrayList (); 31 32 private ComponentModuleDescriptor componentModuleDescriptor; 33 34 public ComponentDescriptor(ComponentModuleDescriptor componentModuleDescriptor) { 35 this.componentModuleDescriptor = componentModuleDescriptor; 36 } 37 38 public void processXML(Node node) throws ComponentDescriptionException { 39 setDescription(XMLUtils.getChildNodeValueOf(node, "description")); 40 setName(XMLUtils.getChildNodeValueOf(node, "name")); 41 setImplementation(XMLUtils.getChildNodeValueOf(node, "implementation")); 42 setSingleton(XMLUtils.getChildNodeValueOf(node, "singleton")); 43 setTypeSingleton(XMLUtils.getChildNodeValueOf(node, "type-singleton")); 44 Node constructorNode = XMLUtils.getChildNodeOf(node, "constructor"); 45 if(constructorNode != null) { 46 ConstructorDescriptor cd = new ConstructorDescriptor(); 47 cd.processXML(constructorNode); 48 setConstructorDescriptor(cd); 49 } 50 51 Iterator it = XMLUtils.getElementsByTagName((Element ) node, "property"); 52 while(it.hasNext()) { 53 Node propertyNode = (Node ) it.next(); 54 PropertyDescriptor pd = new PropertyDescriptor(); 55 pd.processXML(propertyNode); 56 addPropertyDescriptor(pd); 57 } 58 } 59 60 public String getDescription() { 61 return desc; 62 } 63 64 public void setDescription(String desc) { 65 this.desc = desc; 66 } 67 68 public String getImplementation() { 69 return implementation; 70 } 71 72 public void setImplementation(String componentImplementation) { 73 this.implementation = componentImplementation; 74 } 75 76 public String getName() { 77 return name; 78 } 79 80 public void setName(String name) { 81 if(name != null) this.name = name; 82 } 83 84 public boolean isSingleton() { 85 return singleton; 86 } 87 88 public void setSingleton(String singleton) { 89 if(singleton != null && !singleton.equals("")) { 90 if(singleton.equals("true") || singleton.equals("false")) { 91 this.singleton = Boolean.valueOf(singleton).booleanValue(); 92 } 93 } 94 } 95 96 public boolean isTypeSingleton() { 97 return typeSingleton; 98 } 99 100 public void setTypeSingleton(String typeSingleton) { 101 if(typeSingleton != null && !typeSingleton.equals("")) { 102 if(typeSingleton.equals("true") || typeSingleton.equals("false")) { 103 this.typeSingleton = Boolean.valueOf(typeSingleton).booleanValue(); 104 } 105 } 106 } 107 108 public int getPriority() { 109 return componentModuleDescriptor.getPriority(); 110 } 111 112 public ConstructorDescriptor getConstructorDescriptor() { 113 return constructor; 114 } 115 116 public void setConstructorDescriptor(ConstructorDescriptor constructor) { 117 this.constructor = constructor; 118 } 119 120 public void addPropertyDescriptor(PropertyDescriptor pd) { 121 properties.add(pd); 122 } 123 124 public PropertyDescriptor[] getPropertyDescriptors() { 125 return (PropertyDescriptor[]) properties.toArray(new PropertyDescriptor[properties.size()]); 126 } 127 128 public String getModuleDescription() { 129 return componentModuleDescriptor.getDescription(); 130 } 131 132 public static void main(String [] args) { 133 134 } 135 136 } 137 138 | Popular Tags |