geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r765036 - in /geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint: ./ context/ namespace/
Date Wed, 15 Apr 2009 03:39:08 GMT
Author: gawor
Date: Wed Apr 15 03:39:07 2009
New Revision: 765036

URL: http://svn.apache.org/viewvc?rev=765036&view=rev
Log:
some initial parser changes to handle custom elements and attributes

Modified:
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/Activator.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/NamespaceHandlerRegistry.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/context/Parser.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/namespace/NamespaceHandlerRegistryImpl.java

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/Activator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/Activator.java?rev=765036&r1=765035&r2=765036&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/Activator.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/Activator.java
Wed Apr 15 03:39:07 2009
@@ -116,7 +116,7 @@
                 
         if (!urls.isEmpty()) {
             System.out.println("Found config files:" + urls);
-            ModuleContextImpl moduleContext = new ModuleContextImpl(bundle.getBundleContext(),
sender, urls);
+            ModuleContextImpl moduleContext = new ModuleContextImpl(bundle.getBundleContext(),
sender, handlers, urls);
             contextMap.put(bundle, moduleContext);
             moduleContext.create();
         }

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/NamespaceHandlerRegistry.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/NamespaceHandlerRegistry.java?rev=765036&r1=765035&r2=765036&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/NamespaceHandlerRegistry.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/NamespaceHandlerRegistry.java
Wed Apr 15 03:39:07 2009
@@ -38,11 +38,5 @@
      */
     NamespaceHandler getNamespaceHandler(URI uri);
 
-    /**
-     * Add a callback to be run each time the list of namespace handlers changes
-     * @param runnable
-     */
-    void addCallback(Runnable runnable);
-
     void destroy();
 }

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=765036&r1=765035&r2=765036&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
Wed Apr 15 03:39:07 2009
@@ -28,9 +28,11 @@
 
 import org.apache.felix.blueprint.HeaderParser.PathElement;
 import org.apache.felix.blueprint.namespace.ComponentDefinitionRegistryImpl;
+import org.apache.felix.blueprint.namespace.NamespaceHandlerRegistryImpl;
 import org.apache.felix.blueprint.BlueprintConstants;
 import org.apache.felix.blueprint.HeaderParser;
 import org.apache.felix.blueprint.ModuleContextEventSender;
+import org.apache.felix.blueprint.NamespaceHandlerRegistry;
 import org.apache.xbean.recipe.Repository;
 import org.apache.xbean.recipe.ObjectGraph;
 import org.osgi.framework.Bundle;
@@ -53,12 +55,14 @@
 
     private final BundleContext bundleContext;
     private final ModuleContextEventSender sender;
+    private final NamespaceHandlerRegistry handlers;
     private final List<URL> urls;
     private ComponentDefinitionRegistryImpl componentDefinitionRegistry;
 
