You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2009/04/19 04:44:57 UTC

svn commit: r766413 - in /geronimo/sandbox/blueprint: org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/ org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ org.apache.felix.blueprint/src/main/java/org/apache/...

Author: gawor
Date: Sun Apr 19 02:44:56 2009
New Revision: 766413

URL: http://svn.apache.org/viewvc?rev=766413&view=rev
Log:
improved service export (ServiceRegistration proxy and registration listeners)

Added:
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ReflectionUtils.java   (with props)
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ServiceRegistrationProxy.java   (with props)
    geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/FooListener.java   (with props)
Modified:
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/reflect/ServiceExportComponentMetadataImpl.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/resources/test-wiring.xml
    geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Foo.java
    geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java?rev=766413&r1=766412&r2=766413&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java (original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java Sun Apr 19 02:44:56 2009
@@ -30,4 +30,6 @@
     
     public static final String SERVICE_FILTER = "service.Filter";
     
+    public static final String COMPONENT_NAME_PROPERTY = "osgi.service.blueprint.compname";
+    
 }

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java?rev=766413&r1=766412&r2=766413&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java (original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java Sun Apr 19 02:44:56 2009
@@ -25,9 +25,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.lang.reflect.Type;
 
 import org.apache.felix.blueprint.namespace.ComponentDefinitionRegistryImpl;
 import org.apache.felix.blueprint.reflect.ServiceExportComponentMetadataImpl;
@@ -41,8 +38,6 @@
 import org.apache.xbean.recipe.Recipe;
 import org.apache.xbean.recipe.ReferenceRecipe;
 import org.apache.xbean.recipe.Repository;
-import org.apache.xbean.recipe.AbstractRecipe;
-import org.apache.xbean.recipe.RecipeHelper;
 import org.osgi.service.blueprint.convert.ConversionService;
 import org.osgi.service.blueprint.reflect.ArrayValue;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
@@ -55,16 +50,13 @@
 import org.osgi.service.blueprint.reflect.PropertyInjectionMetadata;
 import org.osgi.service.blueprint.reflect.ReferenceNameValue;
 import org.osgi.service.blueprint.reflect.ReferenceValue;
+import org.osgi.service.blueprint.reflect.RegistrationListenerMetadata;
+import org.osgi.service.blueprint.reflect.ServiceExportComponentMetadata;
 import org.osgi.service.blueprint.reflect.SetValue;
 import org.osgi.service.blueprint.reflect.TypedStringValue;
 import org.osgi.service.blueprint.reflect.Value;
-import org.osgi.service.blueprint.reflect.ServiceExportComponentMetadata;
 import org.osgi.service.blueprint.reflect.UnaryServiceReferenceComponentMetadata;
 import org.osgi.service.blueprint.reflect.CollectionBasedServiceReferenceComponentMetadata;
-import org.osgi.service.blueprint.namespace.ComponentDefinitionRegistry;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
 
 /**
  * TODO: javadoc
@@ -149,8 +141,26 @@
             // TODO: factory-component
             return recipe;
         } else if (component instanceof ServiceExportComponentMetadata) {
-            ExportedServiceRecipe recipe = new ExportedServiceRecipe((ServiceExportComponentMetadata) component);
+            ServiceExportComponentMetadata serviceExport = (ServiceExportComponentMetadata) component;
+            ObjectRecipe recipe = new ObjectRecipe(ServiceRegistrationProxy.class);
+            recipe.allow(Option.PRIVATE_PROPERTIES);
             recipe.setName(component.getName());
+            recipe.setProperty("moduleContext", moduleContext);
+            recipe.setProperty("service", getValue(serviceExport.getExportedComponent(), null));   
+            recipe.setProperty("metadata", component);
+            if (component instanceof ServiceExportComponentMetadataImpl) {
+                ServiceExportComponentMetadataImpl impl = (ServiceExportComponentMetadataImpl) component;
+                if (impl.getServicePropertiesValue() != null) {
+                    recipe.setProperty("serviceProperties", getValue(impl.getServicePropertiesValue(), null));
+                }
+            }
+            if (serviceExport.getRegistrationListeners() != null) {
+                CollectionRecipe cr = new CollectionRecipe(ArrayList.class);;
+                for (RegistrationListenerMetadata listener : (Collection<RegistrationListenerMetadata>)serviceExport.getRegistrationListeners()) {
+                    cr.add(createRecipe(listener));
+                }
+                recipe.setProperty("listeners", cr);
+            }
             return recipe;
         } else if (component instanceof UnaryServiceReferenceComponentMetadata) {
             // TODO
@@ -163,6 +173,14 @@
         }
     }
 
+    private Recipe createRecipe(RegistrationListenerMetadata listener) throws Exception {
+        ObjectRecipe recipe = new ObjectRecipe(ServiceRegistrationProxy.Listener.class);
+        recipe.allow(Option.PRIVATE_PROPERTIES);
+        recipe.setProperty("listener", getValue(listener.getListenerComponent(), null));
+        recipe.setProperty("metadata", listener);
+        return recipe;
+    }
+    
     private Object getValue(Value v, Class groupingType) throws Exception {
         if (v instanceof NullValue) {
             return null;
@@ -261,82 +279,5 @@
             }
         }
     }
-
-    /**
-     * TODO: section 5.4.1.5 : expose a proxy to the ServiceRegistration
-     * TODO: destruction should unregister the service
-     */
-    private class ExportedServiceRecipe extends AbstractRecipe {
-
-        private final ServiceExportComponentMetadata metadata;
-        private ServiceRegistration serviceRegistration;
-
-        public ExportedServiceRecipe(ServiceExportComponentMetadata metadata) {
-            this.metadata = metadata;
-        }
-
-        public boolean canCreate(Type type) {
-            return true;
-        }
-
-        protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException {
-            // TODO: metadata.getRegistrationListeners()
-            try {
-                // TODO: if the exported component as a scope='bundle' we should create a ServiceFactory to honor that
-                Object service = getValue(metadata.getExportedComponent(),  null);
-                service = RecipeHelper.convert(Object.class, service, false);
-                Set<String> classes;
-                switch (metadata.getAutoExportMode()) {
-                    case ServiceExportComponentMetadata.EXPORT_MODE_INTERFACES:
-                        classes = getImplementedInterfaces(new HashSet<String>(), service.getClass());
-                        break;
-                    case ServiceExportComponentMetadata.EXPORT_MODE_CLASS_HIERARCHY:
-                        classes = getSuperClasses(new HashSet<String>(), service.getClass());
-                        break;
-                    case ServiceExportComponentMetadata.EXPORT_MODE_ALL:
-                        classes = getSuperClasses(new HashSet<String>(), service.getClass());
-                        classes = getImplementedInterfaces(classes, service.getClass());
-                        break;
-                    default:
-                        classes = metadata.getInterfaceNames();
-                        break;
-                }
-                Map map = metadata.getServiceProperties();
-                if (map == null && metadata instanceof ServiceExportComponentMetadataImpl) {
-                    Object val = getValue(((ServiceExportComponentMetadataImpl) metadata).getServicePropertiesValue(), null);
-                    map = (Map) RecipeHelper.convert(Map.class, val, false); 
-                }
-                if (map == null) {
-                    map = new HashMap();
-                }
-                map.put(Constants.SERVICE_RANKING, metadata.getRanking());
-                String[] classesArray = classes.toArray(new String[classes.size()]);
-                serviceRegistration = moduleContext.getBundleContext().registerService(classesArray, service, new Hashtable(map));
-                return serviceRegistration;
-            } catch (Exception e) {
-                throw new ConstructionException(e);
-            }
-        }
-
-        private Set<String> getImplementedInterfaces(Set<String> classes, Class clazz) {
-            if (clazz != null && clazz != Object.class) {
-                for (Class itf : clazz.getInterfaces()) {
-                    classes.add(itf.getName());
-                    getImplementedInterfaces(classes, itf);
-                }
-                getImplementedInterfaces(classes, clazz.getSuperclass());
-            }
-            return classes;
-        }
-
-        private Set<String> getSuperClasses(Set<String> classes, Class clazz) {
-            if (clazz != null && clazz != Object.class) {
-                classes.add(clazz.getName());
-                getSuperClasses(classes, clazz.getSuperclass());
-            }
-            return classes;
-        }
-
-    }
             
 }

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java?rev=766413&r1=766412&r2=766413&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java (original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java Sun Apr 19 02:44:56 2009
@@ -114,6 +114,8 @@
             instances = graph.createAll(new ArrayList<String>(componentDefinitionRegistry.getComponentDefinitionNames()));
             System.out.println(instances);
 
+            registerAllServices();
+            
             // Register the ModuleContext in the OSGi registry
             Properties props = new Properties();
             props.put("osgi.blueprint.context.symbolicname", bundleContext.getBundle().getSymbolicName());
@@ -146,6 +148,20 @@
         }
     }
     
