* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.system.adapters;
-import org.wamblee.collections.CollectionFilter;
-
-import org.wamblee.conditions.Condition;
-import org.wamblee.conditions.FixedCondition;
-
-import org.wamblee.general.Pair;
-
-import org.wamblee.reflection.ReflectionUtils;
-
-import org.wamblee.system.core.DefaultProvidedInterface;
-import org.wamblee.system.core.DefaultRequiredInterface;
-import org.wamblee.system.core.ProvidedInterface;
-import org.wamblee.system.core.RequiredInterface;
-import org.wamblee.system.core.Scope;
-import org.wamblee.system.core.SystemAssemblyException;
-
-import java.awt.CompositeContext;
-
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
+
+import org.wamblee.collections.CollectionFilter;
+import org.wamblee.conditions.Condition;
+import org.wamblee.reflection.ReflectionUtils;
+import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.core.Scope;
+import org.wamblee.system.core.SystemAssemblyException;
/**
* Represents the configuration for exposing the setters of a class as required
* @author Erik Brakkee
*/
public class SetterConfiguration {
- private Class _class;
+ private Class clazz;
private boolean publicOnly;
* Class which is being configured.
*/
public SetterConfiguration(Class aClass) {
- _class = aClass;
+ clazz = aClass;
publicOnly = true;
setters = new HashMap<Method, ParameterValues>();
}
public SetterConfiguration initAllSetters() {
setters.clear();
- for (Method method : getAllSetters(_class, publicOnly)) {
+ for (Method method : getAllSetters(clazz, publicOnly)) {
setters.put(method, createParameterValues(method));
}
*
*/
public SetterConfiguration remove(Method aMethod) {
- if (!aMethod.getDeclaringClass().isAssignableFrom(_class)) {
+ if (!aMethod.getDeclaringClass().isAssignableFrom(clazz)) {
throw new RuntimeException("Method " + aMethod +
- " not found in class " + _class + " or its superclasses");
+ " not found in class " + clazz + " or its superclasses");
}
for (Method method : setters.keySet()) {
*
*/
public SetterConfiguration add(final String aName) {
- int oldlen = setters.size();
List<Method> methods = new ArrayList<Method>();
- CollectionFilter.filter(getAllSetters(_class, publicOnly), methods,
+ CollectionFilter.filter(getAllSetters(clazz, publicOnly), methods,
new Condition<Method>() {
@Override
public boolean matches(Method aObject) {
if (methods.size() == 0) {
throw new IllegalArgumentException("Method '" + aName +
- "' not found in " + _class.getName());
+ "' not found in " + clazz.getName());
}
// TODO is it possible to get more than one setter here in case the
*/
public SetterConfiguration addSetter(final Class aType) {
List<Method> result = new ArrayList<Method>();
- CollectionFilter.filter(getAllSetters(_class, publicOnly), result,
+ CollectionFilter.filter(getAllSetters(clazz, publicOnly), result,
new Condition<Method>() {
@Override
public boolean matches(Method aObject) {
if (result.size() == 0) {
throw new IllegalArgumentException("No setter found in class '" +
- _class.getName() + "' that has a setter with argument type '" +
+ clazz.getName() + "' that has a setter with argument type '" +
aType.getName() + "'");
}
if (result.size() > 1) {
- String setters = "";
+ StringBuffer settersString = new StringBuffer();
for (Method method : result) {
- setters += (method.getName() + " ");
+ settersString.append((method.getName() + " "));
}
throw new IllegalArgumentException(
- "Multiple setters found in class '" + _class.getName() +
- " that accept type '" + aType.getName() + "': " + setters);
+ "Multiple setters found in class '" + clazz.getName() +
+ " that accept type '" + aType.getName() + "': " + settersString);
}
Method method = result.get(0);
*
*/
public void inject(Scope aScope, Object aObject) {
- if (!_class.isInstance(aObject)) {
+ if (!clazz.isInstance(aObject)) {
throw new IllegalArgumentException("Object '" + aObject +
- "' is not an instance of " + _class.getName());
+ "' is not an instance of " + clazz.getName());
}
for (Method method : setters.keySet()) {