(no commit message)
[utils] / system / general / src / main / java / org / wamblee / system / adapters / SetterConfiguration.java
index af9da338a5c9526b8375a5ec4b0187d011c752e7..18fde542b0050ede0ea92acbdde55093ccfc8cda 100644 (file)
@@ -1,12 +1,12 @@
 /*
- * Copyright 2008 the original author or authors.
- *
+ * Copyright 2005-2010 the original author or authors.
+ * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- *
+ * 
  *      http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  */
 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
@@ -51,7 +37,7 @@ import java.util.Set;
  * @author Erik Brakkee
  */
 public class SetterConfiguration {
-    private Class _class;
+    private Class clazz;
 
     private boolean publicOnly;
 
@@ -64,7 +50,7 @@ public class SetterConfiguration {
      *            Class which is being configured.
      */
     public SetterConfiguration(Class aClass) {
-        _class = aClass;
+        clazz = aClass;
         publicOnly = true;
         setters = new HashMap<Method, ParameterValues>();
     }
@@ -76,7 +62,7 @@ public class SetterConfiguration {
     public SetterConfiguration initAllSetters() {
         setters.clear();
 
-        for (Method method : getAllSetters(_class, publicOnly)) {
+        for (Method method : getAllSetters(clazz, publicOnly)) {
             setters.put(method, createParameterValues(method));
         }
 
@@ -140,9 +126,9 @@ public class SetterConfiguration {
      * 
      */
     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()) {
@@ -167,9 +153,8 @@ public class SetterConfiguration {
      * 
      */
     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) {
@@ -179,7 +164,7 @@ public class SetterConfiguration {
 
         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
@@ -205,7 +190,7 @@ public class SetterConfiguration {
      */
     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) {
@@ -217,20 +202,21 @@ public class SetterConfiguration {
 
         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);
@@ -301,9 +287,9 @@ public class SetterConfiguration {
      * 
      */
     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()) {