felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r585146 [1/4] - in /felix/trunk/ipojo: ./ arch/src/main/resources/ core/src/main/java/org/apache/felix/ipojo/ core/src/main/java/org/apache/felix/ipojo/architecture/ core/src/main/java/org/apache/felix/ipojo/composite/ core/src/main/java/or...
Date Tue, 16 Oct 2007 14:05:21 GMT
Author: clement
Date: Tue Oct 16 07:04:28 2007
New Revision: 585146

URL: http://svn.apache.org/viewvc?rev=585146&view=rev
Log:
Add static and dynamic-priority binding policy.
Fix log access in initializeComponentFactory
Improve bytecode manipulation
Improve exception handling
Improve service tracking
Manage super interfaces (interface extended by the implemented interfaces and by the super-class) 

Added:
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/ServiceReferenceRankingComparator.java
Modified:
    felix/trunk/ipojo/arch/src/main/resources/metadata.xml
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/CompositeFactory.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/CompositeHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ConfigurationException.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Handler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerFactory.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManager.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/importer/ExportHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedServiceHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/FieldMetadata.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManipulationMetadata.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Tracker.java
    felix/trunk/ipojo/core/src/main/resources/metadata.xml
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/FieldAdapter.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/PojoAdapter.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/xml/parser/XMLMetadataParser.java
    felix/trunk/ipojo/metadata/src/main/java/org/apache/felix/ipojo/metadata/Attribute.java
    felix/trunk/ipojo/metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
    felix/trunk/ipojo/pom.xml

Modified: felix/trunk/ipojo/arch/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/arch/src/main/resources/metadata.xml?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/arch/src/main/resources/metadata.xml (original)
+++ felix/trunk/ipojo/arch/src/main/resources/metadata.xml Tue Oct 16 07:04:28 2007
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <iPOJO>
-	<Component className="org.apache.felix.ipojo.arch.ArchCommandImpl">
+	<Component className="org.apache.felix.ipojo.arch.ArchCommandImpl" factory="false">
 		  <Provides/>
 		  <Requires field="m_archs" optional="true"/>
 		  <Requires field="m_factories" optional="true" filter="(!(handler.name=*))"/>

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java Tue Oct 16 07:04:28 2007
@@ -31,7 +31,6 @@
 import java.util.Properties;
 
 import org.apache.felix.ipojo.architecture.ComponentDescription;
-import org.apache.felix.ipojo.architecture.PropertyDescription;
 import org.apache.felix.ipojo.metadata.Element;
 import org.apache.felix.ipojo.util.Logger;
 import org.apache.felix.ipojo.util.Tracker;
@@ -168,10 +167,8 @@
         computeFactoryName();        
         m_logger = new Logger(m_context, m_factoryName, Logger.WARNING);
         
-        m_isPublic = true;
-        if (cm.containsAttribute("factory") && cm.getAttribute("factory").equals("false")) {
-            m_isPublic = false;
-        }
+        String fac = cm.getAttribute("factory");
+        m_isPublic = fac == null || ! fac.equalsIgnoreCase("false");
         
         computeRequiredHandlers();
         
