felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r633138 [7/7] - in /felix/sandbox/clement/ipojo: composite/ composite/src/main/java/org/apache/felix/ipojo/composite/ composite/src/main/java/org/apache/felix/ipojo/composite/architecture/ composite/src/main/java/org/apache/felix/ipojo/comp...
Date Mon, 03 Mar 2008 15:46:43 GMT
Copied: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java (from r631196, felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/AbstractServiceDependency.java)
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java?p2=felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java&p1=felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/AbstractServiceDependency.java&r1=631196&r2=633138&rev=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/AbstractServiceDependency.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java Mon Mar  3 07:46:27 2008
@@ -30,13 +30,15 @@
 import org.osgi.framework.ServiceReference;
 
 /**
- * Abstract dependency model. This class is the parent class of every service dependency. It manages the most part of dependency management. This class creates an insterface between the service tracker and the concrete dependency.
+ * Abstract dependency model. This class is the parent class of every service dependency. It manages the most part of dependency management. This
+ * class creates an insterface between the service tracker and the concrete dependency.
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public abstract class AbstractServiceDependency implements TrackerCustomizer {
+public abstract class DependencyModel implements TrackerCustomizer {
 
     /**
-     * Dependency state : BROKEN. A broken dependency cannot be fulfilled anymore. The dependency becomes broken when a used service disappears in the static binding policy.
+     * Dependency state : BROKEN. A broken dependency cannot be fulfilled anymore. The dependency becomes broken when a used service disappears in the
+     * static binding policy.
      */
     public static final int BROKEN = -1;
 
@@ -61,7 +63,8 @@
     public static final int STATIC_BINDING_POLICY = 1;
 
     /**
-     * Binding policy : Dynamic-Priority. In this policy, services can appears and departs. However, once a service with a highest ranking (according to the used comparator) appears, this new service is re-injected.
+     * Binding policy : Dynamic-Priority. In this policy, services can appears and departs. However, once a service with a highest ranking (according
+     * to the used comparator) appears, this new service is re-injected.
      */
     public static final int DYNAMIC_PRIORITY_BINDING_POLICY = 2;
 
@@ -94,11 +97,11 @@
      * Bundle context used by the dependency. (could be a service context).
      */
     private BundleContext m_context;
-    
+
     /**
-     * Listener object on which invoking the validate and invalidate methods. 
+     * Listener object on which invoking the validate and invalidate methods.
      */
-    private DependencyLifecycleListener m_listener;
+    private final DependencyStateListener m_listener;
 
     /**
      * Actual state of the dependency.
@@ -108,7 +111,7 @@
     /**
      * Binding policy of the dependency.
      */
-    private int m_policy = DYNAMIC_BINDING_POLICY;
+    private int m_policy = DYNAMIC_BINDING_POLICY; // Is notas we have to handler policy change in a future version.
 
     /**
      * Service tracker used by this dependency.
@@ -116,9 +119,10 @@
     private Tracker m_tracker;
 
     /**
-     * List of matching service references. This list is a subset of tracked references. This set is compute according to the filter and the match method.
+     * List of matching service references. This list is a subset of tracked references. This set is compute according to the filter and the match
+     * method.
      */
-    private List m_matchingReferences = new ArrayList();
+    private final List m_matchingRefs = new ArrayList();
 
     /**
      * Constructor.
@@ -131,7 +135,8 @@
      * @param context : bundle context (or service context)
      * @param listener : dependency lifecycle listener to notify from dependency state changes.
      */
