- Timestamp:
- 08/23/12 14:31:23 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/guimodel/GUIElementFactory.java
r603 r604 12 12 import java.io.IOException; 13 13 import java.io.InputStream; 14 import java.lang.reflect.Constructor; 14 15 import java.lang.reflect.InvocationTargetException; 15 16 import java.util.Properties; … … 100 101 } 101 102 102 Class<?>[] parameterTypes = new Class<?>[2]; 103 parameterTypes[0] = specification.getClass(); 104 parameterTypes[1] = parent.getClass(); 105 106 guiElement = (IGUIElement) clazz.getConstructor(parameterTypes).newInstance 107 (specification, parent); 103 Constructor<?> constructor = null; 104 Class<?> parentClass = (parent == null) ? null : parent.getClass(); 105 106 // search for a constructor, that perfectly matches the types 107 for (Constructor<?> candidate : clazz.getConstructors()) { 108 if ((parentClass != null) && 109 (candidate.getParameterTypes().length == 2) && 110 (candidate.getParameterTypes()[0].equals(specification.getClass())) && 111 (candidate.getParameterTypes()[1].equals(parentClass))) 112 { 113 constructor = candidate; 114 break; 115 } 116 else if (parentClass == null) { 117 if ((candidate.getParameterTypes().length >= 1) && 118 (candidate.getParameterTypes()[0].equals(specification.getClass()))) 119 { 120 constructor = candidate; 121 break; 122 } 123 } 124 } 125 126 if (constructor == null) { 127 // search for an assignable constructor 128 for (Constructor<?> candidate : clazz.getConstructors()) { 129 if ((candidate.getParameterTypes().length == 2) && 130 (candidate.getParameterTypes()[0].isInstance(specification)) && 131 (candidate.getParameterTypes()[1].isInstance(parent))) 132 { 133 constructor = candidate; 134 break; 135 } 136 } 137 138 } 139 140 if (constructor != null) { 141 guiElement = (IGUIElement) constructor.newInstance(specification, parent); 142 } 143 else { 144 throw new NoSuchMethodException 145 ("no constructor with two parameters and assignable parameter types for " + 146 specification.getClass() + " and " + 147 (parent != null ? parent.getClass() : "null") + " found in class " + 148 clazz); 149 } 108 150 109 151 return guiElement;
Note: See TracChangeset
for help on using the changeset viewer.