-    public ModuleContextImpl(BundleContext bundleContext, ModuleContextEventSender sender,
List<URL> urls) {
+    public ModuleContextImpl(BundleContext bundleContext, ModuleContextEventSender sender,
NamespaceHandlerRegistry handlers, List<URL> urls) {
         this.bundleContext = bundleContext;
         this.sender = sender;
+        this.handlers = handlers;
         this.urls = urls;
     }
 
@@ -85,6 +89,7 @@
         sender.sendCreating(this);
         try {
             Parser parser = new Parser();
+            parser.setNamespaceHandlerRegistry(handlers);
             parser.parse(urls);
             componentDefinitionRegistry = parser.getRegistry();
             Instanciator i = new Instanciator(bundleContext.getBundle());

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Parser.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Parser.java?rev=765036&r1=765035&r2=765036&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Parser.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Parser.java
Wed Apr 15 03:39:07 2009
@@ -19,6 +19,7 @@
 package org.apache.felix.blueprint.context;
 
 import java.io.InputStream;
+import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -34,10 +35,10 @@
 
 import org.apache.felix.blueprint.NamespaceHandlerRegistry;
 import org.apache.felix.blueprint.namespace.ComponentDefinitionRegistryImpl;
+import org.apache.felix.blueprint.namespace.ParserContextImpl;
 import org.apache.felix.blueprint.reflect.ArrayValueImpl;
 import org.apache.felix.blueprint.reflect.BindingListenerMetadataImpl;
 import org.apache.felix.blueprint.reflect.CollectionBasedServiceReferenceComponentMetadataImpl;
-import org.apache.felix.blueprint.reflect.ComponentMetadataImpl;
 import org.apache.felix.blueprint.reflect.ComponentValueImpl;
 import org.apache.felix.blueprint.reflect.ListValueImpl;
 import org.apache.felix.blueprint.reflect.LocalComponentMetadataImpl;
@@ -53,6 +54,7 @@
 import org.apache.felix.blueprint.reflect.TypedStringValueImpl;
 import org.apache.felix.blueprint.reflect.UnaryServiceReferenceComponentMetadataImpl;
 import org.osgi.service.blueprint.context.ComponentDefinitionException;
+import org.osgi.service.blueprint.namespace.NamespaceHandler;
 import org.osgi.service.blueprint.reflect.ArrayValue;
 import org.osgi.service.blueprint.reflect.BindingListenerMetadata;
 import org.osgi.service.blueprint.reflect.CollectionBasedServiceReferenceComponentMetadata;
@@ -73,6 +75,7 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.EntityReference;
+import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.InputSource;
@@ -189,6 +192,10 @@
         // TODO: Register conversionService, bundle, bundleContext, moduleContext in the
registry
     }
 
+    public void setNamespaceHandlerRegistry(NamespaceHandlerRegistry namespaceHandlerRegistry)
{
+        this.namespaceHandlerRegistry = namespaceHandlerRegistry;
+    }
+    
     public ComponentDefinitionRegistryImpl getRegistry() {
         return registry;
     }
@@ -259,15 +266,22 @@
         if (root.hasAttribute(DEFAULT_AVAILABILITY_ATTRIBUTE)) {
             defaultAvailability = root.getAttribute(DEFAULT_AVAILABILITY_ATTRIBUTE);
         }
+        /*
         // Parse custom attributes
-        NodeList nl = root.getChildNodes();
-        for (int i = 0; i < nl.getLength(); i++) {
-            Node node = nl.item(i);
-            if (node instanceof Attr && !isBlueprintNamespace(node.getNamespaceURI()))
{
-                decorateCustomNode(node, null);
+        NamedNodeMap attributes = root.getAttributes();
+        if (attributes != null) {
+            for (int i = 0; i < attributes.getLength(); i++) {
+                Node node = attributes.item(i);
+                if (node instanceof Attr && 
+                    node.getNamespaceURI() != null && 
+                    !isBlueprintNamespace(node.getNamespaceURI())) {
+                    decorateCustomNode(node, null);
+                }
             }
         }
+        */
         // Parse elements
+        NodeList nl = root.getChildNodes();
         for (int i = 0; i < nl.getLength(); i++) {
             Node node = nl.item(i);
             if (node instanceof Element) {
@@ -278,7 +292,10 @@
                 } else if (isBlueprintCompendiumNamespace(namespaceUri)) {
                     parseBlueprintCompendiumElement(element);
                 } else {
-                    parseCustomElement(element, null);
+                    ComponentMetadata component = parseCustomElement(element, null);
+                    if (component != null) {
+                        registry.registerComponentDefinition(component);
+                    }
                 }
             }
         }
