You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gn...@apache.org on 2015/11/20 17:44:05 UTC

svn commit: r1715387 - in /aries/trunk/blueprint: blueprint-core/ blueprint-core/src/main/java/org/apache/aries/blueprint/container/ blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/ blueprint-core/src/test/java/org/apache/aries/bluepr...

Author: gnodet
Date: Fri Nov 20 16:44:05 2015
New Revision: 1715387

URL: http://svn.apache.org/viewvc?rev=1715387&view=rev
Log:
[ARIES-1456] Support for xsi:schemaLocation

Modified:
    aries/trunk/blueprint/blueprint-core/pom.xml
    aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
    aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/NamespaceHandlerRegistryImpl.java
    aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java
    aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ParserTest.java
    aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/NamespaceHandlerSet.java
    aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/Parser.java

Modified: aries/trunk/blueprint/blueprint-core/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/pom.xml?rev=1715387&r1=1715386&r2=1715387&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/pom.xml (original)
+++ aries/trunk/blueprint/blueprint-core/pom.xml Fri Nov 20 16:44:05 2015
@@ -91,7 +91,7 @@
         </aries.osgi.include.resource>
         <blueprint.annotation.api.version>1.0.0</blueprint.annotation.api.version>
         <blueprint.api.version>1.0.0</blueprint.api.version>
-        <blueprint.parser.version>1.3.3-SNAPSHOT</blueprint.parser.version>
+        <blueprint.parser.version>1.4.0-SNAPSHOT</blueprint.parser.version>
         <proxy.api.version>1.0.0</proxy.api.version>
         <proxy.impl.version>1.0.3</proxy.impl.version>
         <quiesce.api.version>1.0.0</quiesce.api.version>
@@ -105,7 +105,7 @@
             <properties>
                 <blueprint.annotation.api.version>1.0.1</blueprint.annotation.api.version>
                 <blueprint.api.version>1.0.1</blueprint.api.version>
