2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.system.adapters;
18 import org.wamblee.system.core.DefaultProvidedInterface;
19 import org.wamblee.system.core.ProvidedInterface;
20 import org.wamblee.system.core.RequiredInterface;
21 import org.wamblee.system.core.Scope;
23 import java.util.ArrayList;
24 import java.util.List;
27 * The class configuration encapsulates the knowledge of how to wrap a class as
30 * @author Erik Brakkee
32 public class ClassConfiguration {
35 private ConstructorConfiguration constructorConfig;
37 private ObjectConfiguration objectConfig;
40 * Constructs the configuration. By default no constructor is selected and
41 * one of {@link #select(Class...)} or {@link #greedy()} must be called.
46 public ClassConfiguration(Class aClass) {
48 constructorConfig = new ConstructorConfiguration(aClass);
49 objectConfig = new ObjectConfiguration(aClass);
52 public ConstructorConfiguration getConstructorConfig() {
53 return constructorConfig;
56 public ObjectConfiguration getObjectConfig() {
61 * Creates the object in the given scope.
64 * Scope containing required interfaces for this object.
68 public Object create(Scope aScope) {
69 return constructorConfig.create(aScope);
73 * Injects required interfaces through the setters
76 * Scope in which injection takes place.
78 * Object to inject into.
80 public void inject(Scope aScope, Object aObject) {
81 objectConfig.inject(aScope, aObject);
84 public List<ProvidedInterface> getProvidedInterfaces() {
85 List<ProvidedInterface> result = new ArrayList<ProvidedInterface>();
86 result.add(new DefaultProvidedInterface("provided", clazz));
91 public List<RequiredInterface> getRequiredInterfaces() {
92 List<RequiredInterface> result = new ArrayList<RequiredInterface>();
93 result.addAll(constructorConfig.getRequiredInterfaces());
94 result.addAll(objectConfig.getRequiredInterfaces());