geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r776637 - in /geronimo/sandbox/blueprint: blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ blueprint-core/src/main/java/org/apache/geronimo/bluepri...
Date Wed, 20 May 2009 09:40:38 GMT
Author: gnodet
Date: Wed May 20 09:40:37 2009
New Revision: 776637

URL: http://svn.apache.org/viewvc?rev=776637&view=rev
Log:
Begin implementing cm:managed-service-factory

Added:
    geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmManagedServiceFactory.java
Modified:
    geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java
    geronimo/sandbox/blueprint/blueprint-itests/pom.xml
    geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestConfigAdmin.java
    geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml

Added: geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmManagedServiceFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmManagedServiceFactory.java?rev=776637&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmManagedServiceFactory.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmManagedServiceFactory.java
Wed May 20 09:40:37 2009
@@ -0,0 +1,148 @@
+/**
+ * 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.blueprint.compendium.cm;
+
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TODO: if we need to make those exported services tied to their references as for other
<service/> elements
+ * TODO: it becomes a problem as currently we would have to create a specific recipe or something
like that
+ *
+ * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
+ * @version $Rev: 766508 $, $Date: 2009-04-19 22:09:27 +0200 (Sun, 19 Apr 2009) $
+ */
+public class CmManagedServiceFactory {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(CmManagedServiceFactory.class);
+
+    private String id;
+    private BlueprintContainer blueprintContainer;
+    private ConfigurationAdmin configAdmin;
+    private String factoryPid;
+    private List<String> interfaces;
+    private int autoExport;
+    private int ranking;
+    private String managedComponentName;
+
+    private ServiceRegistration registration;
+    private Map<String, ServiceRegistration> pids = new ConcurrentHashMap<String,
ServiceRegistration>();
+    private Map<ServiceRegistration, Object> services = new ConcurrentHashMap<ServiceRegistration,
Object>();
+
+    public void init() {
+        LOGGER.debug("Initializing CmManagedServiceFactory for pid={}", factoryPid);
+        Properties props = new Properties();
+        props.put(Constants.SERVICE_PID, factoryPid);
+        Bundle bundle = blueprintContainer.getBundleContext().getBundle();
+        props.put(Constants.BUNDLE_SYMBOLICNAME, bundle.getSymbolicName());
+        props.put(Constants.BUNDLE_VERSION, bundle.getHeaders().get(Constants.BUNDLE_VERSION));
+        registration = blueprintContainer.getBundleContext().registerService(ManagedServiceFactory.class.getName(),
new ConfigurationWatcher(), props);
+    }
+
+    public void destroy() {
+        if (registration != null) {
+            registration.unregister();
+        }
+    }
+
+    public Map<ServiceRegistration, Object> getServiceMap() {
+        return Collections.unmodifiableMap(services);
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public void setBlueprintContainer(BlueprintContainer blueprintContainer) {
+        this.blueprintContainer = blueprintContainer;
+    }
+
+    public void setConfigAdmin(ConfigurationAdmin configAdmin) {
+        this.configAdmin = configAdmin;
+    }
+
+    public void setFactoryPid(String factoryPid) {
+        this.factoryPid = factoryPid;
+    }
+
+    public void setInterfaces(List<String> interfaces) {
+        this.interfaces = interfaces;
+    }
+
+    public void setAutoExport(int autoExport) {
+        this.autoExport = autoExport;
+    }
+
+    public void setRanking(int ranking) {
+        this.ranking = ranking;
+    }
+
+    public void setManagedComponentName(String managedComponentName) {
+        this.managedComponentName = managedComponentName;
+    }
+
+    protected void updated(String pid, Dictionary props) {
+        LOGGER.error("Updated configuration {} with props {}", pid, props);
+        Object component = blueprintContainer.getComponent(managedComponentName);
+        // TODO: autoExport, ranking, init instance, call listeners, etc...
+        ServiceRegistration reg = blueprintContainer.getBundleContext().registerService(interfaces.toArray(new
String[interfaces.size()]), component, new Properties());
+        services.put(reg, component);
+        pids.put(pid, reg);
+    }
+
+    protected void deleted(String pid) {
+        LOGGER.error("Deleted configuration {}", pid);
+        ServiceRegistration reg = pids.remove(pid);
+        if (reg != null) {
+            // TODO: destroy instance, etc...
+            services.remove(reg);
+            reg.unregister();
+        }
+    }
+
+    private class ConfigurationWatcher implements ManagedServiceFactory {
+
+        public String getName() {
+            return null;
+        }
+
+        public void updated(String pid, Dictionary props) throws ConfigurationException {
+            CmManagedServiceFactory.this.updated(pid, props);
+        }
+
+        public void deleted(String pid) {
+            CmManagedServiceFactory.this.deleted(pid);
+        }
+    }
+
+}

Modified: geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java?rev=776637&r1=776636&r2=776637&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
Wed May 20 09:40:37 2009
@@ -19,10 +19,16 @@
 package org.apache.geronimo.blueprint.compendium.cm;
 
 import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+import java.util.ArrayList;
 
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
+import org.w3c.dom.EntityReference;
 
 import org.apache.geronimo.blueprint.ExtendedComponentDefinitionRegistry;
 import org.apache.geronimo.blueprint.ExtendedParserContext;
@@ -32,6 +38,7 @@
 import org.apache.geronimo.blueprint.mutable.MutableRefMetadata;
 import org.apache.geronimo.blueprint.mutable.MutableReferenceMetadata;
 import org.apache.geronimo.blueprint.mutable.MutableIdRefMetadata;
+import org.apache.geronimo.blueprint.mutable.MutableCollectionMetadata;
 import org.osgi.service.blueprint.container.ComponentDefinitionException;
 import org.osgi.service.blueprint.namespace.ComponentDefinitionRegistry;
 import org.osgi.service.blueprint.namespace.NamespaceHandler;
@@ -45,7 +52,10 @@
 import org.osgi.service.blueprint.reflect.BeanMetadata;
 import org.osgi.service.blueprint.reflect.ServiceMetadata;
 import org.osgi.service.blueprint.reflect.IdRefMetadata;
+import org.osgi.service.blueprint.reflect.CollectionMetadata;
 import org.osgi.service.cm.ConfigurationAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * TODO
@@ -55,6 +65,7 @@
  */
 public class CmNamespaceHandler implements NamespaceHandler {
 
+    public static final String BLUEPRINT_NAMESPACE = "http://www.osgi.org/xmlns/blueprint/v1.0.0";
     public static final String BLUEPRINT_CM_NAMESPACE = "http://www.osgi.org/xmlns/blueprint-cm/v1.0.0";
 
     public static final String PROPERTY_PLACEHOLDER_ELEMENT = "property-placeholder";
@@ -63,6 +74,9 @@
     public static final String CM_PROPERTIES_ELEMENT = "cm-properties";
     public static final String DEFAULT_PROPERTIES_ELEMENT = "default-properties";
     public static final String PROPERTY_ELEMENT = "property";
+    public static final String INTERFACES_ELEMENT = "interfaces";
+    public static final String VALUE_ELEMENT = "value";
+    public static final String MANAGED_COMPONENT_ELEMENT = "managed-component";
 
     public static final String ID_ATTRIBUTE = "id";
     public static final String PERSISTENT_ID_ATTRIBUTE = "persistent-id";
@@ -71,9 +85,22 @@
     public static final String DEFAULTS_REF_ATTRIBUTE = "defaults-ref";
     public static final String UPDATE_STRATEGY_ATTRIBUTE = "update-strategy";
     public static final String UPDATE_METHOD_ATTRIBUTE = "update-method";
+    public static final String FACTORY_PID_ATTRIBUTE = "factory-pid";
+    public static final String AUTO_EXPORT_ATTRIBUTE = "auto-export";
+    public static final String RANKING_ATTRIBUTE = "ranking";
+    public static final String INTERFACE_ATTRIBUTE = "interface";
 
     public static final String CONFIG_ADMIN_REFERENCE_NAME = "blueprint.configadmin";
 
+    public static final String AUTO_EXPORT_DISABLED = "disabled";
+    public static final String AUTO_EXPORT_INTERFACES = "interfaces";
+    public static final String AUTO_EXPORT_CLASS_HIERARCHY = "class-hierarchy";
+    public static final String AUTO_EXPORT_ALL = "all-classes";
+    public static final String AUTO_EXPORT_DEFAULT = AUTO_EXPORT_DISABLED;
+    public static final String RANKING_DEFAULT = "0";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(CmNamespaceHandler.class);
+
     private int nameCounter;
 
     public URL getSchemaLocation(String namespace) {
@@ -81,6 +108,7 @@
     }
 
     public ComponentMetadata parse(Element element, ParserContext ctx) {
+        LOGGER.debug("Parsing element {" + element.getNamespaceURI() + "}" + element.getLocalName());
         ExtendedParserContext context = (ExtendedParserContext) ctx;
         ExtendedComponentDefinitionRegistry registry = (ExtendedComponentDefinitionRegistry)
context.getComponentDefinitionRegistry();
         createConfigAdminProxy(context, registry);
@@ -94,6 +122,7 @@
     }
 
     public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext
ctx) {
+        LOGGER.debug("Decorating node {" + node.getNamespaceURI() + "}" + node.getLocalName());
         ExtendedParserContext context = (ExtendedParserContext) ctx;
         ExtendedComponentDefinitionRegistry registry = (ExtendedComponentDefinitionRegistry)
context.getComponentDefinitionRegistry();
         createConfigAdminProxy(context, registry);
@@ -113,6 +142,7 @@
     private ComponentMetadata parsePropertyPlaceholder(ExtendedParserContext context, Element
element) {
         MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
         metadata.setId(getName(element));
+        metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
         metadata.setRuntimeClass(CmPropertyPlaceholder.class);
         metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
         metadata.addProperty("configAdmin", createRef(context, CONFIG_ADMIN_REFERENCE_NAME));
@@ -168,8 +198,72 @@
     }
 
     private ComponentMetadata parseManagedServiceFactory(ExtendedParserContext context, Element
element) {
-        // TODO: implement managed-service-factory
-        throw new UnsupportedOperationException("Not implemented yet");
+        String id = getName(element);
+
+        MutableBeanMetadata factoryMetadata = context.createMetadata(MutableBeanMetadata.class);
+        factoryMetadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+        factoryMetadata.setRuntimeClass(CmManagedServiceFactory.class);
+        factoryMetadata.setInitMethodName("init");
+        factoryMetadata.setDestroyMethodName("destroy");
+        factoryMetadata.addProperty("id", createValue(context, id));
+        factoryMetadata.addProperty("configAdmin", createRef(context, CONFIG_ADMIN_REFERENCE_NAME));
+        factoryMetadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
+        factoryMetadata.addProperty("factoryPid", createValue(context, element.getAttribute(FACTORY_PID_ATTRIBUTE)));
+        String autoExport = element.hasAttribute(AUTO_EXPORT_ATTRIBUTE) ? element.getAttribute(AUTO_EXPORT_ATTRIBUTE)
: AUTO_EXPORT_DEFAULT;
+        if (AUTO_EXPORT_DISABLED.equals(autoExport)) {
+            autoExport = Integer.toString(ServiceMetadata.AUTO_EXPORT_DISABLED);
+        } else if (AUTO_EXPORT_INTERFACES.equals(autoExport)) {
+            autoExport = Integer.toString(ServiceMetadata.AUTO_EXPORT_INTERFACES);
+        } else if (AUTO_EXPORT_CLASS_HIERARCHY.equals(autoExport)) {
+            autoExport = Integer.toString(ServiceMetadata.AUTO_EXPORT_CLASS_HIERARCHY);
+        } else if (AUTO_EXPORT_ALL.equals(autoExport)) {
+            autoExport = Integer.toString(ServiceMetadata.AUTO_EXPORT_ALL_CLASSES);
+        } else {
+            throw new ComponentDefinitionException("Illegal value (" + autoExport + ") for
" + AUTO_EXPORT_ATTRIBUTE + " attribute");
+        }
+        factoryMetadata.addProperty("autoExport", createValue(context, autoExport));
+        String ranking = element.hasAttribute(RANKING_ATTRIBUTE) ? element.getAttribute(RANKING_ATTRIBUTE)
: RANKING_DEFAULT;
+        factoryMetadata.addProperty("ranking", createValue(context, ranking));
+
+        List<String> interfaces = null;
+        if (element.hasAttribute(INTERFACE_ATTRIBUTE)) {
+            interfaces = Collections.singletonList(element.getAttribute(INTERFACE_ATTRIBUTE));
+            factoryMetadata.addProperty("interfaces", createList(context, interfaces));
+        }
+
+        // Parse elements
+        NodeList nl = element.getChildNodes();
+        for (int i = 0; i < nl.getLength(); i++) {
+            Node node = nl.item(i);
+            if (node instanceof Element) {
+                Element e = (Element) node;
+                if (isBlueprintNamespace(e.getNamespaceURI())) {
+                    if (nodeNameEquals(e, INTERFACES_ELEMENT)) {
+                        if (interfaces != null) {
+                            throw new ComponentDefinitionException("Only one of " + INTERFACE_ATTRIBUTE
+ " attribute or " + INTERFACES_ELEMENT + " element must be used");
+                        }
+                        interfaces = parseInterfaceNames(e);
+                        factoryMetadata.addProperty("interfaces", createList(context, interfaces));
+                    }
+                    // TODO: parse service-properties, listeners, etc...
+                } else if (BLUEPRINT_CM_NAMESPACE.equals(e.getNamespaceURI())) {
+                    if (nodeNameEquals(e, MANAGED_COMPONENT_ELEMENT)) {
+                        MutableBeanMetadata managedComponent = context.parseElement(MutableBeanMetadata.class,
null, e);
+                        generateIdIfNeeded(managedComponent);
+                        managedComponent.setScope("prototype");
+                        context.getComponentDefinitionRegistry().registerComponentDefinition(managedComponent);
+                        factoryMetadata.addProperty("managedComponentName", createIdRef(context,
managedComponent.getId()));
+                    }
+                }
+            }
+        }
+
+        MutableBeanMetadata mapMetadata = context.createMetadata(MutableBeanMetadata.class);
+        mapMetadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+        mapMetadata.setId(id);
+        mapMetadata.setFactoryComponent(factoryMetadata);
+        mapMetadata.setFactoryMethodName("getServiceMap");
+        return mapMetadata;
     }
 
     private ComponentMetadata decorateCmProperties(ExtendedParserContext context, Element
element, ComponentMetadata component) {
@@ -181,12 +275,10 @@
     }
 
     private ComponentMetadata decorateManagedProperties(ExtendedParserContext context, Element
element, ComponentMetadata component) {
-        if (!(component instanceof BeanMetadata)) {
+        if (!(component instanceof MutableBeanMetadata)) {
             throw new ComponentDefinitionException("Element " + MANAGED_PROPERTIES_ELEMENT
+ " must be used inside a <bp:bean> element");
         }
-        if (component.getId() == null) {
-            throw new IllegalStateException("Component does not have an id: " + component);
-        }
+        generateIdIfNeeded(((MutableBeanMetadata) component));
         MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
         metadata.setId(getName(element));
         metadata.setRuntimeClass(CmManagedProperties.class);
@@ -246,10 +338,57 @@
         return m;
     }
 
+    private static CollectionMetadata createList(ExtendedParserContext context, List<String>
list) {
+        MutableCollectionMetadata m = context.createMetadata(MutableCollectionMetadata.class);
+        m.setCollectionClass(List.class);
+        m.setValueTypeName(String.class.getName());
+        for (String v : list) {
+            m.addValue(createValue(context, v, String.class.getName()));
+        }
+        return m;
+    }
+
+    private List<String> parseInterfaceNames(Element element) {
+        List<String> interfaceNames = new ArrayList<String>();
+        NodeList nl = element.getChildNodes();
+        for (int i = 0; i < nl.getLength(); i++) {
+            Node node = nl.item(i);
+            if (node instanceof Element) {
+                Element e = (Element) node;
+                if (nodeNameEquals(e, VALUE_ELEMENT)) {
+                    String v = getTextValue(e).trim();
+                    if (interfaceNames.contains(v)) {
+                        throw new ComponentDefinitionException("The element " + INTERFACES_ELEMENT
+ " should not contain the same interface twice");
+                    }
+                    interfaceNames.add(getTextValue(e));
+                } else {
+                    throw new ComponentDefinitionException("Unsupported element " + e.getNodeName()
+ " inside an " + INTERFACES_ELEMENT + " element");
+                }
+            }
+        }
+        return interfaceNames;
+    }
+
+    private static String getTextValue(Element element) {
+        StringBuffer value = new StringBuffer();
+        NodeList nl = element.getChildNodes();
+        for (int i = 0; i < nl.getLength(); i++) {
+            Node item = nl.item(i);
+            if ((item instanceof CharacterData && !(item instanceof Comment)) ||
item instanceof EntityReference) {
+                value.append(item.getNodeValue());
+            }
+        }
+        return value.toString();
+    }
+
     private static boolean nodeNameEquals(Node node, String name) {
         return (name.equals(node.getNodeName()) || name.equals(node.getLocalName()));
     }
 
+    public static boolean isBlueprintNamespace(String ns) {
+        return BLUEPRINT_NAMESPACE.equals(ns);
+    }
+
     public String getName(Element element) {
         if (element.hasAttribute(ID_ATTRIBUTE)) {
             return element.getAttribute(ID_ATTRIBUTE);
@@ -258,4 +397,10 @@
         }
     }
 
+    public void generateIdIfNeeded(MutableBeanMetadata metadata) {
+        if (metadata.getId() == null) {
+            metadata.setId("cm-" + ++nameCounter);
+        }
+    }
+
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java?rev=776637&r1=776636&r2=776637&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
Wed May 20 09:40:37 2009
@@ -635,6 +635,7 @@
             throw new NoSuchComponentException(name);
         }
         try {
+            LOGGER.debug("Instantiating component {}", name);
             return instantiator.create(name);
         } catch (NoSuchObjectException e) {
             throw new NoSuchComponentException(name);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectRecipe.java?rev=776637&r1=776636&r2=776637&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectRecipe.java
Wed May 20 09:40:37 2009
@@ -45,14 +45,18 @@
 import org.apache.geronimo.blueprint.di.ReferenceRecipe;
 import org.apache.geronimo.blueprint.utils.ReflectionUtils;
 import static org.apache.geronimo.blueprint.utils.TypeUtils.toClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  *
  * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
- * @version $Rev: 775978 $, $Date: 2009-05-18 16:55:23 +0200 (Mon, 18 May 2009) $
+ * @version $Rev$, $Date$
  */
 public class BlueprintObjectRecipe extends AbstractRecipe {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(BlueprintObjectRecipe.class);
+
     private Class typeClass;
     private final LinkedHashMap<String,Object> properties = new LinkedHashMap<String,Object>();
     private final EnumSet<Option> options = EnumSet.noneOf(Option.class);
@@ -249,6 +253,9 @@
                 throw new ConstructionException("Multiple matching factory methods " + factoryMethod
+ " found on class " + getType() + " for arguments " + args + " when instanciating bean "
+ getName());
             }
         } else {
+            if (getType() == null) {
+                throw new ConstructionException("No factoryMethod nor class is defined for
this bean"); 
+            }
             // Map of matching constructors
             Map<Constructor, List<Object>> matches = findMatchingConstructors(getType(),
args, argTypes);
             if (matches.size() == 1) {
@@ -550,7 +557,7 @@
                 Throwable root = e.getTargetException();
                 throw new ConstructionException("init-method generated exception", root);
             } catch (Exception e) {
-                e.printStackTrace(); // TODO: log
+                LOGGER.info("Error invoking init method", e);
             }
         }
         
@@ -572,7 +579,7 @@
                 method.invoke(obj);
             }
         } catch (Exception e) {
-            e.printStackTrace(); // TODO: log
+            LOGGER.info("Error invoking destroy method", e);
         }
         for (BeanProcessor processor : blueprintContainer.getBeanProcessors()) {
             processor.afterDestroy(obj, getName());

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java?rev=776637&r1=776636&r2=776637&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
Wed May 20 09:40:37 2009
@@ -369,6 +369,8 @@
             return type.cast(parseBeanProperty(enclosingComponent, element));
         } else if (MapEntry.class.isAssignableFrom(type)) {
             return type.cast(parseMapEntry(element, enclosingComponent));
+        } else if (BeanMetadata.class.isAssignableFrom(type)) {
+            return type.cast(parseBeanMetadata(element, false));
         } else if (Metadata.class.isAssignableFrom(type)) {
             return type.cast(parseValueElement(element, enclosingComponent, true));
         } else {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java?rev=776637&r1=776636&r2=776637&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java
Wed May 20 09:40:37 2009
@@ -67,6 +67,7 @@
             // TODO: should we generate a unique name?
             throw new IllegalArgumentException("Component must have a valid id");
         }
+        // TODO: perform other validation: scope, class/runtimeClass/factoryMethod, etc...
         if (components.containsKey(id)) {
             throw new ComponentNameAlreadyInUseException(id);
         }

Modified: geronimo/sandbox/blueprint/blueprint-itests/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-itests/pom.xml?rev=776637&r1=776636&r2=776637&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-itests/pom.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-itests/pom.xml Wed May 20 09:40:37 2009
@@ -83,6 +83,13 @@
             <artifactId>pax-url-mvn</artifactId>
             <scope>test</scope>
         </dependency>
+        <!-- Frameworks -->
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.main</artifactId>
+            <version>1.6.0</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <repositories>

Modified: geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestConfigAdmin.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestConfigAdmin.java?rev=776637&r1=776636&r2=776637&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestConfigAdmin.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestConfigAdmin.java
Wed May 20 09:40:37 2009
@@ -144,6 +144,25 @@
         assertEquals("USD", foo.getProps().get("currency"));
     }
 
+    @Test
+    public void testManagedServiceFactory() throws Exception {
+        ConfigurationAdmin ca = getOsgiService(ConfigurationAdmin.class);
+        Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory",
null);
+        Hashtable<String,String> props = new Hashtable<String,String>();
+        props.put("a", "5");
+        props.put("currency", "PLN");
+        cf.update(props);
+
+        Bundle bundle = getInstalledBundle("blueprint-sample");
+        assertNotNull(bundle);
+        bundle.start();
+
+        BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("blueprint-sample",
5000);
+        assertNotNull(blueprintContainer);
+
+        Thread.sleep(5000);
+    }
+
     @org.ops4j.pax.exam.junit.Configuration
     public static Option[] configuration() {
         Option[] options = options(
@@ -157,7 +176,7 @@
 
 
             // this is how you set the default log level when using pax logging (logProfile)
-            systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+            systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
 
             // Bundles
             mavenBundle("org.apache.geronimo", "blueprint-bundle"),

Modified: geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml?rev=776637&r1=776636&r2=776637&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
(original)
+++ geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
Wed May 20 09:40:37 2009
@@ -11,6 +11,11 @@
 
     </type-converters>
 
+    <cm:managed-service-factory id="managed-service-factory" factory-pid="blueprint-sample-managed-service-factory"
+            interface="org.apache.geronimo.blueprint.sample.Foo">
+        <cm:managed-component class="org.apache.geronimo.blueprint.sample.Foo"/>
+    </cm:managed-service-factory>
+
     <cm:property-placeholder id="property-placeholder" persistent-id="blueprint-sample-placeholder">
         <cm:default-properties>
             <cm:property name="key.b" value="-1"/>



Mime
View raw message