X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fadapters%2FConstructorConfiguration.java;h=9050b9557fcb4a5428a836f98a227b6fb2e56e3c;hb=0d8d8f24656e585ee75558cfd6a4c661f8f14985;hp=7a5c259d621c13cf9f6932d1939ea9e443b5d668;hpb=da48a523c81e59fe0eac34e43d12937396161f25;p=utils diff --git a/system/general/src/main/java/org/wamblee/system/adapters/ConstructorConfiguration.java b/system/general/src/main/java/org/wamblee/system/adapters/ConstructorConfiguration.java index 7a5c259d..9050b955 100644 --- a/system/general/src/main/java/org/wamblee/system/adapters/ConstructorConfiguration.java +++ b/system/general/src/main/java/org/wamblee/system/adapters/ConstructorConfiguration.java @@ -44,10 +44,10 @@ import org.wamblee.system.core.SystemAssemblyException; * */ public class ConstructorConfiguration { - private Class _class; - private Constructor _constructor; - private ParameterValues _values; - private boolean _publicOnly; + private Class clazz; + private Constructor constructor; + private ParameterValues values; + private boolean publicOnly; /** * Constructs the configuration. By default the public constructor with the @@ -55,9 +55,9 @@ public class ConstructorConfiguration { * @param aClass Class to construct. */ public ConstructorConfiguration(Class aClass) { - _class = aClass; - _constructor = null; - _publicOnly = true; + clazz = aClass; + constructor = null; + publicOnly = true; } /** @@ -67,9 +67,9 @@ public class ConstructorConfiguration { * @return */ public ConstructorConfiguration setNonPublic(boolean aNonPublic) { - _publicOnly = !aNonPublic; - _constructor = null; - _values = null; + publicOnly = !aNonPublic; + constructor = null; + values = null; return this; } @@ -80,7 +80,7 @@ public class ConstructorConfiguration { */ public ConstructorConfiguration select(Class... aTypes) { try { - _constructor = _class.getDeclaredConstructor(aTypes); + constructor = clazz.getDeclaredConstructor(aTypes); } catch (Exception e) { throw new SystemAssemblyException(e.getMessage(), e); } @@ -95,9 +95,9 @@ public class ConstructorConfiguration { * identified. */ public ConstructorConfiguration greedy() { - Constructor[] declared = _class.getDeclaredConstructors(); + Constructor[] declared = clazz.getDeclaredConstructors(); if (declared.length == 0) { - throw new SystemAssemblyException("Class '" + _class + throw new SystemAssemblyException("Class '" + clazz + " is an interface, primitive type, or array"); } int max = -1; @@ -106,7 +106,7 @@ public class ConstructorConfiguration { new Condition>() { @Override public boolean matches(Constructor aObject) { - if ( !_publicOnly ) { + if ( !publicOnly ) { return true; } else { return Modifier.isPublic(aObject.getModifiers()); @@ -132,22 +132,22 @@ public class ConstructorConfiguration { throw new SystemAssemblyException( "Greediest constructor cannot be uniquely determined"); } - _constructor = longest.get(0); + constructor = longest.get(0); resetValues(); return this; } public ParameterValues getParameters() { getConstructor(); // initialize constructor if needed. - return _values; + return values; } /** * Resets the values. */ private void resetValues() { - _constructor.setAccessible(true); - _values = new ParameterValues(_constructor.getParameterTypes()); + constructor.setAccessible(true); + values = new ParameterValues(constructor.getParameterTypes()); } /** @@ -156,24 +156,24 @@ public class ConstructorConfiguration { * @return object. */ public Object create(Scope aScope) { - Object[] values = _values.values(aScope); + Object[] valueArray = values.values(aScope); try { - return getConstructor().newInstance(values); + return getConstructor().newInstance(valueArray); } catch (Exception e) { throw new SystemAssemblyException("Could not construct object " - + getConstructor() + " " + Arrays.asList(values), e); + + getConstructor() + " " + Arrays.asList(valueArray), e); } } public List getRequiredInterfaces() { getConstructor(); // initialize constructor if needed. - return _values.getRequiredInterfaces(); + return values.getRequiredInterfaces(); } private Constructor getConstructor() { - if (_constructor == null ) { + if (constructor == null ) { greedy(); } - return _constructor; + return constructor; } }