felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r1492155 [3/4] - in /felix/trunk/ipojo/runtime: composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/importer/ composite-it/src/it/ipojo-composite-import-export-test/src/test/resources/ co...
Date Wed, 12 Jun 2013 11:38:30 GMT
Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/DefaultServiceTrackingInterceptor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/DefaultServiceTrackingInterceptor.java?rev=1492155&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/DefaultServiceTrackingInterceptor.java
(added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/DefaultServiceTrackingInterceptor.java
Wed Jun 12 11:38:27 2013
@@ -0,0 +1,65 @@
+/*
+ * 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.dependency.interceptors;
+
+import org.apache.felix.ipojo.util.DependencyModel;
+import org.osgi.framework.BundleContext;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Default implementation of the default service tracking interceptor.
+ * It accepts all references and keeps the dependencies in the `dependencies` list. This
list is guarded by the
+ * monitor lock.
+ *
+ * It also provides an `invalidateMatchingServices` method notifying all managed dependencies
of a change in the
+ * matching service set.
+ */
+public class DefaultServiceTrackingInterceptor extends DefaultDependencyInterceptor implements
ServiceTrackingInterceptor {
+
+    /**
+     * Default implementation of the accept method.
+     * The default behavior is to accept all services as they are (no transformation).
+     * @param dependency the dependency the dependency
+     * @param context the context of the dependency the bundle context used by the dependency
+     * @param ref the reference the reference to accept, transform or reject
+     * @param <S> the type of service
+     * @return the reference as it is.
+     */
+    public <S> TransformedServiceReference<S> accept(DependencyModel dependency,
BundleContext context, TransformedServiceReference<S> ref) {
+        return ref;
+    }
+
+    /**
+     * Notifies the managed dependencies of a change in the set of services accepted by this
interceptor.
+     * The dependency will call the accept method to recompute the set of matching services.
+     */
+    public void invalidateMatchingServices() {
+        List<DependencyModel> list = new ArrayList<DependencyModel>();
+        synchronized (this) {
+            list.addAll(dependencies);
+        }
+
+        for (DependencyModel dep : list) {
+            dep.invalidateMatchingServices();
+        }
+    }
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/DependencyInterceptor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/DependencyInterceptor.java?rev=1492155&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/DependencyInterceptor.java
(added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/DependencyInterceptor.java
Wed Jun 12 11:38:27 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.dependency.interceptors;
+
+import org.apache.felix.ipojo.util.DependencyModel;
+
+/**
+ * Dependency interceptor are collaborating with the service dependency during the service
resolution.
+ *
+ * Interceptors publishes a service property (target) to select the dependencies they handle.
+ *
+ * Notice that interceptor can invalidate the set of service used by a dependency by calling
{@link org.apache.felix
+ * .ipojo.util.DependencyModel#invalidateMatchingServices()} and {@link org.apache.felix.ipojo.util
+ * .DependencyModel#invalidateSelectedServices()}.
+ */
+public interface DependencyInterceptor {
+
+    /**
+     * A mandatory property published by provider of this service.
+     * The value must be a LDAP filter (Filter or String). This filter will be confronted
to the dependency property.
+     *
+     * @see org.osgi.framework.Filter
+     */
+    public static String TARGET_PROPERTY = "target";
+
+
+    /**
+     * The interceptor is plugged to the given dependency.
+     * @param dependency the dependency starting using the interceptor.
+     */
+    public void open(DependencyModel dependency);
+
+    /**
+     * The interceptor won't be use anymore by the given dependency.
+     * This method is called either when the interceptor is replace or when the instance's
dependency is stopping.
+     * @param dependency the dependency stopping its use of the interceptor
+     */
+    public void close(DependencyModel dependency);
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/ServiceRankingInterceptor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/ServiceRankingInterceptor.java?rev=1492155&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/ServiceRankingInterceptor.java
(added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/ServiceRankingInterceptor.java
Wed Jun 12 11:38:27 2013
@@ -0,0 +1,79 @@
+/*
+ * 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.dependency.interceptors;
+
+import org.apache.felix.ipojo.util.DependencyModel;
+import org.osgi.framework.ServiceReference;
+
+import java.util.List;
+
+/**
+ * A service to influence the sorting of services on a service dependency.
+ *
+ * Only one ranking interceptor can be plugged on a dependency, but an interceptor can handle
several dependencies.
+ *
+ * This interceptors is called to compute the selected set of services from the matching
set,
+ * i.e. the set of services that matching the filter (actually accepted by the tracking interceptors).
+ */
+public interface ServiceRankingInterceptor extends DependencyInterceptor {
+
+    /**
+     * Gets the sorted set of selected reference.
+     * @param dependency the dependency
+     * @param matching the set of service to sort
+     * @return the sorted set of selected reference. This set is a sub-set potentially empty
of the given list of
+     * references.
+     */
+    public List<ServiceReference> getServiceReferences(DependencyModel dependency,
List<ServiceReference> matching);
+
+    /**
+     * A new service arrives in the matching set. This method is called to retrieve the new
sorted set of selected
+     * services.
+     * @param dependency the dependency
+     * @param matching the set of matching service
+     * @param reference the arriving reference
+     * @return the new sorted set of service
+     */
+    public List<ServiceReference> onServiceArrival(DependencyModel dependency, List<ServiceReference>
matching,
+                                                   ServiceReference<?> reference);
+
+    /**
+     * A service leaves the matching set. This method is called to retrieve the new sorted
set of selected
+     * services.
+     * @param dependency the dependency
+     * @param matching the set of matching service
+     * @param reference the leaving reference
+     * @return the new sorted set of service
+     */
+    public List<ServiceReference> onServiceDeparture(DependencyModel dependency, List<ServiceReference>
matching,
+                                                     ServiceReference<?> reference);
+
+    /**
+     * A service from the matching set was modified. This method is called to retrieve the
new sorted set of selected
+     * services.
+     * @param dependency the dependency
+     * @param matching the set of matching service
+     * @param reference the modified service
+     * @return the new sorted set of service
+     */
+    public List<ServiceReference> onServiceModified(DependencyModel dependency, List<ServiceReference>
matching,
+                                              ServiceReference<?> reference);
+
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/ServiceTrackingInterceptor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/ServiceTrackingInterceptor.java?rev=1492155&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/ServiceTrackingInterceptor.java
(added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/ServiceTrackingInterceptor.java
Wed Jun 12 11:38:27 2013
@@ -0,0 +1,61 @@
+/*
+ * 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.dependency.interceptors;
+
+import org.apache.felix.ipojo.util.DependencyModel;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * A service to influence the visibility of services within a service dependency.
+ * This service is called to determine which services from the tracker (base set) is going
to the matching set.
+ *
+ * Several tracking interceptors can be plugged to the same service dependency. In this case,
+ * a chain is created where all interceptor can influence the next one. If the dependency
has a filter,
+ * a tracking interceptor using this filter is the last interceptor of the chain.
+ *
+ * Obviously an interceptor can be plugged to several interceptors.
+ */
+public interface ServiceTrackingInterceptor extends DependencyInterceptor {
+
+    /**
+     * Does the interceptor accepts the reference of not ?
+     * This methods has two goals. It can filter out undesirable services by returning {@literal
null}. In addition,
+     * it can <em>transform</em> the service reference to add / remove service
properties. In this case,
+     * it must return the <strong>same</strong> instance of {@link TransformedServiceReference},
+     * but with the new set of properties.
+     *
+     * So to filter out the service, return {@literal null}. To accept the service,
+     * return the reference as it is. To transform the service update the service reference
and return it.
+     *
+     * When several interceptors are collaborating on the same dependency, a chain is created.
The received reference
+     * is the reference modified by the preceding interceptor. Notice that once an interceptor
returns {@literal
+     * null} the chain is interrupted and the service rejected.
+     *
+     * @param dependency the dependency
+     * @param context the context of the dependency
+     * @param ref the reference
+     * @param <S> the type of service
+     * @return {@literal null} to filter out the service, the, optionally updated, reference
to accept it.
+     */
+    public <S> TransformedServiceReference<S> accept(DependencyModel dependency,
BundleContext context,
+                                                     TransformedServiceReference<S>
ref);
+
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/TransformedServiceReference.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/TransformedServiceReference.java?rev=1492155&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/TransformedServiceReference.java
(added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/dependency/interceptors/TransformedServiceReference.java
Wed Jun 12 11:38:27 2013
@@ -0,0 +1,88 @@
+/*
+ * 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.dependency.interceptors;
+
+import org.apache.felix.ipojo.Factory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+import java.util.*;
+
+/**
+ * Transformed service reference is an interface letting updating the properties of a service
reference.
+ *
+ * Transformed service reference wraps a <i>real</i> service reference and has
all its properties.
+ */
+public interface TransformedServiceReference<S> extends ServiceReference<S> {
+
+    /**
+     * These properties are cannot be removed, added or updated.
+     */
+    public static final List<String> FORBIDDEN_KEYS = Arrays.asList(
+            Constants.SERVICE_ID,
+            Constants.SERVICE_PID,
+            Factory.INSTANCE_NAME_PROPERTY
+    );
+
+
+    /**
+     * Adds a property to the reference
+     * @param name the property name
+     * @param value the value (must not be null)
+     * @return the current transformed service reference
+     */
+    public TransformedServiceReference<S> addProperty(String name, Object value);
+
+    /**
+     * Adds a property to the service reference if this property is not already set on the
reference.
+     * @param name the property name
+     * @param value the value
+     * @return the current transformed service reference
+     */
+    public TransformedServiceReference<S> addPropertyIfAbsent(String name, Object value);
+
+    /**
+     * Gets the current value of a property.
+     * @param name the property name
+     * @return the current value of the property, {@literal null} if not in the properties.
+     */
+    public Object get(String name);
+
+    /**
+     * Removes a property from the reference.
+     * @param name the property name
+     * @return the current transformed service reference
+     */
+    public TransformedServiceReference<S> removeProperty(String name);
+
+    /**
+     * Does the service reference contains the given property ?
+     * @param name the property name
+     * @return whether the current reference contains a property with the given name
+     */
+    public boolean contains(String name);
+
+    /**
+     * Gets the wrapped service reference
+     * @return the wrapped service reference
+     */
+    public ServiceReference<S> getWrappedReference();
+}

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java?rev=1492155&r1=1492154&r2=1492155&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
(original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
Wed Jun 12 11:38:27 2013
@@ -283,7 +283,7 @@ public class Dependency extends Dependen
                         } else {
                             // The service left already, or the service object cannot be
created.
                             // We consider it as a departure.
-                            removedService(refs[i],  null);
+                            m_serviceReferenceManager.removedService(refs[i], null);
                         }
                     }
                 } else {
@@ -294,7 +294,7 @@ public class Dependency extends Dependen
                     } else {
                         // The service left already, or the service object cannot be created.
                         // We consider it as a departure.
-                        removedService(refs[0],  null);
+                        m_serviceReferenceManager.removedService(refs[0], null);
                     }
                 }
             }
@@ -374,7 +374,7 @@ public class Dependency extends Dependen
                         // We can't get the service object (https://issues.apache.org/jira/browse/FELIX-3896).
                         // This is probably because the service is leaving.
                         // We consider it as a departure.
-                        removedService(ref, null);
+                        m_serviceReferenceManager.removedService(ref, null);
                     }
                 }
             }
@@ -557,7 +557,7 @@ public class Dependency extends Dependen
      * Get the used service references list.
      * @return the used service reference or null if no service reference are available.
      */
-    public List getServiceReferencesAsList() {
+    public List<ServiceReference> getServiceReferencesAsList() {
         ServiceReference[] refs = super.getServiceReferences();
         if (refs == null) {
             return null;

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java?rev=1492155&r1=1492154&r2=1492155&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java
(original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java
Wed Jun 12 11:38:27 2013
@@ -76,7 +76,7 @@ public class DependencyDescription {
      * @return the list of matching service reference,
      * <code>null</code> if no service reference.
      */
-    public List getServiceReferences() { return m_dependency.getServiceReferencesAsList();
}
+    public List<ServiceReference> getServiceReferences() { return m_dependency.getServiceReferencesAsList();
}
 
     /**
      * Gets the service reference if only one service reference is used.
@@ -97,7 +97,7 @@ public class DependencyDescription {
      * @return the list [service reference] containing the used services,
      * <code>null</code> if no providers are used
      */
-    public List getUsedServices() { return m_dependency.getUsedServiceReferences(); }
+    public List<ServiceReference> getUsedServices() { return m_dependency.getUsedServiceReferences();
}
     
     /**
      * Sets the dependency comparator.
@@ -141,6 +141,8 @@ public class DependencyDescription {
     public String getSpecification() {
         return m_dependency.getSpecification().getName();
     }
-    
 
+    public Dependency getDependency() {
+        return m_dependency;
+    }
 }

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java?rev=1492155&r1=1492154&r2=1492155&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
(original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
Wed Jun 12 11:38:27 2013
@@ -26,10 +26,7 @@ import org.apache.felix.ipojo.metadata.E
 import org.apache.felix.ipojo.parser.FieldMetadata;
 import org.apache.felix.ipojo.parser.MethodMetadata;
 import org.apache.felix.ipojo.parser.PojoMetadata;
-import org.apache.felix.ipojo.util.DependencyModel;
-import org.apache.felix.ipojo.util.DependencyStateListener;
-import org.apache.felix.ipojo.util.InstanceConfigurationSource;
-import org.apache.felix.ipojo.util.SystemPropertiesSource;
+import org.apache.felix.ipojo.util.*;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Filter;
@@ -434,11 +431,11 @@ public class DependencyHandler extends P
 
             Class spec = null;
             if (serviceSpecification != null) {
-                spec = DependencyModel.loadSpecification(serviceSpecification, getInstanceManager().getContext());
+                spec = DependencyMetadataHelper.loadSpecification(serviceSpecification, getInstanceManager().getContext());
             }
 
-            int policy = DependencyModel.getPolicy(dependencyElement);
-            Comparator cmp = DependencyModel.getComparator(dependencyElement, getInstanceManager().getGlobalContext());
+            int policy = DependencyMetadataHelper.getPolicy(dependencyElement);
+            Comparator cmp = DependencyMetadataHelper.getComparator(dependencyElement, getInstanceManager().getGlobalContext());
 
             Dependency dep = new Dependency(this, field, spec, fil, optional, aggregate,
nullable, isProxy, identity, context, policy, cmp, defaultImpl);
 
@@ -584,14 +581,11 @@ public class DependencyHandler extends P
                 methodType = DependencyCallback.MODIFIED;
             }
 
-            dep.addDependencyCallback(createDependencyCallback(dep, method, methodType));
+            DependencyCallback callback = new DependencyCallback(dep, method, methodType);
+            dep.addDependencyCallback(callback);
         }
     }
 
-    protected DependencyCallback createDependencyCallback(final Dependency dep, final String
method, final int type) {
-        return new DependencyCallback(dep, method, type);
-    }
-
     private Filter createAndCheckFilter(String filter) throws ConfigurationException {
         Filter fil = null;
         if (filter != null) {

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java?rev=1492155&r1=1492154&r2=1492155&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
(original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
Wed Jun 12 11:38:27 2013
@@ -143,12 +143,10 @@ public class DependencyHandlerDescriptio
             }
             
             dep.addAttribute(new Attribute("State", state));
-            List set = m_dependencies[i].getUsedServices();
+            List<ServiceReference> set = m_dependencies[i].getUsedServices();
             if (set != null) {
-                Iterator iterator = set.iterator();
-                while (iterator.hasNext()) {
+                for (ServiceReference ref : set) {
                     Element use = new Element("Uses", "");
-                    ServiceReference ref = (ServiceReference) iterator.next();
                     use.addAttribute(new Attribute(Constants.SERVICE_ID, ref.getProperty(Constants.SERVICE_ID).toString()));
                     String instance = (String) ref.getProperty(Factory.INSTANCE_NAME_PROPERTY);
                     if (instance != null) {
@@ -157,7 +155,35 @@ public class DependencyHandlerDescriptio
                     dep.addElement(use);
                 }
             }
-            
+
+            set = m_dependencies[i].getServiceReferences();
+            if (set != null) {
+                for (ServiceReference ref : set) {
+                    Element use = new Element("Selected", "");
+                    use.addAttribute(new Attribute(Constants.SERVICE_ID, ref.getProperty(Constants.SERVICE_ID).toString()));
+                    String instance = (String) ref.getProperty(Factory.INSTANCE_NAME_PROPERTY);
+                    if (instance != null) {
+                        use.addAttribute(new Attribute(Factory.INSTANCE_NAME_PROPERTY, instance));
+                    }
+                    dep.addElement(use);
+                }
+            }
+
+            if (m_dependencies[i].getDependency() != null) {
+                set = m_dependencies[i].getDependency().getServiceReferenceManager().getMatchingServices();
+                if (set != null) {
+                    for (ServiceReference ref : set) {
+                        Element use = new Element("Matches", "");
+                        use.addAttribute(new Attribute(Constants.SERVICE_ID, ref.getProperty(Constants.SERVICE_ID).toString()));
+                        String instance = (String) ref.getProperty(Factory.INSTANCE_NAME_PROPERTY);
+                        if (instance != null) {
+                            use.addAttribute(new Attribute(Factory.INSTANCE_NAME_PROPERTY,
instance));
+                        }
+                        dep.addElement(use);
+                    }
+                }
+            }
+
             deps.addElement(dep);
         }
         return deps;

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/ContextSourceManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/ContextSourceManager.java?rev=1492155&r1=1492154&r2=1492155&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/ContextSourceManager.java
(original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/ContextSourceManager.java
Wed Jun 12 11:38:27 2013
@@ -290,7 +290,6 @@ public class ContextSourceManager implem
          * @see TrackerCustomizer#addedService(org.osgi.framework.ServiceReference)
          */
         public void addedService(ServiceReference reference) {
-            System.out.println("Source added");
             addContextSource((ContextSource) m_tracker.getService(reference));
         }
 

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/DependencyMetadataHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/DependencyMetadataHelper.java?rev=1492155&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/DependencyMetadataHelper.java
(added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/DependencyMetadataHelper.java
Wed Jun 12 11:38:27 2013
@@ -0,0 +1,109 @@
+/*
+ * 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 org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.framework.BundleContext;
+
+import java.util.Comparator;
+
+/**
+ * A set of methods to simplify the parsing of  dependency attributes.
+ */
+public class DependencyMetadataHelper {
+
+
+    /**
+     * 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     the Element describing the dependency
+     * @param context the bundle context (to load the comparator class)
+     * @return the comparator object, <code>null</code> if not set.
+     * @throws org.apache.felix.ipojo.ConfigurationException the comparator class cannot
be load or the
+     *                                comparator cannot be instantiated correctly.
+     */
+    public static Comparator getComparator(Element dep, BundleContext context) throws ConfigurationException
{
+        Comparator cmp = null;
+        String comp = dep.getAttribute("comparator");
+        if (comp != null) {
+            if (comp.equalsIgnoreCase("osgi")) {
+                cmp = new ServiceReferenceRankingComparator();
+            } else {
+                try {
+                    Class cla = context.getBundle().loadClass(comp);
+                    cmp = (Comparator) cla.newInstance();
+                } catch (ClassNotFoundException e) {
+                    throw new ConfigurationException("Cannot load a customized comparator",
e);
+                } catch (IllegalAccessException e) {
+                    throw new ConfigurationException("Cannot create a customized comparator",
e);
+                } catch (InstantiationException e) {
+                    throw new ConfigurationException("Cannot create a customized comparator",
e);
+                }
+            }
+        }
+        return cmp;
+    }
+
+    /**
+     * Loads the given specification class.
+     *
+     * @param specification the specification class name to load
+     * @param context       the bundle context
+     * @return the class object for the given specification
+     * @throws org.apache.felix.ipojo.ConfigurationException if the class cannot be loaded
correctly.
+     */
+    public static Class loadSpecification(String specification, BundleContext context) throws
ConfigurationException {
+        Class spec;
+        try {
+            spec = context.getBundle().loadClass(specification);
+        } catch (ClassNotFoundException e) {
+            throw new ConfigurationException("A required specification cannot be loaded :
" + specification, e);
+        }
+        return spec;
+    }
+
+    /**
+     * 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 the Element describing the dependency
+     * @return the policy attached to this dependency
+     * @throws org.apache.felix.ipojo.ConfigurationException if an unknown binding policy
was described.
+     */
+    public static int getPolicy(Element dep) throws ConfigurationException {
+        String policy = dep.getAttribute("policy");
+        if (policy == null || policy.equalsIgnoreCase("dynamic")) {
+            return DependencyModel.DYNAMIC_BINDING_POLICY;
+        } else if (policy.equalsIgnoreCase("dynamic-priority")) {
+            return DependencyModel.DYNAMIC_PRIORITY_BINDING_POLICY;
+        } else if (policy.equalsIgnoreCase("static")) {
+            return DependencyModel.STATIC_BINDING_POLICY;
+        } else {
+            throw new ConfigurationException("Binding policy unknown : " + policy);
+        }
+    }
+}



Mime
View raw message