@@ -200,10 +197,10 @@
         for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
             HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
             if (hi.m_reference == null && match(hi, reference)) {
-                int oldP = hi.getPriority();
+                int oldP = hi.m_level;
                 hi.setReference(reference);
                 // If the priority has changed, sort the list.
-                if (oldP != hi.getPriority()) {
+                if (oldP != hi.m_level) {
                     Collections.sort(m_handlerIdentifiers);
                 }
                 return true;
@@ -218,7 +215,14 @@
      * @see org.apache.felix.ipojo.util.TrackerCustomizer#addedService(org.osgi.framework.ServiceReference)
      */
     public void addedService(ServiceReference reference) {
-        computeFactoryState();
+        if (m_state == INVALID) {
+            try {
+                computeFactoryState();
+            } catch (org.apache.felix.ipojo.ConfigurationException e) {
+                m_logger.log(Logger.ERROR, "The component type metadata are not correct : " + e.getMessage());
+                stop();
+            }
+        }
     }
 
     /**
@@ -228,12 +232,12 @@
      * @return true if the metadata are correct
      */
     public boolean check(Element cm) {
-        if (cm.containsAttribute("className")) {
-            m_componentClassName = cm.getAttribute("className");
-            return true;
-        } else {
+        m_componentClassName = cm.getAttribute("className");
+        if (m_componentClassName == null) {
             System.err.println("A component needs a class name : " + cm);
             return false;
+        } else {
+            return true;
         }
     }
 
@@ -264,11 +268,7 @@
      * @throws org.apache.felix.ipojo.ConfigurationException : when the instance configuration failed.
      * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
      */
-    public synchronized ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext) throws UnacceptableConfiguration, MissingHandlerException, org.apache.felix.ipojo.ConfigurationException {
-        if (m_state == INVALID) {
-            throw new MissingHandlerException(getMissingHandlers());
-        }
-        
+    public synchronized ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext) throws UnacceptableConfiguration, MissingHandlerException, org.apache.felix.ipojo.ConfigurationException {        
         if (configuration == null) {
             configuration = new Properties();
         }
@@ -284,16 +284,14 @@
         String n = null;
         if (configuration.get("name") != null) {
             n = (String) configuration.get("name");
+            if (m_instancesName.contains(n)) {
+                throw new UnacceptableConfiguration("Name already used : " + n);
+            }
         } else {
             n = generateName();
             configuration.put("name", n);
         }
-        
-        if (m_instancesName.contains(n)) {
-            throw new UnacceptableConfiguration("Name already used : " + n);
-        } else {
-            m_instancesName.add(n);
-        }
+        m_instancesName.add(n);
 
         BundleContext context = null;
         if (serviceContext == null) {
@@ -301,14 +299,19 @@
         } else {
             context = new IPojoContext(m_context, serviceContext);
         }
+        
         List handlers = new ArrayList();
         for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
             HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
             handlers.add(getHandlerInstance(hi, serviceContext));
         }
         
-        InstanceManager instance = new InstanceManager(this, context, (HandlerManager[]) handlers.toArray(new HandlerManager[0]));
-        instance.configure(m_componentMetadata, configuration);
+        InstanceManager instance = new InstanceManager(this, context, (HandlerManager[]) handlers.toArray(new HandlerManager[m_handlerIdentifiers.size()]));
+        try {
+            instance.configure(m_componentMetadata, configuration);
+        } catch (org.apache.felix.ipojo.ConfigurationException e) {
+            throw new org.apache.felix.ipojo.ConfigurationException(e.getMessage(), m_factoryName);
+        }
 
         m_componentInstances.put(n, instance);
         instance.start();
@@ -322,9 +325,8 @@
      * @param b : byte array of the class
      * @param domain : protection domain of the class
      * @return the defined class object
-     * @throws Exception : an exception occur during the definition
      */
-    public Class defineClass(String name, byte[] b, ProtectionDomain domain) throws Exception {
+    public Class defineClass(String name, byte[] b, ProtectionDomain domain) {
         if (m_classLoader == null) {
             m_classLoader = new FactoryClassloader();
         }
@@ -360,7 +362,7 @@
      * @see org.apache.felix.ipojo.Factory#getDescription()
      */
     public Element getDescription() {
-        if (m_componentDesc == null) { return new Element("No description available for " + getName(), ""); }
+        if (m_componentDesc == null) { return new Element("No description available for " + m_factoryName, ""); }
         return m_componentDesc.getDescription();
     }
     
@@ -412,6 +414,14 @@
         return l;
     }
     
+    public String getClassName() {
+        return m_componentClassName;
+    }
+
+    public int getState() {
+        return m_state;
+    }
+    
     /**
      * Return the URL of a resource.
      * @param resName : resource name
@@ -491,8 +501,8 @@
             return; // The instance does not exist.
         } else {
             checkAcceptability(properties); // Test if the configuration is acceptable
+            cm.reconfigure(properties); // re-configure the component
         }
-        cm.reconfigure(properties); // re-configure the component
     }
 
     /**
@@ -503,15 +513,19 @@
      */
     public void removedService(ServiceReference reference, Object service) {
         // Look for the implied reference and invalid the handler identifier
-        boolean touched = false;
         for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
             HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
             if (reference.equals(hi.getReference())) {
-                hi.setReference(null); // This method will unget the service.
-                touched = true;
+                hi.unRef(); // This method will unget the service.
+                try {
+                    computeFactoryState();
+                } catch (org.apache.felix.ipojo.ConfigurationException e) {
+                    m_logger.log(Logger.ERROR, "The component type metadata are not correct : " + e.getMessage());
+                    stop();
+                }
+                return; // The factory can be used only once.
             }
         }
-        if (touched) { computeFactoryState(); }
     }
 
     /**
@@ -533,21 +547,28 @@
             return;
         } 
         
-        try {
-            String filter = "(&(" + Constants.OBJECTCLASS + "=" + Factory.class.getName() + ")"
-                    + "(" + Handler.HANDLER_NAME_PROPERTY + "=*)" + "(" + Handler.HANDLER_NAMESPACE_PROPERTY + "=*)" /* Look only for handlers */
-                    + "(" + Handler.HANDLER_TYPE_PROPERTY + "=" + PrimitiveHandler.HANDLER_TYPE + ")" 
-                    + "(factory.state=1)"
-                    + ")";
-            m_tracker = new Tracker(m_context, m_context.createFilter(filter), this);
-            m_tracker.open();
+        if (m_handlerIdentifiers.size() != 0) {
+            try {
+                String filter = "(&(" + Constants.OBJECTCLASS + "=" + Factory.class.getName() + ")"
+                        + "(" + Handler.HANDLER_TYPE_PROPERTY + "=" + PrimitiveHandler.HANDLER_TYPE + ")" 
+                        + "(factory.state=1)"
+                        + ")";
+                m_tracker = new Tracker(m_context, m_context.createFilter(filter), this);
+                m_tracker.open();
+            } catch (InvalidSyntaxException e) {
+                m_logger.log(Logger.ERROR, "A factory filter is not valid: " + e.getMessage());
+                stop();
+                return;
+            }
+        }
             
-        } catch (InvalidSyntaxException e) {
-            m_logger.log(Logger.ERROR, "A factory filter is not valid: " + e.getMessage());
+        try {
+            computeFactoryState();
+        } catch (org.apache.felix.ipojo.ConfigurationException e) {
+            m_logger.log(Logger.ERROR, "The component type metadata are not correct : " + e.getMessage());
+            stop();
             return;
         }
-        
-        computeFactoryState();
 
         if (m_isPublic) {        
             // Exposition of the factory service
@@ -582,10 +603,7 @@
         
         // Release each handler
         for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
-            HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
-            if (hi.getReference() != null) {
-                hi.setReference(null);
-            }
+            ((HandlerIdentifier) m_handlerIdentifiers.get(i)).unRef();
         }
         
         m_tracker = null;
@@ -641,18 +659,15 @@
      * @throws MissingHandlerException : the factory is not valid.
      */
     protected void checkAcceptability(Dictionary conf) throws UnacceptableConfiguration, MissingHandlerException {
-        computeFactoryState();
-        
         if (m_state == Factory.INVALID) {
             throw new MissingHandlerException(getMissingHandlers());
         }
         
-        final PropertyDescription[] props = m_componentDesc.getProperties();
-        for (int i = 0; i < props.length; i++) {
-            final PropertyDescription pd = props[i];
+        List props = m_componentDesc.getRequiredProperties();
+        for (int i = 0; i < props.size(); i++) {
             // Failed if the props has no default value and the configuration does not push a value
-            if (pd.getValue() == null && conf.get(pd.getName()) == null) {
-                throw new UnacceptableConfiguration("The configuration does not contains the \"" + pd.getName() + "\" property");
+            if (conf.get(props.get(i)) == null) {
+                throw new UnacceptableConfiguration("The configuration does not contains the \"" + props.get(i) + "\" property");
             }
         }
     }
@@ -663,21 +678,20 @@
      * @throws org.apache.felix.ipojo.ConfigurationException if one handler has rejected the configuration.
      */
     protected void computeDescription() throws org.apache.felix.ipojo.ConfigurationException {
-        List l = new ArrayList();
-        for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
-            HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
-            l.add(hi.getFullName());
-        }
-
-        m_componentDesc = new ComponentDescription(getName(), m_componentClassName, m_state, l, getMissingHandlers(), m_context.getBundle().getBundleId());
+        m_componentDesc = new ComponentDescription(this);
          
         for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
             HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
             HandlerManager hm = getHandlerInstance(hi, null);
-            hm.getHandler();
             Handler ch =  hm.getHandler();
-            ch.initializeComponentFactory(m_componentDesc, m_componentMetadata);
-            ((Pojo) ch).getComponentInstance().dispose();
+            try {
+                ch.setLogger(getLogger());
+                ch.initializeComponentFactory(m_componentDesc, m_componentMetadata);
+                ((Pojo) ch).getComponentInstance().dispose();
+            } catch (org.apache.felix.ipojo.ConfigurationException e) {
+                ((Pojo) ch).getComponentInstance().dispose();
+                throw new org.apache.felix.ipojo.ConfigurationException(e.getMessage(), m_factoryName);
+            }
         }
     }
 
@@ -685,69 +699,71 @@
      * Compute the factory name.
      */
     protected void computeFactoryName() {
-        if (m_componentMetadata.containsAttribute("name")) {
-            m_factoryName = m_componentMetadata.getAttribute("name");
-        } else if (m_componentMetadata.containsAttribute("factory") && ! m_componentMetadata.getAttribute("factory").equalsIgnoreCase("false")) {
+        m_factoryName = m_componentMetadata.getAttribute("name");
+        if (m_factoryName == null) { // No factory name, try with factory attribute
             m_factoryName = m_componentMetadata.getAttribute("factory");
-        } else {
-            m_factoryName = m_componentMetadata.getAttribute("className");
+            if (m_factoryName == null || m_factoryName.equalsIgnoreCase("true") || m_factoryName.equalsIgnoreCase("false")) { // Avoid boolean case
+                m_factoryName = m_componentMetadata.getAttribute("className");
+            }
         }
     }
     
     /**
      * Compute factory state.
+     * @throws org.apache.felix.ipojo.ConfigurationException : occurs when the component type cannot be initialize.
      */
-    protected void computeFactoryState() {
+    protected void computeFactoryState() throws org.apache.felix.ipojo.ConfigurationException {
         boolean isValid = true;
         for (int i = 0; isValid && i < m_handlerIdentifiers.size(); i++) {
             HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
             isValid = hi.m_reference != null;
         }
-
-        if (isValid && m_componentDesc == null) {
-            try {
-                computeDescription();
-            } catch (org.apache.felix.ipojo.ConfigurationException e) {
-                m_logger.log(Logger.ERROR, "The component type metadata are not correct : " + e.getMessage());
-                stop();
+        
+        if (isValid) {
+            if (m_state == INVALID) {
+                
+                if (m_componentDesc == null) {
+                    computeDescription();
+                }
+                
+                m_state = VALID;
+                if (m_sr != null) {
+                    m_sr.setProperties(getProperties());
+                }
+                for (int i = 0; i < m_listeners.size(); i++) {
+                    ((FactoryStateListener) m_listeners.get(i)).stateChanged(this, VALID);
+                }
                 return;
             }
-        }
-
-        if (isValid && m_state == INVALID) {
-            m_state = VALID;
-            if (m_sr != null) {
-                m_sr.setProperties(getProperties());
-            }
-            for (int i = 0; i < m_listeners.size(); i++) {
-                ((FactoryStateListener) m_listeners.get(i)).stateChanged(this, VALID);
-            }
-            return;
-        }
-
-        if (!isValid && m_state == VALID) {
-            m_state = INVALID;
-
-            final Collection col = m_componentInstances.values();
-            final Iterator it = col.iterator();
-            while (it.hasNext()) {
-                InstanceManager ci = (InstanceManager) it.next();
-                if (ci.getState() != ComponentInstance.DISPOSED) {
-                    ci.kill();
+        } else {
+            if (m_state == VALID) {
+                m_state = INVALID;
+                
+                // Notify listeners.
+                for (int i = 0; i < m_listeners.size(); i++) {
+                    ((FactoryStateListener) m_listeners.get(i)).stateChanged(this, INVALID);
                 }
-                m_instancesName.remove(ci.getInstanceName());
-            }
 
-            m_componentInstances.clear();
+                // Dispose created instances.
+                final Collection col = m_componentInstances.values();
+                final Iterator it = col.iterator();
+                while (it.hasNext()) {
+                    InstanceManager ci = (InstanceManager) it.next();
+                    if (ci.getState() != ComponentInstance.DISPOSED) {
+                        ci.kill();
+                    }
+                    m_instancesName.remove(ci.m_name);
+                }
 
-            if (m_sr != null) {
-                m_sr.setProperties(getProperties());
-            }
+                m_componentInstances.clear();
 
-            for (int i = 0; i < m_listeners.size(); i++) {
-                ((FactoryStateListener) m_listeners.get(i)).stateChanged(this, INVALID);
+                // Update service properties TODO : really useful ?
+                if (m_sr != null) {
+                    m_sr.setProperties(getProperties());
+                }
+                
+                return;
             }
-            return;
         }
     }
     
@@ -763,15 +779,17 @@
             if (! m_handlerIdentifiers.contains(hi)) { m_handlerIdentifiers.add(hi); }
         }
         
-        // Add architecture if needed
-        HandlerIdentifier hi = new HandlerIdentifier("architecture", "");
-        if (! m_handlerIdentifiers.contains(hi) && m_componentMetadata.containsAttribute("architecture") && m_componentMetadata.getAttribute("architecture").equalsIgnoreCase("true")) {
+        // Add architecture if architecture != 'false'
+        HandlerIdentifier hi = new HandlerIdentifier("architecture", null);
+        String arch = m_componentMetadata.getAttribute("architecture");
+        if (arch == null || arch.equalsIgnoreCase("true")) {
             m_handlerIdentifiers.add(hi);
         }
         
         // Add lifecycle callback if immediate = true
-        HandlerIdentifier hi2 = new HandlerIdentifier("callback", "");
-        if (! m_handlerIdentifiers.contains(hi2) && m_componentMetadata.containsAttribute("immediate") && m_componentMetadata.getAttribute("immediate").equalsIgnoreCase("true")) {
+        HandlerIdentifier hi2 = new HandlerIdentifier("callback", null);
+        String imm = m_componentMetadata.getAttribute("immediate");
+        if (! m_handlerIdentifiers.contains(hi2) && imm != null && imm.equalsIgnoreCase("true")) {
             m_handlerIdentifiers.add(hi2);
         }
     }
@@ -781,8 +799,9 @@
      * @param ci : the destroyed instance
      */
     protected void disposed(ComponentInstance ci) {
-        m_instancesName.remove(ci.getInstanceName());
-        m_componentInstances.remove(ci.getInstanceName());
+        String name = ci.getInstanceName();
+        m_instancesName.remove(name);
+        m_componentInstances.remove(name);
     }
     
     /**
@@ -790,10 +809,10 @@
      * @return an non already used name
      */
     protected synchronized String generateName() {
-        String name = getName() + "-" + m_index;
+        String name = m_factoryName + "-" + m_index;
         while (m_instancesName.contains(name)) {
             m_index = m_index + 1;
-            name = getName() + "-" + m_index;
+            name = m_factoryName + "-" + m_index;
         }
         return name;
     }
@@ -802,7 +821,7 @@
      * Return the bundle context.
      * @return the Bundle Context.
      */
-    protected BundleContext getBundleContext() {
+    public BundleContext getBundleContext() {
         return m_context;
     }
 
@@ -831,7 +850,6 @@
             props.put("component.providedServiceSpecifications", m_componentDesc.getprovidedServiceSpecification());
             props.put("component.properties", m_componentDesc.getProperties());
             props.put("component.description", m_componentDesc);
-            props.put("component.desc", m_componentDesc.toString());
         }
         
         // Add factory state
@@ -850,30 +868,31 @@
         String name = (String) ref.getProperty(Handler.HANDLER_NAME_PROPERTY);
         String ns = (String) ref.getProperty(Handler.HANDLER_NAMESPACE_PROPERTY);
         if (IPojoConfiguration.IPOJO_NAMESPACE.equals(ns)) {
-            ns = "";
+            return name.equals(hi.m_name) && hi.m_namespace == null;
         }
         return name.equals(hi.m_name) && ns.equals(hi.m_namespace); 
     }
 
     /**
      * Return an handler object.
-     * 
      * @param hi : handler to create.
      * @param sc : service context in which create the handler (instance context).
      * @return the Handler object.
      */
     private HandlerManager getHandlerInstance(HandlerIdentifier hi, ServiceContext sc) {
-        Factory factory = hi.getFactory();
         try {
-            return (HandlerManager) factory.createComponentInstance(null, sc);
+            return (HandlerManager) hi.getFactory().createComponentInstance(null, sc);
         } catch (MissingHandlerException e) {
             m_logger.log(Logger.ERROR, "The creation of the handler " + hi.getFullName() + " has failed: " + e.getMessage());
+            stop();
             return null;
         } catch (UnacceptableConfiguration e) {
             m_logger.log(Logger.ERROR, "The creation of the handler " + hi.getFullName() + " has failed (UnacceptableConfiguration): " + e.getMessage());
+            stop();
             return null;
         } catch (org.apache.felix.ipojo.ConfigurationException e) {
             m_logger.log(Logger.ERROR, "The configuration of the handler " + hi.getFullName() + " has failed (ConfigurationException): " + e.getMessage());
+            stop();
             return null;
         }
     }
@@ -925,10 +944,11 @@
          * @see java.lang.Object#equals(java.lang.Object)
          */
         public boolean equals(Object o) {
-            if (o instanceof HandlerIdentifier) {
-                return ((HandlerIdentifier) o).getName().equalsIgnoreCase(m_name) && ((HandlerIdentifier) o).getNamespace().equalsIgnoreCase(m_namespace);
-            } 
-            return false;
+            if (m_namespace == null) {
+                return ((HandlerIdentifier) o).m_name.equalsIgnoreCase(m_name) && ((HandlerIdentifier) o).m_namespace == null;
+            } else {
+                return ((HandlerIdentifier) o).m_name.equalsIgnoreCase(m_name) && m_namespace.equalsIgnoreCase(((HandlerIdentifier) o).m_namespace);
+            }
         }
         
         /**
@@ -951,7 +971,7 @@
          * @return the handler full name
          */
         public String getFullName() {
-            if ("".equals(m_namespace)) {
+            if (m_namespace == null) {
                 return IPojoConfiguration.IPOJO_NAMESPACE + ":" + m_name;
             } else {
                 return m_namespace + ":" + m_name;
@@ -970,32 +990,32 @@
             return m_reference;
         }
         
-        public int getPriority() {
+        public int getLevel() {
             return m_level;
         }
         
         /**
-         * Set the service reference.
-         * If the new service reference is null, it unget the used factory (if already get).
-         * @param ref : new service reference.
+         * Release the reference of the used factory.
          */
-        public void setReference(ServiceReference ref) {
-            // First release the previous reference
+        public void unRef() {
             if (m_reference != null) {
                 m_tracker.ungetService(m_reference);
                 m_factory = null;
-                m_level = Integer.MAX_VALUE; // Reset the reference to 
+                m_reference = null;
             }
-            
+        }
+        
+        /**
+         * Set the service reference.
+         * If the new service reference is null, it unget the used factory (if already get).
+         * @param ref : new service reference.
+         */
+        public void setReference(ServiceReference ref) {            
             m_reference = ref;
-            // If the given reference is not null, set the priority.
-            if (m_reference != null) {
-                Integer p = (Integer) m_reference.getProperty(Handler.HANDLER_LEVEL_PROPERTY);
-                if (p != null) {
-                    m_level = p.intValue();
-                }
+            Integer p = (Integer) m_reference.getProperty(Handler.HANDLER_LEVEL_PROPERTY);
+            if (p != null) {
+                m_level = p.intValue();
             }
-            
         }
 
         /**
@@ -1032,14 +1052,12 @@
 
         /**
          * The defineClass method.
-         * 
          * @param name : name of the class
          * @param b : the byte array of the class
          * @param domain : the protection domain
          * @return : the defined class.
-         * @throws Exception : if a problem is detected during the loading
          */
-        public Class defineClass(String name, byte[] b, ProtectionDomain domain) throws Exception {
+        public Class defineClass(String name, byte[] b, ProtectionDomain domain) {
             if (m_definedClasses.containsKey(name)) {
                 return (Class) m_definedClasses.get(name);
             }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/CompositeFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/CompositeFactory.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/CompositeFactory.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/CompositeFactory.java Tue Oct 16 07:04:28 2007
@@ -65,13 +65,12 @@
      * @see org.apache.felix.ipojo.ComponentFactory#check(org.apache.felix.ipojo.metadata.Element)
      */
     public boolean check(Element cm) {
-     // Get the name
-        if (cm.containsAttribute("name")) {
-            m_factoryName = cm.getAttribute("name");
-            return true;
-        } else {
+        m_factoryName = cm.getAttribute("name");
+        if (m_factoryName == null) {
             System.err.println("A composite needs a name");
             return false;
+        } else {
+            return true;
         }
     }
     
@@ -89,13 +88,14 @@
         
         if ("composite".equals(type)) {
             if (IPojoConfiguration.IPOJO_NAMESPACE.equals(ns)) {
-                ns = "";
+                return name.equals(hi.getName()) && hi.getNamespace() == null;
             }
             return name.equals(hi.getName()) && ns.equals(hi.getNamespace()); 
         } else {
             return false;
         }
     }
+        
     
     /**
      * Compute required handlers.
@@ -108,9 +108,10 @@
             if (! m_handlerIdentifiers.contains(hi)) { m_handlerIdentifiers.add(hi); }
         }
         
-        // Add architecture if needed
-        if (m_componentMetadata.containsAttribute("architecture") && m_componentMetadata.getAttribute("architecture").equalsIgnoreCase("true")) {
-            HandlerIdentifier hi = new HandlerIdentifier("architecture", "");
+        // Add architecture if architecture != 'false'
+        String arch = m_componentMetadata.getAttribute("architecture");
+        if (arch == null || arch.equalsIgnoreCase("true")) {
+            HandlerIdentifier hi = new HandlerIdentifier("architecture", null);
             if (! m_handlerIdentifiers.contains(hi)) { m_handlerIdentifiers.add(hi); }
         }
     }
@@ -119,7 +120,9 @@
      * Stop all the instance managers.
      */
     public synchronized void stop() {
-        m_tracker.close();
+        if (m_tracker != null) {
+            m_tracker.close();
+        }
         
         final Collection col = m_componentInstances.values();
         final Iterator it = col.iterator();
@@ -148,22 +151,29 @@
         if (m_componentDesc != null) { // Already started.
             return;
         } 
-        try {
-            String filter = "(&(" + Constants.OBJECTCLASS + "=" + Factory.class.getName() + ")"
-                    + "(" + Handler.HANDLER_NAME_PROPERTY + "=*)" + "(" + Handler.HANDLER_NAMESPACE_PROPERTY + "=*)" /* Look only for handlers */
+        if (m_handlerIdentifiers.size() != 0) {
+            try {
+                String filter = "(&(" + Constants.OBJECTCLASS + "=" + Factory.class.getName() + ")"
                     + "(" + Handler.HANDLER_TYPE_PROPERTY + "=" + CompositeHandler.HANDLER_TYPE + ")" 
                     + "(factory.state=1)"
                     + ")";
-            m_tracker = new Tracker(m_context, m_context.createFilter(filter), this);
-            m_tracker.open();
-            
-        } catch (InvalidSyntaxException e) {
-            m_logger.log(Logger.ERROR, "A factory filter is not valid: " + e.getMessage());
+                m_tracker = new Tracker(m_context, m_context.createFilter(filter), this);
+                m_tracker.open();
+            } catch (InvalidSyntaxException e) {
+                m_logger.log(Logger.ERROR, "A factory filter is not valid: " + e.getMessage());
+                stop();
+                return;
+            }
+        }
+
+        try {
+            computeFactoryState();
+        } catch (ConfigurationException e) {
+            m_logger.log(Logger.ERROR, "The component type metadata are not correct : " + e.getMessage());
+            stop();
             return;
         }
         
-        computeFactoryState();
-        
         // Check if the factory should be exposed
         if (m_isPublic) {
             // Exposition of the factory service
@@ -184,7 +194,6 @@
             props.put("component.providedServiceSpecifications", m_componentDesc.getprovidedServiceSpecification());
             props.put("component.properties", m_componentDesc.getProperties());
             props.put("component.description", m_componentDesc);
-            props.put("component.desc", m_componentDesc.toString());
         }
         
         // Add factory state
@@ -194,6 +203,10 @@
         
         return props;
     }
+    
+    public String getClassName() {
+        return "composite";
+    }
 
 
     /**
@@ -224,10 +237,6 @@
      * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
      */
     public synchronized ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
-        if (m_state == INVALID) {
-            throw new MissingHandlerException(getMissingHandlers());
-        }
-        
         if (configuration == null) {
             configuration = new Properties();
         }
@@ -301,8 +310,9 @@
     
     /**
      * Compute factory state.
+     * @throws ConfigurationException : occurs if the component type cannot be initialized correctly.
      */
-    protected void computeFactoryState() {
+    protected void computeFactoryState() throws ConfigurationException {
         boolean isValid = true;
         for (int i = 0; isValid && i < m_handlerIdentifiers.size(); i++) {
             HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
@@ -310,13 +320,7 @@
         }
 
         if (isValid && m_componentDesc == null) {
-            try {
-                computeDescription();
-            } catch (org.apache.felix.ipojo.ConfigurationException e) {
-                m_logger.log(Logger.ERROR, "The component type metadata are not correct : " + e.getMessage());
-                stop();
-                return;
-            }
+            computeDescription();
         }
 
         if (isValid && m_state == INVALID) {
@@ -367,7 +371,7 @@
             l.add(hi.getFullName());
         }
         
-        m_componentDesc = new ComponentDescription(getName(), "composite", m_state, l, getMissingHandlers(), m_context.getBundle().getBundleId());
+        m_componentDesc = new ComponentDescription(this);
        
         for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
             HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
@@ -391,12 +395,15 @@
             return (HandlerManager) factory.createComponentInstance(null, sc);
         } catch (MissingHandlerException e) {
             m_logger.log(Logger.ERROR, "The creation of the composite handler " + handler.getFullName() + " has failed: " + e.getMessage());
+            stop();
             return null;
         } catch (UnacceptableConfiguration e) {
             m_logger.log(Logger.ERROR, "The creation of the composite handler " + handler.getFullName() + " has failed (UnacceptableConfiguration): " + e.getMessage());
+            stop();
             return null;
         } catch (ConfigurationException e) {
             m_logger.log(Logger.ERROR, "The creation of the composite handler " + handler.getFullName() + " has failed (ConfigurationException): " + e.getMessage());
+            stop();
             return null;
         }
     }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/CompositeHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/CompositeHandler.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/CompositeHandler.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/CompositeHandler.java Tue Oct 16 07:04:28 2007
@@ -42,31 +42,13 @@
      * This method me be called only once time.
      * @param cm : the composite manager.
      */
-    public final void attach(ComponentInstance cm) {
+    protected final void attach(ComponentInstance cm) {
         m_manager = (CompositeManager) cm;
+        setLogger(m_manager.getFactory().getLogger());
     }
     
     public final CompositeManager getCompositeManager() {
         return m_manager;
-    }
-        
-    /**
-     * Log method.
-     * @param level : message level (Logger class constant)
-     * @param message : message to log
-     */
-    public void log(int level, String message) {
-        m_manager.getFactory().getLogger().log(level, message);
-    }
-    
-    /**
-     * Log method.
-     * @param level : message level (Logger class constant)
-     * @param message : message to log
-     * @param ex : exception to attach to the message
-     */
-    public void log(int level, String message, Throwable ex) {
-        m_manager.getFactory().getLogger().log(level, message, ex);
     }
     
     /**

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ConfigurationException.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ConfigurationException.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ConfigurationException.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ConfigurationException.java Tue Oct 16 07:04:28 2007
@@ -45,18 +45,30 @@
      * @param mes : message
      * @param typ : component type
      */
-    public ConfigurationException(String mes, String typ) {
+    ConfigurationException(String mes, String typ) {
         m_type = typ;
         m_message = mes;
     }
     
     /**
+     * Constructor.
+     * @param mes : message
+     */
+    public ConfigurationException(String mes) {
+        m_message = mes;
+    }
+    
+    /**
      * Get the error message.
      * @return the error message.
      * @see java.lang.Throwable#getMessage()
      */
     public String getMessage() {
-        return "The configuration is not correct for the type " + m_type + " : " + m_message;
+        if (m_type != null) {
+            return "The configuration is not correct for the type " + m_type + " : " + m_message;
+        } else {
+            return m_message;
+        }
     }
 
 }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java Tue Oct 16 07:04:28 2007
@@ -23,6 +23,7 @@
 
 import org.apache.felix.ipojo.architecture.ComponentDescription;
 import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.framework.BundleContext;
 
 /**
  * Component Type Factory Service. This service is exposed by a instance manager factory, and allows the dynamic creation of component instance.
@@ -117,5 +118,24 @@
      * @return the list containing the name of required handlers (Name : namespace:name)
      */
     List getRequiredHandlers();
+
+    /**
+     * Return the classname of the component type.
+     * For factories which does not contains a class, return "composite"
+     * @return the class name of the component type or "composite"
+     */
+    String getClassName();
+
+    /**
+     * Return the state of the factory.
+     * @return the state of the factory
+     */
+    int getState();
+
+    /**
+     * Get the bundle context of the factory.
+     * @return the bundle context of the factory.
+     */
+    BundleContext getBundleContext();
 
 }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Handler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Handler.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Handler.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Handler.java Tue Oct 16 07:04:28 2007
@@ -53,11 +53,26 @@
     public static final String HANDLER_LEVEL_PROPERTY = "handler.level";
     
     /**
+     * Handler logger.
+     */
+    private Logger m_logger;
+    
+    /**
+     * Set the logger use by this handler.
+     * @param logger : the logger object to use.
+     */
+    final void setLogger(Logger logger) {
+        m_logger = logger;
+    }
+    
+    /**
      * Log method.
      * @param level : message level (Logger class constant)
      * @param message : message to log
      */
-    public abstract void log(int level, String message);
+    public final void log(int level, String message) {
+        m_logger.log(level, message);
+    }
     
     /**
      * Log method.
@@ -65,7 +80,9 @@
      * @param message : message to log
      * @param ex : exception to attach to the message
      */
-    public abstract void log(int level, String message, Throwable ex);
+    public final void log(int level, String message, Throwable ex) {
+        m_logger.log(level, message, ex);
+    }
     
     /**
      * Get a plugged handler of the same container.
@@ -90,12 +107,7 @@
      * @return true if the handler is valid.
      */
     public final boolean isValid() {
-        if (this instanceof Pojo) {
-            return ((Pojo) this).getComponentInstance().getState() == ComponentInstance.VALID;
-        } else {
-            log(Logger.ERROR, "The handler is not a POJO : " + this.getClass().getName());
-            return false;
-        }
+        return ((Pojo) this).getComponentInstance().getState() == ComponentInstance.VALID;
     }
     
     
@@ -104,12 +116,7 @@
      * @return : the component instance.
      */
     public final ComponentInstance getInstance() {
-        if (this instanceof Pojo) {
-            return ((Pojo) this).getComponentInstance();
-        } else {
-            log(Logger.ERROR, "The handler is not a POJO : " + this.getClass().getName());
-            return null;
-        }
+        return ((Pojo) this).getComponentInstance();
     }
     
     /**

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerFactory.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerFactory.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerFactory.java Tue Oct 16 07:04:28 2007
@@ -19,15 +19,17 @@
 package org.apache.felix.ipojo;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Dictionary;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
 
+import org.apache.felix.ipojo.architecture.ComponentDescription;
 import org.apache.felix.ipojo.metadata.Element;
 import org.apache.felix.ipojo.util.Logger;
 import org.apache.felix.ipojo.util.Tracker;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceRegistration;
 
@@ -72,25 +74,27 @@
         super(bc, cm);
         
         // Get the name
-        if (cm.containsAttribute("name")) {
-            m_factoryName = cm.getAttribute("name").toLowerCase();
-        } else {
+        m_factoryName = cm.getAttribute("name").toLowerCase();
+        if (m_factoryName == null) {
             System.err.println("An Handler needs a name");
             return;
         }
         
         // Get the type
-        if (cm.containsAttribute("type")) {
-            m_type = cm.getAttribute("type");
+        String t = cm.getAttribute("type");
+        if (t != null) {
+            m_type = t;
         }
         
-        if (cm.containsAttribute("level")) {
-            m_level = new Integer(cm.getAttribute("level")).intValue();
+        String l = cm.getAttribute("level");
+        if (l != null) {
+            m_level = new Integer(l).intValue();
         }
         
         // Get the namespace
-        if (cm.containsAttribute("namespace")) {
-            m_namespace = cm.getAttribute("namespace").toLowerCase();
+        String ns = cm.getAttribute("namespace");
+        if (ns != null) {
+            m_namespace = ns.toLowerCase();
         }        
     }
     
@@ -114,27 +118,33 @@
      * Start all the instance managers.
      */
     public synchronized void start() {
-        if (m_componentDesc != null) { // Already started.
+        if (m_sr != null) { // Already started.
             return;
-        } 
+        }
         
-        try {
-            String filter = "(&(" + Constants.OBJECTCLASS + "=" + Factory.class.getName() + ")"
-                    + "(" + Handler.HANDLER_NAME_PROPERTY + "=*)" + "(" + Handler.HANDLER_NAMESPACE_PROPERTY + "=*)" /* Look only for handlers */
-                    + "(" + Handler.HANDLER_TYPE_PROPERTY + "=" + PrimitiveHandler.HANDLER_TYPE + ")" 
+        if (m_handlerIdentifiers.size() != 0) {
+            try {
+                String filter = "(&(" + Handler.HANDLER_TYPE_PROPERTY + "=" + PrimitiveHandler.HANDLER_TYPE + ")" 
                     + "(factory.state=1)"
                     + ")";
-            m_tracker = new Tracker(m_context, m_context.createFilter(filter), this);
-            m_tracker.open();
-            
-        } catch (InvalidSyntaxException e) {
-            m_logger.log(Logger.ERROR, "A factory filter is not valid: " + e.getMessage());
-            return;
+                m_tracker = new Tracker(m_context, m_context.createFilter(filter), this);
+                m_tracker.open();
+            } catch (InvalidSyntaxException e) {
+                m_logger.log(Logger.ERROR, "A factory filter is not valid: " + e.getMessage());
+                stop();
+                return;
+            }
         }
                 
-        computeFactoryState();
+        try {
+            computeFactoryState();
+        } catch (ConfigurationException e) {
+            m_logger.log(Logger.ERROR, "Cannot initilize the factory " + e.getMessage());
+            stop();
+            return;
+        }
         
-        // Exposition of the factory service
+        // Exposition of the factory service (always public for handlers)
         m_sr = m_context.registerService(new String[] { Factory.class.getName()}, this, getProperties());
     }
     
@@ -149,20 +159,18 @@
             m_sr = null;
         }
         
-        m_tracker.close();
+        if (m_tracker != null) {
+            m_tracker.close();
+            m_tracker = null;
+        }
         
         // Release each handler
         for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
-            HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
-            if (hi.getReference() != null) {
-                hi.setReference(null);
-            }
+            ((HandlerIdentifier) m_handlerIdentifiers.get(i)).unRef();
         }
         
         m_handlerIdentifiers.clear();        
         m_listeners.clear();
-        m_tracker = null;
-        m_componentDesc = null;
         m_state = INVALID;        
     }
     
@@ -174,7 +182,10 @@
      * @see org.apache.felix.ipojo.ComponentFactory#getProperties()
      */
     protected Properties getProperties() {
-        final Properties props = super.getProperties();
+        Properties props = new Properties();
+        
+        // Add factory state
+        props.put("factory.state", "" + m_state);
 
         props.put(Handler.HANDLER_NAME_PROPERTY, m_factoryName);
         props.put(Handler.HANDLER_NAMESPACE_PROPERTY, m_namespace);
@@ -187,6 +198,73 @@
     }
     
     /**
+     * Compute handler factory state.
+     * @throws ConfigurationException : occurs when an handler cannot be initialized.
+     */
+    protected void computeFactoryState() throws ConfigurationException {
+        boolean isValid = true;
+        for (int i = 0; isValid && i < m_handlerIdentifiers.size(); i++) {
+            HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
+            isValid = hi.getReference() != null;
+        }
+        
+        if (isValid) {            
+            if (m_state == INVALID) {
+                m_state = VALID;
+                
+                if (m_sr == null) {
+                    m_componentDesc = new ComponentDescription(this);
+                    for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
+                        HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
+                        HandlerManager hm = getHandlerInstance(hi, null);
+                        hm.getHandler();
+                        Handler ch = hm.getHandler();
+                        ch.setLogger(getLogger());
+                        ch.initializeComponentFactory(m_componentDesc, m_componentMetadata);
+                        ((Pojo) ch).getComponentInstance().dispose();
+                    }
+                }
+                
+                if (m_sr != null) {
+                    m_sr.setProperties(getProperties());
+                }
+                for (int i = 0; i < m_listeners.size(); i++) {
+                    ((FactoryStateListener) m_listeners.get(i)).stateChanged(this, VALID);
+                }
+                return;
+            }
+        } else {
+            if (m_state == VALID) {
+                m_state = INVALID;
+                
+                // Notify listeners.
+                for (int i = 0; i < m_listeners.size(); i++) {
+                    ((FactoryStateListener) m_listeners.get(i)).stateChanged(this, INVALID);
+                }
+
+                // Dispose created instances.
+                final Collection col = m_componentInstances.values();
+                final Iterator it = col.iterator();
+                while (it.hasNext()) {
+                    InstanceManager ci = (InstanceManager) it.next();
+                    if (ci.getState() != ComponentInstance.DISPOSED) {
+                        ci.kill();
+                    }
+                    m_instancesName.remove(ci.m_name);
+                }
+
+                m_componentInstances.clear();
+
+                if (m_sr != null) {
+                    m_sr.setProperties(getProperties());
+                }
+                
+                return;
+            }
+        }
+    }
+    
+    /**
      * Create an instance. The given configuration needs to contain the 'name'
      * property.
      * @param configuration : configuration of the created instance.
@@ -199,7 +277,7 @@
      * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
      */
     public synchronized ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext) throws UnacceptableConfiguration, MissingHandlerException, org.apache.felix.ipojo.ConfigurationException {
-        if (m_state == INVALID) {
+        if (m_state == Factory.INVALID) {
             throw new MissingHandlerException(getMissingHandlers());
         }
         
@@ -207,14 +285,6 @@
             configuration = new Properties();
         }
         
-        try {
-            checkAcceptability(configuration);
-        } catch (UnacceptableConfiguration e) {
-            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());
-        }
-
-        
         String in = null;
         if (configuration.get("name") != null) {
             in = (String) configuration.get("name");
@@ -257,17 +327,19 @@
      * @return the Handler object.
      */
     private HandlerManager getHandlerInstance(HandlerIdentifier hi, ServiceContext sc) {
-        Factory factory = hi.getFactory();
         try {
-            return (HandlerManager) factory.createComponentInstance(null, sc);
+            return (HandlerManager) hi.getFactory().createComponentInstance(null, sc);
         } catch (MissingHandlerException e) {
             m_logger.log(Logger.ERROR, "The creation of the handler " + hi.getFullName() + " has failed: " + e.getMessage());
+            stop();
             return null;
         } catch (UnacceptableConfiguration e) {
             m_logger.log(Logger.ERROR, "The creation of the handler " + hi.getFullName() + " has failed (UnacceptableConfiguration): " + e.getMessage());
+            stop();
             return null;
         } catch (org.apache.felix.ipojo.ConfigurationException e) {
             m_logger.log(Logger.ERROR, "The configuration of the handler " + hi.getFullName() + " has failed (ConfigurationException): " + e.getMessage());
+            stop();
             return null;
         }
     }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManager.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManager.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManager.java Tue Oct 16 07:04:28 2007
@@ -151,9 +151,4 @@
         m_handler = null;
     }
 
-    
-    
-    
-   
-
 }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceCreator.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceCreator.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceCreator.java Tue Oct 16 07:04:28 2007
@@ -188,10 +188,13 @@
             config.setFactory(fact.getName());
         } catch (UnacceptableConfiguration e) {
             m_logger.log(Logger.ERROR, "A factory is available for the configuration but the configuration is not acceptable", e);
+            stop();
         } catch (MissingHandlerException e) {
             m_logger.log(Logger.ERROR, "The instance creation has failed, at least one handler is missing", e);
+            stop();
         } catch (ConfigurationException e) {
             m_logger.log(Logger.ERROR, "The instance creation has failed, an error during the configuration has occured", e);
+            stop();
         }
     }
 

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java Tue Oct 16 07:04:28 2007
@@ -106,6 +106,11 @@
      * Queue of stored state changed. 
      */
     private List m_stateQueue = new ArrayList();
+    
+    /**
+     * Map of [field, value], storing POJO field value.
+     */
+    private Map m_map = new HashMap();
 
     /**
      * Construct a new Component Manager.
@@ -258,6 +263,7 @@
             m_handlers[i].dispose();
         }
         
+        m_map.clear();
         m_handlers = new HandlerManager[0];
         m_fieldRegistration = new HashMap();
         m_methodRegistration = new HashMap();
@@ -286,6 +292,7 @@
             m_handlers[i].dispose();
         }
         
+        m_map.clear();
         m_handlers = new HandlerManager[0];
         m_fieldRegistration = new HashMap();
         m_methodRegistration = new HashMap();
@@ -393,6 +400,7 @@
             m_clazz = m_factory.loadClass(m_className);
         } catch (ClassNotFoundException e) {
             m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Class not found during the loading phase : " + e.getMessage());
+            stop();
             return;
         }
     }
@@ -488,19 +496,24 @@
 
         } catch (InstantiationException e) {
             m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> The Component Instance cannot be instancied : " + e.getMessage());
+            stop();
         } catch (IllegalAccessException e) {
             m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> The Component Instance is not accessible : " + e.getMessage());
+            stop();
         } catch (SecurityException e) {
-            m_factory.getLogger().log(Logger.ERROR,
-                    "[" + m_name + "] createInstance -> The Component Instance is not accessible (security reason) : " + e.getMessage());
+            m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> The Component Instance is not accessible (security reason) : " + e.getMessage());
+            stop();
         } catch (InvocationTargetException e) {
             m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> Cannot invoke the constructor method (illegal target) : " + e.getMessage());
             e.printStackTrace();
+            stop();
         } catch (NoSuchMethodException e) {
             m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> Cannot invoke the constructor (method not found) : " + e.getMessage());
+            stop();
         }
         if (instance == null) {
             m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> Cannot create the instance");
+            stop();
         }
 
         // Register the new instance
@@ -661,26 +674,37 @@
      * 
      * @param fieldName : the field name on which the GETFIELD instruction is
      * called
-     * @param initialValue : the value of the field in the code
      * @return the value decided by the last asked handler (throw a warning if
      * two fields decide two different values)
      */
-    public synchronized Object getterCallback(String fieldName, Object initialValue) {
-        Object result = null;
+    public synchronized Object getterCallback(String fieldName) {
+        Object initialValue = m_map.get(fieldName);
+        Object result = initialValue;
         // Get the list of registered handlers
         PrimitiveHandler[] list = (PrimitiveHandler[]) m_fieldRegistration.get(fieldName);
         for (int i = 0; list != null && i < list.length; i++) {
             Object handlerResult = list[i].getterCallback(fieldName, initialValue);
-            if (handlerResult != initialValue) {
+            if (handlerResult == initialValue) {
+                continue; // Non-binding case (default implementation).
+            } else {
+                if (result != initialValue) {
+                    if ((handlerResult != null && ! handlerResult.equals(result)) || (result != null && handlerResult == null)) {
+                        m_factory.getLogger().log(Logger.WARNING, "A conflict was detected on the injection of " + fieldName + " - return the last value from " + list[i].getInstance().getInstanceName());
+                    }
+                }
                 result = handlerResult;
             }
         }
-
-        if (result != null) {
-            return result;
-        } else {
-            return initialValue;
+        
+        if ((result != null && ! result.equals(initialValue)) || (result == null && initialValue != null)) {
+            // A change occurs => notify the change
+            m_map.put(fieldName, result);
+            for (int i = 0; list != null && i < list.length; i++) {
+                list[i].setterCallback(fieldName, result);
+            }
         }
+        
+        return result;        
     }
     
     /**
@@ -717,11 +741,13 @@
      * @param objectValue : the value of the field
      */
     public synchronized void setterCallback(String fieldName, Object objectValue) {
-        // Get the list of registered handlers
-        PrimitiveHandler[] list = (PrimitiveHandler[]) m_fieldRegistration.get(fieldName);
-
-        for (int i = 0; list != null && i < list.length; i++) {
-            list[i].setterCallback(fieldName, objectValue);
+        Object o = m_map.get(fieldName);
+        if ((o != null && ! o.equals(objectValue)) || (o == null && objectValue != null)) {
+            m_map.put(fieldName, objectValue);
+            PrimitiveHandler[] list = (PrimitiveHandler[]) m_fieldRegistration.get(fieldName);
+            for (int i = 0; list != null && i < list.length; i++) {
+                list[i].setterCallback(fieldName, objectValue);
+            }
         }
     }
 
@@ -793,11 +819,6 @@
             }
             setState(VALID);
             return;
-        }
-        
-        if (newState == DISPOSED) {
-            dispose();
-        }
-        
+        }        
     }
 }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java Tue Oct 16 07:04:28 2007
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.ipojo;
 
+
+
 /**
 * Abstract class to extends for primitive handler.
 * 
@@ -42,6 +44,7 @@
      */
     protected final void attach(ComponentInstance im) {
         m_manager = (InstanceManager) im;
+        setLogger(m_manager.getFactory().getLogger());
     }
     
     public InstanceManager getInstanceManager() {
@@ -49,25 +52,6 @@
     }
     
     /**
-     * Log method.
-     * @param level : message level (Logger class constant)
-     * @param message : message to log
-     */
-    public void log(int level, String message) {
-        m_manager.getFactory().getLogger().log(level, message);
-    }
-    
-    /**
-     * Log method.
-     * @param level : message level (Logger class constant)
-     * @param message : message to log
-     * @param ex : exception to attach to the message
-     */
-    public void log(int level, String message, Throwable ex) {
-        m_manager.getFactory().getLogger().log(level, message, ex);
-    }
-    
-    /**
      * Get a plugged handler of the same container.
      * This method must be call only in the start method (or after). 
      * In the configure method, this method can not return a consistent
@@ -84,12 +68,14 @@
      * @param fieldName : the field name
      * @param value : the value passed to the field
      */
-    public void setterCallback(String fieldName, Object value) { }
+    public void setterCallback(String fieldName, Object value) {
+        return;
+    }
 
     /**
      * This method is called when a GETFIELD operation is detected.
      * @param fieldName : the field name
-     * @param value : the value passed to the field (by the previous handler)
+     * @param value : the value passed to the field (by the previous call)
      * @return : the managed value of the field
      */
     public Object getterCallback(String fieldName, Object value) {

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java Tue Oct 16 07:04:28 2007
@@ -18,11 +18,14 @@
  */
 package org.apache.felix.ipojo.architecture;
 
+import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.felix.ipojo.ComponentFactory;
 import org.apache.felix.ipojo.Factory;
 import org.apache.felix.ipojo.metadata.Attribute;
 import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.framework.BundleContext;
 
 /**
  * Component Type description.
@@ -36,56 +39,32 @@
     private String[] m_providedServiceSpecification = new String[0];
 
     /**
-     * Component Type implementation class.
-     */
-    private String m_className;
-
-    /**
      * Configuration Properties accepted by the component type.
      */
     private PropertyDescription[] m_properties = new PropertyDescription[0];
-
+    
     /**
-     * Get the name of this component type.
+     * List of required properties.
+     * This list contains only property which does not have a default value.
      */
-    private String m_name;
+    private List m_requiredProperties = new ArrayList();
 
-    /**
-     * Bundle Id of the bundle containing this type.
-     */
-    private long m_bundleId;
-
-    /**
-     * State of the factory.
-     */
-    private int m_state;
-
-    /**
-     * Required handler list.
-     */
-    private List m_rh;
 
     /**
-     * Missing handler list.
+     * Represented factory.
      */
-    private List m_mh;
-
+    private Factory m_factory;
+    
     /**
      * Constructor.
-     * @param name : name.
-     * @param className : implementation class or "composite"
-     * @param state : state of the type (valid or invalid)
-     * @param rh : required handler list
-     * @param mh : missing handler list
-     * @param bundle : bundle containing the type
-     */
-    public ComponentDescription(String name, String className, int state, List rh, List mh, long bundle) {
-        m_name = name;
-        m_className = className;
-        m_bundleId = bundle;
-        m_state = state;
-        m_rh = rh;
-        m_mh = mh;
+     * @param factory : represented factory.
+     */
+    public ComponentDescription(Factory factory) {
+        m_factory = factory;
+    }
+    
+    public List getRequiredProperties() {
+        return m_requiredProperties;
     }
 
     /**
@@ -102,7 +81,7 @@
      * @return the component type implementation class name.
      */
     public String getClassName() {
-        return m_className;
+        return m_factory.getClassName();
     }
 
     /**
@@ -128,18 +107,27 @@
      * @param pd : the property to add
      */
     public void addProperty(PropertyDescription pd) {
-        if ("name".equals(pd.getName())) {
-            pd = new PropertyDescription(pd.getName(), pd.getType(), null); // Erase the instance name
+        String n = pd.getName();
+        if ("name".equals(n)) {
+            pd = new PropertyDescription(n, pd.getType(), null); // Instance name case.
         }
-
+        
+        // Check if the property is not already in the array
         for (int i = 0; i < m_properties.length; i++) {
-            if (m_properties[i].getName().equals(pd.getName())) { return; }
+            PropertyDescription desc = m_properties[i];
+            if (desc.getName().equals(n)) {
+                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;
+        
+        if (pd.getValue() == null) {
+            m_requiredProperties.add(n);
+        }
     }
 
     /**
@@ -166,7 +154,7 @@
      * @return the name of this component type
      */
     public String getName() {
-        return m_name;
+        return m_factory.getName();
     }
 
     /**
@@ -176,26 +164,27 @@
     public Element getDescription() {
         Element desc = new Element("Factory", "");
 
-        desc.addAttribute(new Attribute("name", m_name));
-        desc.addAttribute(new Attribute("bundle", "" + m_bundleId));
+        desc.addAttribute(new Attribute("name", m_factory.getName()));
+        desc.addAttribute(new Attribute("bundle", "" + ((ComponentFactory) m_factory).getBundleContext().getBundle().getBundleId()));
 
-        if (m_className != null) {
-            desc.addAttribute(new Attribute("Implementation-Class", m_className));
-        } else {
+        String cn = getClassName();
+        if (cn == null) {
             desc.addAttribute(new Attribute("Composite", "true"));
+        } else {
+            desc.addAttribute(new Attribute("Implementation-Class", getClassName()));
         }
 
         String state = "valid";
-        if (m_state == Factory.INVALID) {
+        if (m_factory.getState() == Factory.INVALID) {
             state = "invalid";
         }
         desc.addAttribute(new Attribute("state", state));
 
         // Display required & missing handlers
         Element rh = new Element("RequiredHandlers", "");
-        rh.addAttribute(new Attribute("list", m_rh.toString()));
+        rh.addAttribute(new Attribute("list", m_factory.getRequiredHandlers().toString()));
         Element mh = new Element("MissingHandlers", "");
-        mh.addAttribute(new Attribute("list", m_mh.toString()));
+        mh.addAttribute(new Attribute("list", m_factory.getMissingHandlers().toString()));
         desc.addElement(rh);
         desc.addElement(mh);
 
@@ -218,6 +207,10 @@
         }
 
         return desc;
+    }
+
+    public BundleContext getBundleContext() {
+        return m_factory.getBundleContext();
     }
 
 }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java Tue Oct 16 07:04:28 2007
@@ -30,6 +30,7 @@
 import org.apache.felix.ipojo.UnacceptableConfiguration;
 import org.apache.felix.ipojo.architecture.ComponentDescription;
 import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.framework.BundleContext;
 
 /**
  * Bridge representing a Factory inside a composition.
@@ -159,6 +160,18 @@
 
     public ComponentDescription getComponentDescription() {
         return m_delegate.getComponentDescription();
+    }
+
+    public String getClassName() {
+        return m_delegate.getClassName();
+    }
+
+    public int getState() {
+        return m_delegate.getState();
+    }
+
+    public BundleContext getBundleContext() {
+        return m_delegate.getBundleContext();
     }
 
 }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java Tue Oct 16 07:04:28 2007
@@ -241,7 +241,7 @@
                 conf = parseInstance(instances[i]);
             } catch (ParseException e) {
                 log(Logger.ERROR, "An instance cannot be parsed correctly", e);
-                throw new ConfigurationException("An instance cannot be parsed correctly : " + e.getMessage(), getCompositeManager().getFactory().getName());
+                throw new ConfigurationException("An instance cannot be parsed correctly : " + e.getMessage());
             }
             m_configurations[i] = new ManagedConfiguration(conf);
         }
@@ -255,12 +255,17 @@
      */
     private Dictionary parseInstance(Element instance) throws ParseException {
         Dictionary dict = new Properties();
-        if (instance.containsAttribute("name")) {
-            dict.put("name", instance.getAttribute("name"));
+        String name = instance.getAttribute("name");
+        if (name != null) {
+            dict.put("name", name);
+        }
+        
+        String comp = instance.getAttribute("component");
+        if (comp == null) { 
+            throw new ParseException("An instance does not have the 'component' attribute"); 
+        } else {
+            dict.put("component", comp);
         }
-        if (!instance.containsAttribute("component")) { throw new ParseException("An instance does not have the 'component' attribute"); }
-
-        dict.put("component", instance.getAttribute("component"));
 
         for (int i = 0; i < instance.getElements("property").length; i++) {
             parseProperty(instance.getElements("property")[i], dict);
@@ -277,10 +282,12 @@
      */
     private void parseProperty(Element prop, Dictionary dict) throws ParseException {
         // Check that the property has a name
-        if (!prop.containsAttribute("name")) { throw new ParseException("A property does not have the 'name' attribute"); }
+        String name = prop.getAttribute("name");
+        String value = prop.getAttribute("value");
+        if (name == null) { throw new ParseException("A property does not have the 'name' attribute"); }
         // Final case : the property element has a 'value' attribute
-        if (prop.containsAttribute("value")) {
-            dict.put(prop.getAttribute("name"), prop.getAttribute("value"));
+        if (value != null) {
+            dict.put(name, value);
         } else {
             // Recursive case
             // Check if there is 'property' element
@@ -301,7 +308,7 @@
     public void start() { 
         for (int j = 0; j < m_factories.length; j++) {
             String factName = m_factories[j].getName();
-            String className = m_factories[j].getComponentDescription().getClassName(); 
+            String className = m_factories[j].getClassName(); 
             for (int i = 0; i < m_configurations.length; i++) {
                 if (m_configurations[i].getInstance() == null && (m_configurations[i].getNeededFactoryName().equals(factName) || m_configurations[i].getNeededFactoryName().equals(className))) {
                     createInstance(m_factories[j], m_configurations[i]);

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/importer/ExportHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/importer/ExportHandler.java?rev=585146&r1=585145&r2=585146&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/importer/ExportHandler.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/importer/ExportHandler.java Tue Oct 16 07:04:28 2007
@@ -28,7 +28,6 @@
 import org.apache.felix.ipojo.architecture.ComponentDescription;
 import org.apache.felix.ipojo.architecture.HandlerDescription;
 import org.apache.felix.ipojo.metadata.Element;
-import org.apache.felix.ipojo.util.Logger;
 import org.osgi.framework.BundleContext;
 
 /**
@@ -64,15 +63,19 @@
      * Initialize the component type.
      * @param cd : component type description to populate.
      * @param metadata : component type metadata.
+     * @throws ConfigurationException : occurs when the 'specification' attribute is missing
      * @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentDescription, org.apache.felix.ipojo.metadata.Element)
      */
-    public void initializeComponentFactory(ComponentDescription cd, Element metadata) {
+    public void initializeComponentFactory(ComponentDescription cd, Element metadata) throws ConfigurationException {
         // Update the component type description
         Element[] exp = metadata.getElements("exports");
         for (int i = 0; i < exp.length; i++) {
-            if (exp[i].containsAttribute("specification")) { // Malformed exports
-                String specification = exp[i].getAttribute("specification");
-                cd.addProvidedServiceSpecification(specification);
+            String spec = exp[i].getAttribute("specification");
+            if (spec != null) { 
+                cd.addProvidedServiceSpecification(spec);
+            } else {
+                // Malformed exports
+                throw new ConfigurationException("Malformed exports - Missing the specification attribute");
             }
         }
     }
@@ -94,32 +97,21 @@
         for (int i = 0; i < exp.length; i++) {
             boolean optional = false;
             boolean aggregate = false;
-            String specification = null;
-
-            if (exp[i].containsAttribute("specification")) {
-                specification = exp[i].getAttribute("specification");
-                String filter = "(objectClass=" + specification + ")";
-                if (exp[i].containsAttribute("optional") && exp[i].getAttribute("optional").equalsIgnoreCase("true")) {
-                    optional = true;
-                }
-                if (exp[i].containsAttribute("aggregate") && exp[i].getAttribute("aggregate").equalsIgnoreCase("true")) {
-                    aggregate = true;
-                }
-                if (exp[i].containsAttribute("filter")) {
-                    String classnamefilter = "(objectClass=" + specification + ")";
-                    filter = null;
-                    if ("".equals(exp[i].getAttribute("filter"))) {
-                        filter = classnamefilter;
-                    } else {
-                        filter = "(&" + classnamefilter + exp[i].getAttribute("filter") + ")";
-                    }
-                }
-                ServiceExporter si = new ServiceExporter(specification, filter, aggregate, optional, m_scope, m_context, this);
-                m_exporters.add(si);
-            } else { // Malformed exports
-                log(Logger.ERROR, "Malformed exports : the specification attribute is mandatory");
-                throw new ConfigurationException("Malformed exports : the specification attribute is mandatory", getCompositeManager().getFactory().getName());
+            String specification = exp[i].getAttribute("specification");
+            String filter = "(objectClass=" + specification + ")";
+                
+            String opt = exp[i].getAttribute("optional");
+            optional =  opt != null && opt.equalsIgnoreCase("true");
+                
+            String agg = exp[i].getAttribute("aggregate");
+            aggregate = agg != null && agg.equalsIgnoreCase("true");
+
+            String f = exp[i].getAttribute("filter");
+            if (f != null) {
+                filter = "(&" + filter + f + ")";
             }
+            ServiceExporter si = new ServiceExporter(specification, filter, aggregate, optional, m_scope, m_context, this);
+            m_exporters.add(si);
         }
     }
 



Mime
View raw message