felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r529623 [3/9] - in /incubator/felix/trunk: ./ ipojo.arch/ ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ ipojo.metadata/ ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/ ipojo.plugin/ ipojo.plugin/src/main/java/org/apach...
Date Tue, 17 Apr 2007 14:31:47 GMT
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=529623&r1=529622&r2=529623
==============================================================================
--- 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 17 07:31:35 2007
@@ -20,6 +20,7 @@
 
 /**
  * Component Type information.
+ * 
  * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
  */
 public class ComponentDescription {
@@ -43,34 +44,38 @@
      * Get the name of this component type.
      */
     private String m_name;
-    
+
     /**
      * Constructor.
-     * @param name : name of the component type (factory name). 
+     * 
+     * @param name : name of the component type (factory name).
      * @param className : implementation class.
      */
     public ComponentDescription(String name, String className) {
-    	m_name = name;
-    	m_className = className;
+        m_name = name;
+        m_className = className;
     }
-    
+
     /**
      * Constructor for composite.
-     * @param name : name of the component type (factory name). 
+     * 
+     * @param name : name of the component type (factory name).
      */
     public ComponentDescription(String name) {
-    	m_name = name;
+        m_name = name;
     }
-    
+
     /**
+     * Get a displayable form of the current component type description.
+     * @return displayable form of the component type description
      * @see java.lang.Object#toString()
      */
     public String toString() {
         String res = "";
         if (m_className == null) {
-        	res += "Component Type : " + m_name + " (Composition) \n";
+            res += "Component Type : " + m_name + " (Composition) \n";
         } else {
-        	res += "Component Type : " + m_name + " (" + m_className + ") \n";
+            res += "Component Type : " + m_name + " (" + m_className + ") \n";
         }
         for (int i = 0; i < m_providedServiceSpecification.length; i++) {
             res += "\tProvides : " + m_providedServiceSpecification[i] + "\n";
@@ -82,54 +87,66 @@
     }
 
     /**
+     * Get the implementation class of this component type.
      * @return the component type implementation class name.
      */
-    public String getClassName() { return m_className; }
+    public String getClassName() {
+        return m_className;
+    }
 
     /**
-     * @return the list of configuration properties accepted by the component type.
+     * Get component-type properties.
+     * @return the list of configuration properties accepted by the component type
+     * type.
      */
-    public PropertyDescription[] getProperties() { return m_properties; }
+    public PropertyDescription[] getProperties() {
+        return m_properties;
+    }
 
     /**
      * Add a configuration properties to the component type.
+     * 
      * @param pd : the property to add
      */
-    public void addProperty(PropertyDescription pd) { 
-    	for (int i = 0; i < m_properties.length; i++) {
-    		if (m_properties[i].getName().equals(pd.getName())) { return; }
-    	}
-    	
-    	PropertyDescription[] newProps = new PropertyDescription[m_properties.length + 1];
+    public void addProperty(PropertyDescription pd) {
+        for (int i = 0; i < m_properties.length; i++) {
+            if (m_properties[i].getName().equals(pd.getName())) {
+                return;
+            }
+        }
+
+        PropertyDescription[] newProps = new PropertyDescription[m_properties.length + 1];
         System.arraycopy(m_properties, 0, newProps, 0, m_properties.length);
         newProps[m_properties.length] = pd;
         m_properties = newProps;
     }
 
     /**
+     * Get the list of provided service offered by instances of this type.
      * @return the list of the provided service.
      */
-    public String[] getprovidedServiceSpecification() { return m_providedServiceSpecification; }
+    public String[] getprovidedServiceSpecification() {
+        return m_providedServiceSpecification;
+    }
 
     /**
-     * add a provided service to the component type.
-     * @param serviceSpecification : the provided service to add (interface name)
+     * Add a provided service to the component type.
+     * @param serviceSpecification : the provided service to add (interface
+     * name)
      */
-    public void addProvidedServiceSpecification(String serviceSpecification) { 
+    public void addProvidedServiceSpecification(String serviceSpecification) {
         String[] newSs = new String[m_providedServiceSpecification.length + 1];
         System.arraycopy(m_providedServiceSpecification, 0, newSs, 0, m_providedServiceSpecification.length);
         newSs[m_providedServiceSpecification.length] = serviceSpecification;
         m_providedServiceSpecification = newSs;
     }
-    
+
     /**
+     * Return the component-type name.
      * @return the name of this component type
      */
-    public String getName() { return m_name; }
-    
-    
-
-
-
+    public String getName() {
+        return m_name;
+    }
 
 }

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/HandlerDescription.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/HandlerDescription.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/HandlerDescription.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/HandlerDescription.java Tue Apr 17 07:31:35 2007
@@ -18,14 +18,16 @@
  */
 package org.apache.felix.ipojo.architecture;
 
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
 
 /**
  * Handler Description.
+ * 
  * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
  */
 public class HandlerDescription {
 
-
     /**
      * Handler Class Name (i.e namespace).
      */
@@ -36,9 +38,9 @@
      */
     private boolean m_isValid;
 
-
     /**
      * Constructor.
+     * 
      * @param name : handler name
      * @param isValid : is the handler valid
      */
@@ -48,18 +50,34 @@
     }
 
     /**
+     * Check if the handler is valid.
      * @return true if the handler is valid.
      */
-    public boolean isValid() { return m_isValid; }
+    public boolean isValid() {
+        return m_isValid;
+    }
 
     /**
+     * Get the handler name.
      * @return the handler name (i.e. namespace).
      */
-    public String getHandlerName() { return m_handlerName; }
+    public String getHandlerName() {
+        return m_handlerName;
+    }
 
     /**
+     * Get handler information.
      * @return the handler information.
      */
-    public String getHandlerInfo() { return ""; };
+    public Element getHandlerInfo() {
+        Element elem = new Element("Handler", "");
+        elem.addAttribute(new Attribute("name", m_handlerName));
+        if (m_isValid) {
+            elem.addAttribute(new Attribute("state", "valid"));
+        } else {
+            elem.addAttribute(new Attribute("state", "invalid"));
+        }
+        return elem;
+    }
 
 }

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=529623&r1=529622&r2=529623
==============================================================================
--- 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 17 07:31:35 2007
@@ -18,8 +18,13 @@
  */
 package org.apache.felix.ipojo.architecture;
 
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+
 /**
  * Instance Description.
+ * 
  * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
  */
 public class InstanceDescription {
@@ -48,12 +53,12 @@
      * BundleId who create the instance.
      */
     private long m_bundleId;
-    
+
     /**
      * Component Type of the instance.
      */
     private ComponentDescription m_type;
-    
+
     /**
      * COntained instance list.
      */
@@ -61,6 +66,7 @@
 
     /**
      * Constructor.
+     * 
      * @param name : the name of the component instance.
      * @param state : the state of the instance.
      * @param bundleId : bundle id owning this instance.
@@ -77,29 +83,44 @@
     }
 
     /**
-     * @return the name of the component.
+     * Get the instance name.
+     * @return the name of the instance.
      */
-    public String getName() { return m_name; }
+    public String getName() {
+        return m_name;
+    }
 
     /**
+     * Get the list of object created by the described instance.
      * @return the created instances
      */
-    public String[] getCreatedObjects() { return m_createdObjects; }
+    public String[] getCreatedObjects() {
+        return m_createdObjects;
+    }
 
     /**
-     * Set the instances array.
+     * Set the array of objects created by the described instance.
+     * @param objects : the list of create objects.
      */
-    public void setCreatedObjects(String[] objects) { m_createdObjects = objects; }
+    public void setCreatedObjects(String[] objects) {
+        m_createdObjects = objects;
+    }
 
     /**
+     * Get the component type description of the described instance.
      * @return : the component type description of this instance.
      */
-    public ComponentDescription getComponentDescription() { return m_type; }
+    public ComponentDescription getComponentDescription() {
+        return m_type;
+    }
 
     /**
+     * Get the plugged handler list.
      * @return the live handler list
      */
-    public HandlerDescription[] getHandlers() { return m_handlers; }
+    public HandlerDescription[] getHandlers() {
+        return m_handlers;
+    }
 
     /**
      * Add an handler description to the list.
@@ -107,27 +128,30 @@
      */
     public void addHandler(HandlerDescription hd) {
         // Verify that the dependency description is not already in the array.
-        for (int i = 0; (i < m_handlers.length); i++) {
+        for (int i = 0; i < m_handlers.length; i++) {
             if (m_handlers[i] == hd) {
-                return; //NOTHING TO DO, the description is already in the array
+                return; // NOTHING TO DO, the description is already in the
+                        // array
             }
         }
-            // The component Description is not in the array, add it
+        // The component Description is not in the array, add it
         HandlerDescription[] newHd = new HandlerDescription[m_handlers.length + 1];
         System.arraycopy(m_handlers, 0, newHd, 0, m_handlers.length);
         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++) {
+        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
+                return; // NOTHING TO DO, the description is already in the
+                        // array
             }
         }
         // The component Description is not in the array, add it
@@ -139,24 +163,79 @@
 
     /**
      * Set the state of the component.
+     * 
      * @param i : the state
      */
-    public void setState(int i) { m_state = i; }
+    public void setState(int i) {
+        m_state = i;
+    }
 
     /**
-     * @return the state of the component.
+     * Get the state of the described instance.
+     * @return the state of the instance.
      */
-    public int getState() { return m_state; }
+    public int getState() {
+        return m_state;
+    }
 
     /**
+     * Get the bundle id of the bundle containing the described instance.
      * @return the bundle id owning the component implementation class.
      */
-    public long getBundleId() { return m_bundleId; }
-    
+    public long getBundleId() {
+        return m_bundleId;
+    }
+
     /**
+     * Get the list of contained instance in the describe instance.
+     * This list contains only instances who exposed their architecture.
      * @return the list of contained instances.
      */
-    public InstanceDescription[] getContainedInstances() { return m_containedInstances; }
+    public InstanceDescription[] getContainedInstances() {
+        return m_containedInstances;
+    }
+
+    /**
+     * Get the instance description.
+     * @return the instance description
+     */
+    public Element getDescription() {
+        Element instance = new Element("Instance", "");
+        instance.addAttribute(new Attribute("name", getName())); // Name
+        // State
+        if (m_state == ComponentInstance.STOPPED) {
+            instance.addAttribute(new Attribute("state", "stopped"));
+        }
+        if (m_state == ComponentInstance.VALID) {
+            instance.addAttribute(new Attribute("state", "valid"));
+        }
+        if (m_state == ComponentInstance.INVALID) {
+            instance.addAttribute(new Attribute("state", "invalid"));
+        }
+        // Bundle
+        instance.addAttribute(new Attribute("bundle", "" + m_bundleId));
 
+        // Component Type
+        instance.addAttribute(new Attribute("component.type", m_type.getName()));
+
+        // Handlers
+        for (int i = 0; i < m_handlers.length; i++) {
+            instance.addElement(m_handlers[i].getHandlerInfo());
+        }
+        // Created Object (empty is composite)
+        for (int i = 0; i < m_createdObjects.length; i++) {
+            Element obj = new Element("Object", "");
+            obj.addAttribute(new Attribute("name", ((Object) m_createdObjects[i]).toString()));
+            instance.addElement(obj);
+        }
+        // Contained instance (exposing architecture) (empty if primitive)
+        for (int i = 0; i < m_containedInstances.length; i++) {
+            Element inst = new Element("ContainedInstances", "");
+            inst.addElement(m_containedInstances[i].getDescription());
+            instance.addElement(inst);
+        }
+        return instance;
+
+    }
 
 }

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java Tue Apr 17 07:31:35 2007
@@ -20,6 +20,7 @@
 
 /**
  * Property Information.
+ * 
  * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
  */
 public class PropertyDescription {
@@ -41,6 +42,7 @@
 
     /**
      * Constructor.
+     * 
      * @param name : name of the property
      * @param type : type of the property
      * @param value : default value of the property
@@ -52,28 +54,39 @@
     }
 
     /**
+     * Get the current property name.
      * @return the property name.
      */
-    public String getName() { return m_name; }
-    
+    public String getName() {
+        return m_name;
+    }
+
     /**
+     * Get the current property type.
      * @return the property type.
      */
-    public String getType() { return m_type; }
+    public String getType() {
+        return m_type;
+    }
 
     /**
+     * Get the current property value.
      * @return the default value for the property.
      */
-    public String getValue() { return m_value; }
+    public String getValue() {
+        return m_value;
+    }
 
     /**
+     * Get a displayed form of the current property.
+     * @return : a String representing this property.
      * @see java.lang.Object#toString()
      */
     public String toString() {
-        if (m_value != null) { 
-        	return getName() + " - " + getType() + " - " + getValue(); 
-        } else { 
-        	return getName() + " - " + getType() + " - REQUIRED"; 
+        if (m_value != null) {
+            return getName() + " - " + getType() + " - " + getValue();
+        } else {
+            return getName() + " - " + getType() + " - REQUIRED";
         }
     }
 

Modified: 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=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java Tue Apr 17 07:31:35 2007
@@ -35,233 +35,293 @@
 import org.osgi.framework.ServiceRegistration;
 
 /**
- * CompositeServiceContext Class.
- * This class provides an implementation of the service context for composite.
+ * 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;
-	}
+
+    /**
+     * Structure stoing the referense, the factory and the registration.
+     */
+    private class Record {
+        /**
+         * Reference of the proxed factory from the external context.
+         */
+        private ServiceReference m_ref;
+        /**
+         * Registration of the factory in the internal context.
+         */
+        private ServiceRegistration m_reg;
+        /**
+         * Proxed Factory. 
+         */
+        private FactoryProxy m_fact;
+    }
+
+    /**
+     * List of imported factories.
+     */
+    private List m_factories = new ArrayList();
+
+    /**
+     * External context.
+     */
+    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;
+    }
+
+    /**
+     * Add a service listener.
+     * @param arg0 : The service listener to add
+     * @see org.apache.felix.ipojo.ServiceContext#addServiceListener(org.osgi.framework.ServiceListener)
+     */
+    public void addServiceListener(ServiceListener arg0) {
+        m_registry.addServiceListener(arg0);
+    }
+
+    /**
+     * Add a filtered service listener.
+     * @param arg0 : the service listner object to add
+     * @param arg1 : the LDAP filter for this listener
+     * @throws InvalidSyntaxException : throwed if the LDAP filter is malformed
+     * @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);
+    }
+
+    /**
+     * Get all service references.
+     * @param arg0 : The requried service interface.
+     * @param arg1 : LDAP filter
+     * @return the list of all service reference matching with the query
+     * @throws InvalidSyntaxException : occurs when the given filter is malformed
+     * @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);
+    }
+
+    /**
+     * Get a service object for the given service reference.
+     * @param arg0 : the service reference
+     * @return the service object or null if the reference is no more valid or if the object is not accessible
+     * @see org.apache.felix.ipojo.ServiceContext#getService(org.osgi.framework.ServiceReference)
+     */
+    public Object getService(ServiceReference arg0) {
+        return m_registry.getService(m_instance, arg0);
+    }
+
+    
+    /**
+     * Get a service reference for the required interface.
+     * @param arg0 : the requried interface name
+     * @return the service reference or null if no available provider
+     * @see org.apache.felix.ipojo.ServiceContext#getServiceReference(java.lang.String)
+     */
+    public ServiceReference getServiceReference(String arg0) {
+        return m_registry.getServiceReference(arg0);
+    }
+
+    /**
+     * Get all accessible service reference for the given query.
+     * @param clazz : required interface
+     * @param filter : LDAP filter
+     * @return the list (array) of service reference matching with the query.
+     * @throws InvalidSyntaxException : occurs when the LDAP filter is malformed
+     * @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);
+    }
+
+
+    /**
+     * Register a service inside the composite context.
+     * @param arg0 : list of interfaces to register.
+     * @param arg1 : service object
+     * @param arg2 : properties list
+     * @return the service registration
+     * @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);
+    }
+
+    /**
+     * Register a service inside the composite context.
+     * @param arg0 : interface to register.
+     * @param arg1 : service object
+     * @param arg2 : properties list
+     * @return the service registration
+     * @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);
+    }
+
+    /**
+     * Remove a service listener.
+     * @param arg0 : the service listener to remove
+     * @see org.apache.felix.ipojo.ServiceContext#removeServiceListener(org.osgi.framework.ServiceListener)
+     */
+    public void removeServiceListener(ServiceListener arg0) {
+        m_registry.removeServiceListener(arg0);
+    }
+
+    /**
+     * Unget a service.
+     * @param arg0 the service reference to unget
+     * @return true
+     * @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) {
+        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) {
+        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);
+        }
+    }
+
+    /**
+     * Service Listener implementation.
+     * @param event : the service event
+     * @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;
+    }
 }

Modified: 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=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java Tue Apr 17 07:31:35 2007
@@ -28,55 +28,102 @@
 
 /**
  * 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); }
+
+    /**
+     * Delegated factory.
+     */
+    private Factory m_delegate;
+
+    /**
+     * Destination context.
+     */
+    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;
+    }
+
+    /**
+     * Create an instance manager (i.e. component type instance).
+     * 
+     * @param configuration : the configuration properties for this component.
+     * @return the created instance manager.
+     * @throws UnacceptableConfiguration : when a given configuration is not valid.
+     * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
+     */
+    public ComponentInstance createComponentInstance(Dictionary configuration) throws UnacceptableConfiguration {
+        return m_delegate.createComponentInstance(configuration, m_context);
+    }
+
+    /**
+     * Create an instance manager (i.e. component type instance). This has these
+     * service interaction in the scope given in argument.
+     * 
+     * @param configuration : the configuration properties for this component.
+     * @param serviceContext : the service context of the component.
+     * @return the created instance manager.
+     * @throws UnacceptableConfiguration : when the given configuration isnot valid.
+     * @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);
+    }
+
+    /**
+     * Get the component type information containing provided service,
+     * configuration properties ...
+     * 
+     * @return the component type information.
+     * @see org.apache.felix.ipojo.Factory#getComponentDescription()
+     */
+    public ComponentDescription getComponentDescription() {
+        return m_delegate.getComponentDescription();
+    }
+
+    /**
+     * Return the factory name.
+     * @return the name of the factory.
+     * @see org.apache.felix.ipojo.Factory#getName()
+     */
+    public String getName() {
+        return m_delegate.getName();
+    }
+
+    /**
+     * Check if the given configuration is acceptable as a configuration of a
+     * component instance.
+     * 
+     * @param conf : the configuration to test
+     * @return true if the configuration is acceptable
+     * @see org.apache.felix.ipojo.Factory#isAcceptable(java.util.Dictionary)
+     */
+    public boolean isAcceptable(Dictionary conf) {
+        return m_delegate.isAcceptable(conf);
+    }
+
+    /**
+     * Reconfigure an instance already created. This configuration need to have
+     * the name property to identify the instance.
+     * 
+     * @param conf : the configuration to reconfigure the instance.
+     * @throws UnacceptableConfiguration : if the given configuration is not
+     * consistent for the tragetted instance.
+     * @see org.apache.felix.ipojo.Factory#reconfigure(java.util.Dictionary)
+     */
+    public void reconfigure(Dictionary conf) throws UnacceptableConfiguration {
+        m_delegate.reconfigure(conf);
+    }
 
 }

Modified: 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=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java Tue Apr 17 07:31:35 2007
@@ -18,70 +18,89 @@
  */
 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.
+ * 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;
-	}
+
+    /**
+     * 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.
+     * @return null
+     * @see org.osgi.framework.ServiceReference#getBundle()
+     */
+    public Bundle getBundle() {
+        throw new UnsupportedOperationException("getUsingBundles is not supported in scope");
+    }
+
+    /**
+     * Get the service registration for this reference.
+     * @return the service registration for this service reference.
+     */
+    public ServiceRegistrationImpl getServiceRegistration() {
+        return m_registration;
+    }
+
+
+    /**
+     * Get a property value.
+     * @param s : the key of the required property.
+     * @return the property value or null if no property for the given key.
+     * @see org.osgi.framework.ServiceReference#getProperty(java.lang.String)
+     */
+    public Object getProperty(String s) {
+        return m_registration.getProperty(s);
+    }
+
+    /**
+     * Get the String arrays of service property keys.
+     * @return : the list of property keys.
+     * @see org.osgi.framework.ServiceReference#getPropertyKeys()
+     */
+    public String[] getPropertyKeys() {
+        return m_registration.getPropertyKeys();
+    }
+
+
+    /**
+     * Unsupported Operation inside composite.
+     * @return bundles using this reference.
+     * @see org.osgi.framework.ServiceReference#getUsingBundles()
+     */
+    public Bundle[] getUsingBundles() {
+        throw new UnsupportedOperationException("getUsingBundles is not supported in scope");
+    }
+
+    /**
+     * Check if the current service reference is assignable to the given bundle.
+     * @param arg0 : the bundle to check
+     * @param arg1 : the class name to check.
+     * @return true in the case of composite
+     * @see org.osgi.framework.ServiceReference#isAssignableTo(org.osgi.framework.Bundle, java.lang.String)
+     */
+    public boolean isAssignableTo(Bundle arg0, String arg1) {
+        return true;
+    }
 
 }

