felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r527156 [1/2] - in /incubator/felix/trunk: ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/ ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ ipojo.plugin/...
Date Tue, 10 Apr 2007 15:16:58 GMT
Author: rickhall
Date: Tue Apr 10 08:16:56 2007
New Revision: 527156

URL: http://svn.apache.org/viewvc?view=rev&rev=527156
Log:
Applied patch (FELIX-266) to add support to iPOJO for composite 
services.

Added:
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/StringMap.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/architecture/
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportDescription.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportHandler.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ServiceExporter.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ServiceImporter.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorDescription.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorHandler.java   (with props)
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java   (with props)
Modified:
    incubator/felix/trunk/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
    incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
    incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java
    incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java
    incubator/felix/trunk/ipojo/pom.xml
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/IPojoContext.java
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContext.java
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java

Modified: incubator/felix/trunk/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java (original)
+++ incubator/felix/trunk/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java Tue Apr 10 08:16:56 2007
@@ -207,7 +207,7 @@
 		name = name.toLowerCase();
 		Element[] list = new Element[0];
 		for (int i = 0; i < m_elements.length; i++) {
-			if (m_elements[i].getName().equals(name) && m_elements[i].getNameSpace().equals("")) {
+			if (m_elements[i].getName().equalsIgnoreCase(name) && m_elements[i].getNameSpace().equals("")) {
 				list = Element.addElement(list, m_elements[i]);
 			}
 		}

Modified: incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java (original)
+++ incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java Tue Apr 10 08:16:56 2007
@@ -72,8 +72,9 @@
 	
 	/**
 	 * @return the method list.
+	 * Modified for performance issue.
 	 */
-	public List getMethods() { return m_methods; }
+	public List getMethods() { /*return m_methods;*/ return new ArrayList(); }
 
 	/**
      * Manipulate the class.

Modified: incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java (original)
+++ incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java Tue Apr 10 08:16:56 2007
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.ipojo.parser;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.logging.Level;
 
 import org.apache.felix.ipojo.metadata.Attribute;
@@ -41,15 +43,38 @@
      * @throws ParseException when an error occurs in the xml parsing
      */
     public Element[] getComponentsMetadata() throws ParseException {
-    	return m_elements[0].getElements("Component");
+    	Element[] comp = m_elements[0].getElements("Component");
+    	Element[] compo = m_elements[0].getElements("Composite");
+    	Element[] metadata = new Element[comp.length + compo.length];
+    	int l = 0;
+    	for(int i = 0; i < comp.length; i++) { metadata[l] = comp[i]; l++;}
+    	for(int i = 0; i < compo.length; i++) { metadata[l] = compo[i]; l++;}
+    	return metadata;
+    }
+    
+    public List getReferredPackages() {
+    	List referred = new ArrayList();
+    	Element[] compo = m_elements[0].getElements("Composite");
+    	for(int i= 0; i < compo.length; i++) {
+    		for(int j = 0; j < compo[i].getElements().length; j++) {
+    			if(compo[i].getElements()[j].containsAttribute("specification")) {
+    				String p = compo[i].getElements()[j].getAttribute("specification");
+    				int last = p.lastIndexOf('.');
+    				if(last != -1) { referred.add(p.substring(0, last)); }
+    			}
+    		}
+    	}
+    	return referred;
     }
     
     public Element[] getMetadata() throws ParseException {
     	Element[] comp = m_elements[0].getElements("Component");
+    	Element[] compo = m_elements[0].getElements("Composite");
     	Element[] conf = m_elements[0].getElements("Instance");
-    	Element[] metadata = new Element[comp.length + conf.length];
+    	Element[] metadata = new Element[comp.length + conf.length + compo.length];
     	int l = 0;
     	for(int i = 0; i < comp.length; i++) { metadata[l] = comp[i]; l++;}
+    	for(int i = 0; i < compo.length; i++) { metadata[l] = compo[i]; l++;}
     	for(int i = 0; i < conf.length; i++) { metadata[l] = conf[i]; l++;}
     	return metadata;
     }

Modified: incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java (original)
+++ incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java Tue Apr 10 08:16:56 2007
@@ -151,7 +151,8 @@
 	 */
 	private OsgiManifest				osgiManifest;
 	
-	private String[][] namespaces; 
+	private String[][] namespaces;
+	private List referedPackages; 
 
 	/**
 	 * Execute this Mojo
@@ -482,6 +483,12 @@
 			}
 		}
 		
+		// Add refered imports form the metadata
+		for(int i = 0; i < referedPackages.size(); i++) {
+			String pack = (String) referedPackages.get(i);
+			referred.add(pack);
+		}
+		
 		// Add org.apache.felix.ipojo, org.apache.felix.ipojo.architecture is not already in the set
 		referred.add(IPojoPluginConfiguration.ipojo_package);
 		referred.add(IPojoPluginConfiguration.ipojo_arch_package);
@@ -872,6 +879,7 @@
 			parser.parse(is);
 		    
 		    meta = handler.getMetadata();
+		    referedPackages = handler.getReferredPackages();
 		    
 		} catch (MalformedURLException e) {
 			getLog().error("Malformed URL for " + outputDirectory+path+ "("+e.getMessage()+")");

Modified: incubator/felix/trunk/ipojo/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/pom.xml?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo/pom.xml (original)
+++ incubator/felix/trunk/ipojo/pom.xml Tue Apr 10 08:16:56 2007
@@ -52,6 +52,7 @@
               org.apache.felix.ipojo.util,
               org.apache.felix.ipojo.handlers.dependency,
               org.apache.felix.ipojo.handlers.providedservice, 
+              org.apache.felix.ipojo.composite,
               org.osgi.service.cm; specification-version="1.2",
               org.osgi.service.log; specification-version="1.3"
             </exportPackage>

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java Tue Apr 10 08:16:56 2007
@@ -51,6 +51,11 @@
      * The key of this hashmap is the name (i.e. pid) of the created instance
      */
     private HashMap m_componentInstances = new HashMap();
+    
+    /**
+     * Ture if the component is a composition. 
+     */
+    private boolean m_isComposite = false;
 
     /**
      * The bundle context reference.
@@ -66,6 +71,11 @@
      * Component Implementation Class Name.
      */
     private String m_componentClassName = null;
+    
+    /**
+     * Composition Name. 
+     */
+    private String m_compositeName = null;
 
     /**
      * Classloader to delegate loading.
@@ -97,6 +107,11 @@
      * Logger for the factory (and all component instance).
      */
     private Logger m_logger;
+    
+    /**
+     * True when the factory is active (non stopping and non starting).
+     */
+    private boolean m_active = false;
 
     /**
      * FactoryClassloader.
@@ -183,19 +198,44 @@
      */
     public ComponentFactory(BundleContext bc, Element cm) {
         m_context = bc;
-        m_componentClassName = cm.getAttribute("className");
         m_componentMetadata = cm;
-        
-        // Get factory PID :
-        if (m_componentMetadata.containsAttribute("factory") && !m_componentMetadata.getAttribute("factory").equalsIgnoreCase("no")) { 
-        	m_factoryName = m_componentMetadata.getAttribute("factory");
-        } else { m_factoryName = m_componentMetadata.getAttribute("className"); }
-        
-        m_logger = new Logger(m_context, m_factoryName, Logger.WARNING);
+        if (cm.getName().equalsIgnoreCase("composite")) {
+        	m_componentClassName = null;
+        	m_isComposite = true;
+        	// Get the name
+        	if (cm.containsAttribute("name")) { 
+        		m_compositeName = cm.getAttribute("name");
+        	} else { 
+        		System.err.println("A composite needs a name"); return;
+        	}
+        	// Compute factory name
+        	if (m_componentMetadata.containsAttribute("factory") && !m_componentMetadata.getAttribute("factory").equalsIgnoreCase("no")) { 
+            	m_factoryName = m_componentMetadata.getAttribute("factory");
+            } else { m_factoryName = m_compositeName; }
+        } else  {
+        	if (cm.containsAttribute("className")) { 
+        		m_componentClassName = cm.getAttribute("className");
+        	} else { 
+        		System.err.println("A component needs a class name"); return;
+        	}
+        	if (m_componentMetadata.containsAttribute("factory") && !m_componentMetadata.getAttribute("factory").equalsIgnoreCase("no")) { 
+            	m_factoryName = m_componentMetadata.getAttribute("factory");
+            } else { m_factoryName = m_componentMetadata.getAttribute("className"); }
+        }
+        if (m_factoryName != null) {
+        	m_logger = new Logger(m_context, m_factoryName, Logger.WARNING);
+        } else {
+        	if (m_isComposite) {
+        		m_logger = new Logger(m_context, m_compositeName, Logger.WARNING);
+        	} else {
+        		m_logger = new Logger(m_context, m_componentClassName, Logger.WARNING);
+        	}
+        }
     }
 
     /**
      * Create a instance manager factory. The class is given in parameter.
+     * The component type is not a composite.
      * @param bc : bundle context
      * @param clazz : the component class
      * @param cm : metadata of the component
@@ -217,12 +257,15 @@
     /**
      * Stop all the instance managers.
      */
-    public void stop() {
+    public synchronized void stop() {
+    	m_active = false;
         Collection col = m_componentInstances.values();
         Iterator it = col.iterator();
         while (it.hasNext()) {
             ComponentInstance ci = (ComponentInstance) it.next();
-            if (ci.isStarted()) { ci.stop(); }
+            if (ci.isStarted()) {
+            	ci.stop();
+            }
         }
         m_componentInstances.clear();
         if (m_sr != null) { m_sr.unregister(); }
@@ -232,20 +275,33 @@
     /**
      * Start all the instance managers.
      */
-    public void start() {        
+    public synchronized void start() {        
         Properties props = new Properties();
 
         // create a ghost component
-        InstanceManager ghost = new InstanceManager(this, m_context);
-        Properties p = new Properties();
-        p.put("name", "ghost");
-        ghost.configure(m_componentMetadata, p);
-        m_componentDesc = ghost.getComponentDescription();
+        if (!m_isComposite) {
+        	InstanceManager ghost = new InstanceManager(this, m_context);
+        	Properties p = new Properties();
+        	p.put("name", "ghost");
+        	ghost.configure(m_componentMetadata, p);
+        	m_componentDesc = ghost.getComponentDescription();
+        } else {
+        	CompositeManager ghost = new CompositeManager(this, m_context);
+        	Properties p = new Properties();
+        	p.put("name", "ghost");
+        	ghost.configure(m_componentMetadata, p);
+        	m_componentDesc = ghost.getComponentDescription();
+        }
         
         // Check if the factory should be exposed
         if (m_componentMetadata.containsAttribute("factory") && m_componentMetadata.getAttribute("factory").equalsIgnoreCase("no")) { return; }
         
-        props.put("component.class", m_componentClassName);
+        if (!m_isComposite) { 
+        	props.put("component.class", m_componentClassName);
+        } else { 
+        	props.put("component.class", "no implementation class"); 
+        }
+        props.put("factory.name", m_factoryName);
         props.put("component.providedServiceSpecifications", m_componentDesc.getprovidedServiceSpecification());
         props.put("component.properties", m_componentDesc.getProperties());
         props.put("component.description", m_componentDesc);
@@ -255,8 +311,19 @@
         props.put(Constants.SERVICE_PID, m_factoryName);
 
         // Exposition of the factory service
+        m_active = true;
         m_sr = m_context.registerService(new String[] {Factory.class.getName(), ManagedServiceFactory.class.getName()}, this, props);
     }
+    
+    /**
+     * Callback called by instance when stopped.
+     * @param ci : the instance stopping
+     */
+    protected synchronized void stopped(ComponentInstance ci) {
+    	if (m_active) {
+    		m_componentInstances.remove(ci.getInstanceName());
+    	}
+    }
 
     /**
      * @see org.apache.felix.ipojo.Factory#getComponentInfo()
@@ -318,15 +385,30 @@
     	}
     	
         IPojoContext context = new IPojoContext(m_context);
-        InstanceManager instance = new InstanceManager(this, context);
-        context.setComponentInstance(instance);
-        instance.configure(m_componentMetadata, configuration);
+        ComponentInstance instance = null;
+        if (!m_isComposite) {
+        	InstanceManager inst = new InstanceManager(this, context);
+        	//context.setComponentInstance(inst);
+        	inst.configure(m_componentMetadata, configuration);
+        	instance = inst;
+        } else {
+        	CompositeManager inst = new CompositeManager(this, context);
+        	//context.setComponentInstance(inst);
+        	inst.configure(m_componentMetadata, configuration);
+        	instance = inst;
+        }
 
         String pid = null;
         if (configuration.get("name") != null) { 
         	pid = (String) configuration.get("name"); 
-        } else { pid = m_componentMetadata.getAttribute("className"); }
-
+        } else {
+        	throw new UnacceptableConfiguration("The name attribute is missing");
+        }
+        
+        if (m_componentInstances.containsKey(pid)) {
+        	throw new UnacceptableConfiguration("Name already used : " + pid);
+        }
+        
         m_componentInstances.put(pid, instance);
         instance.start();
         return instance;
@@ -342,17 +424,30 @@
     		m_logger.log(Logger.ERROR, "The configuration is not acceptable : " + e.getMessage());
     		throw new UnacceptableConfiguration("The configuration " + configuration + " is not acceptable for " + m_factoryName + ": " + e.getMessage());
     	}
-    	
+
     	IPojoContext context = new IPojoContext(m_context, serviceContext);
-        InstanceManager instance = new InstanceManager(this, context);
-        context.setComponentInstance(instance);
-        instance.configure(m_componentMetadata, configuration);
+    	ComponentInstance instance = null;
+    	if (!m_isComposite) {
+        	InstanceManager inst = new InstanceManager(this, context);
+        	//context.setComponentInstance(inst);
+        	inst.configure(m_componentMetadata, configuration);
+        	instance = inst;
+        } else {
+        	CompositeManager inst = new CompositeManager(this, context);
+        	//context.setComponentInstance(inst);
+        	inst.configure(m_componentMetadata, configuration);
+        	instance = inst;
+        }
 
-        String pid = null;
+    	String pid = null;
         if (configuration.get("name") != null) { 
         	pid = (String) configuration.get("name"); 
-        } else { 
-        	pid = m_componentMetadata.getAttribute("className");
+        } else {
+        	throw new UnacceptableConfiguration("The name attribute is missing");
+        }
+        
+        if (m_componentInstances.containsKey(pid)) {
+        	throw new UnacceptableConfiguration("Name already used : " + pid);
         }
 
         m_componentInstances.put(pid, instance);
@@ -450,7 +545,12 @@
 	public void reconfigure(Dictionary properties) throws UnacceptableConfiguration {
 		if (properties == null || properties.get("name") == null) { throw new UnacceptableConfiguration("The configuration does not contains the \"name\" property"); }
 		String name = (String) properties.get("name");
-		InstanceManager cm = (InstanceManager) m_componentInstances.get(name);
+		ComponentInstance cm = null;
+		if (m_isComposite) {
+			cm = (CompositeManager) m_componentInstances.get(name);
+		} else  {
+			cm = (InstanceManager) m_componentInstances.get(name);
+		}
         if (cm == null) { 
         	return;  // The instance does not exist.
         } else {

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java Tue Apr 10 08:16:56 2007
@@ -80,7 +80,7 @@
     ComponentFactory getFactory();
     
     /**
-     * @return the context of the instance manager
+     * @return the context of the component instance
      */
     BundleContext getContext();
     

Added: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java?view=auto&rev=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java (added)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java Tue Apr 10 08:16:56 2007
@@ -0,0 +1,74 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.felix.ipojo;
+
+import java.util.Dictionary;
+
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Element;
+
+/**
+ * Composite Handler Abstract Class.
+ * An composite handler need implements these method to be notifed of lifecycle change...
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public abstract class CompositeHandler {
+	
+	/**
+     * Configure the handler.
+     * @param im : the instance manager
+     * @param metadata : the metadata of the component
+     * @param configuration : the instance configuration
+     */
+    public abstract void configure(CompositeManager im, Element metadata, Dictionary configuration);
+
+    /**
+     * Stop the handler : stop the management.
+     */
+    public abstract void stop();
+
+    /**
+     * Start the handler : start the management.
+     */
+    public abstract void start();
+
+    /**
+     * Is the actual state valid for this handler ?
+     * @return true is the state seems valid for the handler
+     */
+    public boolean isValid() { return true; }
+
+    /**
+     * This method is called when the component state changed.
+     * @param state : the new state
+     */
+    public void stateChanged(int state) { }
+
+    /**
+     * @return the description of the handler..
+     */
+    public HandlerDescription getDescription() { return new HandlerDescription(this.getClass().getName(), isValid()); }
+
+	/**
+	 * The instance is reconfiguring.
+	 * @param configuration : New instance configuration.
+	 */
+	public void reconfigure(Dictionary configuration) { }
+
+}

Propchange: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java?view=auto&rev=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java (added)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java Tue Apr 10 08:16:56 2007
@@ -0,0 +1,364 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.felix.ipojo;
+
+import java.util.Dictionary;
+
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.composite.CompositeServiceContext;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.util.Logger;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * iPOJO Composite manager.
+ * The composite manager class manages one instance of a component type which is a composition.
+ * It manages component lifecycle, and handlers...
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class CompositeManager implements ComponentInstance {
+	
+	/**
+     * Parent factory (ComponentFactory).
+     */
+    private ComponentFactory m_factory;
+    
+    /**
+     * Name of the component instance.
+     */
+    private String m_name;
+
+    /**
+     * The context of the component.
+     */
+    private BundleContext m_context;
+
+    /**
+     * Composite Handler list.
+     */
+    private CompositeHandler[] m_handlers = new CompositeHandler[0];
+
+    /**
+     * Component state (STOPPED at the beginning).
+     */
+    private int m_state = STOPPED;
+
+    /**
+     * Component type information.
+     */
+    private ComponentDescription m_componentDesc;
+    
+    /**
+     * Internal service context of the composition.
+     */
+    private CompositeServiceContext m_internalContext;
+    
+
+    // Constructor
+    /**
+     * Construct a new Component Manager.
+     * @param factory : the factory managing the instance manager
+     * @param bc : the bundle context to give to the instance
+     */
+    public CompositeManager(ComponentFactory factory, BundleContext bc) {
+        m_factory = factory;
+        m_context = bc;
+        // Initialize the service context.
+        m_internalContext = new CompositeServiceContext(m_context, this);
+        m_factory.getLogger().log(Logger.INFO, "[Bundle " + m_context.getBundle().getBundleId() + "] Create an instance manager from the factory " + m_factory);
+    }
+
+    /**
+     * Configure the instance manager.
+     * Stop the existings handler, clear the handler list, change the metadata, recreate the handlers
+     * @param cm : the component type metadata
+     * @param configuration : the configuration of the instance
+     */
+    public void configure(Element cm, Dictionary configuration) {
+        // Stop all previous registred handler
+        if (m_handlers.length != 0) { stop(); }
+
+        // Clear the handler list
+        m_handlers = new CompositeHandler[0];
+
+        // ComponentInfo initialization
+        m_componentDesc = new ComponentDescription(m_factory.getName());
+        
+        // Add the name
+        m_name = (String) configuration.get("name");
+
+        // Create the standard handlers and add these handlers to the list
+        for (int i = 0; i < IPojoConfiguration.INTERNAL_COMPOSITE_HANDLERS.length; i++) {
+            // Create a new instance
+            try {
+            	CompositeHandler h = (CompositeHandler) IPojoConfiguration.INTERNAL_COMPOSITE_HANDLERS[i].newInstance();
+                h.configure(this, cm, configuration);
+            } catch (InstantiationException e) {
+                m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
+            } catch (IllegalAccessException e) {
+                m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
+            }
+        }
+
+        // Look for namespaces
+        for (int i = 0; i < cm.getNamespaces().length; i++) {
+            if (!cm.getNamespaces()[i].equals("")) {
+                // It is not an internal handler, try to load it
+                try {
+                    Class c = m_context.getBundle().loadClass(cm.getNamespaces()[i]);
+                    CompositeHandler h = (CompositeHandler) c.newInstance();
+                    h.configure(this, cm, configuration);
+                } catch (ClassNotFoundException e) {
+                    m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+                } catch (InstantiationException e) {
+                    m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+                } catch (IllegalAccessException e) {
+                    m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+                }
+            }
+        }
+    }
+
+    /**
+     * @return the component type information.
+     */
+    public ComponentDescription getComponentDescription() { return m_componentDesc; }
+    
+    /**
+     * @return the instance description.
+     */
+    public synchronized InstanceDescription getInstanceDescription() {
+    	int componentState = getState();
+        InstanceDescription instanceDescription = new InstanceDescription(m_name, componentState, getContext().getBundle().getBundleId(), m_componentDesc);
+        CompositeHandler[] handlers = getRegistredCompositeHandlers();
+        for (int i = 0; i < handlers.length; i++) {
+        	instanceDescription.addHandler(handlers[i].getDescription());
+        }
+        
+        // Get instances description of internal instance
+        ServiceReference[] refs;
+		try {
+			refs = m_internalContext.getServiceReferences(Architecture.class.getName(), null);
+			if (refs != null) {
+				for (int i = 0; i < refs.length; i++) {
+					Architecture arch = (Architecture) m_internalContext.getService(refs[i]);
+					instanceDescription.addInstance(arch.getInstanceDescription());
+					m_internalContext.ungetService(refs[i]);
+				}
+			}
+		} catch (InvalidSyntaxException e) {
+			e.printStackTrace(); // Should not happen
+		}
+        return instanceDescription;
+    }
+
+    /**
+     * @return the list of the registred handlers.
+     */
+    public CompositeHandler[] getRegistredCompositeHandlers() { return m_handlers; }
+
+    /**
+     * Return a specified handler.
+     * @param name : class name of the handler to find
+     * @return : the handler, or null if not found
+     */
+    public CompositeHandler getCompositeHandler(String name) {
+        for (int i = 0; i < m_handlers.length; i++) {
+            if (m_handlers[i].getClass().getName().equalsIgnoreCase(name)) { return m_handlers[i]; }
+        }
+        return null;
+    }
+
+    // ===================== Lifecycle management =====================
+
+    /**
+     * Start the instance manager.
+     */
+    public void start() {
+    	if (m_state != STOPPED) { return; } // Instance already started
+    	
+        // Start all the handlers
+        m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] Start the instance manager with " + m_handlers.length + " handlers");
+
+        // The new state of the component is UNRESOLVED
+        m_state = INVALID;
+        
+        m_internalContext.start(); // Turn on the factory tracking
+
+        for (int i = 0; i < m_handlers.length; i++) {
+            m_handlers[i].start();
+        }
+
+        // Defines the state of the component :
+        checkInstanceState();
+    }
+
+    /**
+     * Stop the instance manager.
+     */
+    public void stop() {
+    	if (m_state == STOPPED) { return; } // Instance already stopped
+    	
+        setState(INVALID);
+        // Stop all the handlers
+        for (int i = m_handlers.length - 1; i > -1; i--) {
+            m_handlers[i].stop();
+        }
+        
+        m_internalContext.stop(); // Turn off the factory tracking
+        m_state = STOPPED;
+        m_factory.stopped(this);
+    }
+
+    /**
+     * Set the state of the component.
+     * if the state changed call the stateChanged(int) method on the handlers
+     */
+    public void setState(int state) {
+        if (m_state != state) {
+
+            // Log the state change
+            if (state == INVALID) { m_factory.getLogger().log(Logger.INFO, "[" + m_name + "]  State -> INVALID"); }
+            if (state == VALID) { m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] State -> VALID"); }
+
+            // The state changed call the handler stateChange method
+            m_state = state;
+            for (int i = m_handlers.length - 1; i > -1; i--) {
+                m_handlers[i].stateChanged(state);
+            }
+        }
+    }
+
+    /**
+     * @return the actual state of the component.
+     */
+    public int getState() { return m_state; }
+    
+    /**
+     * @see org.apache.felix.ipojo.ComponentInstance#isStarted()
+     */
+    public boolean isStarted() { return m_state != STOPPED; }
+
+    // ===================== end Lifecycle management =====================
+
+    // ================== Class & Instance management ===================
+
+    /**
+     * @return the factory of the component
+     */
+    public ComponentFactory getFactory() { return m_factory; }
+
+    //  ======================== Handlers Management ======================
+
+    /**
+     * Register the given handler to the current instance manager.
+     * @param h : the handler to register
+     */
+    public void register(CompositeHandler h) {
+        for (int i = 0; (m_handlers != null) && (i < m_handlers.length); i++) {
+            if (m_handlers[i] == h) {
+                return;
+            }
+        }
+
+        if (m_handlers != null) {
+        	CompositeHandler[] newList = new CompositeHandler[m_handlers.length + 1];
+            System.arraycopy(m_handlers, 0, newList, 0, m_handlers.length);
+            newList[m_handlers.length] = h;
+            m_handlers = newList;
+        }
+    }
+
+    /**
+     * Unregister the given handler.
+     * @param h : the handler to unregiter
+     */
+    public void unregister(CompositeHandler h) {
+        int idx = -1;
+        for (int i = 0; i < m_handlers.length; i++) {
+            if (m_handlers[i] == h) {
+                idx = i;
+                break;
+            }
+        }
+
+        if (idx >= 0) {
+            if ((m_handlers.length - 1) == 0) {
+                m_handlers = new CompositeHandler[0];
+            } else {
+            	CompositeHandler[] newList = new CompositeHandler[m_handlers.length - 1];
+                System.arraycopy(m_handlers, 0, newList, 0, idx);
+                if (idx < newList.length)             {
+                    System.arraycopy(
+                            m_handlers, idx + 1, newList, idx, newList.length - idx);
+                }
+                m_handlers = newList;
+            }
+        }
+    }
+
+
+    /**
+     * @return the parent context of the instance.
+     */
+    public BundleContext getContext() { return m_context; }
+
+    /**
+     * Check the state of all handlers.
+     */
+    public void checkInstanceState() {
+        m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] Check the instance state");
+        boolean isValid = true;
+        for (int i = 0; i < m_handlers.length; i++) {
+            boolean b = m_handlers[i].isValid();
+            isValid = isValid && b;
+        }
+
+        // Update the component state if necessary
+        if (!isValid && m_state == VALID) {
+            // Need to update the state to UNRESOLVED
+            setState(INVALID);
+            return;
+        }
+        if (isValid && m_state == INVALID) { setState(VALID); }
+    }
+
+	/**
+	 * @see org.apache.felix.ipojo.ComponentInstance#getInstanceName()
+	 */
+	public String getInstanceName() { return m_name; }
+
+	/**
+	 * @see org.apache.felix.ipojo.ComponentInstance#reconfigure(java.util.Dictionary)
+	 */
+	public void reconfigure(Dictionary configuration) {
+		for (int i = 0; i < m_handlers.length; i++) {
+	        m_handlers[i].reconfigure(configuration);
+	    }
+	}
+	
+	/**
+	 * @return the internal service context.
+	 */
+	public ServiceContext getServiceContext() { return m_internalContext; }
+}

Propchange: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java Tue Apr 10 08:16:56 2007
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.ipojo;
 
+import org.apache.felix.ipojo.composite.service.importer.ImportExportHandler;
+import org.apache.felix.ipojo.composite.service.instantiator.ServiceInstantiatorHandler;
 import org.apache.felix.ipojo.handlers.architecture.ArchitectureHandler;
 import org.apache.felix.ipojo.handlers.configuration.ConfigurationHandler;
 import org.apache.felix.ipojo.handlers.dependency.DependencyHandler;
@@ -48,5 +50,14 @@
         LifecycleCallbackHandler.class,
         ArchitectureHandler.class
     };
