2 * Copyright 2008 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 java.util.ArrayList;
19 import java.util.List;
21 import org.wamblee.system.core.DefaultProvidedInterface;
22 import org.wamblee.system.core.ProvidedInterface;
23 import org.wamblee.system.core.RequiredInterface;
24 import org.wamblee.system.core.Scope;
27 * The class configuration encapsulates the knowledge of how to wrap a class as a component.
29 * @author Erik Brakkee
32 public class ClassConfiguration {
35 private ConstructorConfiguration _constructorConfig;
36 private ObjectConfiguration _objectConfig;
39 * Constructs the configuration. By default no constructor is selected and
40 * one of {@link #select(Class...)} or
41 * {@link #greedy()} must be called.
42 * @param aClass Class to construct.
44 public ClassConfiguration(Class aClass) {
46 _constructorConfig = new ConstructorConfiguration(aClass);
47 _objectConfig = new ObjectConfiguration(aClass);
50 public ConstructorConfiguration getConstructorConfig() {
51 return _constructorConfig;
54 public ObjectConfiguration getObjectConfig() {
59 * Creates the object in the given scope.
60 * @param aScope Scope containing required interfaces for this object.
63 public Object create(Scope aScope) {
64 return _constructorConfig.create(aScope);
68 * Injects required interfaces through the setters
69 * @param aObject Object to inject into.
70 * @param aScope Scope in which injection takes place.
72 public void inject(Scope aScope, Object aObject) {
73 _objectConfig.inject(aScope, aObject);
76 public List<ProvidedInterface> getProvidedInterfaces() {
77 List<ProvidedInterface> result = new ArrayList<ProvidedInterface>();
78 result.add(new DefaultProvidedInterface("provided", _class));
82 public List<RequiredInterface> getRequiredInterfaces() {
83 List<RequiredInterface> result = new ArrayList<RequiredInterface>();
84 result.addAll(_constructorConfig.getRequiredInterfaces());
85 result.addAll(_objectConfig.getRequiredInterfaces());