geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r779883 - in /geronimo/sandbox/blueprint: blueprint-bundle/ blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/ blueprint-cm/src/main/resources/OSGI-INF/blueprint/ blueprint-core/ blueprint-core/src/main/java/org/apache/...
Date Fri, 29 May 2009 07:50:26 GMT
Author: gnodet
Date: Fri May 29 07:50:25 2009
New Revision: 779883

URL: http://svn.apache.org/viewvc?rev=779883&view=rev
Log:
Add a geronimo specific extension namespace

Added:
    geronimo/sandbox/blueprint/blueprint-cm/src/main/resources/OSGI-INF/blueprint/blueprint-cm.xml
      - copied unchanged from r779856, geronimo/sandbox/blueprint/blueprint-cm/src/main/resources/OSGI-INF/blueprint/cm.xml
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/AbstractPropertyPlaceholder.java
      - copied, changed from r779864, geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/beans/AbstractPropertyPlaceholder.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/PlaceholdersUtils.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/SystemPropertyPlaceholder.java
      - copied, changed from r779856, geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/beans/SystemPropertyPlaceholder.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/resources/OSGI-INF/
    geronimo/sandbox/blueprint/blueprint-core/src/main/resources/OSGI-INF/blueprint/
    geronimo/sandbox/blueprint/blueprint-core/src/main/resources/OSGI-INF/blueprint/blueprint-ext.xml
    geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/
    geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd
Removed:
    geronimo/sandbox/blueprint/blueprint-cm/src/main/resources/OSGI-INF/blueprint/cm.xml
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/beans/
Modified:
    geronimo/sandbox/blueprint/blueprint-bundle/pom.xml
    geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
    geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmPropertyPlaceholder.java
    geronimo/sandbox/blueprint/blueprint-core/pom.xml
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
    geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml

Modified: geronimo/sandbox/blueprint/blueprint-bundle/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-bundle/pom.xml?rev=779883&r1=779882&r2=779883&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-bundle/pom.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-bundle/pom.xml Fri May 29 07:50:25 2009
@@ -53,11 +53,11 @@
                             *
                         </Import-Package>
                         <Export-Package>
-                            =org.osgi.service.blueprint;uses:="org.osgi.service.blueprint.container,org.osgi.service.blueprint.reflect,org.apache.geronimo.blueprint,org.apache.geronimo.blueprint.beans,org.apache.geronimo.blueprint.mutable";version="1.0",
+                            =org.osgi.service.blueprint;uses:="org.osgi.service.blueprint.container,org.osgi.service.blueprint.reflect,org.apache.geronimo.blueprint,org.apache.geronimo.blueprint.ext,org.apache.geronimo.blueprint.mutable";version="1.0",
                             org.osgi.service.blueprint.container;version="1.0",
                             org.osgi.service.blueprint.reflect;version="1.0",
                             org.apache.geronimo.blueprint;version="${pom.version}",
-                            org.apache.geronimo.blueprint.beans;version="${pom.version}",
+                            org.apache.geronimo.blueprint.ext;version="${pom.version}",
                             org.apache.geronimo.blueprint.mutable;version="${pom.version}"
                         </Export-Package>
                         <Private-Package>

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=779883&r1=779882&r2=779883&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
Fri May 29 07:50:25 2009
@@ -29,6 +29,7 @@
 import org.apache.geronimo.blueprint.ComponentDefinitionRegistry;
 import org.apache.geronimo.blueprint.NamespaceHandler;
 import org.apache.geronimo.blueprint.ParserContext;
+import org.apache.geronimo.blueprint.ext.PlaceholdersUtils;
 import org.apache.geronimo.blueprint.container.Parser;
 import org.apache.geronimo.blueprint.container.ParserContextImpl;
 import org.apache.geronimo.blueprint.mutable.MutableBeanMetadata;
@@ -180,39 +181,11 @@
             }
         }
         
-        validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
+        PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
         
         return metadata;
     }
 