+    private void registerAllServices() {
+        for (ServiceExportComponentMetadata service : getExportedServicesMetadata()) {
+            ServiceRegistrationProxy proxy = (ServiceRegistrationProxy) getComponent(service.getName());
+            proxy.register();
+        }
+    }
+    
+    private void unregisterAllServices() {
+        for (ServiceExportComponentMetadata service : getExportedServicesMetadata()) {
+            ServiceRegistrationProxy proxy = (ServiceRegistrationProxy) getComponent(service.getName());
+            proxy.unregister();
+        }
+    }
+    
     public Set<String> getComponentNames() {
         return componentDefinitionRegistry.getComponentDefinitionNames();
     }
@@ -205,6 +221,7 @@
             registration.unregister();
         }
         sender.sendDestroying(this);
+        unregisterAllServices();
         System.out.println("Module context destroyed: " + this.bundleContext);
         // TODO: destroy all instances
         sender.sendDestroyed(this);

Added: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ReflectionUtils.java?rev=766413&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ReflectionUtils.java (added)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ReflectionUtils.java Sun Apr 19 02:44:56 2009
@@ -0,0 +1,69 @@
+/**
+ * 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.blueprint.context;
+
+import java.lang.reflect.Method;
+import java.util.Set;
+
+public class ReflectionUtils {
+           
+    public static Set<String> getImplementedInterfaces(Set<String> classes, Class clazz) {
+        if (clazz != null && clazz != Object.class) {
+            for (Class itf : clazz.getInterfaces()) {
+                classes.add(itf.getName());
+                getImplementedInterfaces(classes, itf);
+            }
+            getImplementedInterfaces(classes, clazz.getSuperclass());
+        }
+        return classes;
+    }
+
+    public static Set<String> getSuperClasses(Set<String> classes, Class clazz) {
+        if (clazz != null && clazz != Object.class) {
+            classes.add(clazz.getName());
+            getSuperClasses(classes, clazz.getSuperclass());
+        }
+        return classes;
+    }
+    
+    public static Method findMethod(Class clazz, String name, Class[] paramTypes) {    
+        try {
+            return clazz.getMethod(name, paramTypes);
+        } catch (NoSuchMethodException e) {
+            return findCompatibileMethod(clazz, name, paramTypes);
+        }
+    }
+
+    public static Method findCompatibileMethod(Class clazz, String name, Class[] paramTypes) {
+        Method[] methods = clazz.getMethods();
+        for (Method method :  methods) {
+            Class[] methodParams = method.getParameterTypes();
+            if (name.equals(method.getName()) && methodParams.length == paramTypes.length) {
+                boolean assignable = true;
+                for (int i = 0; i < paramTypes.length && assignable; i++) {
+                    assignable = methodParams[i].isAssignableFrom(paramTypes[i]);
+                }
+                if (assignable) {
+                    return method;
+                }                        
+            }
+        }
+        return null;
+    }        
+}

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ReflectionUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ReflectionUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ReflectionUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ServiceRegistrationProxy.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ServiceRegistrationProxy.java?rev=766413&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ServiceRegistrationProxy.java (added)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ServiceRegistrationProxy.java Sun Apr 19 02:44:56 2009
@@ -0,0 +1,207 @@
+/**
+ * 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.blueprint.context;
+
+import java.lang.reflect.Method;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.felix.blueprint.BlueprintConstants;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.blueprint.context.ModuleContext;
+import org.osgi.service.blueprint.reflect.ReferenceValue;
+import org.osgi.service.blueprint.reflect.RegistrationListenerMetadata;
+import org.osgi.service.blueprint.reflect.ServiceExportComponentMetadata;
+
+/** 
+ * TODO: if the exported component as a scope='bundle' we should create a ServiceFactory to honor that
+ * 
+ * TODO: javadoc
+ */
+public class ServiceRegistrationProxy implements ServiceRegistration {
+  
+    private ModuleContext moduleContext;
+    private Object service;
+    private Map serviceProperties;
+    private List<Listener> listeners;
+    private ServiceExportComponentMetadata metadata;
+
+    private ServiceRegistration registration = null;
+    private Map registrationProperties = null;
+    
+    protected Object getService() {
+        return service;
+    }
+        
+    protected Map getRegistrationProperties() {
+        return registrationProperties;
+    }
+    
+    public synchronized void register() {
+        if (registration != null) {
+            return;
+        }
+        
+        Set<String> classes;
+        switch (metadata.getAutoExportMode()) {
+            case ServiceExportComponentMetadata.EXPORT_MODE_INTERFACES:
+                classes = ReflectionUtils.getImplementedInterfaces(new HashSet<String>(), service.getClass());
+                break;
+            case ServiceExportComponentMetadata.EXPORT_MODE_CLASS_HIERARCHY:
+                classes = ReflectionUtils.getSuperClasses(new HashSet<String>(), service.getClass());
+                break;
+            case ServiceExportComponentMetadata.EXPORT_MODE_ALL:
+                classes = ReflectionUtils.getSuperClasses(new HashSet<String>(), service.getClass());
+                classes = ReflectionUtils.getImplementedInterfaces(classes, service.getClass());
+                break;
+            default:
+                classes = metadata.getInterfaceNames();
+                break;
+        }
+        
+        Hashtable props = new Hashtable();
+        if (serviceProperties != null) {
+            props.putAll(serviceProperties);
+        }
+        props.put(Constants.SERVICE_RANKING, metadata.getRanking());
+        String componentName = getComponentName();
+        if (componentName != null) {
+            props.put(BlueprintConstants.COMPONENT_NAME_PROPERTY, componentName);
+        }
+        String[] classesArray = classes.toArray(new String[classes.size()]);
+        registration = moduleContext.getBundleContext().registerService(classesArray, service, props);
+        registrationProperties = props;
+        
+        System.out.println("service registered: " + service);
+        
+        if (listeners != null) {
+            for (Listener listener : listeners) {
+                listener.register(this);
+            }
+        }
+    }
+                       
+    private String getComponentName() {
+        if (metadata.getExportedComponent() instanceof ReferenceValue) {
+            ReferenceValue ref = (ReferenceValue) metadata.getExportedComponent();
+            return ref.getComponentName();
+        } else {
+            return null;
+        }
+    }
+    
+    public String toString() {
+        return service + " " + serviceProperties + " " + listeners;
+    }
+
+    // ServiceRegistation methods
+        
+    public synchronized void unregister() {   
+        if (registration != null) {
+            registration.unregister();
+            
+            System.out.println("service unregistered: " + service);
+            
+            if (listeners != null) {
+                for (Listener listener : listeners) {
+                    listener.unregister(this);
+                }
+            }
+            
+            registration = null;
+            registrationProperties = null;
+        }
+    }
+    
+    public ServiceReference getReference() {
+        if (registration == null) {
+            throw new IllegalStateException();
+        } else {
+            return registration.getReference();
+        }
+    }
+
+    public void setProperties(Dictionary props) {
+        if (registration == null) {
+            throw new IllegalStateException();
+        } else {
+            registration.setProperties(props);     
+            // TODO: set serviceProperties? convert somehow? should listeners be notified of this?
+        }
+    }
+    
+    public static class Listener {
+        
+        private Object listener;
+        private RegistrationListenerMetadata metadata;
+        
+        private Method registerMethod;
+        private Method unregisterMethod;
+        private boolean initialized = false;
+        
+        private synchronized void init(ServiceRegistrationProxy registration) {
+            if (initialized) {
+                return;
+            }
+            
+            Object service = registration.getService();
+            Class[] paramTypes = new Class[] { service.getClass(), Map.class };
+            Class listenerClass = listener.getClass();
+            
+            if (metadata.getRegistrationMethodName() != null) { 
+                registerMethod = ReflectionUtils.findMethod(listenerClass, metadata.getRegistrationMethodName(), paramTypes);
+            }
+            if (metadata.getUnregistrationMethodName() != null) {
+                unregisterMethod = ReflectionUtils.findMethod(listenerClass, metadata.getUnregistrationMethodName(), paramTypes);
+            }
+            
+            initialized = true;
+        }
+        
+        public void register(ServiceRegistrationProxy registration) {
+            init(registration);
+            invokeMethod(registerMethod, registration);
+        }
+        
+        public void unregister(ServiceRegistrationProxy registration) {
+            invokeMethod(unregisterMethod, registration);
+        }
+                
+        private void invokeMethod(Method method, ServiceRegistrationProxy registration) {
+            if (method == null) {
+                return;
+            }
+            Object service = registration.getService();
+            Map properties = registration.getRegistrationProperties();
+            Object[] args = new Object[] { service, properties };
+            try {
+                method.invoke(listener, args);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+                           
+    }
+}

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ServiceRegistrationProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ServiceRegistrationProxy.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ServiceRegistrationProxy.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/reflect/ServiceExportComponentMetadataImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/reflect/ServiceExportComponentMetadataImpl.java?rev=766413&r1=766412&r2=766413&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/reflect/ServiceExportComponentMetadataImpl.java (original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/reflect/ServiceExportComponentMetadataImpl.java Sun Apr 19 02:44:56 2009
@@ -80,7 +80,11 @@
     }
 
     public Set<String> getInterfaceNames() {
-        return Collections.unmodifiableSet(interfaceNames);
+        if (interfaceNames == null) {
+            return Collections.emptySet();
+        } else {
+            return Collections.unmodifiableSet(interfaceNames);
+        }
     }
 
     public void setInterfaceNames(Set<String> interfaceNames) {
@@ -120,7 +124,11 @@
     }
 
     public Collection<RegistrationListenerMetadata> getRegistrationListeners() {
-        return Collections.unmodifiableCollection(registrationListeners);
+        if (registrationListeners == null) {
+            return Collections.emptySet();
+        } else {
+            return Collections.unmodifiableCollection(registrationListeners);
+        }
     }
 
     public void setRegistrationListeners(Collection<RegistrationListenerMetadata> registrationListeners) {

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java?rev=766413&r1=766412&r2=766413&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java (original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java Sun Apr 19 02:44:56 2009
@@ -28,6 +28,7 @@
 import org.apache.felix.blueprint.pojos.PojoB;
 import org.apache.xbean.recipe.ObjectGraph;
 import org.apache.xbean.recipe.Repository;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.blueprint.convert.ConversionService;
 
 public class WiringTest extends AbstractBlueprintTest {
@@ -85,6 +86,10 @@
         assertEquals(new Integer(1), pojoa.getNumberArray()[0]);
         assertEquals(new BigInteger("50"), pojoa.getNumberArray()[1]);
         assertEquals(new Long(100), pojoa.getNumberArray()[2]);
+        
+        Object obj3 = graph.create("service1");
+        assertNotNull(obj3);
+        assertTrue(obj3 instanceof ServiceRegistration);
     }
 
     private static class TestInstanciator extends Instanciator {

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/resources/test-wiring.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/resources/test-wiring.xml?rev=766413&r1=766412&r2=766413&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/resources/test-wiring.xml (original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/resources/test-wiring.xml Sun Apr 19 02:44:56 2009
@@ -10,6 +10,13 @@
             </component>
     </type-converters>
     
+    <service id="service1" ref="pojoB" interface="foo">
+        <service-properties>
+            <entry key="key1" value="value1"/>
+            <entry key="key2" value="value2"/>
+        </service-properties>    
+    </service>
+    
     <component id="pojoB" class="org.apache.felix.blueprint.pojos.PojoB">
         <property name="uri" value="urn:myuri" />
     </component>

Modified: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Foo.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Foo.java?rev=766413&r1=766412&r2=766413&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Foo.java (original)
+++ geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/Foo.java Sun Apr 19 02:44:56 2009
@@ -16,10 +16,11 @@
  */
 package org.apache.geronimo.osgi.example;
 
+import java.io.Serializable;
 import java.util.Currency;
 import java.util.Date;
 
-public class Foo {
+public class Foo implements Serializable {
     
     private int a;
     private int b;

Added: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/FooListener.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/FooListener.java?rev=766413&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/FooListener.java (added)
+++ geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/FooListener.java Sun Apr 19 02:44:56 2009
@@ -0,0 +1,32 @@
+/**
+ *  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.geronimo.osgi.example;
+
+import java.io.Serializable;
+import java.util.Map;
+
+public class FooListener {
+        
+    public void serviceRegistered(Serializable foo, Map props) {
+        System.out.println("Service registration notification: " + foo + " " + props);
+    }
+    
+    public void serviceUnregistered(Foo foo, Map props) {
+        System.out.println("Service unregistration notification: " + foo + " " + props);
+    }
+
+}

Propchange: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/FooListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/FooListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/blueprint/sample/src/main/java/org/apache/geronimo/osgi/example/FooListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml?rev=766413&r1=766412&r2=766413&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml (original)
+++ geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml Sun Apr 19 02:44:56 2009
@@ -35,10 +35,16 @@
     <component id="converter2" class="org.apache.geronimo.osgi.example.CurrencyTypeConverter"/>
 
     <service ref="foo" auto-export="all-classes">
+        <registration-listener ref="fooListener"         
+                               registration-method="serviceRegistered"
+                               unregistration-method="serviceUnregistered"/>
+                                   
         <service-properties>
             <entry key="key" value="value"/>
         </service-properties>
     </service>
     
+    <component id="fooListener" class="org.apache.geronimo.osgi.example.FooListener"/>
+    
 </components>