Modified: 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=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java Tue Apr 17 07:31:35 2007
@@ -32,39 +32,40 @@
 import org.osgi.framework.ServiceRegistration;
 
 /**
- * Internal service registration implemenation.
- * This class is used for in the composition.
+ * 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. 
+     * 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.
+     * 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. 
+     * Associated property dictionary.
      */
     private Map m_propMap = null;
 
@@ -75,10 +76,11 @@
 
     /**
      * Constructor.
+     * 
      * @param registry : the service registry
      * @param cm : component instance
      * @param classes : published interfaces array
-     * @param serviceId : the unique service id 
+     * @param serviceId : the unique service id
      * @param svcObj : the service object or the service factory object
      * @param dict : service properties
      */
@@ -87,33 +89,44 @@
         m_classes = classes;
         m_serviceId = serviceId;
         m_svcObj = svcObj;
-        m_factory = (m_svcObj instanceof ServiceFactory)
-            ? (ServiceFactory) m_svcObj : null;
-
+        if (m_svcObj instanceof ServiceFactory) { m_factory = (ServiceFactory) m_svcObj; }
         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
+        // 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);
     }
 
     /**
+     * Check if the service registration still valid.
      * @return true if the service registration is valid.
      */
-    protected boolean isValid() { return (m_svcObj != null); }
+    protected boolean isValid() {
+        return m_svcObj != null;
+    }
 
     /**
+     * Get the service reference attached with this service registration.
+     * @return the service reference
      * @see org.osgi.framework.ServiceRegistration#getReference()
      */
