source code formatting.
[utils] / system / general / src / main / java / org / wamblee / system / adapters / ObjectAdapter.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.AbstractComponent;
19 import org.wamblee.system.core.DefaultProvidedInterface;
20 import org.wamblee.system.core.ProvidedInterface;
21 import org.wamblee.system.core.RequiredInterface;
22 import org.wamblee.system.core.Scope;
23
24
25 /**
26  * An adapter class that adapts an existing object to a component.
27  *
28  * @author Erik Brakkee
29  */
30 public class ObjectAdapter extends AbstractComponent<Object> {
31     /**
32      * DOCUMENT ME!
33      */
34     private ObjectConfiguration objectConfig;
35
36     /**
37      * DOCUMENT ME!
38      */
39     private Object object;
40
41     /**
42      * Creates a new ObjectAdapter object.
43      *
44      * @param aName DOCUMENT ME!
45      * @param aObject DOCUMENT ME!
46      * @param aObjectConfig DOCUMENT ME!
47      */
48     public ObjectAdapter(String aName, Object aObject,
49         ObjectConfiguration aObjectConfig) {
50         super(aName,
51             new ProvidedInterface[] {
52                 new DefaultProvidedInterface(aName, aObject.getClass())
53             },
54             aObjectConfig.getRequiredInterfaces()
55             .toArray(new RequiredInterface[0]));
56         objectConfig     = aObjectConfig;
57         object           = aObject;
58     }
59
60     /**
61      * DOCUMENT ME!
62      *
63      * @param aScope DOCUMENT ME!
64      *
65      * @return DOCUMENT ME!
66      */
67     @Override
68     protected Object doStart(Scope aScope) {
69         objectConfig.inject(aScope, object);
70
71         for (ProvidedInterface provided : getProvidedInterfaces()) {
72             addInterface(provided, object, aScope);
73         }
74
75         return object;
76     }
77
78     /**
79      * DOCUMENT ME!
80      *
81      * @param aRuntime DOCUMENT ME!
82      */
83     @Override
84     protected void doStop(Object aRuntime) {
85         // Empty. 
86     }
87 }