-    public AbstractServiceDependency(Class specification, boolean aggregate, boolean optional, Filter filter, Comparator comparator, int policy, BundleContext context, DependencyLifecycleListener listener) {
+    public DependencyModel(Class specification, boolean aggregate, boolean optional, Filter filter, Comparator comparator, int policy,
+            BundleContext context, DependencyStateListener listener) {
         m_specification = specification;
         m_aggregate = aggregate;
         m_optional = optional;
@@ -168,7 +173,8 @@
     }
 
     /**
-     * Is the reference set frozen (cannot change anymore) ? This method must be override by concrete dependency to support the static binding policy. This method is just used by default. The method must always return false for non-static dependency.
+     * Is the reference set frozen (cannot change anymore) ? This method must be override by concrete dependency to support the static binding policy.
+     * This method is just used by default. The method must always return false for non-static dependency.
      * @return true if the reference set is frozen.
      */
     public boolean isFrozen() {
@@ -176,7 +182,8 @@
     }
 
     /**
-     * Does the service reference match ? This method must be override by concrete dependency if they need to advanced testing on service reference (that cannot be express in the LDAP filter). By default this method return true.
+     * Does the service reference match ? This method must be override by concrete dependency if they need to advanced testing on service reference
+     * (that cannot be express in the LDAP filter). By default this method return true.
      * @param ref : tested reference.
      * @return true
      */
@@ -193,7 +200,7 @@
         boolean mustCallValidate = false;
         boolean mustCallInvalidate = false;
         synchronized (this) {
-            if (m_optional || m_matchingReferences.size() > 0) {
+            if (m_optional || !m_matchingRefs.isEmpty()) {
                 // The dependency is valid
                 if (m_state == UNRESOLVED) {
                     m_state = RESOLVED;
@@ -240,7 +247,8 @@
     }
 
     /**
-     * Manage the arrival of a new service reference. The reference is valid and match the filter and the match method. This method has different behavior according to the binding policy.
+     * Manage the arrival of a new service reference. The reference is valid and match the filter and the match method. This method has different
+     * behavior according to the binding policy.
      * @param ref : the new reference
      */
     private void manageArrival(ServiceReference ref) {
@@ -250,14 +258,14 @@
         int size;
 
         synchronized (this) {
-            m_matchingReferences.add(ref);
+            m_matchingRefs.add(ref);
 
             // Sort the collection if needed.
             if (m_comparator != null) {
-                Collections.sort(m_matchingReferences, m_comparator);
+                Collections.sort(m_matchingRefs, m_comparator);
             }
 
-            size = m_matchingReferences.size();
+            size = m_matchingRefs.size();
         }
 
         if (m_aggregate) {
@@ -271,10 +279,11 @@
                 computeDependencyState();
             } else {
                 // In the case of a dynamic priority binding, we have to test if we have to update the bound reference
-                if (m_policy == DYNAMIC_PRIORITY_BINDING_POLICY && m_matchingReferences.get(0) == ref) {
-                    // We are sure that we have at least two references, so if the highest ranked references (first one) is the new received references,
+                if (m_policy == DYNAMIC_PRIORITY_BINDING_POLICY && m_matchingRefs.get(0) == ref) {
+                    // We are sure that we have at least two references, so if the highest ranked references (first one) is the new received
+                    // references,
                     // we have to unbind the used one and to bind the the new one.
-                    onServiceDeparture((ServiceReference) m_matchingReferences.get(1));
+                    onServiceDeparture((ServiceReference) m_matchingRefs.get(1));
                     onServiceArrival(ref);
                 }
             }
@@ -289,7 +298,7 @@
      * @see org.apache.felix.ipojo.util.TrackerCustomizer#removedService(org.osgi.framework.ServiceReference, java.lang.Object)
      */
     public void removedService(ServiceReference ref, Object arg1) {
-        if (m_matchingReferences.contains(ref)) {
+        if (m_matchingRefs.contains(ref)) {
             manageDeparture(ref, arg1);
         }
     }
@@ -308,33 +317,34 @@
             }
         } else {
             synchronized (this) {
-                m_matchingReferences.remove(ref);
+                m_matchingRefs.remove(ref);
             }
-            if (obj != null) {
+            if (obj == null) {
+                computeDependencyState(); // check if the dependency stills valid.
+            } else {
                 onServiceDeparture(ref);
                 ServiceReference newRef = getServiceReference();
-                if (newRef != null) { // Check if there is another provider.
+                if (newRef == null) { // Check if there is another provider.
+                    computeDependencyState(); // no more references.
+                } else {
                     if (!m_aggregate) {
                         onServiceArrival(newRef); // Injecting the new service reference for non aggregate dependencies.
                     }
-                } else {
-                    computeDependencyState(); // no more references.
                 }
-            } else {
-                computeDependencyState(); // check if the dependency stills valid.
             }
         }
 
     }
 
     /**
-     * Service tracker modified service callback. This method must handle if the modified service should be considered as a depart or an arrival. According to the dependency filter, a service can now match or can no match anymore.
+     * Service tracker modified service callback. This method must handle if the modified service should be considered as a depart or an arrival.
+     * According to the dependency filter, a service can now match or can no match anymore.
      * @param ref : modified reference
      * @param arg1 : service object if already get.
      * @see org.apache.felix.ipojo.util.TrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference, java.lang.Object)
      */
     public void modifiedService(ServiceReference ref, Object arg1) {
-        if (m_matchingReferences.contains(ref)) {
+        if (m_matchingRefs.contains(ref)) {
             // It's a used service. Check if the service always match.
             if (!(m_filter == null || m_filter.match(ref)) && match(ref)) {
                 // The service does not match anymore. Call removedService.
@@ -355,31 +365,51 @@
      * Get the next matching service reference.
      * @return null if no more provider is available, else return the first reference from the matching set.
      */
-    public synchronized ServiceReference getServiceReference() {
-        if (m_matchingReferences.isEmpty()) {
-            return null;
-        } else {
-            return (ServiceReference) m_matchingReferences.get(0);
+    public ServiceReference getServiceReference() {
+        synchronized (this) {
+            if (m_matchingRefs.isEmpty()) {
+                return null;
+            } else {
+                return (ServiceReference) m_matchingRefs.get(0);
+            }
         }
     }
-    
+
     /**
-     * Get matching service references. 
-     * @return the sorted (if a comparator is used) array of matching service references, null if no references are available. 
+     * Get matching service references.
+     * @return the sorted (if a comparator is used) array of matching service references, null if no references are available.
      */
-    public synchronized ServiceReference[] getServiceReferences() {
-        if (m_matchingReferences.isEmpty()) { return null; }
-        return (ServiceReference[]) m_matchingReferences.toArray(new ServiceReference[m_matchingReferences.size()]);
+    public ServiceReference[] getServiceReferences() {
+        synchronized (this) {
+            if (m_matchingRefs.isEmpty()) { return null; }
+            return (ServiceReference[]) m_matchingRefs.toArray(new ServiceReference[m_matchingRefs.size()]);
+        }
     }
-    
 
     /**
      * Get the list of currently used service references.
      * @return the list of used reference (according to the service tracker).
      */
     public List getUsedServiceReferences() {
-        return m_tracker.getUsedServiceReferences();
-        //TODO : does this method support dependency reconfiguration ?
+        synchronized (this) {
+            // The list must confront actual matching services with already get services from the tracker.
+
+            int size = m_matchingRefs.size();
+            List usedByTracker = m_tracker.getUsedServiceReferences();
+            if (size == 0 || usedByTracker == null) { return null; }
+
+            List list = new ArrayList(1);
+            for (int i = 0; i < size; i++) {
+                if (usedByTracker.contains(m_matchingRefs.get(i))) {
+                    list.add(m_matchingRefs.get(i)); // Add the service in the list.
+                    if (!isAggregate()) { // IF we are not multiple, return the list when the first element is found.
+                        return list;
+                    }
+                }
+            }
+
+            return list;
+        }
     }
 
     /**
@@ -387,7 +417,7 @@
      * @return the number of matching references
      */
     public int getSize() {
-        return m_matchingReferences.size();
+        return m_matchingRefs.size();
     }
 
     /**
@@ -401,10 +431,10 @@
      * @param ref : the leaving service reference.
      */
     public abstract void onServiceDeparture(ServiceReference ref);
-    
+
     /**
-     * This method can be override by the concrete dependency to be notified of service modification.
-     * This modification is not an arrival or a departure.
+     * This method can be override by the concrete dependency to be notified of service modification. This modification is not an arrival or a
+     * departure.
      * @param ref : modified service reference.
      */
     public void onServiceModification(ServiceReference ref) {
@@ -412,7 +442,8 @@
     }
 
     /**
-     * Concrete dependency callback. This method is called when the dependency is reconfigured and when this reconfiguration implies changes on the matching service set ( and by the way on the injected service).
+     * Concrete dependency callback. This method is called when the dependency is reconfigured and when this reconfiguration implies changes on the
+     * matching service set ( and by the way on the injected service).
      * @param departs : service leaving the matching set.
      * @param arrivals : service arriving in the matching set.
      */
@@ -464,7 +495,7 @@
      * Set the filter of the dependency. This method recompute the matching set and call the onDependencyReconfiguration callback.
      * @param filter : new LDAP filter.
      */
-    public void setFilter(Filter filter) {
+    public void setFilter(Filter filter) { //NOPMD
         m_filter = filter;
         if (m_tracker != null) { // Tracking started ...
             List toRemove = new ArrayList();
@@ -473,14 +504,21 @@
             synchronized (this) {
 
                 // Store the used service references.
-                if (!m_aggregate && m_matchingReferences.size() > 0) {
-                    usedRef = (ServiceReference) m_matchingReferences.get(0);
+                if (!m_aggregate && !m_matchingRefs.isEmpty()) {
+                    usedRef = (ServiceReference) m_matchingRefs.get(0);
                 }
 
                 // Get actually all tracked references.
                 ServiceReference[] refs = m_tracker.getServiceReferences();
 
-                if (refs != null) {
+                if (refs == null) {
+                    for (int j = 0; j < m_matchingRefs.size(); j++) {
+                        // All references need to be removed.
+                        toRemove.add(m_matchingRefs.get(j));
+                    }
+                    // No more matching dependency. Clear the matching reference set.
+                    m_matchingRefs.clear();
+                } else {
                     // Compute matching services.
                     List matching = new ArrayList();
                     for (int i = 0; i < refs.length; i++) {
@@ -489,8 +527,8 @@
                         }
                     }
                     // Now compare with used services.
-                    for (int j = 0; j < m_matchingReferences.size(); j++) {
-                        ServiceReference ref = (ServiceReference) m_matchingReferences.get(j);
+                    for (int j = 0; j < m_matchingRefs.size(); j++) {
+                        ServiceReference ref = (ServiceReference) m_matchingRefs.get(j);
                         // Check if the reference is inside the matching list:
                         if (!matching.contains(ref)) {
                             // The reference should be removed
@@ -499,31 +537,24 @@
                     }
 
                     // Then remove services which do no more match.
-                    m_matchingReferences.removeAll(toRemove);
+                    m_matchingRefs.removeAll(toRemove);
 
                     // Then, add new matching services.
 
                     for (int k = 0; k < matching.size(); k++) {
-                        if (!m_matchingReferences.contains(matching.get(k))) {
-                            m_matchingReferences.add(matching.get(k));
+                        if (!m_matchingRefs.contains(matching.get(k))) {
+                            m_matchingRefs.add(matching.get(k));
                             toAdd.add(matching.get(k));
                         }
                     }
-                    
+
                     // Sort the collections if needed.
                     if (m_comparator != null) {
-                        Collections.sort(m_matchingReferences, m_comparator);
+                        Collections.sort(m_matchingRefs, m_comparator);
                         Collections.sort(toAdd, m_comparator);
                         Collections.sort(toRemove, m_comparator);
                     }
-                    
-                } else {
-                    for (int j = 0; j < m_matchingReferences.size(); j++) {
-                        // All references need to be removed.
-                        toRemove.add(m_matchingReferences.get(j));
-                    }
-                    // No more matching dependency. Clear the matching reference set.
-                    m_matchingReferences.clear();
+
                 }
             }
 
@@ -531,47 +562,44 @@
             if (m_aggregate) {
                 ServiceReference[] rem = null;
                 ServiceReference[] add = null;
-                if (toAdd.size() > 0) {
+                if (!toAdd.isEmpty()) {
                     add = (ServiceReference[]) toAdd.toArray(new ServiceReference[toAdd.size()]);
                 }
-                if (toRemove.size() > 0) {
+                if (!toRemove.isEmpty()) {
                     rem = (ServiceReference[]) toRemove.toArray(new ServiceReference[toRemove.size()]);
                 }
-                onDependencyReconfiguration(rem, add); //TODO : In the case where both set are null, does we notify no change ? 
+                if (rem != null || add != null) { // Notify the change only when a change is made on the matching reference list.
+                    onDependencyReconfiguration(rem, add);
+                }
             } else {
-                // Create a local copy to avoid un-sync reference list access. 
+                // Create a local copy to avoid un-sync reference list access.
                 int size;
                 ServiceReference newRef = null;
-                synchronized (m_matchingReferences) {
-                    size = m_matchingReferences.size();
+                synchronized (m_matchingRefs) {
+                    size = m_matchingRefs.size();
                     if (size > 0) {
-                        newRef = (ServiceReference) m_matchingReferences.get(0);
+                        newRef = (ServiceReference) m_matchingRefs.get(0);
                     }
                 }
                 // Non aggregate case.
-                // If the used reference was not null 
-                if (usedRef != null) {
+                // If the used reference was not null
+                if (usedRef == null) {
+                    // The used ref was null,
+                    if (size > 0) {
+                        onDependencyReconfiguration(null, new ServiceReference[] { newRef });
+                    } // Don't notify the change, if the set is not touched by the reconfiguration.
+                } else {
                     // If the used ref disappears, inject a new service if available, else reinject null.
                     if (toRemove.contains(usedRef)) {
                         // We have to replace the service.
                         if (size > 0) {
-                            onDependencyReconfiguration(new ServiceReference[] {usedRef}, new ServiceReference[] {newRef});
+                            onDependencyReconfiguration(new ServiceReference[] { usedRef }, new ServiceReference[] { newRef });
                         } else {
-                            onDependencyReconfiguration(new ServiceReference[] {usedRef}, null);
+                            onDependencyReconfiguration(new ServiceReference[] { usedRef }, null);
                         }
-                    } else if (m_policy == DYNAMIC_PRIORITY_BINDING_POLICY) {
+                    } else if (m_policy == DYNAMIC_PRIORITY_BINDING_POLICY && newRef != usedRef) { //NOPMD
                         // In the case of dynamic-priority, check if the used ref is no more the highest reference
-                        if (newRef != usedRef) {
-                            onDependencyReconfiguration(new ServiceReference[] {usedRef}, new ServiceReference[] {newRef});
-                        }
-                    }
-                } else {
-                    // The used ref was null, 
-                    if (size > 0) {
-                        onDependencyReconfiguration(null, new ServiceReference[] {newRef});
-                    } else {
-                        // TODO : Is is really useful : notify no change ?
-                        onDependencyReconfiguration(null, null);
+                        onDependencyReconfiguration(new ServiceReference[] { usedRef }, new ServiceReference[] { newRef });
                     }
                 }
             }
@@ -585,17 +613,15 @@
      * @return the String form of the LDAP filter used by this dependency, null if not set.
      */
     public String getFilter() {
-        if (m_filter != null) {
-            return m_filter.toString();
-        } else {
+        if (m_filter == null) {
             return null;
+        } else {
+            return m_filter.toString();
         }
     }
 
     /**
-     * Set the aggregate attribute of the current dependency.
-     * If the tracking is open, it will call arrival and 
-     * departure callbacks.
+     * Set the aggregate attribute of the current dependency. If the tracking is open, it will call arrival and departure callbacks.
      * @param isAggregate : new aggregate attribute value.
      */
     public synchronized void setAggregate(boolean isAggregate) {
@@ -608,16 +634,16 @@
                 // Call the callback on all non already injected service.
                 if (m_state == RESOLVED) {
 
-                    for (int i = 1; i < m_matchingReferences.size(); i++) { // The loop begin at 1, as the 0 is already injected.
-                        onServiceArrival((ServiceReference) m_matchingReferences.get(i));
+                    for (int i = 1; i < m_matchingRefs.size(); i++) { // The loop begin at 1, as the 0 is already injected.
+                        onServiceArrival((ServiceReference) m_matchingRefs.get(i));
                     }
                 }
             } else if (m_aggregate && !isAggregate) {
                 m_aggregate = false;
                 // We become non-aggregate.
                 if (m_state == RESOLVED) {
-                    for (int i = 1; i < m_matchingReferences.size(); i++) { // The loop begin at 1, as the 0 stills injected.
-                        onServiceDeparture((ServiceReference) m_matchingReferences.get(i));
+                    for (int i = 1; i < m_matchingRefs.size(); i++) { // The loop begin at 1, as the 0 stills injected.
+                        onServiceDeparture((ServiceReference) m_matchingRefs.get(i));
                     }
                 }
             }
@@ -640,7 +666,7 @@
             computeDependencyState();
         }
     }
-    
+
     public boolean isOptional() {
         return m_optional;
     }
@@ -652,36 +678,32 @@
     public int getBindingPolicy() {
         return m_policy;
     }
-    
+
     /**
-     * Set the binding policy.
-     * Not yet supported.
+     * Set the binding policy. Not yet supported.
      */
     public void setBindingPolicy() {
         throw new UnsupportedOperationException("Binding Policy change is not yet supported");
-        //TODO supporting dynamic policy change. 
+        // TODO supporting dynamic policy change.
     }
 
-
     public void setComparator(Comparator cmp) {
         m_comparator = cmp;
         // NOTE: the array will be sorted at the next get.
     }
 
     /**
-     * Set the bundle context used by this dependency.
-     * This operation is not supported if the tracker is already opened.
-     * @param bc : bundle context or service context to use
+     * Set the bundle context used by this dependency. This operation is not supported if the tracker is already opened.
+     * @param context : bundle context or service context to use
      */
-    public void setBundleContext(BundleContext bc) {
+    public void setBundleContext(BundleContext context) {
         if (m_tracker == null) { // Not started ...
-            m_context = bc;
+            m_context = context;
         } else {
             throw new UnsupportedOperationException("Dynamic bundle (i.e. service) context change is not supported");
         }
     }
 
-
     /**
      * Get a service object for the given reference.
      * @param ref : wanted service reference
@@ -700,18 +722,15 @@
     }
 
     /**
-     * Helper method parsing the comparator attribute and returning the
-     * comparator object. If the 'comparator' attribute is not set, this 
-     * method returns null. If the 'comparator' attribute is set to 'osgi',
-     * this method returns the normal OSGi comparator. In other case, it 
-     * tries to create an instance of the declared comparator class.
+     * Helper method parsing the comparator attribute and returning the comparator object. If the 'comparator' attribute is not set, this method
+     * returns null. If the 'comparator' attribute is set to 'osgi', this method returns the normal OSGi comparator. In other case, it tries to create
+     * an instance of the declared comparator class.
      * @param dep : Element describing the dependency
-     * @param bc : bundle context (to load the comparator class)
+     * @param context : bundle context (to load the comparator class)
      * @return the comparator object, null if not set.
-     * @throws ConfigurationException the comparator class cannot be load or 
-     * the comparator cannot be instantiated correctly.
+     * @throws ConfigurationException the comparator class cannot be load or the comparator cannot be instantiated correctly.
      */
-    public static Comparator getComparator(Element dep, BundleContext bc) throws ConfigurationException {
+    public static Comparator getComparator(Element dep, BundleContext context) throws ConfigurationException {
         Comparator cmp = null;
         String comp = dep.getAttribute("comparator");
         if (comp != null) {
@@ -719,7 +738,7 @@
                 cmp = new ServiceReferenceRankingComparator();
             } else {
                 try {
-                    Class cla = bc.getBundle().loadClass(comp);
+                    Class cla = context.getBundle().loadClass(comp);
                     cmp = (Comparator) cla.newInstance();
                 } catch (ClassNotFoundException e) {
                     throw new ConfigurationException("Cannot load a customized comparator : " + e.getMessage());
@@ -736,14 +755,14 @@
     /**
      * Load the given specification class.
      * @param specification : specification class name to load
-     * @param bc : bundle context
+     * @param context : bundle context
      * @return : the class object for the given specification
      * @throws ConfigurationException : the class cannot be loaded correctly.
      */
-    public static Class loadSpecification(String specification, BundleContext bc) throws ConfigurationException {
+    public static Class loadSpecification(String specification, BundleContext context) throws ConfigurationException {
         Class spec = null;
         try {
-            spec = bc.getBundle().loadClass(specification);
+            spec = context.getBundle().loadClass(specification);
         } catch (ClassNotFoundException e) {
             throw new ConfigurationException("A required specification cannot be loaded : " + specification);
         }
@@ -751,11 +770,9 @@
     }
 
     /**
-     * Helper method parsing the binding policy.
-     * If the 'policy' attribute is not set in the dependency, the method
-     * returns the 'DYNAMIC BINDING POLICY'. Accepted policy values are :
-     * dynamic, dynamic-priority and static. 
-     * @param dep : Element describing the dependency 
+     * Helper method parsing the binding policy. If the 'policy' attribute is not set in the dependency, the method returns the 'DYNAMIC BINDING
+     * POLICY'. Accepted policy values are : dynamic, dynamic-priority and static.
+     * @param dep : Element describing the dependency
      * @return : the policy attached to this dependency
      * @throws ConfigurationException : an unknown biding policy was described.
      */

Copied: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyStateListener.java (from r631196, felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyLifecycleListener.java)
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyStateListener.java?p2=felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyStateListener.java&p1=felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyLifecycleListener.java&r1=631196&r2=633138&rev=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyLifecycleListener.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyStateListener.java Mon Mar  3 07:46:27 2008
@@ -23,17 +23,17 @@
  * This interface allows a class to be notified of dependency state changes.
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public interface DependencyLifecycleListener {
+public interface DependencyStateListener {
 
     /**
      * The given dependency becomes valid.
      * @param dependency : dependency becoming valid.
      */
-    void validate(AbstractServiceDependency dependency);
+    void validate(DependencyModel dependency);
     
     /**
      * The given dependency becomes invalid.
      * @param dependency : dependency becoming invalid.
      */
-    void invalidate(AbstractServiceDependency dependency);
+    void invalidate(DependencyModel dependency);
 }

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Logger.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Logger.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Logger.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Logger.java Mon Mar  3 07:46:27 2008
@@ -72,24 +72,24 @@
     /**
      * Constructor.
      * 
-     * @param bc : bundle context
+     * @param context : bundle context
      * @param name : name of the logger
      * @param level : trace level
      */
-    public Logger(BundleContext bc, String name, int level) {
+    public Logger(BundleContext context, String name, int level) {
         m_name = name;
         m_level = level;
-        m_context = bc;
+        m_context = context;
     }
     
     /**
      * Constructor.
      * 
-     * @param bc : bundle context
+     * @param context : bundle context
      * @param name : name of the logger
      */
-    public Logger(BundleContext bc, String name) {
-        this(bc, name, getDefaultLevel(bc));
+    public Logger(BundleContext context, String name) {
+        this(context, name, getDefaultLevel(context));
     }
 
     /**
@@ -109,11 +109,11 @@
      * 
      * @param level : level of the message
      * @param msg : message to log
-     * @param ex : exception attached to the message
+     * @param exception : exception attached to the message
      */
-    public void log(int level, String msg, Throwable ex) {
+    public void log(int level, String msg, Throwable exception) {
         if (m_level >= level) {
-            dispatch(level, msg, ex);
+            dispatch(level, msg, exception);
         }
     }
     
@@ -138,31 +138,31 @@
                 if (log != null) {
                     log.log(LogService.LOG_DEBUG, message);
                 }
-                System.err.println(message);
+                System.err.println(message); // NOPMD
                 break;
             case ERROR:
                 message = "[" + m_name + "] ERROR: " + msg;
                 if (log != null) {
                     log.log(LogService.LOG_ERROR, message);
                 }
-                System.err.println(message);
+                System.err.println(message); //NOPMD
                 break;
             case INFO:
                 message = "[" + m_name + "] INFO: " + msg;
                 if (log != null) {
                     log.log(LogService.LOG_INFO, message);
                 }
-                System.err.println(message);
+                System.err.println(message); // NOPMD
                 break;
             case WARNING:
                 message = "[" + m_name + "] WARNING: " + msg;
                 if (log != null) {
                     log.log(LogService.LOG_WARNING, message);
                 }
-                System.err.println(message);
+                System.err.println(message); // NOPMD
                 break;
             default:
-                System.err.println("[" + m_name + "] UNKNOWN[" + level + "]: " + msg);
+                System.err.println("[" + m_name + "] UNKNOWN[" + level + "]: " + msg); // NOPMD
                 break;
         }
         
@@ -176,9 +176,9 @@
      * 
      * @param level : level of the message.
      * @param msg : message to log
-     * @param ex : exception attached to the message
+     * @param exception : exception attached to the message
      */
-    private void dispatch(int level, String msg, Throwable ex) {
+    private void dispatch(int level, String msg, Throwable exception) {
         
         ServiceReference ref = m_context.getServiceReference(LogService.class.getName());
         LogService log = null;
@@ -191,38 +191,38 @@
             case DEBUG:
                 message = "[" + m_name + "] DEBUG: " + msg;
                 if (log != null) {
-                    log.log(LogService.LOG_DEBUG, message, ex);
+                    log.log(LogService.LOG_DEBUG, message, exception);
                 }
-                System.err.println(message);
-                ex.printStackTrace();
+                System.err.println(message); // NOPMD
+                exception.printStackTrace(); // NOPMD
                 break;
             case ERROR:
                 message = "[" + m_name + "] ERROR: " + msg;
                 if (log != null) {
-                    log.log(LogService.LOG_ERROR, message, ex);
+                    log.log(LogService.LOG_ERROR, message, exception);
                 }
-                System.err.println(message);
-                ex.printStackTrace(System.err);
+                System.err.println(message); // NOPMD
+                exception.printStackTrace(System.err); // NOPMD
                 break;
             case INFO:
                 message = "[" + m_name + "] INFO: " + msg;
                 if (log != null) {
-                    log.log(LogService.LOG_INFO, message, ex);
+                    log.log(LogService.LOG_INFO, message, exception);
                 }
-                System.err.println(message);
-                ex.printStackTrace(System.err);
+                System.err.println(message); // NOPMD
+                exception.printStackTrace(System.err); // NOPMD
                 break;
             case WARNING:
                 message = "[" + m_name + "] WARNING: " + msg;
                 if (log != null) {
-                    log.log(LogService.LOG_WARNING, message, ex);
+                    log.log(LogService.LOG_WARNING, message, exception);
                 }
-                System.err.println(message);
-                ex.printStackTrace(System.err);
+                System.err.println(message); // NOPMD
+                exception.printStackTrace(System.err); // NOPMD
                 break;
             default:
-                System.err.println("[" + m_name + "] UNKNOWN[" + level + "]: " + msg);
-                ex.printStackTrace();
+                System.err.println("[" + m_name + "] UNKNOWN[" + level + "]: " + msg); // NOPMD
+                exception.printStackTrace(); // NOPMD
                 break;
         }
         
@@ -235,26 +235,26 @@
      * Get the default logger level.
      * The property is searched inside the framework properties, the system properties,
      * and in the manifest from the given bundle context. By default, set the level to WARNING. 
-     * @param bc : bundle context.
+     * @param context : bundle context.
      * @return the default log level.
      */
-    private static int getDefaultLevel(BundleContext bc) {
+    private static int getDefaultLevel(BundleContext context) {
         // First check in the framework and in the system properties
-        String l = bc.getProperty(IPOJO_LOG_LEVEL);
+        String level = context.getProperty(IPOJO_LOG_LEVEL);
         
         // If null, look in bundle manifest
-        if (l == null) {
-            l = (String) bc.getBundle().getHeaders().get(IPOJO_LOG_LEVEL);
+        if (level == null) {
+            level = (String) context.getBundle().getHeaders().get(IPOJO_LOG_LEVEL);
         }
         
-        if (l != null) {
-            if (l.equalsIgnoreCase("info")) {
+        if (level != null) {
+            if (level.equalsIgnoreCase("info")) {
                 return INFO;
-            } else if (l.equalsIgnoreCase("debug")) {
+            } else if (level.equalsIgnoreCase("debug")) {
                 return DEBUG;
-            } else if (l.equalsIgnoreCase("warning")) {
+            } else if (level.equalsIgnoreCase("warning")) {
                 return WARNING;
-            } else if (l.equalsIgnoreCase("error")) {
+            } else if (level.equalsIgnoreCase("error")) {
                 return ERROR;
             }
         }

Added: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java?rev=633138&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java (added)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java Mon Mar  3 07:46:27 2008
@@ -0,0 +1,447 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.util;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.parser.ParseUtils;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Property class managing a property.
+ * This class allows storing property value and calling setter method too.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Property {
+
+    /**
+     * Name of the property (filed name if not set).
+     */
+    private String m_name;
+
+    /**
+     * Field of the property.
+     */
+    private String m_field;
+
+    /**
+     * Setter method of the property.
+     */
+    private Callback m_method;
+
+    /**
+     * Value of the property.
+     */
+    private Object m_value;
+
+    /**
+     * Type of the property.
+     */
+    private Class m_type;
+
+    /**
+     * Handler object on to use the logger.
+     */
+    private Handler m_handler;
+    
+    /**
+     * Instance Manager.
+     */
+    private InstanceManager m_manager;
+
+    /**
+     * Configurable Property Constructor. At least the method or the field need
+     * to be referenced.
+     * 
+     * @param name : name of the property (optional)
+     * @param field : name of the field
+     * @param method : method name
+     * @param value : initial value of the property (optional)
+     * @param type : the type of the property
+     * @param manager : instance manager
+     * @param handler : handler object which manage this property.
+     * @throws ConfigurationException : occurs when the property value cannot be set.
+     */
+    public Property(String name, String field, String method, String value, String type, InstanceManager manager, Handler handler) throws ConfigurationException {
+        m_handler = handler;
+        m_manager = manager;
+        m_field = field;
+
+        if (name == null) {
+            if (m_field == null) {
+                m_name = method;
+            } else {
+                m_name = field;
+            }
+        } else {
+            m_name = name;
+        }
+        
+        m_field = field;
+        m_type = computeType(type, manager.getGlobalContext());
+        if (value != null) {
+            m_value = create(m_type, value);
+        }
+
+        if (method != null) {
+            m_method = new Callback(method, new String[] { m_type.getName() }, false, manager);
+        }
+
+    }
+
+    /**
+     * The set type method computes and returns the property type according to the given type name.
+     * @param type : the type name
+     * @param context : bundle context (used to load classes)
+     * @return the class of the given type
+     * @throws ConfigurationException if an error occurs when loading the type class for non-primitive types.
+     */
+    public static Class computeType(String type, BundleContext context) throws ConfigurationException {
+        // Array :
+        if (type.endsWith("[]")) {
+            return computeArrayType(type, context);
+        } else {
+            // Syntactic sugar to avoid writing java.lang.String
+            if ("string".equals(type) || "String".equals(type)) {
+                return java.lang.String.class;
+            } else if ("boolean".equals(type)) {
+                return Boolean.TYPE;
+            } else if ("byte".equals(type)) {
+                return Byte.TYPE;
+            } else if ("short".equals(type)) {
+                return  Short.TYPE;
+            } else if ("int".equals(type)) {
+                return Integer.TYPE;
+            } else if ("long".equals(type)) {
+                return Long.TYPE;
+            } else if ("float".equals(type)) {
+                return Float.TYPE;
+            } else if ("double".equals(type)) {
+                return Double.TYPE;
+            } else if ("char".equals(type)) {
+                return Character.TYPE;
+            } else {
+                // Non array, complex type.
+                try {
+                    return context.getBundle().loadClass(type);
+                } catch (ClassNotFoundException e) {
+                    throw new ConfigurationException("Class not found exception in setValue on " + type + " : " + e.getMessage());
+                } catch (SecurityException e) {
+                    throw new ConfigurationException("Security excption in setValue on " + type + " : " + e.getMessage());
+                } catch (IllegalArgumentException e) {
+                    throw new ConfigurationException("Argument problem to call the constructor of the type " + type);
+                }
+            }
+        }
+    }
+
+    /**
+     * Get the Class object of a type array.
+     * @param type : the string descriptor of the type (must end by [] )
+     * @param context : bundle context (used to load classes)
+     * @return the Class object of the given type array.
+     * @throws ConfigurationException : if the class cannot be loaded
+     */
+    private static Class computeArrayType(String type, BundleContext context) throws ConfigurationException {
+        String internalType = type.substring(0, type.length() - 2);
+        if ("string".equals(internalType) || "String".equals(internalType)) {
+            return new String[0].getClass();
+        }
+        if ("boolean".equals(internalType)) {
+            return new boolean[0].getClass();
+        }
+        if ("byte".equals(internalType)) {
+            return new byte[0].getClass();
+        }
+        if ("short".equals(internalType)) {
+            return new short[0].getClass();
+        }
+        if ("int".equals(internalType)) {
+            return new int[0].getClass();
+        }
+        if ("long".equals(internalType)) {
+            return new long[0].getClass();
+        }
+        if ("float".equals(internalType)) {
+            return new float[0].getClass();
+        }
+        if ("double".equals(internalType)) {
+            return new double[0].getClass();
+        }
+        if ("char".equals(internalType)) {
+            return new char[0].getClass();
+        }
+
+        // Complex array type.
+        try {
+            Class clazz = context.getBundle().loadClass(internalType);
+            Object[] object = (Object[]) Array.newInstance(clazz, 0);
+            return object.getClass();
+        } catch (ClassNotFoundException e) {
+            throw new ConfigurationException("Class not found exception in setValue on " + internalType);
+        } catch (SecurityException e) {
+            throw new ConfigurationException("Secutiry Exception in setValue on " + internalType);
+        } catch (IllegalArgumentException e) {
+            throw new ConfigurationException("Argument problem to call the constructor of the type " + internalType);
+        }
+    }
+
+    public String getName() {
+        return m_name;
+    }
+
+    public String getField() {
+        return m_field;
+    }
+
+    /**
+     * Get method name, null if no method.
+     * @return the method name.
+     */
+    public String getMethod() {
+        if (m_method == null) { return null; }
+        return m_method.getMethod();
+    }
+
+    /**
+     * Check if the property has a method callback.
+     * @return true if the property has a method.
+     */
+    public boolean hasMethod() {
+        return m_method != null;
+    }
+
+    /**
+     * Check if the property has a field.
+     * @return true if the property has a field.
+     */
+    public boolean hasField() {
+        return m_field != null;
+    }
+
+    public Object getValue() {
+        return m_value;
+    }
+
+    /**
+     * Fix the value of the property.
+     * @param value : the new value.
+     */
+    public void setValue(Object value) {
+        // Is the object is directly assignable to the property, affect it.
+        if (isAssignable(m_type, value)) {
+            m_value = value;
+        } else {
+            // If the object is a String, we must recreate the object from the String form
+            if (value instanceof String) {
+                try {
+                    m_value = create(m_type, (String) value);
+                } catch (ConfigurationException e) {
+                    throw new ClassCastException("Incompatible type for the property " + m_name + " : " + e.getMessage());
+                }
+            } else {
+                // Error, the given property cannot be injected.
+                throw new ClassCastException("Incompatible type for the property " + m_name + " " + m_type.getName() + " expected, " + value.getClass() + " received");
+            }
+        }
+    }
+
+    /**
+     * Test if the given value is assignable to the given type.
+     * @param type : class of the type
+     * @param value : object to check
+     * @return true if the object is assignable in the property of type 'type'.
+     */
+    public static boolean isAssignable(Class type, Object value) {
+        if (value == null || type.isInstance(value)) { // When the value is null, the assign works necessary.
+            return true;
+        } else if (type.isPrimitive()) {
+            // Manage all boxing types.
+            if (value instanceof Boolean && Boolean.TYPE.equals(type)) { return true; }
+            if (value instanceof Byte && Byte.TYPE.equals(type)) { return true; }
+            if (value instanceof Short && Short.TYPE.equals(type)) { return true; }
+            if (value instanceof Integer && Integer.TYPE.equals(type)) { return true; }
+            if (value instanceof Long && Long.TYPE.equals(type)) { return true; }
+            if (value instanceof Float && Float.TYPE.equals(type)) { return true; }
+            if (value instanceof Double && Double.TYPE.equals(type)) { return true; }
+            if (value instanceof Character && Character.TYPE.equals(type)) { return true; }
+            return false;
+        } else {
+            // Else return false.
+            return false;
+        }
+    }
+
+    /**
+     * Create an object of the given type with the given String value.
+     * @param type : type of the returned object
+     * @param strValue : String value.
+     * @return the object of type 'type' created from the String 'value'
+     * @throws ConfigurationException occurs when the object cannot be created.
+     */
+    public static Object create(Class type, String strValue) throws ConfigurationException {
+        if (Boolean.TYPE.equals(type)) { return new Boolean(strValue); }
+        if (Byte.TYPE.equals(type)) { return new Byte(strValue); }
+        if (Short.TYPE.equals(type)) { return new Short(strValue); }
+        if (Integer.TYPE.equals(type)) { return new Integer(strValue); }
+        if (Long.TYPE.equals(type)) { return new Long(strValue); }
+        if (Float.TYPE.equals(type)) { return new Float(strValue); }
+        if (Double.TYPE.equals(type)) { return new Double(strValue); }
+        if (Character.TYPE.equals(type)) { return new Character(strValue.charAt(0)); }
+
+        // Array :
+        if (type.isArray()) { return createArrayObject(type.getComponentType(), ParseUtils.parseArrays(strValue)); }
+        // Else it is a neither a primitive type neither a String -> create
+        // the object by calling a constructor with a string in argument.
+        try {
+            Constructor cst = type.getConstructor(new Class[] { String.class });
+            return cst.newInstance(new Object[] { strValue });
+        } catch (SecurityException e) {
+            throw new ConfigurationException("Security exception in create on " + type + " : " + e.getMessage());
+        } catch (NoSuchMethodException e) {
+            throw new ConfigurationException("Constructor not found exception in create on " + type + " : " + e.getMessage());
+        } catch (IllegalArgumentException e) {
+            throw new ConfigurationException("Argument problem to call the constructor of the type " + type);
+        } catch (InstantiationException e) {
+            throw new ConfigurationException("Instantiation problem  " + type);
+        } catch (IllegalAccessException e) {
+            throw new ConfigurationException("Illegal Access " + type);
+        } catch (InvocationTargetException e) {
+            throw new ConfigurationException("Invocation problem " + type + " : " + e.getTargetException().getMessage());
+        }
+
+    }
+
+    /**
+     * Create an array object containing the type 'interntype' from the String array 'values'.
+     * @param interntype : internal type of the array.
+     * @param values : String array
+     * @return the array containing objects created from the 'values' array
+     * @throws ConfigurationException occurs when the array cannot be created correctly
+     */
+    public static Object createArrayObject(Class interntype, String[] values) throws ConfigurationException {
+        if (Boolean.TYPE.equals(interntype)) {
+            boolean[] bool = new boolean[values.length];
+            for (int i = 0; i < values.length; i++) {
+                bool[i] = new Boolean(values[i]).booleanValue();
+            }
+            return bool;
+        }
+        if (Byte.TYPE.equals(interntype)) {
+            byte[] byt = new byte[values.length];
+            for (int i = 0; i < values.length; i++) {
+                byt[i] = new Byte(values[i]).byteValue();
+            }
+            return byt;
+        }
+        if (Short.TYPE.equals(interntype)) {
+            short[] shor = new short[values.length];
+            for (int i = 0; i < values.length; i++) {
+                shor[i] = new Short(values[i]).shortValue();
+            }
+            return shor;
+        }
+        if (Integer.TYPE.equals(interntype)) {
+            int[] ints = new int[values.length];
+            for (int i = 0; i < values.length; i++) {
+                ints[i] = new Integer(values[i]).intValue();
+            }
+            return ints;
+        }
+        if (Long.TYPE.equals(interntype)) {
+            long[] longs = new long[values.length];
+            for (int i = 0; i < values.length; i++) {
+                longs[i] = new Long(values[i]).longValue();
+            }
+            return longs;
+        }
+        if (Float.TYPE.equals(interntype)) {
+            float[] floats = new float[values.length];
+            for (int i = 0; i < values.length; i++) {
+                floats[i] = new Float(values[i]).floatValue();
+            }
+            return floats;
+        }
+        if (Double.TYPE.equals(interntype)) {
+            double[] doubles = new double[values.length];
+            for (int i = 0; i < values.length; i++) {
+                doubles[i] = new Double(values[i]).doubleValue();
+            }
+            return doubles;
+        }
+        if (Character.TYPE.equals(interntype)) {
+            char[] chars = new char[values.length];
+            for (int i = 0; i < values.length; i++) {
+                chars[i] = values[i].toCharArray()[0];
+            }
+            return chars;
+        }
+
+        // Else it is a neither a primitive type -> create the
+        // object by calling a constructor with a string in argument.
+        try {
+            Constructor cst = interntype.getConstructor(new Class[] { String.class });
+            Object[] object = (Object[]) Array.newInstance(interntype, values.length);
+            for (int i = 0; i < values.length; i++) {
+                object[i] = cst.newInstance(new Object[] { values[i].trim() });
+            }
+            return object;
+        } catch (NoSuchMethodException e) {
+            throw new ConfigurationException("Constructor not found exception in setValue on " + interntype.getName());
+        } catch (IllegalArgumentException e) {
+            throw new ConfigurationException("Argument problem to call the constructor of the type " + interntype.getName());
+        } catch (InstantiationException e) {
+            throw new ConfigurationException("Instantiation problem  " + interntype.getName());
+        } catch (IllegalAccessException e) {
+            throw new ConfigurationException("Illegal Access Exception in  " + interntype.getName());
+        } catch (InvocationTargetException e) {
+            throw new ConfigurationException("Invocation problem " + interntype.getName() + " : " + e.getTargetException().getMessage());
+        }
+    }
+
+    /**
+     * Invoke the setter method on the given pjo object. If no specified pojo object, will call on each created pojo object.
+     * @param instance : the created object (could be null
+     * @see org.apache.felix.ipojo.Handler#onCreation(java.lang.Object)
+     */
+    public void invoke(Object instance) {
+        try {
+            if (instance == null) {
+                m_method.call(new Object[] { m_value });
+            } else {
+                m_method.call(instance, new Object[] { m_value });
+            }
+        } catch (NoSuchMethodException e) {
+            m_handler.error("The method " + m_method + " does not exist in the class " + m_manager.getClassName());
+            m_manager.stop();
+        } catch (IllegalAccessException e) {
+            m_handler.error("The method " + m_method + " is not accessible in the class " + m_manager.getClassName());
+            m_manager.stop();
+        } catch (InvocationTargetException e) {
+            m_handler.error("The method " + m_method + " in the class " + m_manager.getClassName() + "throws an exception : " + e.getTargetException().getMessage(), e.getTargetException());
+            m_manager.setState(ComponentInstance.INVALID);
+        }
+    }
+}

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Tracker.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Tracker.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Tracker.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Tracker.java Mon Mar  3 07:46:27 2008
@@ -42,7 +42,7 @@
     /**
      * Bundle context against which this Tracker object is tracking.
      */
-    protected final BundleContext m_context;
+    protected BundleContext m_context;
 
     /**
      * Filter specifying search criteria for the services to track.
@@ -52,22 +52,22 @@
     /**
      * TrackerCustomizer object for this tracker.
      */
-    final TrackerCustomizer m_customizer;
+    protected TrackerCustomizer m_customizer;
 
     /**
      * Filter string for use when adding the ServiceListener. If this field is set, then certain optimizations can be taken since we don't have a user supplied filter.
      */
-    final String m_listenerFilter;
+    protected String m_listenerFilter;
 
     /**
      * Class name to be tracked. If this field is set, then we are tracking by class name.
      */
-    private final String m_trackClass;
+    private String m_trackClass;
 
     /**
      * Reference to be tracked. If this field is set, then we are tracking a single ServiceReference.
      */
-    private final ServiceReference m_trackReference;
+    private ServiceReference m_trackReference;
 
     /**
      * Tracked services: ServiceReference object -> customized. Object and ServiceListener object
@@ -126,13 +126,13 @@
         } else {
             m_customizer = customizer;
         }
-        this.m_listenerFilter = "(" + Constants.OBJECTCLASS + "=" + clazz.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        this.m_listenerFilter = "(" + Constants.OBJECTCLASS + "=" + clazz + ")";
         try {
             this.m_filter = context.createFilter(m_listenerFilter);
         } catch (InvalidSyntaxException e) { // we could only get this exception
             // if the clazz argument was
             // malformed
-            throw new IllegalArgumentException("unexpected InvalidSyntaxException: " + e.getMessage()); //$NON-NLS-1$
+            throw new IllegalArgumentException("unexpected InvalidSyntaxException: " + e.getMessage());
         }
     }
 
@@ -157,7 +157,7 @@
             m_customizer = customizer;
         }
         if ((context == null) || (filter == null)) { // we throw a NPE here to be consistent with the other constructors
-            throw new NullPointerException();
+            throw new NullPointerException(); // NOPMD by clement on 29/02/08 14:12
         }
     }
 
@@ -188,7 +188,7 @@
                 // the initial
                 // references
             } catch (InvalidSyntaxException e) {
-                throw new RuntimeException("unexpected InvalidSyntaxException: " + e.getMessage()); //$NON-NLS-1$
+                throw new IllegalStateException("unexpected InvalidSyntaxException: " + e.getMessage()); //$NON-NLS-1$
             }
         }
         /* Call tracked outside of synchronized region */
@@ -220,8 +220,8 @@
 
         try {
             m_context.removeServiceListener(outgoing);
-        } catch (IllegalStateException e) {
-            System.err.println("Context stopped");
+        } catch (IllegalStateException e) { //NOPMD
+            //System.err.println("Context stopped");
             /* In case the context was stopped. */
         }
         if (references != null) {
@@ -254,7 +254,7 @@
      * @see org.apache.felix.ipojo.util.TrackerCustomizer#addedService(org.osgi.framework.ServiceReference)
      */
     public void addedService(ServiceReference reference) {
-
+        // Nothing to do.
     }
 
     /**
@@ -266,6 +266,7 @@
      * @see TrackerCustomizer
      */
     public void modifiedService(ServiceReference reference, Object service) {
+        // Nothing to do.
     }
 
     /**
@@ -412,11 +413,13 @@
         Object object = null;
         synchronized (tracked) {
             object = tracked.get(reference);
-            if (object != null) { // The object was already get.
-                return object;
-            } else if (tracked.containsKey(reference)) { // Not already get
-                object = m_context.getService(reference);
-                tracked.put(reference, object);
+            if (object == null) {
+                if (tracked.containsKey(reference)) { // Not already get but already tracked.
+                    object = m_context.getService(reference);
+                    tracked.put(reference, object);
+                    return object;
+                }
+            } else { // The object was already get.
                 return object;
             }
             // Not already tracked.
@@ -454,10 +457,10 @@
         synchronized (tracked) {
             ServiceReference[] references = getServiceReferences();
             int length = 0;
-            if (references != null) {
-                length = references.length;
-            } else {
+            if (references == null) {
                 return null;
+            } else {
+                length = references.length;
             }
             Object[] objects = new Object[length];
             for (int i = 0; i < length; i++) {
@@ -565,7 +568,7 @@
             while (true) {
                 ServiceReference reference;
                 synchronized (this) {
-                    if (m_initial.size() == 0) { //  if there are no more inital services
+                    if (m_initial.isEmpty()) { //  if there are no more inital services
                         return; // we are done
                     }
 
@@ -604,14 +607,14 @@
             switch (event.getType()) {
                 case ServiceEvent.REGISTERED:
                 case ServiceEvent.MODIFIED:
-                    if (m_listenerFilter != null) { // constructor supplied filter
-                        track(reference);
-                    } else { // user supplied filter
+                    if (m_listenerFilter == null) { // user supplied filter 
                         if (m_filter.match(reference)) {
                             track(reference); // Arrival
                         } else {
                             untrack(reference); // Departure
                         }
+                    } else { // constructor supplied filter
+                        track(reference);
                     }
                     break;
                 case ServiceEvent.UNREGISTERING:

Modified: felix/sandbox/clement/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java (original)
+++ felix/sandbox/clement/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java Mon Mar  3 07:46:27 2008
@@ -62,7 +62,7 @@
     /** 
      * configure : construct the structure JmxConfigFieldMap.and the Dynamic Mbean.
      * @param metadata Element
-     * @param dict Dictionnary
+     * @param dict Dictionary
      */
     public void configure(Element metadata, Dictionary dict) {
         
@@ -169,8 +169,6 @@
      */
     public void stop() {
         if (m_serviceRegistration != null) { m_serviceRegistration.unregister(); }
-        
-        
     }
     
     
@@ -223,7 +221,7 @@
         if (field == null) {
             return null;
         } else {
-            return field.getReflectionType();
+            return FieldMetadata.getReflectionType(field.getFieldType());
         }
     }
     



Mime
View raw message