-                <blueprint.parser.version>1.3.2-SNAPSHOT</blueprint.parser.version>
+                <blueprint.parser.version>1.4.0-SNAPSHOT</blueprint.parser.version>
                 <proxy.api.version>1.0.1</proxy.api.version>
                 <proxy.impl.version>1.0.1</proxy.impl.version>
                 <quiesce.api.version>1.0.0</quiesce.api.version>

Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java?rev=1715387&r1=1715386&r2=1715387&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java (original)
+++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java Fri Nov 20 16:44:05 2015
@@ -320,9 +320,9 @@ public class BlueprintContainerImpl
                         }
                         resetComponentDefinitionRegistry();
                         if (xmlValidation == null || "true".equals(xmlValidation)) {
-                            parser.validate(handlerSet.getSchema());
+                            parser.validate(handlerSet.getSchema(parser.getSchemaLocations()));
                         } else if ("structure".equals(xmlValidation)) {
-                            parser.validate(handlerSet.getSchema(), new ValidationHandler());
+                            parser.validate(handlerSet.getSchema(parser.getSchemaLocations()), new ValidationHandler());
                         }
                         parser.populate(handlerSet, componentDefinitionRegistry);
                         state = State.Populated;

Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/NamespaceHandlerRegistryImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/NamespaceHandlerRegistryImpl.java?rev=1715387&r1=1715386&r2=1715387&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/NamespaceHandlerRegistryImpl.java (original)
+++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/NamespaceHandlerRegistryImpl.java Fri Nov 20 16:44:05 2015
@@ -248,9 +248,10 @@ public class NamespaceHandlerRegistryImp
 
     private Schema getSchema(Map<URI, NamespaceHandler> handlers,
                              final Bundle bundle,
-                             final Properties schemaMap) throws IOException, SAXException {
+                             final Properties schemaMap,
+                             Map<String, String> locations) throws IOException, SAXException {
         if (schemaMap != null && !schemaMap.isEmpty()) {
-            return createSchema(handlers, bundle, schemaMap);
+            return createSchema(handlers, bundle, schemaMap, locations);
         }
         // Find a schema that can handle all the requested namespaces
         // If it contains additional namespaces, it should not be a problem since
@@ -258,7 +259,7 @@ public class NamespaceHandlerRegistryImp
         Schema schema = getExistingSchema(handlers);
         if (schema == null) {
             // Create schema
-            schema = createSchema(handlers, bundle, schemaMap);
+            schema = createSchema(handlers, bundle, schemaMap, locations);
             cacheSchema(handlers, schema);
         }
         return schema;
@@ -320,7 +321,8 @@ public class NamespaceHandlerRegistryImp
 
     private Schema createSchema(Map<URI, NamespaceHandler> handlers,
                                 Bundle bundle,
-                                Properties schemaMap) throws IOException, SAXException {
+                                Properties schemaMap,
+                                Map<String, String> locations) throws IOException, SAXException {
         final List<StreamSource> schemaSources = new ArrayList<StreamSource>();
         try {
             schemaSources.add(new StreamSource(getClass().getResourceAsStream("/org/apache/aries/blueprint/blueprint.xsd")));
@@ -328,6 +330,12 @@ public class NamespaceHandlerRegistryImp
             // It will speed things as it can be reused for all other blueprint containers
             for (URI ns : handlers.keySet()) {
                 URL url = handlers.get(ns).getSchemaLocation(ns.toString());
+                if (url == null && locations != null) {
+                    String loc = locations.get(ns.toString());
+                    if (loc != null) {
+                        url = handlers.get(ns).getSchemaLocation(loc);
+                    }
+                }
                 if (url == null) {
                     LOGGER.warn("No URL is defined for schema " + ns + ". This schema will not be validated");
                 } else {
@@ -550,11 +558,15 @@ public class NamespaceHandlerRegistryImp
         }
 
         public Schema getSchema() throws SAXException, IOException {
+            return getSchema(null);
+        }
+
+        public Schema getSchema(Map<String, String> locations) throws SAXException, IOException {
             if (!isComplete()) {
                 throw new IllegalStateException("NamespaceHandlerSet is not complete");
             }
             if (schema == null) {
-                schema = NamespaceHandlerRegistryImpl.this.getSchema(handlers, bundle, schemaMap);
+                schema = NamespaceHandlerRegistryImpl.this.getSchema(handlers, bundle, schemaMap, locations);
             }
             return schema;
         }

Modified: aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java?rev=1715387&r1=1715386&r2=1715387&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java (original)
+++ aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java Fri Nov 20 16:44:05 2015
@@ -21,6 +21,7 @@ package org.apache.aries.blueprint;
 import java.io.IOException;
 import java.net.URI;
 import java.util.Collections;
+import java.util.Map;
 import java.util.Set;
 
 import javax.xml.validation.Schema;
@@ -53,6 +54,9 @@ public abstract class AbstractBlueprintT
             public Schema getSchema() throws SAXException, IOException {
                 return null;
             }
+            public Schema getSchema(Map<String, String> locations) throws SAXException, IOException {
+              return null;
+            }
             public boolean isComplete() {
                 return false;
             }

Modified: aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ParserTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ParserTest.java?rev=1715387&r1=1715386&r2=1715387&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ParserTest.java (original)
+++ aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/ParserTest.java Fri Nov 20 16:44:05 2015
@@ -23,6 +23,7 @@ import java.net.URL;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.io.IOException;
 
@@ -244,6 +245,10 @@ public class ParserTest extends Abstract
             return null;
         }
 
+        public Schema getSchema(Map<String, String> locations) throws SAXException, IOException {
+            return null;
+        }
+
         public void addListener(NamespaceHandlerSet.Listener listener) {
         }
 

Modified: aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/NamespaceHandlerSet.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/NamespaceHandlerSet.java?rev=1715387&r1=1715386&r2=1715387&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/NamespaceHandlerSet.java (original)
+++ aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/NamespaceHandlerSet.java Fri Nov 20 16:44:05 2015
@@ -20,6 +20,7 @@ package org.apache.aries.blueprint.parse
 
 import java.io.IOException;
 import java.net.URI;
+import java.util.Map;
 import java.util.Set;
 
 import javax.xml.validation.Schema;
@@ -51,6 +52,13 @@ public interface NamespaceHandlerSet {
     Schema getSchema() throws SAXException, IOException;
 
     /**
+     * Obtain a schema to validate the XML for the given list of namespaces
+     *
+     * @return the schema to use to validate the XML
+     */
+    Schema getSchema(Map<String, String> locations) throws SAXException, IOException;
+
+    /**
      * Add a new Listener to be called when namespace handlers are registerd or unregistered
      *
      * @param listener the listener to register

Modified: aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/Parser.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/Parser.java?rev=1715387&r1=1715386&r2=1715387&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/Parser.java (original)
+++ aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/Parser.java Fri Nov 20 16:44:05 2015
@@ -22,11 +22,14 @@ import java.io.InputStream;
 import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import javax.xml.XMLConstants;
@@ -209,6 +212,7 @@ public class Parser {
     private String defaultAvailability;
     private String defaultActivation;
     private Set<URI> namespaces;
+    private Map<String, String> locations;
 
     public Parser() {
       this(null);
@@ -256,20 +260,36 @@ public class Parser {
     public Set<URI> getNamespaces() {
         if (this.namespaces == null) {
             Set<URI> namespaces = new LinkedHashSet<URI>();
+            Map<String, String> locations = new HashMap<String, String>();
             for (Document doc : documents) {
-                findNamespaces(namespaces, doc);
+                findNamespaces(namespaces, locations, doc);
             }
             this.namespaces = namespaces;
+            this.locations = locations;
         }
         return this.namespaces;
     }
 
-    private void findNamespaces(Set<URI> namespaces, Node node) {
+    public Map<String, String> getSchemaLocations() {
+        getNamespaces();
+        return locations;
+    }
+
+    private void findNamespaces(Set<URI> namespaces, Map<String, String> locations, Node node) {
         if (node instanceof Element || node instanceof Attr) {
             String ns = node.getNamespaceURI();
-            if (ns != null && !isBlueprintNamespace(ns) && !isIgnorableAttributeNamespace(ns)) {
+            if ("http://www.w3.org/2001/XMLSchema-instance".equals(ns)
+                    && node instanceof Attr
+                    && "schemaLocation".equals(node.getLocalName())) {
+                String val = ((Attr) node).getValue();
+                List<String> locs = new ArrayList<String>(Arrays.asList(val.split("\\s+")));
+                locs.remove("");
+                for (int i = 0; i < locs.size() / 2; i++) {
+                    locations.put(locs.get(i * 2), locs.get(i * 2 + 1));
+                }
+            } else if (ns != null && !isBlueprintNamespace(ns) && !isIgnorableAttributeNamespace(ns)) {
                 namespaces.add(URI.create(ns));
-            }else if ( ns == null && //attributes from blueprint are unqualified as per schema.
+            } else if (ns == null && //attributes from blueprint are unqualified as per schema.
                        node instanceof Attr &&
                        SCOPE_ATTRIBUTE.equals(node.getNodeName()) &&
                        ((Attr)node).getOwnerElement() != null && //should never occur from parsed doc.
@@ -286,12 +306,12 @@ public class Parser {
         NamedNodeMap nnm = node.getAttributes();
         if(nnm!=null){
             for(int i = 0; i< nnm.getLength() ; i++){
-                findNamespaces(namespaces, nnm.item(i));
+                findNamespaces(namespaces, locations, nnm.item(i));
             }
         }
         NodeList nl = node.getChildNodes();
         for (int i = 0; i < nl.getLength(); i++) {
-            findNamespaces(namespaces, nl.item(i));
+            findNamespaces(namespaces, locations, nl.item(i));
         }
     }