-    public ServiceReference getReference() { return m_ref; }
+    public ServiceReference getReference() {
+        return m_ref;
+    }
 
     /**
+     * Add properties to a service registration.
+     * @param dict : the properties to add
      * @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."); }
+        if (!isValid()) {
+            throw new IllegalStateException("The service registration is no longer valid.");
+        }
         // Set the properties.
         initializeProperties(dict);
         // Tell registry about it.
@@ -121,6 +134,7 @@
     }
 
     /**
+     * Unregister the service.
      * @see org.osgi.framework.ServiceRegistration#unregister()
      */
     public void unregister() {
@@ -128,15 +142,17 @@
             m_registry.unregisterService(this);
             m_svcObj = null;
             m_factory = null;
-        } else { 
-        	throw new IllegalStateException("Service already unregistered."); 
+        } else {
+            throw new IllegalStateException("Service already unregistered.");
         }
     }
 
     /**
-     * Look for a property in the service properties. 
+     * 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.
+     * @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);
@@ -148,6 +164,7 @@
     private transient ArrayList m_list = new ArrayList();
 
     /**
+     * Get the property keys.
      * @return the property keys list.
      */
     protected String[] getPropertyKeys() {
@@ -163,26 +180,30 @@
     }
 
     /**
+     * Get the service object.
      * @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; }
+            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 (m_propMap == null) {
+            m_propMap = new StringMap(false);
+        } else {
+            m_propMap.clear();
         }
 
         if (dict != null) {
@@ -198,6 +219,7 @@
     }
 
     /**
+     * Get a service object via a service factory.
      * @return the service object via the service factory invocation.
      */
     private Object getFactoryUnchecked() {
@@ -205,28 +227,30 @@
     }
 
     /**
-     * Unget a service.
-     * (Internal Method)
+     * 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);
-    	}
-        
+        if (cm instanceof InstanceManager) {
+            m_factory.ungetService(((InstanceManager) cm).getContext().getBundle(), this, svcObj);
+        }
+
     }
 
-	/**
-	 * Unget a service.
+    /**
+     * 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.
+     */
+    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);
         }
