aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1471280 - in /aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container: BlueprintContainerImpl.java SimpleNamespaceHandlerSet.java
Date Wed, 24 Apr 2013 07:56:36 GMT
Author: gnodet
Date: Wed Apr 24 07:56:35 2013
New Revision: 1471280

URL: http://svn.apache.org/r1471280
Log:
[ARIES-1055] Allow use of custom namespaces in blueprint-noosgi

Modified:
    aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
    aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/SimpleNamespaceHandlerSet.java

Modified: aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java?rev=1471280&r1=1471279&r2=1471280&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
(original)
+++ aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
Wed Apr 24 07:56:35 2013
@@ -24,6 +24,7 @@ import org.apache.aries.blueprint.Proces
 import org.apache.aries.blueprint.di.Recipe;
 import org.apache.aries.blueprint.di.Repository;
 import org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl;
+import org.apache.aries.blueprint.parser.NamespaceHandlerSet;
 import org.apache.aries.blueprint.parser.Parser;
 import org.apache.aries.blueprint.reflect.MetadataUtil;
 import org.apache.aries.blueprint.reflect.PassThroughMetadataImpl;
@@ -81,14 +82,9 @@ public class BlueprintContainerImpl impl
         return System.getProperty(key);
     }
 
-    public void init() throws Exception {
-        // Parse xml resources
-        Parser parser = new Parser();
-        parser.parse(getResources());
-        // Create handler set
-        SimpleNamespaceHandlerSet handlerSet = new SimpleNamespaceHandlerSet();
+    protected NamespaceHandlerSet createNamespaceHandlerSet(Set<URI> namespaces) {
+        NamespaceHandlerSet handlerSet = new SimpleNamespaceHandlerSet();
         // Check namespaces
-        Set<URI> namespaces = parser.getNamespaces();
         Set<URI> unsupported = new LinkedHashSet<URI>();
         for (URI ns : namespaces) {
             if (!handlerSet.getNamespaces().contains(ns)) {
@@ -98,6 +94,17 @@ public class BlueprintContainerImpl impl
         if (unsupported.size() > 0) {
             throw new IllegalArgumentException("Unsupported namespaces: " + unsupported.toString());
         }
+        return handlerSet;
+    }
+
+    public void init() throws Exception {
+        // Parse xml resources
+        Parser parser = new Parser();
+        parser.parse(getResources());
+        // Check namespaces
+        Set<URI> namespaces = parser.getNamespaces();
+        // Create handler set
+        NamespaceHandlerSet handlerSet = createNamespaceHandlerSet(namespaces);
         // Add predefined beans
         componentDefinitionRegistry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintContainer",
this));
         // Validate

Modified: aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/SimpleNamespaceHandlerSet.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/SimpleNamespaceHandlerSet.java?rev=1471280&r1=1471279&r2=1471280&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/SimpleNamespaceHandlerSet.java
(original)
+++ aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/SimpleNamespaceHandlerSet.java
Wed Apr 24 07:56:35 2013
@@ -29,23 +29,34 @@ import javax.xml.transform.stream.Stream
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
+import java.net.URL;
 import java.util.*;
 
 public class SimpleNamespaceHandlerSet implements NamespaceHandlerSet {
 
     public static final URI EXT_1_2_NAMESPACE = URI.create("http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0");
 
-    private Set<URI> namespaces;
+    private Map<URI, URL> namespaces;
+    private Map<URI, NamespaceHandler> handlers;
     private Schema schema;
 
     public SimpleNamespaceHandlerSet() {
-        this.namespaces = new LinkedHashSet<URI>();
-        this.namespaces.add(EXT_1_2_NAMESPACE);
+        this.namespaces = new LinkedHashMap<URI, URL>();
+        this.handlers = new LinkedHashMap<URI, NamespaceHandler>();
+        addNamespace(EXT_1_2_NAMESPACE,
+                getClass().getResource("/org/apache/aries/blueprint/ext/impl/blueprint-ext-1.2.xsd"),
+                new ExtNamespaceHandler());
     }
 
     public Set<URI> getNamespaces() {
-        return Collections.unmodifiableSet(namespaces);
+        return Collections.unmodifiableSet(namespaces.keySet());
+    }
+
+    public void addNamespace(URI namespace, URL schema, NamespaceHandler handler) {
+        namespaces.put(namespace, schema);
+        handlers.put(namespace, handler);
     }
 
     public boolean isComplete() {
@@ -53,19 +64,29 @@ public class SimpleNamespaceHandlerSet i
     }
 
     public NamespaceHandler getNamespaceHandler(URI uri) {
-        if (EXT_1_2_NAMESPACE.equals(uri)) {
-            return new ExtNamespaceHandler();
-        }
-        return null;
+        return handlers.get(uri);
     }
 
     public Schema getSchema() throws SAXException, IOException {
         if (schema == null) {
             final List<StreamSource> schemaSources = new ArrayList<StreamSource>();
-            schemaSources.add(new StreamSource(getClass().getResourceAsStream("/org/apache/aries/blueprint/blueprint.xsd")));
-            schemaSources.add(new StreamSource(getClass().getResourceAsStream("/org/apache/aries/blueprint/ext/impl/blueprint-ext-1.2.xsd")));
-            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-            schema = schemaFactory.newSchema(schemaSources.toArray(new Source[schemaSources.size()]));
+            final List<InputStream> streams = new ArrayList<InputStream>();
+            try {
+                InputStream is = getClass().getResourceAsStream("/org/apache/aries/blueprint/blueprint.xsd");
+                streams.add(is);
+                schemaSources.add(new StreamSource(is));
+                for (URI uri : namespaces.keySet()) {
+                    is = namespaces.get(uri).openStream();
+                    streams.add(is);
+                    schemaSources.add(new StreamSource(is));
+                }
+                SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+                schema = schemaFactory.newSchema(schemaSources.toArray(new Source[schemaSources.size()]));
+            } finally {
+                for (InputStream is : streams) {
+                    is.close();
+                }
+            }
         }
         return schema;
     }



Mime
View raw message