001/* 
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.felix.ipojo.composite;
020
021import java.util.Dictionary;
022import java.util.List;
023
024import org.apache.felix.ipojo.ComponentInstance;
025import org.apache.felix.ipojo.ConfigurationException;
026import org.apache.felix.ipojo.Factory;
027import org.apache.felix.ipojo.FactoryStateListener;
028import org.apache.felix.ipojo.MissingHandlerException;
029import org.apache.felix.ipojo.ServiceContext;
030import org.apache.felix.ipojo.UnacceptableConfiguration;
031import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
032import org.apache.felix.ipojo.metadata.Element;
033import org.osgi.framework.BundleContext;
034
035/**
036 * Bridge representing a Factory inside a composition.
037 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
038 */
039public class FactoryProxy implements Factory {
040
041    /**
042     * Delegated factory.
043     */
044    private Factory m_delegate;
045
046    /**
047     * Destination context.
048     */
049    private ServiceContext m_context;
050
051    /**
052     * Constructor.
053     * @param fact : the targeted factory.
054     * @param svcContext : the service context to target.
055     */
056    public FactoryProxy(Factory fact, ServiceContext svcContext) {
057        m_delegate = fact;
058        m_context = svcContext;
059    }
060
061    /**
062     * Create an instance manager (i.e. component type instance).
063     * @param configuration : the configuration properties for this component.
064     * @return the created instance manager.
065     * @throws UnacceptableConfiguration : when a given configuration is not valid.
066     * @throws MissingHandlerException : occurs when the creation failed due to a missing handler (the factory should be invalid)
067     * @throws ConfigurationException : occurs when the creation failed due to a configuration issue
068     * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
069     */
070    public ComponentInstance createComponentInstance(Dictionary configuration) throws UnacceptableConfiguration, MissingHandlerException,
071            ConfigurationException {
072        return m_delegate.createComponentInstance(configuration, m_context);
073    }
074
075    /**
076     * Create an instance manager (i.e. component type instance). This has these service interaction in the scope given in argument.
077     * @param configuration : the configuration properties for this component.
078     * @param serviceContext : the service context of the component.
079     * @return the created instance manager.
080     * @throws UnacceptableConfiguration : when the given configuration is not valid.
081     * @throws MissingHandlerException : when at least one handler is missing.
082     * @throws ConfigurationException : when an issue occurs during the oconfiguration of the instance.
083     * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary, org.apache.felix.ipojo.ServiceContext)
084     */
085    public ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext) throws UnacceptableConfiguration,
086            MissingHandlerException, ConfigurationException {
087        return m_delegate.createComponentInstance(configuration, serviceContext);
088    }
089
090    /**
091     * Get the component type information containing provided service, configuration properties ...
092     * @return the component type information.
093     * @see org.apache.felix.ipojo.Factory#getDescription()
094     */
095    public Element getDescription() {
096        return m_delegate.getDescription();
097    }
098
099    /**
100     * Return the factory name.
101     * @return the name of the factory.
102     * @see org.apache.felix.ipojo.Factory#getName()
103     */
104    public String getName() {
105        return m_delegate.getName();
106    }
107
108    /**
109     * Check if the given configuration is acceptable as a configuration of a component instance.
110     * @param conf : the configuration to test
111     * @return true if the configuration is acceptable
112     * @see org.apache.felix.ipojo.Factory#isAcceptable(java.util.Dictionary)
113     */
114    public boolean isAcceptable(Dictionary conf) {
115        return m_delegate.isAcceptable(conf);
116    }
117
118    /**
119     * Reconfigure an instance already created. This configuration need to have the name property to identify the instance.
120     * @param conf : the configuration to reconfigure the instance.
121     * @throws UnacceptableConfiguration : if the given configuration is not consistent for the targeted instance.
122     * @throws MissingHandlerException : when at least one handler is missing
123     * @see org.apache.felix.ipojo.Factory#reconfigure(java.util.Dictionary)
124     */
125    public void reconfigure(Dictionary conf) throws UnacceptableConfiguration, MissingHandlerException {
126        m_delegate.reconfigure(conf);
127    }
128
129    /**
130     * Add a factory listener.
131     * @param listener : the listener to add.
132     * @see org.apache.felix.ipojo.Factory#addFactoryStateListener(org.apache.felix.ipojo.FactoryStateListener)
133     */
134    public void addFactoryStateListener(FactoryStateListener listener) {
135        m_delegate.addFactoryStateListener(listener);
136
137    }
138
139    public List getMissingHandlers() {
140        return m_delegate.getMissingHandlers();
141    }
142
143    public List getRequiredHandlers() {
144        return m_delegate.getRequiredHandlers();
145    }
146
147    /**
148     * Remove a service listener.
149     * @param listener : the listener to remove
150     * @see org.apache.felix.ipojo.Factory#removeFactoryStateListener(org.apache.felix.ipojo.FactoryStateListener)
151     */
152    public void removeFactoryStateListener(FactoryStateListener listener) {
153        m_delegate.removeFactoryStateListener(listener);
154
155    }
156
157    public ComponentTypeDescription getComponentDescription() {
158        return m_delegate.getComponentDescription();
159    }
160
161    public String getClassName() {
162        return m_delegate.getClassName();
163    }
164
165    public int getState() {
166        return m_delegate.getState();
167    }
168
169    public BundleContext getBundleContext() {
170        return m_delegate.getBundleContext();
171    }
172
173    public String getVersion() {
174        return m_delegate.getVersion();
175    }
176
177    public Element getComponentMetadata() {
178        return m_delegate.getComponentMetadata();
179    }
180
181    public List<ComponentInstance> getInstances() {
182        return m_delegate.getInstances();
183    }
184
185    public List<String> getInstancesNames() {
186        return m_delegate.getInstancesNames();
187    }
188
189}