-    private void validatePlaceholder(MutableBeanMetadata metadata, ComponentDefinitionRegistry
registry) {
-        String prefix = getPlaceholderProperty(metadata, "placeholderPrefix");
-        String suffix = getPlaceholderProperty(metadata, "placeholderSuffix");
-        for (String id : registry.getComponentDefinitionNames()) {
-            ComponentMetadata component = registry.getComponentDefinition(id);
-            if (component instanceof BeanMetadata) {
-                BeanMetadata bean = (BeanMetadata) component;
-                if (bean.getRuntimeClass() == CmPropertyPlaceholder.class) {
-                    String otherPrefix = getPlaceholderProperty(bean, "placeholderPrefix");
-                    String otherSuffix = getPlaceholderProperty(bean, "placeholderSuffix");
-                    if (prefix.equals(otherPrefix) && suffix.equals(otherSuffix))
{
-                        throw new ComponentDefinitionException("Multiple placeholders with
the same prefix and suffix are not allowed");
-                    }
-                }
-            }
-        }
-    }
-    
-    private String getPlaceholderProperty(BeanMetadata bean, String name) {
-        for (BeanProperty property : bean.getProperties()) {
-            if (name.equals(property.getName())) {
-                ValueMetadata value = (ValueMetadata) property.getValue();
-                return value.getStringValue();
-            }
-        }
-        return null;
-    }
-    
     private Metadata parseDefaultProperties(ParserContext context, MutableBeanMetadata enclosingComponent,
Element element) {
         MutableMapMetadata props = context.createMetadata(MutableMapMetadata.class);
         NodeList nl = element.getChildNodes();

Modified: geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmPropertyPlaceholder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmPropertyPlaceholder.java?rev=779883&r1=779882&r2=779883&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmPropertyPlaceholder.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmPropertyPlaceholder.java
Fri May 29 07:50:25 2009
@@ -22,12 +22,9 @@
 import java.util.Dictionary;
 import java.util.Map;
 
-import org.apache.geronimo.blueprint.beans.AbstractPropertyPlaceholder;
-import org.apache.geronimo.blueprint.mutable.MutableValueMetadata;
+import org.apache.geronimo.blueprint.ext.AbstractPropertyPlaceholder;
 import org.osgi.service.blueprint.container.BlueprintContainer;
 import org.osgi.service.blueprint.container.ComponentDefinitionException;
-import org.osgi.service.blueprint.reflect.Metadata;
-import org.osgi.service.blueprint.reflect.ValueMetadata;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.slf4j.Logger;

Modified: geronimo/sandbox/blueprint/blueprint-core/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/pom.xml?rev=779883&r1=779882&r2=779883&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/pom.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-core/pom.xml Fri May 29 07:50:25 2009
@@ -71,7 +71,7 @@
                     <instructions>
                         <Export-Package>
                             org.apache.geronimo.blueprint;version="${pom.version}",
-                            org.apache.geronimo.blueprint.beans;version="${pom.version}"
+                            org.apache.geronimo.blueprint.ext;version="${pom.version}"
                             org.apache.geronimo.blueprint.mutable;version="${pom.version}"
                         </Export-Package>
                         <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>

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=779883&r1=779882&r2=779883&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
Fri May 29 07:50:25 2009
@@ -254,18 +254,14 @@
                             }
                         };
                         timeoutFuture = executors.schedule(r, timeout, TimeUnit.MILLISECONDS);
-                        if (checkAllSatisfiables() || !waitForDependencies) {
-                            state = State.InitialReferencesSatisfied;
-                        } else {
-                            eventDispatcher.blueprintEvent(new BlueprintEvent(BlueprintEvent.GRACE_PERIOD,
getBundleContext().getBundle(), getExtenderBundle(), getMissingDependencies()));
-                            state = State.WaitForInitialReferences;
-                        }
+                        state = State.WaitForInitialReferences;
                         break;
                     case WaitForInitialReferences:
                         if (checkAllSatisfiables()) {
                             state = State.InitialReferencesSatisfied;
                             break;
                         } else {
+                            eventDispatcher.blueprintEvent(new BlueprintEvent(BlueprintEvent.GRACE_PERIOD,
getBundleContext().getBundle(), getExtenderBundle(), getMissingDependencies()));
                             return;
                         }
                     case InitialReferencesSatisfied:
