geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r772371 - in /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context: RecipeBuilder.java ServiceRegistrationProxy.java TriggerService.java
Date Wed, 06 May 2009 17:20:10 GMT
Author: gawor
Date: Wed May  6 17:20:10 2009
New Revision: 772371

URL: http://svn.apache.org/viewvc?rev=772371&view=rev
Log:
handle service properties for TriggerServices

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TriggerService.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java?rev=772371&r1=772370&r2=772371&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java
Wed May  6 17:20:10 2009
@@ -177,12 +177,9 @@
             recipe.setProperty("service", getValue(serviceExport.getServiceComponent(), null));
         }
         recipe.setProperty("metadata", serviceExport);
-        if (serviceExport.getServiceProperties() != null) {
-            MutableMapMetadata map = MetadataUtil.createMetadata(MutableMapMetadata.class);
-            for (MapEntry e : serviceExport.getServiceProperties()) {
-                map.addEntry(e);
-            }
-            recipe.setProperty("serviceProperties", getValue(map, null));
+        Recipe propertiesRecipe = getServicePropertiesRecipe(serviceExport);
+        if (propertiesRecipe != null) {
+            recipe.setProperty("serviceProperties", propertiesRecipe);
         }
         if (serviceExport.getRegistrationListeners() != null) {
             CollectionRecipe listenersRecipe = new CollectionRecipe(ArrayList.class);
@@ -194,6 +191,19 @@
         return recipe;
     }
 
+    protected Recipe getServicePropertiesRecipe(ServiceMetadata metadata) throws Exception
{
+        List<MapEntry> properties = metadata.getServiceProperties();
+        if (properties != null) {
+            MutableMapMetadata map = MetadataUtil.createMetadata(MutableMapMetadata.class);
+            for (MapEntry e : properties) {
+                map.addEntry(e);
+            }
+            return getValue(map, null);
+        } else {
+            return null;
+        }
+    }
+    
     private BlueprintObjectRecipe createBeanRecipe(BeanMetadata local) throws Exception {
         Class clazz = local.getRuntimeClass() != null ? local.getRuntimeClass() : loadClass(local.getClassName());
         BlueprintObjectRecipe recipe = new BlueprintObjectRecipe(blueprintContext, clazz);
@@ -263,7 +273,7 @@
         }
     }
     
-    private Object getValue(Metadata v, Class groupingType) throws Exception {
+    private Recipe getValue(Metadata v, Class groupingType) throws Exception {
         if (v instanceof NullMetadata) {
             return null;
         } else if (v instanceof ComponentMetadata) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java?rev=772371&r1=772370&r2=772371&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java
Wed May  6 17:20:10 2009
@@ -87,11 +87,13 @@
         if (componentName != null) {
             props.put(BlueprintConstants.COMPONENT_NAME_PROPERTY, componentName);
         }
-        String[] classes = getClasses();
-        registration = blueprintContext.getBundleContext().registerService(classes, service,
props);
+        Set<String> classes = getClasses();
+        String[] classArray = classes.toArray(new String[classes.size()]);
+        registration = blueprintContext.getBundleContext().registerService(classArray, service,
props);
         registrationProperties = props;
         
-        LOGGER.debug("Service {} registered with interfaces {}", service, classes);
+        LOGGER.debug("Service {} registered with interfaces {} and properties {}", 
+                     new Object [] { service, classes, props });
         
         if (listeners != null) {
             for (Listener listener : listeners) {
@@ -109,7 +111,7 @@
         }
     }
     
-    private String[] getClasses() {
+    private Set<String> getClasses() {
         Class serviceClass = service.getClass();
         if (service instanceof BundleScopeServiceFactory) {
             serviceClass = ((BundleScopeServiceFactory) service).getServiceClass();
@@ -130,8 +132,7 @@
                 classes = new HashSet<String>(metadata.getInterfaceNames());
                 break;
         }
-        String[] classesArray = classes.toArray(new String[classes.size()]);
-        return classesArray;
+        return classes;
     }
     
     public String toString() {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TriggerService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TriggerService.java?rev=772371&r1=772370&r2=772371&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TriggerService.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TriggerService.java
Wed May  6 17:20:10 2009
@@ -18,10 +18,13 @@
  */
 package org.apache.geronimo.blueprint.context;
 
+import java.util.Arrays;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.geronimo.blueprint.BlueprintConstants;
+import org.apache.xbean.recipe.Recipe;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
@@ -41,13 +44,15 @@
     
     private ServiceMetadata metadata;
     private BlueprintContextImpl blueprintContext;  
-    private ServiceRegistration registration;
+    private ServiceRegistration registration;    
+    private Map serviceProperties;
     
     private Object service;
     
     public TriggerService(ServiceMetadata metadata, BlueprintContextImpl blueprintContext)
{
         this.metadata = metadata;
         this.blueprintContext = blueprintContext;
+        this.serviceProperties = getServiceProperties();
     }
     
     public synchronized void register() {
@@ -56,16 +61,36 @@
         }
         
         Hashtable props = new Hashtable();
-        // TODO: handle service properties?
+        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[] classes = getClasses();
-        registration = blueprintContext.getBundleContext().registerService(classes, this,
props);
+        List<String> classes = getClasses();
+        String[] classArray = classes.toArray(new String[classes.size()]);
+        registration = blueprintContext.getBundleContext().registerService(classArray, this,
props);
         
-        LOGGER.debug("Trigger service {} registered with interfaces {}", this, classes);
+        LOGGER.debug("Trigger service {} registered with interfaces {} and properties {}",

+                     new Object[] { this, classes, props });
+    }
+    
+    private Map getServiceProperties() {
+        RecipeBuilder builder = new RecipeBuilder(blueprintContext);
+        Recipe recipe;
+        try {
+            recipe = builder.getServicePropertiesRecipe(metadata);
+            if (recipe == null) {
+                return null;
+            } else {
+                return (Map) recipe.create(Map.class, false);
+            }
+        } catch (Exception e) {
+            LOGGER.debug("Failed to convert MapMetadata to Map", e);
+            return null;
+        }
     }
     
     private String getComponentName() {
@@ -77,9 +102,8 @@
         }
     }
     
-    private String[] getClasses() {
-        List<String> interfaces = metadata.getInterfaceNames();
-        return interfaces.toArray(new String[interfaces.size()]);
+    private List<String> getClasses() {
+        return metadata.getInterfaceNames();
     }
     
     public synchronized void unregister() {   



Mime
View raw message