-	}
+    }
 
 }

Modified: 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=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java Tue Apr 17 07:31:35 2007
@@ -32,275 +32,308 @@
 import org.osgi.framework.ServiceRegistration;
 
 /**
- * Internal Service Registry.
- * This class is used for in the composition.
+ * 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();
-	}
+
+    /**
+     * 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 {
+        /**
+         * Listener object.
+         */
+        private ServiceListener m_listener;
+        /**
+         * Filter associated with the filter.
+         */
+        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 occurs when the LDAP filter is malformed.
+     */
+    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()));
+        }
+    }
+
+    /**
+     * Reset the service registry.
+     */
+    protected void reset() {
+        m_serviceId = 1L;
+        m_listeners = new ArrayList();
+        m_regs = new ArrayList();
+    }
 }

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/StringMap.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/StringMap.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/StringMap.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/StringMap.java Tue Apr 17 07:31:35 2007
@@ -23,37 +23,39 @@
 import java.util.TreeMap;
 
 /**
- * Simple utility class that creates a map for string-based keys by
- * extending <tt>TreeMap</tt>. This map can be set to use case-sensitive
- * or case-insensitive comparison when searching for the key.
- * Any keys put into this map will be converted to
- * a <tt>String</tt> using the <tt>toString()</tt> method,
- * since it is only intended to compare strings.
-**/
+ * Simple utility class that creates a map for string-based keys by extending
+ * <tt>TreeMap</tt>. This map can be set to use case-sensitive or
+ * case-insensitive comparison when searching for the key. Any keys put into
+ * this map will be converted to a <tt>String</tt> using the
+ * <tt>toString()</tt> method, since it is only intended to compare strings.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
 public class StringMap extends TreeMap {
-    
-	/**
-	 * serialVersionUID.
-	 */
-	private static final long serialVersionUID = 6948801857034259744L;
 
-	/**
+    /**
+     * serialVersionUID.
+     */
+    private static final long serialVersionUID = 6948801857034259744L;
+
+    /**
      * Constructor.
      */
     public StringMap() {
         this(true);
     }
-    
+
     /**
      * Constructor.
+     * 
      * @param caseSensitive : fix if the map if case sensitive or not.
      */
     public StringMap(boolean caseSensitive) {
         super(new StringComparator(caseSensitive));
     }
-    
+
     /**
      * Constructor.
+     * 
      * @param map : initial properties.
      * @param caseSensitive : fix if the map if case sensitive or not.
      */
@@ -61,15 +63,20 @@
         this(caseSensitive);
         putAll(map);
     }
