aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1338249 - in /aries/branches/blueprint-0.3.2-fixes/blueprint-core: ./ src/main/java/org/apache/aries/blueprint/namespace/NamespaceHandlerRegistryImpl.java
Date Mon, 14 May 2012 15:16:05 GMT
Author: dkulp
Date: Mon May 14 15:16:04 2012
New Revision: 1338249

URL: http://svn.apache.org/viewvc?rev=1338249&view=rev
Log:
[ARIES-626] Part 3 - Go back to handler registry to get schemas

Modified:
    aries/branches/blueprint-0.3.2-fixes/blueprint-core/   (props changed)
    aries/branches/blueprint-0.3.2-fixes/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/NamespaceHandlerRegistryImpl.java

Propchange: aries/branches/blueprint-0.3.2-fixes/blueprint-core/
------------------------------------------------------------------------------
    svn:mergeinfo = /aries/trunk/blueprint/blueprint-core:1200572,1203335

Modified: aries/branches/blueprint-0.3.2-fixes/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/NamespaceHandlerRegistryImpl.java
URL: http://svn.apache.org/viewvc/aries/branches/blueprint-0.3.2-fixes/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/NamespaceHandlerRegistryImpl.java?rev=1338249&r1=1338248&r2=1338249&view=diff
==============================================================================
--- aries/branches/blueprint-0.3.2-fixes/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/NamespaceHandlerRegistryImpl.java
(original)
+++ aries/branches/blueprint-0.3.2-fixes/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/NamespaceHandlerRegistryImpl.java
Mon May 14 15:16:04 2012
@@ -36,6 +36,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.HashSet;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
 
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
@@ -43,6 +45,9 @@ import javax.xml.transform.stream.Stream
 import javax.xml.transform.Source;
 import javax.xml.XMLConstants;
 
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
+
 import org.apache.aries.blueprint.NamespaceHandler;
 import org.apache.aries.blueprint.container.NamespaceHandlerRegistry;
 import org.osgi.framework.Bundle;
@@ -52,7 +57,9 @@ import org.osgi.util.tracker.ServiceTrac
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
 import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 /**
  * Default implementation of the NamespaceHandlerRegistry.
@@ -227,7 +234,7 @@ public class NamespaceHandlerRegistryImp
             }
         }
         if (schema == null) {
-            List<StreamSource> schemaSources = new ArrayList<StreamSource>();
+            final List<StreamSource> schemaSources = new ArrayList<StreamSource>();
             try {
                 schemaSources.add(new StreamSource(getClass().getResourceAsStream("/org/apache/aries/blueprint/blueprint.xsd")));
                 // Create a schema for all namespaces known at this point
@@ -240,7 +247,77 @@ public class NamespaceHandlerRegistryImp
                         schemaSources.add(new StreamSource(url.openStream(), url.toExternalForm()));
                     }
                 }
-                schema = getSchemaFactory().newSchema(schemaSources.toArray(new Source[schemaSources.size()]));
+                SchemaFactory factory = getSchemaFactory();
+                factory.setResourceResolver(new LSResourceResolver() {
+                    public LSInput resolveResource(String type, 
+                                                   final String namespaceURI, 
+                                                   final String publicId,
+                                                   String systemId, String baseURI) {
+                        
+                        URI uri = URI.create((String) namespaceURI);
+                        Set<NamespaceHandler> hs = NamespaceHandlerRegistryImpl.this.handlers.get(uri);
+                        if (hs == null) {
+                            return null;
+                        }
+                        for (NamespaceHandler h : hs) {
+                            final URL url = h.getSchemaLocation(namespaceURI);
+                            if (url != null) {
+                                try {
+                                    final StreamSource source 
+                                        = new StreamSource(url.openStream(), url.toExternalForm());
+                                    schemaSources.add(source);
+                                    return new LSInput() {
+                                        public Reader getCharacterStream() {
+                                            return null;
+                                        }
+                                        public void setCharacterStream(Reader characterStream)
{
+                                        }
+                                        public InputStream getByteStream() {
+                                            return source.getInputStream();
+                                        }
+                                        public void setByteStream(InputStream byteStream)
{
+                                        }
+                                        public String getStringData() {
+                                            return null;
+                                        }
+                                        public void setStringData(String stringData) {
+                                        }
+                                        public String getSystemId() {
+                                            return url.toExternalForm();
+                                        }
+                                        public void setSystemId(String systemId) {
+                                        }
+                                        public String getPublicId() {
+                                            return publicId;
+                                        }
+                                        public void setPublicId(String publicId) {
+                                        }
+                                        public String getBaseURI() {
+                                            return null;
+                                        }
+                                        public void setBaseURI(String baseURI) {
+                                        }
+                                        public String getEncoding() {
+                                            return null;
+                                        }
+                                        public void setEncoding(String encoding) {
+                                        }
+                                        public boolean getCertifiedText() {
+                                            return false;
+                                        }
+                                        public void setCertifiedText(boolean certifiedText)
{
+                                        }
+                                    };
+                                } catch (IOException e) {
+                                    throw new RuntimeException(e);
+                                }
+                            }
+                        }
+                        return null;
+                    }
+                    
+                });
+                schema = factory.newSchema(schemaSources.toArray(new Source[schemaSources.size()]));
                 // Remove schemas that are fully included
                 for (Iterator<Map<URI, NamespaceHandler>> iterator = schemas.keySet().iterator();
iterator.hasNext();) {
                     Map<URI, NamespaceHandler> key = iterator.next();
@@ -284,7 +361,6 @@ public class NamespaceHandlerRegistryImp
     }
 
     private SchemaFactory getSchemaFactory() {
-        SchemaFactory schemaFactory = null;
         if (schemaFactory == null) {
             schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
         }



Mime
View raw message