Changeset 25
- Timestamp:
- 07/26/05 10:18:38 (3 years ago)
- Files:
-
- trunk/src/net/schst/XJConf/AttributeDefinition.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/CDataDefinition.java (modified) (2 diffs)
- trunk/src/net/schst/XJConf/ChildDefinition.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/ConstructorDefinition.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/Definition.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/Examples/TestConstructor.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/Tag.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/TagDefinition.java (modified) (6 diffs)
- trunk/xml/defines-constructor.xml (modified) (1 diff)
- trunk/xml/test-constructor.xml (modified) (1 diff)
- trunk/xml/test.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/net/schst/XJConf/AttributeDefinition.java
r23 r25 101 101 } 102 102 103 /** 104 * Get the type of the attribute 105 * 106 * @return Class object 107 */ 108 public Class getValueType(Tag tag) { 109 try { 110 return Class.forName(this.type); 111 } catch (ClassNotFoundException e) { 112 throw new RuntimeException("Could not return type."); 113 } 114 } 115 103 116 /** 104 117 * Get the type of the attribute trunk/src/net/schst/XJConf/CDataDefinition.java
r21 r25 67 67 String value = tag.getData(); 68 68 Object instance = null; 69 Constructor co = null; 69 70 try { 70 71 Class cl = Class.forName(this.type, true,loader); 71 Class paramTypes[] = { value.getClass()};72 Class paramTypes[] = {String.class}; 72 73 73 Constructorco = cl.getConstructor(paramTypes);74 co = cl.getConstructor(paramTypes); 74 75 String params[] = {value}; 75 76 instance = co.newInstance(params); … … 88 89 89 90 /** 91 * Get the type of the cdata 92 * 93 * @return Class object 94 */ 95 public Class getValueType(Tag tag) { 96 try { 97 return Class.forName(this.type); 98 } catch (ClassNotFoundException e) { 99 throw new RuntimeException("Could not return type."); 100 } 101 } 102 103 /** 90 104 * Get the setter method, which is setData() by default 91 105 */ trunk/src/net/schst/XJConf/ChildDefinition.java
r21 r25 38 38 Tag child = tag.getChild(this.getName()); 39 39 if (child == null) { 40 return null;40 throw new RuntimeException("Child element " + this.getName() + " does not exist"); 41 41 } 42 42 return child.getConvertedValue(loader); 43 43 } 44 44 45 /** 46 * Get the type of the attribute 47 * 48 * @return Class object 49 */ 50 public Class getValueType(Tag tag) { 51 Tag child = tag.getChild(this.getName()); 52 if (child == null) { 53 throw new RuntimeException("Child element " + this.getName() + " does not exist"); 54 } 55 return child.getValueType(tag); 56 } 57 45 58 /** 46 59 * This does not provide a setter method. trunk/src/net/schst/XJConf/ConstructorDefinition.java
r21 r25 48 48 49 49 /** 50 * Get the type of the constructor 51 * 52 * @return Always returns null 53 */ 54 public Class getValueType(Tag tag) { 55 return null; 56 } 57 58 59 /** 50 60 * Get the setter method 51 61 */ trunk/src/net/schst/XJConf/Definition.java
r21 r25 28 28 29 29 /** 30 * Get the type of the converted value 31 * @param tag TODO 32 * 33 * @return 34 */ 35 public Class getValueType(Tag tag); 36 37 /** 30 38 * Get the name of the setter method 31 39 * trunk/src/net/schst/XJConf/Examples/TestConstructor.java
r21 r25 26 26 ConstructorColor color = (ConstructorColor)conf.getConfigValue("color"); 27 27 System.out.println(color); 28 color = (ConstructorColor)conf.getConfigValue("color-no-atts"); 29 System.out.println(color); 28 30 color = (ConstructorColor)conf.getConfigValue("color2"); 29 31 System.out.println(color); trunk/src/net/schst/XJConf/Tag.java
r21 r25 163 163 } 164 164 165 /** 166 * Get the type of the attribute 167 * 168 * @return Class object 169 */ 170 public Class getValueType(Tag tag) { 171 return this.def.getValueType(tag); 172 } 173 165 174 /** 166 175 * Get the key, under which the tag will be stored in trunk/src/net/schst/XJConf/TagDefinition.java
r24 r25 135 135 return this.type; 136 136 } 137 137 138 /** 139 * Get the type of the tag 140 * 141 * @return Class object 142 */ 143 public Class getValueType(Tag tag) { 144 try { 145 return Class.forName(this.type); 146 } catch (ClassNotFoundException e) { 147 throw new RuntimeException("Could not return type."); 148 } 149 } 150 138 151 /** 139 152 * Set the setter method … … 209 222 paramDef = (Definition)conParams.get(i); 210 223 Object val = paramDef.convertValue(tag,loader); 211 if (val == null) { 212 //TODO schst Definition interface braucht noch type method 213 throw new RuntimeException("argument for constructor must be available!!"); 214 } 215 cParamTypes[i] = val.getClass(); 224 cParamTypes[i] = paramDef.getValueType(tag); 216 225 cParams[i] = val; 217 226 } … … 242 251 try { 243 252 methodName = att.getSetterMethod(); 244 Class meParamTypes[] = { val.getClass()};253 Class meParamTypes[] = {att.getValueType(tag)}; 245 254 246 255 Method me = cl.getMethod(methodName, meParamTypes); … … 277 286 if (instance instanceof java.util.Properties) { 278 287 String key = (String)child.getKey(); 279 Class childParamTypes[] = { Class.forName("java.lang.String"), Class.forName("java.lang.String")};288 Class childParamTypes[] = {String.class, String.class}; 280 289 Method childMethod = cl.getMethod("setProperty", childParamTypes); 281 290 String params[] = {key, (String)childValue}; … … 285 294 } else if (instance instanceof java.util.AbstractMap) { 286 295 Object name = (Object)child.getKey(); 287 Class childParamTypes[] = { Class.forName("java.lang.Object"), Class.forName("java.lang.Object")};296 Class childParamTypes[] = {Object.class, Object.class}; 288 297 Method childMethod = cl.getMethod("put", childParamTypes); 289 298 290 299 Object params[] = {name, childValue}; 291 300 childMethod.invoke(instance, params); 301 292 302 // Check, whether the current instance is a collection 293 303 } else if (methodName == null && instance instanceof java.util.AbstractCollection) { 294 Class childParamTypes[] = { Class.forName("java.lang.Object")};304 Class childParamTypes[] = {Object.class}; 295 305 Method childMethod = cl.getMethod("add", childParamTypes); 296 306 childMethod.invoke(instance, childParams); 307 297 308 // instance is any generic object 298 309 } else { 299 Class childParamTypes[] = {child Value.getClass()};310 Class childParamTypes[] = {child.getValueType(child)}; 300 311 Method childMethod = null; 301 312 … … 303 314 childMethod = cl.getMethod(methodName, childParamTypes); 304 315 } catch (NoSuchMethodException e) { 305 Class interfaces[] = (Class[]) this.determineAllInterfaces(new ArrayList(), child Value.getClass()).toArray(new Class[0]);316 Class interfaces[] = (Class[]) this.determineAllInterfaces(new ArrayList(), child.getValueType(child)).toArray(new Class[0]); 306 317 for (int j = 0; j < interfaces.length; j++) { 307 318 try { trunk/xml/defines-constructor.xml
r21 r25 1 1 <defines> 2 <tag name="color" type="net.schst.XJConf.Examples.ConstructorColor" >2 <tag name="color" type="net.schst.XJConf.Examples.ConstructorColor" keyAttribute="id"> 3 3 <constructor> 4 4 <attribute name="red" type="java.lang.Integer"/> trunk/xml/test-constructor.xml
r21 r25 1 1 <configuration> 2 <color red="100" green="25" blue="10"/> 2 <color id="color" red="100" green="25" blue="10"/> 3 <color id="color-no-atts"/> 3 4 4 5 <!-- The cdata is the third parameter in the constructor --> trunk/xml/test.xml
r21 r25 5 5 <item>bar</item> 6 6 </array> 7 8 7 <foo>tomato</foo> 9 8 <zahl>124</zahl>
