(no commit message)
[utils] / system / general / src / main / java / org / wamblee / system / adapters / ClassConfiguration.java
1 /*
2  * Copyright 2008 the original author or authors.
3  * 
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
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
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.
15  */
16 package org.wamblee.system.adapters;
17
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;
22
23 /**
24  * The class configuration encapsulates the knowledge of how to wrap a class as a component.
25  * 
26  * @author Erik Brakkee
27  *
28  */
29 public class ClassConfiguration {
30
31         private Class _class; 
32         private ConstructorConfiguration _constructorConfig; 
33         
34         /**
35          * Constructs the configuration. By default no constructor is selected and 
36          * one of {@link #select(Class...)} or 
37          * {@link #greedy()} must be called.  
38          * @param aClass Class to construct. 
39          */
40         public ClassConfiguration(Class aClass) {
41                 _class = aClass; 
42                 _constructorConfig = new ConstructorConfiguration(aClass);  
43         }
44         
45         public ConstructorConfiguration getConstructorConfig() {
46                 return _constructorConfig;
47         }
48
49         /**
50          * Creates the object in the given scope. 
51          * @param aScope Scope containing required interfaces for this object. 
52          * @return object. 
53          */
54         public Object create(Scope aScope) {
55                 return _constructorConfig.create(aScope);
56         }
57         
58         public ProvidedInterface[] getProvidedInterfaces() { 
59                 return new ProvidedInterface[] { 
60                         new DefaultProvidedInterface("provided", _class)        
61                 };
62         }
63         
64         public RequiredInterface[] getRequiredInterface() { 
65                 return _constructorConfig.getRequiredInterfaces().toArray(new RequiredInterface[0]);
66         }
67 }