- /**
- * Gets all setters for the current class.
- * @return List of all setters.
- */
- private List<Pair<Method, ParameterValues>> getAllSetters() {
- List<Pair<Method,ParameterValues>> result =
- new ArrayList<Pair<Method, ParameterValues>>();
- for (Method method : _class.getMethods()) {
- if (method.getName().startsWith("set")
- && method.getParameterTypes().length == 1) {
- String name = getSetterName(method);
- result.add(new Pair<Method,ParameterValues>(method,
- new ParameterValues(
- new String[] { name }, new Class[] { method.getParameterTypes()[0] })));
- }
- }
- return result;
- }
-
- /**
- * Gets the required interfaces based on the configured setteres.
- * @return List of required interfaces.
- */
- public List<RequiredInterface> getRequiredInterfaces() {
- List<RequiredInterface> result = new ArrayList<RequiredInterface>();
- for (Pair<Method,ParameterValues> method: _setters) {
- result.addAll(method.getSecond().getRequiredInterfaces());
- }
- return result;
- }
-
-
- /**
- * Invokes all configured setters with the appropriate values.
- * @param aScope Scope within which invocation takes place.
- * @param aObject Object on which the invocation takes place.
- */
- public void inject(Scope aScope, Object aObject) {
- if ( !_class.isInstance(aObject)) {
- throw new IllegalArgumentException("Object '" + aObject + "' is not an instance of "
- + _class.getName());
- }
- for (Pair<Method,ParameterValues> setter: _setters) {
- Method method = setter.getFirst();
- ParameterValues values = setter.getSecond();
-
- try {
- method.invoke(aObject, values.values(aScope));
- } catch (IllegalAccessException e) {
- throw new SystemAssemblyException("Problem invoking " + method + " with " + values, e);
- } catch (InvocationTargetException e) {
- throw new SystemAssemblyException("Problem invoking " + method + " with " + values, e);
- }
- }
- }
-
- /**
- * Returns the parameter values for allowing detailed configuration of how
- * parameter values are set.
- * @param aSetter Setter name without the "set" prefix with the first
- * character converted to lower case.
- * @return Parameter values.
- */
- public ParameterValues values(String aMethod) {
- String name = createSetterName(aMethod);
- for (Pair<Method,ParameterValues> method: _setters) {
- if ( method.getFirst().getName().equals(name) ) {
- return method.getSecond();
- }
- }
- throw new IllegalArgumentException("No setter method '" + name + "' found");
- }