@@ -283,10 +279,9 @@
                         satisfiables = null;
                         trackServiceReferences();
                         // Check references
-                        if (checkAllSatisfiables() || !waitForDependencies) {
+                        if (!waitForDependencies) {
                             state = State.Create;
                         } else {
-                            eventDispatcher.blueprintEvent(new BlueprintEvent(BlueprintEvent.GRACE_PERIOD,
getBundleContext().getBundle(), getExtenderBundle(), getMissingDependencies()));
                             state = State.WaitForInitialReferences2;
                         }
                         break;
@@ -295,6 +290,7 @@
                             state = State.Create;
                             break;
                         } else {
+                            eventDispatcher.blueprintEvent(new BlueprintEvent(BlueprintEvent.GRACE_PERIOD,
getBundleContext().getBundle(), getExtenderBundle(), getMissingDependencies()));
                             return;
                         }
                     case Create:

Copied: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/AbstractPropertyPlaceholder.java
(from r779864, geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/beans/AbstractPropertyPlaceholder.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/AbstractPropertyPlaceholder.java?p2=geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/AbstractPropertyPlaceholder.java&p1=geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/beans/AbstractPropertyPlaceholder.java&r1=779864&r2=779883&rev=779883&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/beans/AbstractPropertyPlaceholder.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/AbstractPropertyPlaceholder.java
Fri May 29 07:50:25 2009
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.geronimo.blueprint.beans;
+package org.apache.geronimo.blueprint.ext;
 
 import java.util.ArrayList;
 import java.util.List;

Added: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java?rev=779883&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java
Fri May 29 07:50:25 2009
@@ -0,0 +1,214 @@
+/**
+ * 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.ext;
+
+import java.net.URL;
+import java.util.List;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+import org.osgi.service.blueprint.reflect.RefMetadata;
+import org.osgi.service.blueprint.reflect.IdRefMetadata;
+import org.osgi.service.blueprint.reflect.CollectionMetadata;
+import org.osgi.service.blueprint.reflect.BeanProperty;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.apache.geronimo.blueprint.ParserContext;
+import org.apache.geronimo.blueprint.ComponentDefinitionRegistry;
+import org.apache.geronimo.blueprint.mutable.MutableBeanMetadata;
+import org.apache.geronimo.blueprint.mutable.MutableComponentMetadata;
+import org.apache.geronimo.blueprint.mutable.MutableValueMetadata;
+import org.apache.geronimo.blueprint.mutable.MutableRefMetadata;
+import org.apache.geronimo.blueprint.mutable.MutableIdRefMetadata;
+import org.apache.geronimo.blueprint.mutable.MutableCollectionMetadata;
+import org.apache.geronimo.blueprint.mutable.MutableMapMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A namespace handler for geronimo blueprint extensions
+ *
+ * @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 ExtNamespaceHandler implements org.apache.geronimo.blueprint.NamespaceHandler
{
+
+    public static final String BLUEPRINT_NAMESPACE = "http://www.osgi.org/xmlns/blueprint/v1.0.0";
+    public static final String BLUEPRINT_EXT_NAMESPACE = "http://geronimo.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0";
+
+    public static final String SYSTEM_PROPERTY_PLACEHOLDER_ELEMENT = "system-property-placeholder";
+    public static final String DEFAULT_PROPERTIES_ELEMENT = "default-properties";
+    public static final String PROPERTY_ELEMENT = "property";
+    public static final String VALUE_ELEMENT = "value";
+
+    public static final String ID_ATTRIBUTE = "id";
+    public static final String PLACEHOLDER_PREFIX_ATTRIBUTE = "placeholder-prefix";
+    public static final String PLACEHOLDER_SUFFIX_ATTRIBUTE = "placeholder-suffix";
+    public static final String DEFAULTS_REF_ATTRIBUTE = "defaults-ref";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ExtNamespaceHandler.class);
+
+    private int idCounter;
+
+    public URL getSchemaLocation(String namespace) {
+        return getClass().getResource("blueprint-ext.xsd");
+    }
+
+    public Metadata parse(Element element, ParserContext context) {
+        LOGGER.debug("Parsing element {" + element.getNamespaceURI() + "}" + element.getLocalName());
+        ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
+        if (nodeNameEquals(element, SYSTEM_PROPERTY_PLACEHOLDER_ELEMENT)) {
+            return parseSystemPropertyPlaceholder(context, element);
+        } else {
+            throw new ComponentDefinitionException("Unsupported element: " + element.getNodeName());
+        }
+    }
+
+    public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext
context) {
+        throw new ComponentDefinitionException("Illegal use of blueprint ext namespace");
+    }
+
+    private Metadata parseSystemPropertyPlaceholder(ParserContext context, Element element)
{
+        MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
+        metadata.setProcessor(true);
+        metadata.setId(getId(context, element));
+        metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+        metadata.setRuntimeClass(SystemPropertyPlaceholder.class);
+        String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
+                                    ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
+                                    : "${";
+        metadata.addProperty("placeholderPrefix", createValue(context, prefix));
+        String suffix = element.hasAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE)
+                                    ? element.getAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE)
+                                    : "}";
+        metadata.addProperty("placeholderSuffix", createValue(context, suffix));
+        String defaultsRef = element.hasAttribute(DEFAULTS_REF_ATTRIBUTE) ? element.getAttribute(DEFAULTS_REF_ATTRIBUTE)
: null;
+        if (defaultsRef != null) {
+            metadata.addProperty("defaultProperties", createRef(context, defaultsRef));
+        }
+        // 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 (BLUEPRINT_EXT_NAMESPACE.equals(e.getNamespaceURI())) {
+                    if (nodeNameEquals(e, DEFAULT_PROPERTIES_ELEMENT)) {
+                        if (defaultsRef != null) {
+                            throw new ComponentDefinitionException("Only one of " + DEFAULTS_REF_ATTRIBUTE
+ " attribute or " + DEFAULT_PROPERTIES_ELEMENT + " element is allowed");
+                        }
+                        Metadata props = parseDefaultProperties(context, metadata, e);
+                        metadata.addProperty("defaultProperties", props);
+                    }
+                }
+            }
+        }
+
+        PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
+
+        return metadata;
+    }
+
+    private Metadata parseDefaultProperties(ParserContext context, MutableBeanMetadata enclosingComponent,
Element element) {
+        MutableMapMetadata props = context.createMetadata(MutableMapMetadata.class);
+        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 (BLUEPRINT_EXT_NAMESPACE.equals(e.getNamespaceURI())) {
+                    if (nodeNameEquals(e, PROPERTY_ELEMENT)) {
+                        BeanProperty prop = context.parseElement(BeanProperty.class, enclosingComponent,
e);
+                        props.addEntry(createValue(context, prop.getName(), String.class.getName()),
prop.getValue());
+                    }
+                }
+            }
+        }
+        return props;
+    }
+
+    public String getId(ParserContext context, Element element) {
+        if (element.hasAttribute(ID_ATTRIBUTE)) {
+            return element.getAttribute(ID_ATTRIBUTE);
+        } else {
+            return generateId(context);
+        }
+    }
+
+    public void generateIdIfNeeded(ParserContext context, MutableComponentMetadata metadata)
{
+        if (metadata.getId() == null) {
+            metadata.setId(generateId(context));
+        }
+    }
+
+    private String generateId(ParserContext context) {
+        String id;
+        do {
+            id = ".ext-" + ++idCounter;
+        } while (context.getComponentDefinitionRegistry().containsComponentDefinition(id));
+        return id;
+    }
+
+    private static ValueMetadata createValue(ParserContext context, String value) {
+        return createValue(context, value, null);
+    }
+
+    private static ValueMetadata createValue(ParserContext context, String value, String
type) {
+        MutableValueMetadata m = context.createMetadata(MutableValueMetadata.class);
+        m.setStringValue(value);
+        m.setTypeName(type);
+        return m;
+    }
+
+    private static RefMetadata createRef(ParserContext context, String value) {
+        MutableRefMetadata m = context.createMetadata(MutableRefMetadata.class);
+        m.setComponentId(value);
+        return m;
+    }
+
+    private static IdRefMetadata createIdRef(ParserContext context, String value) {
+        MutableIdRefMetadata m = context.createMetadata(MutableIdRefMetadata.class);
+        m.setComponentId(value);
+        return m;
+    }
+
+    private static CollectionMetadata createList(ParserContext 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 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);
+    }
+
+}

Added: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/PlaceholdersUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/PlaceholdersUtils.java?rev=779883&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/PlaceholdersUtils.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/PlaceholdersUtils.java
Fri May 29 07:50:25 2009
@@ -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.geronimo.blueprint.ext;
+
+import org.apache.geronimo.blueprint.mutable.MutableBeanMetadata;
+import org.apache.geronimo.blueprint.ComponentDefinitionRegistry;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.BeanProperty;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+
+/**
+ * Utility for placeholders parsing / validation
+ *
+ * @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 PlaceholdersUtils {
+
+    public static void validatePlaceholder(MutableBeanMetadata metadata, ComponentDefinitionRegistry
registry) {
+        String prefix = getPlaceholderProperty(metadata, "placeholderPrefix");
+        String suffix = getPlaceholderProperty(metadata, "placeholderSuffix");
+        for (String id : registry.getComponentDefinitionNames()) {
+            ComponentMetadata component = registry.getComponentDefinition(id);
+            if (component instanceof BeanMetadata) {
+                BeanMetadata bean = (BeanMetadata) component;
+                if (bean.getRuntimeClass() != null && AbstractPropertyPlaceholder.class.isAssignableFrom(bean.getRuntimeClass()))
{
+                    String otherPrefix = getPlaceholderProperty(bean, "placeholderPrefix");
+                    String otherSuffix = getPlaceholderProperty(bean, "placeholderSuffix");
+                    if (prefix.equals(otherPrefix) && suffix.equals(otherSuffix))
{
+                        throw new ComponentDefinitionException("Multiple placeholders with
the same prefix and suffix are not allowed");
+                    }
+                }
+            }
+        }
+    }
+
+    private static String getPlaceholderProperty(BeanMetadata bean, String name) {
+        for (BeanProperty property : bean.getProperties()) {
+            if (name.equals(property.getName())) {
+                ValueMetadata value = (ValueMetadata) property.getValue();
+                return value.getStringValue();
+            }
+        }
+        return null;
+    }
+
+}

Copied: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/SystemPropertyPlaceholder.java
(from r779856, geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/beans/SystemPropertyPlaceholder.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/SystemPropertyPlaceholder.java?p2=geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/SystemPropertyPlaceholder.java&p1=geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/beans/SystemPropertyPlaceholder.java&r1=779856&r2=779883&rev=779883&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/beans/SystemPropertyPlaceholder.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/SystemPropertyPlaceholder.java
Fri May 29 07:50:25 2009
@@ -16,7 +16,13 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.geronimo.blueprint.beans;
+package org.apache.geronimo.blueprint.ext;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
 
 /**
  * Property placeholder that looks for properties in the System properties.
@@ -26,8 +32,35 @@
  */
 public class SystemPropertyPlaceholder extends AbstractPropertyPlaceholder {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(SystemPropertyPlaceholder.class);
+
+    private Map defaultProperties;
+
+    public Map getDefaultProperties() {
+        return defaultProperties;
+    }
+
+    public void setDefaultProperties(Map defaultProperties) {
+        this.defaultProperties = defaultProperties;
+    }
+
     protected String getProperty(String val) {
-        return System.getProperty(val);
+        LOGGER.debug("Retrieving system property {}", val);
+        Object v = System.getProperty(val);
+        if (v != null) {
+            LOGGER.debug("Found system property {}", v);
+        } else {
+            LOGGER.debug("System property not found {}", v);
+            if (defaultProperties != null) {
+                v = defaultProperties.get(val);
+                if (v != null) {
+                    LOGGER.debug("Retrieved value from defaults {}", v);
+                } else {
+                    throw new ComponentDefinitionException("Property not found: " + val);
+                }
+            }
+        }
+        return v != null ? v.toString() : null;
     }
 
 }

Added: geronimo/sandbox/blueprint/blueprint-core/src/main/resources/OSGI-INF/blueprint/blueprint-ext.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/resources/OSGI-INF/blueprint/blueprint-ext.xml?rev=779883&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/resources/OSGI-INF/blueprint/blueprint-ext.xml
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/resources/OSGI-INF/blueprint/blueprint-ext.xml
Fri May 29 07:50:25 2009
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+
+    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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+    <service interface="org.apache.geronimo.blueprint.NamespaceHandler">
+        <service-properties>
+            <entry key="osgi.service.blueprint.namespace" value="http://geronimo.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"/>
+        </service-properties>
+        <bean class="org.apache.geronimo.blueprint.ext.ExtNamespaceHandler"/>
+    </service>
+
+</blueprint>
\ No newline at end of file

Added: geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd?rev=779883&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd
Fri May 29 07:50:25 2009
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+
+    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.
+
+-->
+<xsd:schema xmlns="http://geronimo.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+            xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+            targetNamespace="http://geronimo.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+            elementFormDefault="qualified"
+            attributeFormDefault="unqualified"
+            version="1.0.0">
+
+    <xsd:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0"/>
+
+    <!-- property placeholder -->
+
+    <xsd:element name="system-property-placeholder" type="TpropertyPlaceholder"/>
+
+    <xsd:complexType name="TpropertyPlaceholder">
+        <xsd:complexContent>
+            <xsd:extension base="bp:Tcomponent">
+                <xsd:sequence>
+                    <!-- nested properties declaration -->
+                    <xsd:element name="default-properties" type="TdefaultProperties" minOccurs="0"
maxOccurs="1"/>
+                </xsd:sequence>
+                <xsd:attribute name="placeholder-prefix" type="xsd:string" use="optional"
default="${"/>
+                <xsd:attribute name="placeholder-suffix" type="xsd:string" use="optional"
default="}"/>
+                <xsd:attribute name="defaults-ref" type="bp:Tidref" use="optional"/>
+            </xsd:extension>
+        </xsd:complexContent>
+    </xsd:complexType>
+
+
+    <!-- #### is this the correct type here?  This is defining placeholder properties,
+         so should this be a restricted set of value types or should this be expanded to
+         all of the elements you can inject into a bean property? -->
+    <xsd:complexType name="TdefaultProperties">
+        <xsd:sequence minOccurs="0" maxOccurs="unbounded">
+            <xsd:element name="property" type="bp:Tproperty"/>
+        </xsd:sequence>
+    </xsd:complexType>
+
+
+</xsd:schema>

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=779883&r1=779882&r2=779883&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
Fri May 29 07:50:25 2009
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
            xmlns:cm="http://www.osgi.org/xmlns/blueprint-cm/v1.0.0"
+           xmlns:ext="http://geronimo.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
            default-availability="optional">
 
     <type-converters>
@@ -11,6 +12,8 @@
 
     </type-converters>
 
+    <ext:system-property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/>
+
     <cm:managed-service-factory id="managed-service-factory" factory-pid="blueprint-sample-managed-service-factory"
             interface="org.apache.geronimo.blueprint.sample.Foo">
         <service-properties>



Mime
View raw message