Author: gnodet
Date: Fri Feb  2 16:29:54 2018
New Revision: 1822985

URL: http://svn.apache.org/viewvc?rev=1822985&view=rev
Log:
[ARIES-1770] Spring schemas can not be validated offline

Modified:
    
aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/ParserContext.java
    
aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/ParserContextImpl.java
    aries/trunk/blueprint/blueprint-spring/pom.xml
    
aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java

Modified: 
aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/ParserContext.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/ParserContext.java?rev=1822985&r1=1822984&r2=1822985&view=diff
==============================================================================
--- 
aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/ParserContext.java
 (original)
+++ 
aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/ParserContext.java
 Fri Feb  2 16:29:54 2018
@@ -17,6 +17,7 @@
 package org.apache.aries.blueprint;
 
 import java.net.URI;
+import java.util.Set;
 
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
 import org.osgi.service.blueprint.reflect.Metadata;
@@ -90,6 +91,11 @@ public interface ParserContext  {
     String getDefaultTimeout();
 
     /**
+     * Retrieve the set of namespaces
+     */
+    Set<URI> getNamespaces();
+
+    /**
      * Retrieve the namespace handler for the given uri
      */
     NamespaceHandler getNamespaceHandler(URI namespaceUri);

Modified: 
aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/ParserContextImpl.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/ParserContextImpl.java?rev=1822985&r1=1822984&r2=1822985&view=diff
==============================================================================
--- 
aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/ParserContextImpl.java
 (original)
+++ 
aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/ParserContextImpl.java
 Fri Feb  2 16:29:54 2018
@@ -19,6 +19,8 @@
 package org.apache.aries.blueprint.parser;
 
 import java.net.URI;
+import java.util.Collections;
+import java.util.Set;
 
 import org.apache.aries.blueprint.ComponentDefinitionRegistry;
 import org.apache.aries.blueprint.NamespaceHandler;
@@ -93,6 +95,11 @@ public class ParserContextImpl implement
     }
 
     @Override
+    public Set<URI> getNamespaces() {
+        return Collections.unmodifiableSet(parser.getNamespaces());
+    }
+
+    @Override
     public NamespaceHandler getNamespaceHandler(URI namespaceUri) {
         return parser.getNamespaceHandler(namespaceUri);
     }

Modified: aries/trunk/blueprint/blueprint-spring/pom.xml
URL: 
http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-spring/pom.xml?rev=1822985&r1=1822984&r2=1822985&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-spring/pom.xml (original)
+++ aries/trunk/blueprint/blueprint-spring/pom.xml Fri Feb  2 16:29:54 2018
@@ -59,8 +59,8 @@
             org.apache.aries.blueprint.spring.Activator
         </aries.osgi.activator>
         <blueprint.api.version>1.0.0</blueprint.api.version>
-        <blueprint.core.version>1.6.2</blueprint.core.version>
-        <blueprint.parser.version>1.4.0</blueprint.parser.version>
+        <blueprint.core.version>1.9.0-SNAPSHOT</blueprint.core.version>
+        <blueprint.parser.version>1.5.0-SNAPSHOT</blueprint.parser.version>
         <!--
         <lastReleaseVersion>1.0.4</lastReleaseVersion>
         -->
@@ -71,7 +71,7 @@
             <id>dev</id>
             <properties>
                 <blueprint.api.version>1.0.1</blueprint.api.version>
-                <blueprint.core.version>1.8.4-SNAPSHOT</blueprint.core.version>
+                <blueprint.core.version>1.9.0-SNAPSHOT</blueprint.core.version>
                 
<blueprint.parser.version>1.5.0-SNAPSHOT</blueprint.parser.version>
             </properties>
         </profile>

Modified: 
aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java?rev=1822985&r1=1822984&r2=1822985&view=diff
==============================================================================
--- 
aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java
 (original)
+++ 
aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java
 Fri Feb  2 16:29:54 2018