+
+	/**
+	 * Available composite handlers in the iPOJO bundle.
+	 */
+	public static final Class[] INTERNAL_COMPOSITE_HANDLERS = new Class[] {
+		ServiceInstantiatorHandler.class,
+		ImportExportHandler.class,
+		org.apache.felix.ipojo.composite.architecture.ArchitectureHandler.class
+	};
 
 }

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/IPojoContext.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/IPojoContext.java?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/IPojoContext.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/IPojoContext.java Tue Apr 10 08:16:56 2007
@@ -196,12 +196,12 @@
 	 * Set the instance to the service context.
 	 * @param ci : the component instance
 	 */
-	public void setComponentInstance(ComponentInstance ci) { m_serviceContext.setComponentInstance(ci); }
+	//public void setComponentInstance(ComponentInstance ci) { m_serviceContext.setComponentInstance(ci); }
 	
 	/**
 	 * Get the instance manager from the service context.
 	 * @return the component manager of the service context
 	 */
-	public ComponentInstance getComponentInstance() { return m_serviceContext.getComponentInstance(); }
+	//public ComponentInstance getComponentInstance() { return m_serviceContext.getComponentInstance(); }
 
 }

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java Tue Apr 10 08:16:56 2007
@@ -165,7 +165,7 @@
      */
     public InstanceDescription getInstanceDescription() {
     	int componentState = getState();
-        InstanceDescription instanceDescription = new InstanceDescription(m_name, m_className, componentState, getContext().getBundle().getBundleId());
+        InstanceDescription instanceDescription = new InstanceDescription(m_name, componentState, getContext().getBundle().getBundleId(), m_componentDesc);
 
         String[] objects = new String[getPojoObjects().length];
         for (int i = 0; i < getPojoObjects().length; i++) {
@@ -243,6 +243,8 @@
         m_pojoObjects = new Object[0];
         
         m_state = STOPPED;
+        
+        m_factory.stopped(this);
     }
 
     /**

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContext.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContext.java?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContext.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContext.java Tue Apr 10 08:16:56 2007
@@ -108,6 +108,6 @@
 	 * Set the component instance using the service context.
 	 * @param ci
 	 */
-	void setComponentInstance(ComponentInstance ci);
+	//void setComponentInstance(ComponentInstance ci);
 
 }

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java Tue Apr 10 08:16:56 2007
@@ -55,11 +55,23 @@
     }
     
     /**
+     * Constructor for composite.
+     * @param name : name of the component type (factory name). 
+     */
+    public ComponentDescription(String name) {
+    	m_name = name;
+    }
+    
+    /**
      * @see java.lang.Object#toString()
      */
     public String toString() {
         String res = "";
-        res += "Component Type : " + m_name + " (" + m_className + ") \n";
+        if (m_className == null) {
+        	res += "Component Type : " + m_name + " (Composition) \n";
+        } else {
+        	res += "Component Type : " + m_name + " (" + m_className + ") \n";
+        }
         for (int i = 0; i < m_providedServiceSpecification.length; i++) {
             res += "\tProvides : " + m_providedServiceSpecification[i] + "\n";
         }

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java?view=diff&rev=527156&r1=527155&r2=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java Tue Apr 10 08:16:56 2007
@@ -25,12 +25,6 @@
 public class InstanceDescription {
 
     /**
-     * The Component class name.
-     * This String is the identifier of the component.
-     */
-    private String m_className;
-
-    /**
      * The name of the component (instance).
      */
     private String m_name;
@@ -51,24 +45,35 @@
     private int m_state;
 
     /**
-     * BundleId of the component.
+     * BundleId who create the instance.
      */
     private long m_bundleId;
+    
+    /**
+     * Component Type of the instance.
+     */
+    private ComponentDescription m_type;
+    
+    /**
+     * COntained instance list.
+     */
+    private InstanceDescription[] m_containedInstances = new InstanceDescription[0];
 
     /**
      * Constructor.
      * @param name : the name of the component instance.
      * @param state : the state of the instance.
-     * @param className : implementation class name.
      * @param bundleId : bundle id owning this instance.
+     * @param cd : the component type description of this instance.
      */
-    public InstanceDescription(String name, String className, int state, long bundleId) {
+    public InstanceDescription(String name, int state, long bundleId, ComponentDescription cd) {
         m_name = name;
-        m_className = className;
         m_state = state;
         m_createdObjects = new String[0];
         m_handlers = new HandlerDescription[0];
+        m_containedInstances = new InstanceDescription[0];
         m_bundleId = bundleId;
+        m_type = cd;
     }
 
     /**
@@ -87,9 +92,9 @@
     public void setCreatedObjects(String[] objects) { m_createdObjects = objects; }
 
     /**
-     * @return : the class name of the component
+     * @return : the component type description of this instance.
      */
-    public String getClassName() { return m_className; }
+    public ComponentDescription getComponentDescription() { return m_type; }
 
     /**
      * @return the live handler list
@@ -113,6 +118,24 @@
         newHd[m_handlers.length] = hd;
         m_handlers = newHd;
     }
+    
+    /**
+     * Add an instance description to the contained instance list.
+     * @param inst : the handler description to add
+     */
+    public void addInstance(InstanceDescription inst) {
+        // Verify that the dependency description is not already in the array.
+        for (int i = 0; (i < m_containedInstances.length); i++) {
+            if (m_containedInstances[i] == inst) {
+                return; //NOTHING TO DO, the description is already in the array
+            }
+        }
+        // The component Description is not in the array, add it
+        InstanceDescription[] newCi = new InstanceDescription[m_containedInstances.length + 1];
+        System.arraycopy(m_containedInstances, 0, newCi, 0, m_containedInstances.length);
+        newCi[m_containedInstances.length] = inst;
+        m_containedInstances = newCi;
+    }
 
     /**
      * Set the state of the component.
@@ -129,6 +152,11 @@
      * @return the bundle id owning the component implementation class.
      */
     public long getBundleId() { return m_bundleId; }
+    
+    /**
+     * @return the list of contained instances.
+     */
+    public InstanceDescription[] getContainedInstances() { return m_containedInstances; }
 
 
 }

Added: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java?view=auto&rev=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java (added)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java Tue Apr 10 08:16:56 2007
@@ -0,0 +1,267 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.felix.ipojo.composite;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * CompositeServiceContext Class.
+ * This class provides an implementation of the service context for composite.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class CompositeServiceContext implements ServiceContext, ServiceListener {
+	
+	private class Record {
+		private ServiceReference m_ref;
+		private ServiceRegistration m_reg;
+		private FactoryProxy m_fact;
+	}
+	
+	private List m_factories = new ArrayList();
+	
+	private BundleContext m_parent;
+	
+	/**
+	 * Internal service registry.
+	 */
+	private ServiceRegistry m_registry;
+	
+	/**
+	 * Component Instance who creates this registry. 
+	 */
+	private ComponentInstance m_instance;
+	
+	/**
+	 * Constructor.
+	 * This constructor instantiate a service registry with the given bundle context.
+	 * @param bc : the bundle context
+	 */
+	public CompositeServiceContext(BundleContext bc) {
+		m_registry = new ServiceRegistry(bc);
+		m_parent = bc;
+	}
+	
+	/**
+	 * Constructor.
+	 * @param bc : the bundle context
+	 * @param ci : the component instance owning this context
+	 */
+	public CompositeServiceContext(BundleContext bc, ComponentInstance ci) {
+		this(bc);
+		m_parent = bc;
+		m_instance = ci;
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.ServiceContext#addServiceListener(org.osgi.framework.ServiceListener)
+	 */
+	public void addServiceListener(ServiceListener arg0) {
+		m_registry.addServiceListener(arg0);
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.ServiceContext#addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)
+	 */
+	public void addServiceListener(ServiceListener arg0, String arg1) throws InvalidSyntaxException {
+		m_registry.addServiceListener(arg0, arg1);
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.ServiceContext#getAllServiceReferences(java.lang.String, java.lang.String)
+	 */
+	public ServiceReference[] getAllServiceReferences(String arg0, String arg1) throws InvalidSyntaxException {
+		return m_registry.getAllServiceReferences(arg0, arg1);
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.ServiceContext#getComponentInstance()
+	 */
+	public ComponentInstance getComponentInstance() {
+		return m_instance;
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.ServiceContext#getService(org.osgi.framework.ServiceReference)
+	 */
+	public Object getService(ServiceReference arg0) {
+		return m_registry.getService(m_instance, arg0);
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.ServiceContext#getServiceReference(java.lang.String)
+	 */
+	public ServiceReference getServiceReference(String arg0) {
+		return m_registry.getServiceReference(arg0);
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.ServiceContext#getServiceReferences(java.lang.String, java.lang.String)
+	 */
+	public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
+		return m_registry.getServiceReferences(clazz, filter);
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.ServiceContext#registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)
+	 */
+	public ServiceRegistration registerService(String[] arg0, Object arg1, Dictionary arg2) {
+		return m_registry.registerService(m_instance, arg0, arg1, arg2);
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.ServiceContext#registerService(java.lang.String, java.lang.Object, java.util.Dictionary)
+	 */
+	public ServiceRegistration registerService(String arg0, Object arg1, Dictionary arg2) {
+		return m_registry.registerService(m_instance, arg0, arg1, arg2);
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.ServiceContext#removeServiceListener(org.osgi.framework.ServiceListener)
+	 */
+	public void removeServiceListener(ServiceListener arg0) {
+		m_registry.removeServiceListener(arg0);
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.ServiceContext#ungetService(org.osgi.framework.ServiceReference)
+	 */
+	public boolean ungetService(ServiceReference arg0) {
+		return m_registry.ungetService(m_instance, arg0);
+	}
+	
+	/**
+	 * Initiate the factory list.
+	 */
+	private void importFactories() {
+		try {
+			ServiceReference[] refs = m_parent.getServiceReferences(Factory.class.getName(), null);
+			if (refs != null) {
+				for (int i = 0; i < refs.length; i++) {
+					importFactory(refs[i]);
+				}
+			}
+		} catch (InvalidSyntaxException e) {
+			e.printStackTrace(); // Should not happen
+		}
+	}
+	
+	/**
+	 * Import a factory form the parent to the internal registry.
+	 * @param ref : the reference of the factory to import.
+	 */
+	private void importFactory(ServiceReference ref) {
+		//System.out.println("Add a new factory in the scope : " + ref.getProperty(Constants.SERVICE_PID));
+		Record rec = new Record();
+		m_factories.add(rec);
+		Dictionary dict = new Properties();
+		for (int j = 0; j < ref.getPropertyKeys().length; j++) {
+			dict.put(ref.getPropertyKeys()[j], ref.getProperty(ref.getPropertyKeys()[j]));
+		}
+		rec.m_fact = new FactoryProxy((Factory) m_parent.getService(ref), this); 
+		rec.m_reg = registerService(Factory.class.getName(), rec.m_fact, dict);
+		rec.m_ref = ref;
+	}
+	
+	/**
+	 * Remove a factory of the available factory list.
+	 * @param ref : the reference on the factory to remove.
+	 */
+	private void removeFactory(ServiceReference ref) {
+		//System.out.println("Remove a factory from the scope : " + ref.getProperty(Constants.SERVICE_PID));
+		for (int i = 0; i < m_factories.size(); i++) {
+			Record rec = (Record) m_factories.get(i);
+			if (rec.m_ref == ref) {
+				rec.m_reg.unregister();
+				rec.m_fact = null;
+				m_parent.ungetService(rec.m_ref);
+				m_factories.remove(rec);
+				return;
+			}
+		}
+	}
+	
+	/**
+	 * Start the registry management.
+	 */
+	public void start() {
+		importFactories();
+		try {
+			m_parent.addServiceListener(this, "(" + Constants.OBJECTCLASS + "=" + Factory.class.getName() + ")");
+		} catch (InvalidSyntaxException e) {
+			// Should not happen
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * Stop the registry management.
+	 */
+	public synchronized void stop() {
+		m_parent.removeServiceListener(this);
+		m_registry.reset();
+		for (int i = 0; i < m_factories.size(); i++) {
+			Record rec = (Record) m_factories.get(i);
+			removeFactory(rec.m_ref);
+		}
+	}
+	
+	/**
+	 * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+	 */
+	public void serviceChanged(ServiceEvent event) {
+		if (event.getType() == ServiceEvent.REGISTERED) {
+			if (!containsRef(event.getServiceReference())) {
+				importFactory(event.getServiceReference());
+			}
+			return;
+		}
+		if (event.getType() == ServiceEvent.UNREGISTERING) {
+			if (containsRef(event.getServiceReference())) {
+				removeFactory(event.getServiceReference());
+			}
+		}
+	}
+	
+	/**
+	 * Check if the factory list contain the given reference.
+	 * @param ref : the reference to find.
+	 * @return true if the list contains the given reference.
+	 */
+	private boolean containsRef(ServiceReference ref) {
+		for (int i = 0; i < m_factories.size(); i++) {
+			Record rec = (Record) m_factories.get(i);
+			if (rec.m_ref == ref) { return true; }
+		}
+		return false;
+	}
+}

Propchange: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java?view=auto&rev=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java (added)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java Tue Apr 10 08:16:56 2007
@@ -0,0 +1,82 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.felix.ipojo.composite;
+
+import java.util.Dictionary;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.UnacceptableConfiguration;
+import org.apache.felix.ipojo.architecture.ComponentDescription;
+
+/**
+ * Bridge representing a Factory inside a composition.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class FactoryProxy implements Factory {
+	
+	private Factory m_delegate;
+	private ServiceContext m_context;
+	
+	/**
+	 * Constructor.
+	 * @param fact : the targetted factory.
+	 * @param s : the service context to target.
+	 */
+	public FactoryProxy(Factory fact, ServiceContext s) {
+		m_delegate = fact;
+		m_context = s;
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
+	 */
+	public ComponentInstance createComponentInstance(Dictionary configuration) throws UnacceptableConfiguration {
+		return m_delegate.createComponentInstance(configuration, m_context);
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary, org.apache.felix.ipojo.ServiceContext)
+	 */
+	public ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext) throws UnacceptableConfiguration {
+		return m_delegate.createComponentInstance(configuration, serviceContext);
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Factory#getComponentDescription()
+	 */
+	public ComponentDescription getComponentDescription() { return m_delegate.getComponentDescription(); }
+
+	/**
+	 * @see org.apache.felix.ipojo.Factory#getName()
+	 */
+	public String getName() { return m_delegate.getName(); }
+
+	/**
+	 * @see org.apache.felix.ipojo.Factory#isAcceptable(java.util.Dictionary)
+	 */
+	public boolean isAcceptable(Dictionary conf) { return m_delegate.isAcceptable(conf); }
+
+	/**
+	 * @see org.apache.felix.ipojo.Factory#reconfigure(java.util.Dictionary)
+	 */
+	public void reconfigure(Dictionary conf) throws UnacceptableConfiguration { m_delegate.reconfigure(conf); }
+
+}

Propchange: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java?view=auto&rev=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java (added)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java Tue Apr 10 08:16:56 2007
@@ -0,0 +1,87 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.felix.ipojo.composite;
+
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Internal service reference implemenation.
+ * This class is used for in the composition.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class ServiceReferenceImpl implements ServiceReference {
+	
+	 /**
+	 * Service Registration attached to the service reference.
+	 */
+	private ServiceRegistrationImpl m_registration = null;
+	 
+	 /**
+	 * Constructor.
+	 * @param cm : component instance publishing the service.
+	 * @param sr : registration attached to this service reference.
+	 */
+	public ServiceReferenceImpl(ComponentInstance cm, ServiceRegistrationImpl sr) { m_registration = sr; }
+
+	/**
+	 * Not supported in composite.
+	 * @see org.osgi.framework.ServiceReference#getBundle()
+	 */
+	public Bundle getBundle() { 
+		throw new UnsupportedOperationException("getUsingBundles is not supported in scope");
+	}
+	
+	/**
+	 * @return the service registration for this service reference.
+	 */
+	public ServiceRegistrationImpl getServiceRegistration() { return m_registration; }
+
+	/**
+	 * @see org.osgi.framework.ServiceReference#getProperty(java.lang.String)
+	 */
+	public Object getProperty(String s) {
+		return m_registration.getProperty(s);
+	}
+
+	/**
+	 * @see org.osgi.framework.ServiceReference#getPropertyKeys()
+	 */
+	public String[] getPropertyKeys() {
+		return m_registration.getPropertyKeys();
+	}
+
+	/**
+	 * Not supported in composite.
+	 * @see org.osgi.framework.ServiceReference#getUsingBundles()
+	 */
+	public Bundle[] getUsingBundles() {
+		throw new UnsupportedOperationException("getUsingBundles is not supported in scope");
+	}
+
+	/**
+	 * @see org.osgi.framework.ServiceReference#isAssignableTo(org.osgi.framework.Bundle, java.lang.String)
+	 */
+	public boolean isAssignableTo(Bundle arg0, String arg1) {
+		return true;
+	}
+
+}

Propchange: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java?view=auto&rev=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java (added)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java Tue Apr 10 08:16:56 2007
@@ -0,0 +1,232 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.felix.ipojo.composite;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.InstanceManager;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Internal service registration implemenation.
+ * This class is used for in the composition.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class ServiceRegistrationImpl implements ServiceRegistration {
+
+    /**
+     * Service Registry. 
+     */
+    private ServiceRegistry m_registry = null;
+   
+    /**
+     * Interfaces associated with the service object.
+     */
+    private String[] m_classes = null;
+    
+    /**
+     *  Service Id associated with the service object.
+     */
+    private Long m_serviceId = null;
+    
+    /**
+     * Service object.
+     */
+    private Object m_svcObj = null;
+    
+    /**
+     * Service factory interface.
+     */
+    private ServiceFactory m_factory = null;
+    
+    /**
+     * Associated property dictionary. 
+     */
+    private Map m_propMap = null;
+
+    /**
+     * Re-usable service reference.
+     */
+    private ServiceReferenceImpl m_ref = null;
+
+    /**
+     * Constructor.
+     * @param registry : the service registry
+     * @param cm : component instance
+     * @param classes : published interfaces array
+     * @param serviceId : the unique service id 
+     * @param svcObj : the service object or the service factory object
+     * @param dict : service properties
+     */
+    public ServiceRegistrationImpl(ServiceRegistry registry, ComponentInstance cm, String[] classes, Long serviceId, Object svcObj, Dictionary dict) {
+        m_registry = registry;
+        m_classes = classes;
+        m_serviceId = serviceId;
+        m_svcObj = svcObj;
+        m_factory = (m_svcObj instanceof ServiceFactory)
+            ? (ServiceFactory) m_svcObj : null;
+
+        initializeProperties(dict);
+
+        // This reference is the "standard" reference for this service and will always be returned by getReference().
+        // Since all reference to this service are supposed to be equal, we use the hashcode of this reference for
+        // a references to this service in ServiceReference.
+        m_ref = new ServiceReferenceImpl(cm, this);
+    }
+
+    /**
+     * @return true if the service registration is valid.
+     */
+    protected boolean isValid() { return (m_svcObj != null); }
+
+    /**
+     * @see org.osgi.framework.ServiceRegistration#getReference()
+     */
+    public ServiceReference getReference() { return m_ref; }
+
+    /**
+     * @see org.osgi.framework.ServiceRegistration#setProperties(java.util.Dictionary)
+     */
+    public void setProperties(Dictionary dict) {
+        // Make sure registration is valid.
+        if (!isValid()) { throw new IllegalStateException("The service registration is no longer valid."); }
+        // Set the properties.
+        initializeProperties(dict);
+        // Tell registry about it.
+        m_registry.servicePropertiesModified(this);
+    }
+
+    /**
+     * @see org.osgi.framework.ServiceRegistration#unregister()
+     */
+    public void unregister() {
+        if (m_svcObj != null) {
+            m_registry.unregisterService(this);
+            m_svcObj = null;
+            m_factory = null;
+        } else { 
+        	throw new IllegalStateException("Service already unregistered."); 
+        }
+    }
+
+    /**
+     * Look for a property in the service properties. 
+     * @param key : property key
+     * @return the object associated with the key or null if the key is not present.
+     */
+    protected Object getProperty(String key) {
+        return m_propMap.get(key);
+    }
+
+    /**
+     * Property Keys List.
+     */
+    private transient ArrayList m_list = new ArrayList();
+
+    /**
+     * @return the property keys list.
+     */
+    protected String[] getPropertyKeys() {
+        synchronized (m_propMap) {
+            m_list.clear();
+            Iterator i = m_propMap.entrySet().iterator();
+            while (i.hasNext()) {
+                Map.Entry entry = (Map.Entry) i.next();
+                m_list.add(entry.getKey());
+            }
+            return (String[]) m_list.toArray(new String[m_list.size()]);
+        }
+    }
+
+    /**
+     * @return the service object. Call the service factory if needed.
+     */
+    protected Object getService() {
+        // If the service object is a service factory, then
+        // let it create the service object.
+        if (m_factory != null) {
+            return getFactoryUnchecked(); 
+        } else { return m_svcObj; }
+    }
+
+    /**
+     * Initialize properties.
+     * @param dict : serivce properties to publish.
+     */
+    private void initializeProperties(Dictionary dict) {
+        // Create a case insensitive map.
+        if (m_propMap == null) { 
+        	m_propMap = new StringMap(false);
+        } else { 
+        	m_propMap.clear();
+        }
+
+        if (dict != null) {
+            Enumeration keys = dict.keys();
+            while (keys.hasMoreElements()) {
+                Object key = keys.nextElement();
+                m_propMap.put(key, dict.get(key));
+            }
+        }
+        // Add the framework assigned properties.
+        m_propMap.put(Constants.OBJECTCLASS, m_classes);
+        m_propMap.put(Constants.SERVICE_ID, m_serviceId);
+    }
+
+    /**
+     * @return the service object via the service factory invocation.
+     */
+    private Object getFactoryUnchecked() {
+        return m_factory.getService(null, this);
+    }
+
+    /**
+     * Unget a service.
+     * (Internal Method)
+     * @param cm : component instance using the service.
+     * @param svcObj : the unget service object.
+     */
+    private void ungetFactoryUnchecked(ComponentInstance cm, Object svcObj) {
+    	if (cm instanceof InstanceManager) {
+    		m_factory.ungetService(((InstanceManager) cm).getContext().getBundle(), this, svcObj);
+    	}
+        
+    }
+
+	/**
+	 * Unget a service.
+     * @param cm : component instance using the service.
+     * @param srvObj : the unget service object.
+	 */
+	public void ungetService(ComponentInstance cm, Object srvObj) {
+		//	If the service object is a service factory, then let is release the service object.
+        if (m_factory != null) {
+            ungetFactoryUnchecked(cm, srvObj);
+        }
+	}
+
+}

Propchange: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java?view=auto&rev=527156
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java (added)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java Tue Apr 10 08:16:56 2007
@@ -0,0 +1,306 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.felix.ipojo.composite;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Internal Service Registry.
+ * This class is used for in the composition.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class ServiceRegistry {
+	
+	/**
+	 * Service Id index. 
+	 */
+	private long m_serviceId = 1L;
+	
+	/**
+	 * List of service listeners. 
+	 */
+	private ArrayList m_listeners = new ArrayList(); // ListenerInfo List
+	
+	/**
+	 * List of service registration. 
+	 */
+	private ArrayList m_regs = new ArrayList();
+	
+	/**
+	 * A "real" bundle context to create LDAP filter.
+	 */
+	private BundleContext m_bc; //BundleContext to create Filter
+	
+	/**
+	 * Listener info structure.
+	 */
+	private class ListenerInfo {	
+		private ServiceListener m_listener;
+		private Filter m_filter;
+	}
+	
+	/**
+	 * Constructor.
+	 * @param bc : bundle context.
+	 */
+	public ServiceRegistry(BundleContext bc) {
+		m_bc = bc;
+	}
+
+	/**
+	 * Add a given service listener with no filter.
+	 * @param arg0 : the service listener to add
+	 */
+	public void addServiceListener(ServiceListener arg0) {
+		ListenerInfo li = new ListenerInfo();
+		li.m_listener = arg0; 
+		li.m_filter = null;
+		m_listeners.add(li);
+	}
+
+	/**
+	 * Unget a service.
+	 * @param cm : instance releasing the service.
+	 * @param ref : released reference. 
+	 * @return true if the unget success
+	 */
+	public boolean ungetService(ComponentInstance cm, ServiceReference ref) {
+		
+		ServiceRegistrationImpl reg = ((ServiceReferenceImpl) ref).getServiceRegistration();
+		if (!reg.isValid()) {
+			return false;
+		} else {
+			reg.ungetService(cm, reg.getService());
+			return true;
+		}
+	}
+
+	/**
+	 * Unregister a service listener.
+	 * @param arg0 : the service listenenr to remove
+	 */
+	public void removeServiceListener(ServiceListener arg0) {
+		m_listeners.remove(arg0);
+	}
+
+	/**
+	 * Register a service.
+	 * @param cm : provider instance.
+	 * @param clazz : provided interface.
+	 * @param svcObj : service object of service factory object.
+	 * @param dict : service properties. 
+	 * @return the created service registration.
+	 */
+	public ServiceRegistration registerService(ComponentInstance cm, String clazz, Object svcObj, Dictionary dict) {
+		synchronized (m_regs) {
+			ServiceRegistrationImpl reg = new ServiceRegistrationImpl(this, cm, new String[] {clazz}, new Long(m_serviceId++), svcObj, dict);
+			m_regs.add(reg);
+			fireServiceChanged(new ServiceEvent(ServiceEvent.REGISTERED, reg.getReference()));
+			return reg;
+		}
+	}
+
+	/**
+	 * Register a service.
+	 * @param cm : provider instance.
+	 * @param clazzes : provided interfaces.
+	 * @param svcObj : service object of service factory object.
+	 * @param dict : service properties. 
+	 * @return the created service registration.
+	 */
+	public ServiceRegistration registerService(ComponentInstance cm, String[] clazzes, Object svcObj, Dictionary dict) {
+		synchronized (m_regs) {
+			ServiceRegistrationImpl reg = new ServiceRegistrationImpl(this, cm, clazzes, new Long(m_serviceId++), svcObj, dict);
+			m_regs.add(reg);
+			fireServiceChanged(new ServiceEvent(ServiceEvent.REGISTERED, reg.getReference()));
+			return reg;
+		}
+	}
+	
+	/**
+	 * Dispatch a service event.
+	 * @param event : the service to dispatch
+	 */
+	private void fireServiceChanged(ServiceEvent event) {
+		synchronized (this) {
+			// Iterate on the service listenner list to notify service listener
+			for (int i = 0; i < m_listeners.size(); i++) {
+				ListenerInfo li = (ListenerInfo) m_listeners.get(i);
+				ServiceReference sr = event.getServiceReference();
+				if (li.m_filter == null) { li.m_listener.serviceChanged(event); }
+				if (li.m_filter != null && li.m_filter.match(sr)) { li.m_listener.serviceChanged(event); }
+			}
+		}
+	}
+
+	/**
+	 * Get available (and accessible) service references.
+	 * @param className : required interface
+	 * @param expr : LDAP filter
+	 * @return : the list of available service references.
+	 * @throws InvalidSyntaxException occurs when the LDAP filter is malformed.
+	 */
+	public ServiceReference[] getServiceReferences(String className, String expr) throws InvalidSyntaxException {
+		synchronized (this) {
+			//	Define filter if expression is not null.
+			Filter filter = null;
+			if (expr != null) { filter = m_bc.createFilter(expr); }
+        
+			ArrayList refs = new ArrayList();
+		
+			for (int i = 0; i < m_regs.size(); i++) {
+				ServiceRegistrationImpl reg = (ServiceRegistrationImpl) m_regs.get(i);
+				//	Determine if the registered services matches the search criteria.
+				boolean matched = false;
+
+				// If className is null, then look at filter only.
+				if ((className == null) && ((filter == null) || filter.match(reg.getReference()))) { 
+					matched = true; 
+				} else if (className != null) {
+					// If className is not null, then first match the
+					// objectClass property before looking at the
+					// filter.
+					String[] objectClass = (String[]) ((ServiceRegistrationImpl) reg).getProperty(Constants.OBJECTCLASS);
+					for (int classIdx = 0; classIdx < objectClass.length; classIdx++) {
+						if (objectClass[classIdx].equals(className) && ((filter == null) || filter.match(reg.getReference()))) {
+							matched = true;
+							break;
+						}
+					}
+				}
+
+				// Add reference if it was a match.
+				if (matched) { refs.add(reg.getReference()); }
+			}
+		
+			if (refs.size() > 0) { return (ServiceReference[]) refs.toArray(new ServiceReference[refs.size()]); }
+			return null;
+		}
+	}
+
+	/**
+	 * Look for a service reference.
+	 * @param clazz : required interface.
+	 * @return the first available provider or null if none available.
+	 */
+	public ServiceReference getServiceReference(String clazz) {
+		synchronized (this) {
+			try {
+				ServiceReference[] refs = getServiceReferences(clazz, null);
+				if (refs != null) { return refs[0]; } // If the refs != null we are sure that it exist one references or more.
+			} catch (InvalidSyntaxException ex) { System.err.println("Scope Service Registry : Problem when look for service reference" + ex.getMessage()); }
+			return null;
+		}
+	}
+
+	/**
+	 * Get a service object.
+	 * @param cm : component instance requiring the service.
+	 * @param ref : the required reference.
+	 * @return the service object.
+	 */
+	public  Object getService(ComponentInstance cm, ServiceReference ref) {
+		synchronized (this) {
+			// Look for the service registration for this ref
+			ServiceRegistrationImpl reg = ((ServiceReferenceImpl) ref).getServiceRegistration();
+			if (reg.isValid()) {
+				// Delegate the service providing to the service registration
+				return reg.getService();
+			} else {
+				return null;
+			}
+		}
+	}
+
+	/**
+	 * Get all service references consistent with the given interface and filter.
+	 * @param clazz : the required interface.
+	 * @param filter : the LDAP filter.
+	 * @return the list of all service reference or null if none available.
+	 * @throws InvalidSyntaxException
+	 */
+	public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
+		synchronized (this) {
+			// Can delegate on getServiceReference, indeed their is no test on the "modularity" conflict.
+			return getServiceReferences(clazz, filter);
+		}
+	}
+
+	/**
+	 * Add a service listener with a filter.
+	 * @param listener : the service listener to add
+	 * @param filter : LDAP filter
+	 */
+	public void addServiceListener(ServiceListener listener, String filter) {
+		synchronized (this) {
+			ListenerInfo li = new ListenerInfo();
+			li.m_listener = listener; 
+			try {
+				li.m_filter = m_bc.createFilter(filter);
+			} catch (InvalidSyntaxException ex) { System.err.println("Scope Service Registry : Problem when creatin a service listener " + ex.getMessage()); }
+			m_listeners.add(li);
+		}
+	}
+
+	/**
+	 * Dispatch a service properties modified event.
+	 * @param reg : the implicated service registration.
+	 */
+	public void servicePropertiesModified(ServiceRegistrationImpl reg) {
+		fireServiceChanged(new ServiceEvent(ServiceEvent.MODIFIED, reg.getReference()));
+	}
+
+	/**
+	 * Unregister a service.
+	 * @param reg : the service registration to unregister
+	 */
+	public void unregisterService(ServiceRegistrationImpl reg) {
+		synchronized (this) {
+			m_regs.remove(reg);
+			fireServiceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, reg.getReference()));
+		}
+	}
+	
+	/**
+	 * @return the size of the service registry.
+	 */
+	protected int getSize() {
+		return m_regs.size();
+	}
+	
+	/**
+	 * Reset the service registry.
+	 */
+	protected void reset() {
+		m_serviceId = 1L;
+		m_listeners = new ArrayList();
+		m_regs = new ArrayList();
+	}
+}

Propchange: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message