/* * Copyright 2008 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. * See the License for the specific language governing permissions and * limitations under the License. */ package org.wamblee.system.adapters; import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.wamblee.collections.CollectionFilter; import org.wamblee.conditions.Condition; 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; /** * The class configuration encapsulates the knowledge of how to wrap a class as a component. * In particular, it provides: * * * @author Erik Brakkee * */ public class ClassConfiguration { private Class _class; private ConstructorConfiguration _constructorConfig; /** * Constructs the configuration. By default no constructor is selected and * one of {@link #select(Class...)} or * {@link #greedy()} must be called. * @param aClass Class to construct. */ public ClassConfiguration(Class aClass) { _class = aClass; _constructorConfig = new ConstructorConfiguration(aClass); } public ConstructorConfiguration getConstructorConfig() { return _constructorConfig; } /** * Creates the object in the given scope. * @param aScope Scope containing required interfaces for this object. * @return object. */ public Object create(Scope aScope) { return _constructorConfig.create(aScope); } public ProvidedInterface[] getProvidedInterfaces() { return new ProvidedInterface[] { new DefaultProvidedInterface("provided", _class) }; } public RequiredInterface[] getRequiredInterface() { return _constructorConfig.getRequiredInterfaces().toArray(new RequiredInterface[0]); } }