@@ -16,6 +16,8 @@
  */
 package org.apache.aries.blueprint.spring;
 
+import java.io.IOException;
+import java.net.URI;
 import java.net.URL;
 import java.util.Collections;
 import java.util.Properties;
@@ -29,6 +31,8 @@ import org.apache.aries.blueprint.PassTh
 import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
 import org.apache.aries.blueprint.mutable.MutablePassThroughMetadata;
 import org.apache.aries.blueprint.mutable.MutableRefMetadata;
+import org.apache.aries.blueprint.parser.Parser;
+import org.apache.aries.blueprint.parser.ParserContextImpl;
 import org.apache.aries.blueprint.services.ExtendedBlueprintContainer;
 import org.osgi.framework.Bundle;
 import org.osgi.service.blueprint.reflect.BeanMetadata;
@@ -53,6 +57,9 @@ import org.springframework.core.io.Resou
 import org.springframework.core.io.UrlResource;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
 
 /**
  * Blueprint NamespaceHandler wrapper for a spring NamespaceHandler
@@ -175,8 +182,13 @@ public class BlueprintNamespaceHandler i
             bm.addArgument(createRef(parserContext, 
SPRING_APPLICATION_CONTEXT_ID), null, 0);
             registry.registerComponentDefinition(bm);
         }
-        // Add the namespace handler's bundle to the application context 
classloader
-        applicationContext.addSourceBundle(bundle);
+        // Add the namespace handlers' bundle to the application context 
classloader
+        for (URI uri : parserContext.getNamespaces()) {
+            NamespaceHandler ns = parserContext.getNamespaceHandler(uri);
+            if (ns instanceof BlueprintNamespaceHandler) {
+                
applicationContext.addSourceBundle(((BlueprintNamespaceHandler) ns).bundle);
+            }
+        }
         return springParserContext;
     }
 
@@ -246,7 +258,7 @@ public class BlueprintNamespaceHandler i
         }
     }
 
-    private org.springframework.beans.factory.xml.ParserContext 
createSpringParserContext(ParserContext parserContext, 
DefaultListableBeanFactory registry) {
+    private org.springframework.beans.factory.xml.ParserContext 
createSpringParserContext(final ParserContext parserContext, 
DefaultListableBeanFactory registry) {
         try {
             SpringVersionBridgeXmlBeanDefinitionReader xbdr = new 
SpringVersionBridgeXmlBeanDefinitionReader(registry);
             Resource resource = new 
UrlResource(parserContext.getSourceNode().getOwnerDocument().getDocumentURI());
@@ -258,6 +270,29 @@ public class BlueprintNamespaceHandler i
             xbdr.setEventListener(listener);
             xbdr.setSourceExtractor(extractor);
             xbdr.setNamespaceHandlerResolver(resolver);
+            xbdr.setEntityResolver(new EntityResolver() {
+                @Override
+                public InputSource resolveEntity(String publicId, String 
systemId) throws IOException {
+                    for (URI ns : parserContext.getNamespaces()) {
+                        NamespaceHandler nh = 
parserContext.getNamespaceHandler(ns);
+                        URL url = null;
+                        if (publicId != null) {
+                            url = nh.getSchemaLocation(publicId);
+                        }
+                        if (url == null && systemId != null) {
+                            url = nh.getSchemaLocation(systemId);
+                        }
+                        if (url != null) {
+                            InputSource is = new InputSource();
+                            is.setPublicId(publicId);
+                            is.setSystemId(systemId);
+                            is.setByteStream(url.openStream());
+                            return is;
+                        }
+                    }
+                    return null;
+                }
+            });
             XmlReaderContext xmlReaderContext = 
xbdr.createReaderContext(resource);
             BeanDefinitionParserDelegate bdpd = new 
BeanDefinitionParserDelegate(xmlReaderContext);
             return new 
org.springframework.beans.factory.xml.ParserContext(xmlReaderContext, bdpd);


Reply via email to