@@ -290,24 +307,19 @@
         } else if (nodeNameEquals(element, TYPE_CONVERTERS_ELEMENT)) {
             parseTypeConverters(element);
         } else if (nodeNameEquals(element, COMPONENT_ELEMENT)) {
-            LocalComponentMetadataImpl component = parseComponentMetadata(element);
-            generateBeanNameIfNeeded(component);
+            LocalComponentMetadata component = parseComponentMetadata(element);
             registry.registerComponentDefinition(component);
         } else if (nodeNameEquals(element, SERVICE_ELEMENT)) {
-            ServiceExportComponentMetadataImpl service = parseService(element);
-            generateBeanNameIfNeeded(service);
+            ServiceExportComponentMetadata service = parseService(element);
             registry.registerComponentDefinition(service);
         } else if (nodeNameEquals(element, REFERENCE_ELEMENT)) {
-            ServiceReferenceComponentMetadataImpl reference = parseUnaryReference(element);
-            generateBeanNameIfNeeded(reference);
+            ServiceReferenceComponentMetadata reference = parseUnaryReference(element);
             registry.registerComponentDefinition(reference);
         } else if (nodeNameEquals(element, REFLIST_ELEMENT) ) {
-            CollectionBasedServiceReferenceComponentMetadataImpl references = parseReferenceCollection(element);
-            generateBeanNameIfNeeded(references);
+            CollectionBasedServiceReferenceComponentMetadata references = parseReferenceCollection(element,
List.class);
             registry.registerComponentDefinition(references);
         } else if (nodeNameEquals(element, REFSET_ELEMENT)) {
-            CollectionBasedServiceReferenceComponentMetadataImpl references = parseReferenceCollection(element);
-            generateBeanNameIfNeeded(references);
+            CollectionBasedServiceReferenceComponentMetadata references = parseReferenceCollection(element,
Set.class);
             registry.registerComponentDefinition(references);
         } else {
             throw new ComponentDefinitionException("Unknown element " + element.getNodeName()
+ " in namespace " + BLUEPRINT_NAMESPACE);
@@ -336,11 +348,9 @@
         }
     }
 
-    private LocalComponentMetadataImpl parseComponentMetadata(Element element) {
+    private LocalComponentMetadata parseComponentMetadata(Element element) {
         LocalComponentMetadataImpl metadata = new LocalComponentMetadataImpl();
-        if (element.hasAttribute(ID_ATTRIBUTE)) {
-            metadata.setName(element.getAttribute(ID_ATTRIBUTE));
-        }
+        metadata.setName(getName(element));
         if (element.hasAttribute(CLASS_ATTRIBUTE)) {
             metadata.setClassName(element.getAttribute(CLASS_ATTRIBUTE));
         }
@@ -373,45 +383,45 @@
         } else {
             metadata.setInitMethodName(defaultDestroyMethod);
         }
-        // Parse custom elements and attributes
+
+        // Parse elements
         int indexConstructor = 0;
         NodeList nl = element.getChildNodes();
         for (int i = 0; i < nl.getLength(); i++) {
             Node node = nl.item(i);
-            if (isBlueprintNamespace(node.getNamespaceURI())) {
-                if (node instanceof Element) {
+            if (node instanceof Element) {
+                Element e = (Element) node;
+                if (isBlueprintNamespace(node.getNamespaceURI())) {                
                     if (nodeNameEquals(node, CONSTRUCTOR_ARG_ELEMENT)) {
                         // TODO: all indexes attributes must be set or none according to
the spec
-                        Element e = (Element) node;
                         int index = e.hasAttribute(INDEX_ATTRIBUTE) ? Integer.parseInt(e.getAttribute(INDEX_ATTRIBUTE))
: indexConstructor;
                         String type = e.hasAttribute(TYPE_ATTRIBUTE) ? e.getAttribute(TYPE_ATTRIBUTE)
: null;
                         Value value = parseValue(e, metadata);
                         metadata.addConsuctorArg(new ParameterSpecificationImpl(value, type,
index));
                         indexConstructor++;
                     } else if (nodeNameEquals(node, PROPERTY_ELEMENT)) {
-                        Element e = (Element) node;
                         String name = e.hasAttribute(NAME_ATTRIBUTE) ? e.getAttribute(NAME_ATTRIBUTE)
: null;
                         Value value = parseValue(e, metadata);
                         metadata.addProperty(new PropertyInjectionMetadataImpl(name, value));
                     }
                 }
-            } else {
-                if (node instanceof Element) {
-                    decorateCustomNode(node, metadata);
-                } else if (node instanceof Attr) {
-                    decorateCustomNode(node, metadata);
-                }
             }
         }
-        return metadata;
+        
+        ComponentMetadata m = metadata;
+        
+        // Parse custom attributes
+        m = handleCustomAttributes(element.getAttributes(), m);
+        
+        // Parse custom elements;
+        m = handleCustomElements(element, m);
+        
+        return (LocalComponentMetadata)m;
     }
 
-    private ServiceExportComponentMetadataImpl parseService(Element element) {
+    private ServiceExportComponentMetadata parseService(Element element) {
         ServiceExportComponentMetadataImpl service = new ServiceExportComponentMetadataImpl();
-        // Parse attributes
-        if (element.hasAttribute(ID_ATTRIBUTE)) {
-            service.setName(element.getAttribute(ID_ATTRIBUTE));
-        }
+        service.setName(getName(element));
         if (element.hasAttribute(INTERFACE_ATTRIBUTE)) {
             service.setInterfaceNames(Collections.singleton(element.getAttribute(INTERFACE_ATTRIBUTE)));
         }
@@ -461,11 +471,6 @@
                         }
                         service.setExportedComponent(new ComponentValueImpl(parseComponentMetadata(e)));
                     }
-                } else {
-                    if (service.getExportedComponent() != null) {
-                        throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE
+ " attribute, " + COMPONENT_ELEMENT + " element or custom inner element can be set");
-                    }
-                    service.setExportedComponent(new ComponentValueImpl(parseCustomElement(e,
service)));
                 }
             }
         }