-    
+
     /**
+     * Put a record in the map.
+     * @param key : key
+     * @param value : value
+     * @return an object.
      * @see java.util.TreeMap#put(K, V)
      */
     public Object put(Object key, Object value) {
         return super.put(key.toString(), value);
     }
-    
+
     /**
+     * Check if the map is case-sensitive.
      * @return true if the map is case sensitive.
      */
     public boolean isCaseSensitive() {
@@ -78,6 +85,7 @@
 
     /**
      * Set the case sensitivity.
+     * 
      * @param b : the new case sensitivity.
      */
     public void setCaseSensitive(boolean b) {
@@ -85,10 +93,14 @@
     }
 
     private static class StringComparator implements Comparator {
+        /**
+         * Is the map case sensitive?
+         */
         private boolean m_isCaseSensitive = true;
 
         /**
          * Constructor.
+         * 
          * @param b : true to enable the case sensitivity.
          */
         public StringComparator(boolean b) {
@@ -96,6 +108,10 @@
         }
 
         /**
+         * Compare to object.
+         * @param o1 : first object to compare
+         * @param o2 : second object to compare
+         * @return the comparison result
          * @see java.util.Comparator#compare(T, T)
          */
         public int compare(Object o1, Object o2) {
@@ -107,6 +123,7 @@
         }
 
         /**
+         * Check if the comparator is case sensitive.
          * @return true if the map is case sensitive.
          */
         public boolean isCaseSensitive() {
@@ -115,17 +132,20 @@
 
         /**
          * Set the case sensitivity.
+         * 
          * @param b : true to enable the case sensitivity
          */
         public void setCaseSensitive(boolean b) {
             m_isCaseSensitive = b;
         }
-        
+
         /**
+         * Does not support cloning.
+         * @return The current map
          * @see java.lang.Object#clone()
          */
         public Object clone() {
-        	return this;
+            return this;
         }
     }
 }

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java Tue Apr 17 07:31:35 2007
@@ -32,17 +32,19 @@
 
 /**
  * Composite Architecture Handler.
+ * 
  * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
  */
 public class ArchitectureHandler extends CompositeHandler implements Architecture {
 
-	/**
+    /**
      * Composite Manager.
      */
     private CompositeManager m_manager;
 
     /**
-     * Service Registration of the Architecture service provided by this handler.
+     * Service Registration of the Architecture service provided by this
+     * handler.
      */
     private ServiceRegistration m_sr;
 
@@ -52,12 +54,20 @@
     private String m_name;
 
     /**
-     * @see org.apache.felix.ipojo.CompositeHandler#configure(org.apache.felix.ipojo.CompositeManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
+     * Configure the handler.
+     * 
+     * @param im : the instance manager
+     * @param metadata : the metadata of the component
+     * @param configuration : the instance configuration
+     * @see org.apache.felix.ipojo.CompositeHandler#configure(org.apache.felix.ipojo.CompositeManager,
+     * org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
      */
     public void configure(CompositeManager im, Element metadata, Dictionary configuration) {
         if (metadata.containsAttribute("architecture")) {
             String isArchitectureEnabled = (metadata.getAttribute("architecture")).toLowerCase();
-            if (isArchitectureEnabled.equalsIgnoreCase("true")) { im.register(this); }
+            if (isArchitectureEnabled.equalsIgnoreCase("true")) {
+                im.register(this);
+            }
         }
 
         m_name = (String) configuration.get("name");
@@ -66,20 +76,27 @@
     }
 
     /**
+     * Stop the handler.
+     * Unregister the service.
      * @see org.apache.felix.ipojo.Handler#stop()
      */
     public void stop() {
-        try {
-            if (m_sr != null) { m_sr.unregister(); m_sr = null; }
-        } catch (Exception e) { return; }
+        if (m_sr != null) {
+            m_sr.unregister();
+            m_sr = null;
+        }
     }
 
     /**
+     * Start the handler.
+     * Register the service.
      * @see org.apache.felix.ipojo.Handler#start()
      */
     public void start() {
         // Unregister the service if already registred
-        if (m_sr != null) { m_sr.unregister(); }
+        if (m_sr != null) {
+            m_sr.unregister();
+        }
 
         // Register the ManagedService
         BundleContext bc = m_manager.getContext();
@@ -91,6 +108,8 @@
     }
 
     /**
+     * Get the instance description.
+     * @return the instance description
      * @see org.apache.felix.ipojo.architecture.Architecture#getComponentDescription()
      */
     public InstanceDescription getInstanceDescription() {

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportDescription.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportDescription.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportDescription.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportDescription.java Tue Apr 17 07:31:35 2007
@@ -21,57 +21,77 @@
 import java.util.List;
 
 import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
 
 /**
+ * Description of the Import Export Handler.
  * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
  */
 public class ImportExportDescription extends HandlerDescription {
-	
-	private List m_imports;
-	private List m_exports;
-
-	/**
-	 * Constructor.
-	 * @param name
-	 * @param isValid
-	 * @param importers
-	 * @param exporters
-	 */
-	public ImportExportDescription(String name, boolean isValid, List importers, List exporters) {
-		super(name, isValid);
-		m_imports = importers;
-		m_exports = exporters;
-	}
-	
-	/**
-	 * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
-	 */
-	public String getHandlerInfo() {
-		String s = "";
-		for (int i = 0; i < m_imports.size(); i++) {
-			ServiceImporter imp = (ServiceImporter) m_imports.get(i);
-			if (imp.isSatisfied()) {
-				s += "\t Specification " + imp.getSpecification() + " provided by \n \t";
-				for (int j = 0; j < imp.getProviders().size(); j++) {
-					String prov = (String) imp.getProviders().get(j);
-					s += prov + " ";
-				}	
-			} else {
-				s += "\t Specification " + imp.getSpecification() + " is not statisfied \n";
-			}
-		}
-		for (int i = 0; i < m_exports.size(); i++) {
-			ServiceExporter exp = (ServiceExporter) m_exports.get(i);
-			if (exp.isSatisfied()) {
-				s += "\t Specification " + exp.getSpecification() + " is exported or optional";
-			} else {
-				s += "\t Specification " + exp.getSpecification() + " is not exported";
-			}
-		}
-		return s;
-		
-	}
-	
-	
+
+    /**
+     * List of imports.
+     */
+    private List m_imports;
+
+    /**
+     * List of exports.
+     */
+    private List m_exports;
+
+    /**
+     * Constructor.
+     * 
+     * @param name : name of the handler
+     * @param isValid : handler validity
+     * @param importers : list of managed imports
+     * @param exporters : list of managed exports
+     */
+    public ImportExportDescription(String name, boolean isValid, List importers, List exporters) {
+        super(name, isValid);
+        m_imports = importers;
+        m_exports = exporters;
+    }
+
+    /**
+     * Build the ImportExport handler description.
+     * @return the handler description
+     * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
+     */
+    public Element getHandlerInfo() {
+        Element handler = super.getHandlerInfo();
+        for (int i = 0; i < m_imports.size(); i++) {
+            ServiceImporter imp = (ServiceImporter) m_imports.get(i);
+            Element impo = new Element("Import", "");
+            impo.addAttribute(new Attribute("Specification", imp.getSpecification()));
+            if (imp.getFilter() != null) { impo.addAttribute(new Attribute("Filter", imp.getFilter())); }
+            if (imp.isSatisfied()) {
+                impo.addAttribute(new Attribute("State", "resolved"));
+                for (int j = 0; j < imp.getProviders().size(); j++) {
+                    Element pr = new Element("Provider", "");
+                    pr.addAttribute(new Attribute("name", (String) imp.getProviders().get(j)));
+                    impo.addElement(pr);
+                }
+            } else {
+                impo.addAttribute(new Attribute("State", "unresolved"));
+            }
+            handler.addElement(impo);
+        }
+        for (int i = 0; i < m_exports.size(); i++) {
+            ServiceExporter exp = (ServiceExporter) m_exports.get(i);
+            Element expo = new Element("Export", "");
+            expo.addAttribute(new Attribute("Specification", exp.getSpecification()));
+            expo.addAttribute(new Attribute("Filter", exp.getFilter()));
+            if (exp.isSatisfied()) {
+                expo.addAttribute(new Attribute("State", "resolved"));
+            } else {
+                expo.addAttribute(new Attribute("State", "unresolved"));
+            }
+            handler.addElement(expo);
+        }
+        return handler;
+
+    }
 
 }



Mime
View raw message