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 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;
26 * An adapter class that adapts an existing object to a component.
28 * @author Erik Brakkee
30 public class ObjectAdapter extends AbstractComponent<Object> {
34 private ObjectConfiguration objectConfig;
39 private Object object;
42 * Creates a new ObjectAdapter object.
44 * @param aName DOCUMENT ME!
45 * @param aObject DOCUMENT ME!
46 * @param aObjectConfig DOCUMENT ME!
48 public ObjectAdapter(String aName, Object aObject,
49 ObjectConfiguration aObjectConfig) {
51 new ProvidedInterface[] {
52 new DefaultProvidedInterface(aName, aObject.getClass())
54 aObjectConfig.getRequiredInterfaces()
55 .toArray(new RequiredInterface[0]));
56 objectConfig = aObjectConfig;
63 * @param aScope DOCUMENT ME!
65 * @return DOCUMENT ME!
68 protected Object doStart(Scope aScope) {
69 objectConfig.inject(aScope, object);
71 for (ProvidedInterface provided : getProvidedInterfaces()) {
72 addInterface(provided, object, aScope);
81 * @param aRuntime DOCUMENT ME!
84 protected void doStop(Object aRuntime) {