@@ -473,7 +478,13 @@
         if (service.getExportedComponent() == null) {
             throw new ComponentDefinitionException("One of " + REF_ATTRIBUTE + " attribute,
" + COMPONENT_ELEMENT + " element or custom inner element must be set");
         }
-        return service;
+        
+        ComponentMetadata s = service;
+        
+        // Parse custom elements;
+        s = handleCustomElements(element, s);
+        
+        return (ServiceExportComponentMetadata)s;
     }
 
     private ArrayValue parseArray(Element element, ComponentMetadata enclosingComponent)
{
@@ -628,16 +639,13 @@
                     }
                     listenerComponent = new ReferenceValueImpl(component);
                 } else if (nodeNameEquals(e, COMPONENT_ELEMENT)) {
-                    LocalComponentMetadataImpl component = parseComponentMetadata(e);
-                    generateBeanNameIfNeeded(component);
+                    LocalComponentMetadata component = parseComponentMetadata(e);
                     listenerComponent = new ComponentValueImpl(component);
                 } else if (nodeNameEquals(e, REFERENCE_ELEMENT)) {
-                    ServiceReferenceComponentMetadataImpl reference = parseUnaryReference(e);
-                    generateBeanNameIfNeeded(reference);
+                    ServiceReferenceComponentMetadata reference = parseUnaryReference(e);
                     listenerComponent = new ComponentValueImpl(reference);
                 } else if (nodeNameEquals(e, SERVICE_ELEMENT)) {
-                    ServiceExportComponentMetadataImpl service = parseService(e);
-                    generateBeanNameIfNeeded(service);
+                    ServiceExportComponentMetadata service = parseService(e);
                     listenerComponent = new ComponentValueImpl(service);
                 }
             }
@@ -660,8 +668,9 @@
         return listener;
     }
 
