geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r785789 - in /geronimo/sandbox/blueprint/blueprint-cm/src/main: java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java resources/OSGI-INF/blueprint/blueprint-cm.xml
Date Wed, 17 Jun 2009 20:47:41 GMT
Author: gnodet
Date: Wed Jun 17 20:47:41 2009
New Revision: 785789

URL: http://svn.apache.org/viewvc?rev=785789&view=rev
Log:
Fix ConfigAdmin support broken because of the classloader change when creating service proxies
for references

Modified:
    geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
    geronimo/sandbox/blueprint/blueprint-cm/src/main/resources/OSGI-INF/blueprint/blueprint-cm.xml

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=785789&r1=785788&r2=785789&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 Jun 17 20:47:41 2009
@@ -104,8 +104,6 @@
     public static final String INTERFACE_ATTRIBUTE = "interface";
     public static final String UPDATE_ATTRIBUTE = "update";
 
-    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";
@@ -117,8 +115,28 @@
     
     private static final Logger LOGGER = LoggerFactory.getLogger(CmNamespaceHandler.class);
 
+    // This property is static but it should be ok since there will be only a single instance
+    // of this class for the bundle
+    private static ConfigurationAdmin configAdmin;
+
     private int idCounter;
 
+    public int getIdCounter() {
+        return idCounter;
+    }
+
+    public void setIdCounter(int idCounter) {
+        this.idCounter = idCounter;
+    }
+
+    public static ConfigurationAdmin getConfigAdmin() {
+        return configAdmin;
+    }
+
+    public void setConfigAdmin(ConfigurationAdmin configAdmin) {
+        this.configAdmin = configAdmin;
+    }
+
     public URL getSchemaLocation(String namespace) {
         return getClass().getResource("blueprint-cm.xsd");
     }
@@ -126,7 +144,6 @@
     public Metadata parse(Element element, ParserContext context) {
         LOGGER.debug("Parsing element {" + element.getNamespaceURI() + "}" + element.getLocalName());
         ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
-        createConfigAdminProxy(context, registry);
         registerManagedObjectManager(context, registry);
         if (nodeNameEquals(element, PROPERTY_PLACEHOLDER_ELEMENT)) {
             return parsePropertyPlaceholder(context, element);
@@ -140,7 +157,6 @@
     public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext
context) {
         LOGGER.debug("Decorating node {" + node.getNamespaceURI() + "}" + node.getLocalName());
         ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
-        createConfigAdminProxy(context, registry);
         registerManagedObjectManager(context, registry);
         if (node instanceof Element) {
             if (nodeNameEquals(node, MANAGED_PROPERTIES_ELEMENT)) {
@@ -162,7 +178,7 @@
         metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
         metadata.setRuntimeClass(CmPropertyPlaceholder.class);
         metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
-        metadata.addProperty("configAdmin", createRef(context, CONFIG_ADMIN_REFERENCE_NAME));
+        metadata.addProperty("configAdmin", createConfigAdminProxy(context));
         metadata.addProperty("persistentId", createValue(context, element.getAttribute(PERSISTENT_ID_ATTRIBUTE)));
         String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
                                     ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
@@ -246,7 +262,7 @@
         factoryMetadata.setRuntimeClass(CmManagedServiceFactory.class);
         factoryMetadata.setInitMethod("init");
         factoryMetadata.setDestroyMethod("destroy");
-        factoryMetadata.addProperty("configAdmin", createRef(context, CONFIG_ADMIN_REFERENCE_NAME));
+        factoryMetadata.addProperty("configAdmin", createConfigAdminProxy(context));
         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;
@@ -349,7 +365,7 @@
             metadata.setDestroyMethod("destroy");
         }
         metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
-        metadata.addProperty("configAdmin", createRef(context, CONFIG_ADMIN_REFERENCE_NAME));
+        metadata.addProperty("configAdmin", createConfigAdminProxy(context));
         metadata.addProperty("managedObjectManager", createRef(context, MANAGED_OBJECT_MANAGER_NAME));
         metadata.addProperty("persistentId", createValue(context, persistentId));
         if (element.hasAttribute(UPDATE_ATTRIBUTE)) {
@@ -378,7 +394,7 @@
             metadata.setDestroyMethod("destroy");
         }
         metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
-        metadata.addProperty("configAdmin", createRef(context, CONFIG_ADMIN_REFERENCE_NAME));
+        metadata.addProperty("configAdmin", createConfigAdminProxy(context));
         metadata.addProperty("managedObjectManager", createRef(context, MANAGED_OBJECT_MANAGER_NAME));
         metadata.addProperty("persistentId", createValue(context, persistentId));
         String updateStrategy = element.getAttribute(UPDATE_STRATEGY_ATTRIBUTE);
@@ -399,17 +415,16 @@
      * Create a reference to the ConfigurationAdmin service if not already done
      * and add it to the registry.
      *
-     * @param registry the registry to add the config admin reference to
+     * @param context the parser context
+     * @return a metadata pointing to the config admin
      */
-    private void createConfigAdminProxy(ParserContext context, ComponentDefinitionRegistry
registry) {
-        if (registry.getComponentDefinition(CONFIG_ADMIN_REFERENCE_NAME) == null) {
-            MutableReferenceMetadata reference = context.createMetadata(MutableReferenceMetadata.class);
-            reference.setId(CONFIG_ADMIN_REFERENCE_NAME);
-            reference.setInterface(ConfigurationAdmin.class.getName());
-            reference.setAvailability(ReferenceMetadata.AVAILABILITY_MANDATORY);
-            reference.setTimeout(300000);
-            registry.registerComponentDefinition(reference);
-        }
+    private Metadata createConfigAdminProxy(ParserContext context) {
+        MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
+        bean.setRuntimeClass(CmNamespaceHandler.class);
+        bean.setFactoryMethod("getConfigAdmin");
+        bean.setInitialization(MutableBeanMetadata.INITIALIZATION_LAZY);
+        bean.setScope(MutableBeanMetadata.SCOPE_PROTOTYPE);
+        return bean;
     }
 
     private void registerManagedObjectManager(ParserContext context, ComponentDefinitionRegistry
registry) {

Modified: geronimo/sandbox/blueprint/blueprint-cm/src/main/resources/OSGI-INF/blueprint/blueprint-cm.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-cm/src/main/resources/OSGI-INF/blueprint/blueprint-cm.xml?rev=785789&r1=785788&r2=785789&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-cm/src/main/resources/OSGI-INF/blueprint/blueprint-cm.xml
(original)
+++ geronimo/sandbox/blueprint/blueprint-cm/src/main/resources/OSGI-INF/blueprint/blueprint-cm.xml
Wed Jun 17 20:47:41 2009
@@ -5,7 +5,11 @@
         <service-properties>
             <entry key="osgi.service.blueprint.namespace" value="http://www.osgi.org/xmlns/blueprint-cm/v1.0.0"/>
         </service-properties>
-        <bean class="org.apache.geronimo.blueprint.compendium.cm.CmNamespaceHandler"/>
+        <bean class="org.apache.geronimo.blueprint.compendium.cm.CmNamespaceHandler">
+            <property name="configAdmin">
+                <reference interface="org.osgi.service.cm.ConfigurationAdmin"/>
+            </property>
+        </bean>
     </service>
 
 </blueprint>
\ No newline at end of file



Mime
View raw message