-    private ServiceReferenceComponentMetadataImpl parseUnaryReference(Element element) {
+    private ServiceReferenceComponentMetadata parseUnaryReference(Element element) {
         UnaryServiceReferenceComponentMetadataImpl reference = new UnaryServiceReferenceComponentMetadataImpl();
+        reference.setName(getName(element));
         parseReference(element, reference);
         String timeout = element.hasAttribute(TIMEOUT_ATTRIBUTE) ? element.getAttribute(TIMEOUT_ATTRIBUTE)
: this.defaultTimeout;
         try {
@@ -669,16 +678,20 @@
         } catch (NumberFormatException e) {
             throw new ComponentDefinitionException("Attribute " + TIMEOUT_ATTRIBUTE + " must
be a valid long (was: " + timeout + ")");
         }
-        return reference;
+        
+        ComponentMetadata r = reference;
+        
+        // Parse custom elements;
+        r = handleCustomElements(element, r);
+        
+        return (ServiceReferenceComponentMetadata)r;
     }
 
-    private CollectionBasedServiceReferenceComponentMetadataImpl parseReferenceCollection(Element
element) {
+    private CollectionBasedServiceReferenceComponentMetadata parseReferenceCollection(Element
element, Class collectionType) {
         CollectionBasedServiceReferenceComponentMetadataImpl references = new CollectionBasedServiceReferenceComponentMetadataImpl();
-        if (nodeNameEquals(element, REFLIST_ELEMENT)) {
-            references.setCollectionType(List.class);
-        } else /*if (nodeNameEquals(element, REFSET_ELEMENT))*/ {
-            references.setCollectionType(Set.class);
-        }
+        references.setName(getName(element));
+        references.setCollectionType(collectionType);
+
         if (element.hasAttribute(COMPARATOR_REF_ATTRIBUTE)) {
             references.setComparator(new ReferenceValueImpl(element.getAttribute(COMPARATOR_REF_ATTRIBUTE)));
         }
@@ -712,7 +725,13 @@
                 }
             }
         }
-        return references;
+        
+        ComponentMetadata r = references;
+        
+        // Parse custom elements;
+        r = handleCustomElements(element, r);
+        
+        return (CollectionBasedServiceReferenceComponentMetadata)r;
     }
 
     private void parseComparator(Element element, CollectionBasedServiceReferenceComponentMetadataImpl
references) {
@@ -730,16 +749,13 @@
                         }
                         comparator = new ReferenceValueImpl(component);
                     } else if (nodeNameEquals(e, COMPONENT_ELEMENT)) {
-                        LocalComponentMetadataImpl component = parseComponentMetadata(e);
-                        generateBeanNameIfNeeded(component);
+                        LocalComponentMetadata component = parseComponentMetadata(e);
                         comparator = new ComponentValueImpl(component);
                     } else if (nodeNameEquals(e, REFERENCE_ELEMENT)) {
-                        ServiceReferenceComponentMetadataImpl reference = parseUnaryReference(e);
-                        generateBeanNameIfNeeded(reference);
+                        ServiceReferenceComponentMetadata reference = parseUnaryReference(e);
                         comparator = new ComponentValueImpl(reference);
                     } else if (nodeNameEquals(e, SERVICE_ELEMENT)) {
-                        ServiceExportComponentMetadataImpl service = parseService(e);
-                        generateBeanNameIfNeeded(service);
+                        ServiceExportComponentMetadata service = parseService(e);
                         comparator = new ComponentValueImpl(service);
                     }
                 } else {
@@ -756,9 +772,6 @@
 
     private void parseReference(Element element, ServiceReferenceComponentMetadataImpl reference)
{
         // Parse attributes
-        if (element.hasAttribute(ID_ATTRIBUTE)) {
-            reference.setName(element.getAttribute(ID_ATTRIBUTE));
-        }
         if (element.hasAttribute(INTERFACE_ATTRIBUTE)) {
             reference.setInterfaceNames(Collections.singleton(element.getAttribute(INTERFACE_ATTRIBUTE)));
         }
@@ -805,7 +818,6 @@
         listener.setBindMethodName(element.getAttribute(BIND_METHOD_ATTRIBUTE));
         listener.setUnbindMethodName(element.getAttribute(UNBIND_METHOD_ATTRIBUTE));
         // Parse elements
-        Value listenerComponent = null;
         NodeList nl = element.getChildNodes();
         for (int i = 0; i < nl.getLength(); i++) {
             Node node = nl.item(i);
@@ -825,22 +837,19 @@
                         if (listener.getListenerComponent() != null) {
                             throw new ComponentDefinitionException("Attribute " + REF_ATTRIBUTE
+ " can not be set in addition to a child element");
                         }
-                        LocalComponentMetadataImpl component = parseComponentMetadata(e);
-                        generateBeanNameIfNeeded(component);
+                        LocalComponentMetadata component = parseComponentMetadata(e);
                         listener.setListenerComponent(new ComponentValueImpl(component));
                     } else if (nodeNameEquals(e, REFERENCE_ELEMENT)) {
                         if (listener.getListenerComponent() != null) {
                             throw new ComponentDefinitionException("Attribute " + REF_ATTRIBUTE
+ " can not be set in addition to a child element");
                         }
-                        ServiceReferenceComponentMetadataImpl reference = parseUnaryReference(e);
-                        generateBeanNameIfNeeded(reference);
+                        ServiceReferenceComponentMetadata reference = parseUnaryReference(e);
                         listener.setListenerComponent(new ComponentValueImpl(reference));
                     } else if (nodeNameEquals(e, SERVICE_ELEMENT)) {
                         if (listener.getListenerComponent() != null) {
                             throw new ComponentDefinitionException("Attribute " + REF_ATTRIBUTE
+ " can not be set in addition to a child element");
                         }
-                        ServiceExportComponentMetadataImpl service = parseService(e);
-                        generateBeanNameIfNeeded(service);
+                        ServiceExportComponentMetadata service = parseService(e);
                         listener.setListenerComponent(new ComponentValueImpl(service));
                     }
                 } else {
@@ -883,13 +892,14 @@
             for (int i = 0; i < nl.getLength(); i++) {
                 Node node = nl.item(i);
                 if (node instanceof Element) {
+                    Element e = (Element) node;
                     if (isBlueprintNamespace(node.getNamespaceURI())) {
                         // Ignore description elements
                         if (!nodeNameEquals(node, DESCRIPTION_ELEMENT)) {
-                            return parseValueElement((Element) node, enclosingComponent);
+                            return parseValueElement(e, enclosingComponent);
                         }
                     } else {
-                        ComponentMetadata innerComponent = parseCustomElement((Element) node,
enclosingComponent);
+                        ComponentMetadata innerComponent = parseCustomElement(e, enclosingComponent);
                         return new ComponentValueImpl(innerComponent);
                     }
                 }
@@ -937,15 +947,58 @@
         }
     }
 
-    private void decorateCustomNode(Node node, ComponentMetadata enclosingComponent) {
-        // TODO: decorate custom nodes
+    private ComponentMetadata handleCustomAttributes(NamedNodeMap attributes, ComponentMetadata
enclosingComponent) {
+        if (attributes != null) {
+            for (int i = 0; i < attributes.getLength(); i++) {
+                Node node = attributes.item(i);
+                if (node instanceof Attr && 
+                    node.getNamespaceURI() != null && 
+                    !isBlueprintNamespace(node.getNamespaceURI())) {
+                    enclosingComponent = decorateCustomNode(node, enclosingComponent);
+                }
+            }
+        }
+        return enclosingComponent;
+    }
+    
+    private ComponentMetadata handleCustomElements(Element element, ComponentMetadata enclosingComponent)
{
+        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(node.getNamespaceURI())) {
+                    enclosingComponent = decorateCustomNode(node, enclosingComponent);
+                }
+            }
+        }
+        return enclosingComponent;
+    }
+    
+    private ComponentMetadata decorateCustomNode(Node node, ComponentMetadata enclosingComponent)
{
+        NamespaceHandler handler = getNamespaceHandler(node);
+        ParserContextImpl context = new ParserContextImpl(registry, enclosingComponent, node);
+        return handler.decorate(node, enclosingComponent, context);
     }
 
     private ComponentMetadata parseCustomElement(Element element, ComponentMetadata enclosingComponent)
{
-        // TODO: parse custom elements
-        throw new ComponentDefinitionException("Unsupported custom element");
+        NamespaceHandler handler = getNamespaceHandler(element);
+        ParserContextImpl context = new ParserContextImpl(registry, enclosingComponent, element);
+        return handler.parse(element, context);
     }
 
+    private NamespaceHandler getNamespaceHandler(Node node) {
+        if (namespaceHandlerRegistry == null) {
+            throw new ComponentDefinitionException("Unsupported node (namespace handler registry
is not set): " + node);
+        }
+        URI ns = URI.create(node.getNamespaceURI());
+        NamespaceHandler handler = this.namespaceHandlerRegistry.getNamespaceHandler(ns);
+        if (handler == null) {
+            throw new ComponentDefinitionException("Unsupported node namespace: " + node.getNamespaceURI());
+        }
+        return handler;
+    }
+    
     private boolean isBlueprintNamespace(String ns) {
         return BLUEPRINT_NAMESPACE.equals(ns);
     }
@@ -961,13 +1014,15 @@
         }
         return documentBuilderFactory;
     }
-
-    private void generateBeanNameIfNeeded(ComponentMetadataImpl component) {
-        if (component.getName() == null) {
-            component.setName("component-" + ++nameCounter);
+    
+    private String getName(Element element) {
+        if (element.hasAttribute(ID_ATTRIBUTE)) {
+            return element.getAttribute(ID_ATTRIBUTE);
+        } else {
+            return "component-" + ++nameCounter;
         }
     }
-
+    
     private static boolean nodeNameEquals(Node node, String name) {
         return (name.equals(node.getNodeName()) || name.equals(node.getLocalName()));
     }

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/namespace/NamespaceHandlerRegistryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/namespace/NamespaceHandlerRegistryImpl.java?rev=765036&r1=765035&r2=765036&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/namespace/NamespaceHandlerRegistryImpl.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/namespace/NamespaceHandlerRegistryImpl.java
Wed Apr 15 03:39:07 2009
@@ -18,19 +18,17 @@
  */
 package org.apache.felix.blueprint.namespace;
 
-import java.util.Map;
+import java.net.URI;
 import java.util.HashMap;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-import java.net.URI;
 
-import org.osgi.service.blueprint.namespace.NamespaceHandler;
+import org.apache.felix.blueprint.NamespaceHandlerRegistry;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.blueprint.namespace.NamespaceHandler;
 import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
-import org.apache.felix.blueprint.NamespaceHandlerRegistry;
 
 /**
  * TODO: javadoc
@@ -44,13 +42,11 @@
 
     private final BundleContext bundleContext;
     private final Map<URI, NamespaceHandler> handlers;
-    private final List<Runnable> runnables;
     private final ServiceTracker tracker;
 
     public NamespaceHandlerRegistryImpl(BundleContext bundleContext) {
         this.bundleContext = bundleContext;
         handlers = new ConcurrentHashMap<URI, NamespaceHandler>();
-        runnables = new CopyOnWriteArrayList<Runnable>();
         tracker = new ServiceTracker(bundleContext, NamespaceHandler.class.getName(), this);
     }
 
@@ -98,10 +94,6 @@
             for (URI uri : (URI[]) ns) {
                 handlers.put(uri, handler);
             }
-            for (Runnable r : runnables) {
-                r.run();
-            }
-
         } else {
             throw new IllegalArgumentException("NamespaceHandler service does not have an
associated " + NAMESPACE + " property defined");
         }
@@ -118,9 +110,6 @@
             for (URI uri : (URI[]) ns) {
                 handlers.remove(uri);
             }
-            for (Runnable r : runnables) {
-                r.run();
-            }
         } else {
             throw new IllegalArgumentException("NamespaceHandler service does not have an
associated " + NAMESPACE + " property defined");
         }
@@ -130,10 +119,6 @@
         return handlers.get(uri);
     }
 
-    public void addCallback(Runnable runnable) {
-        runnables.add(runnable);
-    }
-
     public void destroy() {
         tracker.close();
     }



Mime
View raw message