diff options
Diffstat (limited to 'java/sca')
2 files changed, 35 insertions, 9 deletions
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java index c38061c1bf..59fa5990d6 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java @@ -39,6 +39,7 @@ import javax.xml.XMLConstants; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; import javax.xml.stream.EventFilter; import javax.xml.stream.StreamFilter; import javax.xml.stream.XMLEventReader; @@ -49,6 +50,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.util.XMLEventAllocator; import javax.xml.transform.Source; +import javax.xml.transform.TransformerFactory; import javax.xml.transform.sax.SAXSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; @@ -56,9 +58,11 @@ import javax.xml.validation.SchemaFactory; import org.apache.tuscany.sca.assembly.xsd.Constants; import org.apache.tuscany.sca.common.xml.XMLDocumentHelper; import org.apache.tuscany.sca.common.xml.stax.StAXHelper; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.extensibility.ClassLoaderContext; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.w3c.dom.DOMImplementation; @@ -75,7 +79,7 @@ import org.xml.sax.SAXException; * @version $Rev$ $Date$ */ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory implements LSResourceResolver { - + private ExtensionPointRegistry registry; private XMLInputFactory inputFactory; private DocumentBuilderFactory documentBuilderFactory; private DOMImplementationLS ls; @@ -87,6 +91,7 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory private StAXHelper helper; public DefaultValidatingXMLInputFactory(ExtensionPointRegistry registry) { + this.registry = registry; FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class); this.inputFactory = factoryExtensionPoint.getFactory(XMLInputFactory.class); this.documentBuilderFactory = factoryExtensionPoint.getFactory(DocumentBuilderFactory.class); @@ -102,9 +107,11 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory * @param inputFactory * @param schemas */ + // FOR Test only public DefaultValidatingXMLInputFactory(XMLInputFactory inputFactory, ValidationSchemaExtensionPoint schemas) { this.inputFactory = inputFactory; this.schemas = schemas; + this.registry = new DefaultExtensionPointRegistry(); } @@ -188,8 +195,7 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory } final Collection<? extends Source> sources = aggregate(urls); - // Create an aggregated validation schemas from all the XSDs - final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + final SchemaFactory schemaFactory = newSchemaFactory(); DOMImplementation impl = null; try { impl = documentBuilderFactory.newDocumentBuilder().getDOMImplementation(); @@ -225,6 +231,30 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory } } + /** + * For OSGi: + * Create a SchemaFactory in the context of service provider classloaders + * @return + */ + private SchemaFactory newSchemaFactory() { + ClassLoader cl = + ClassLoaderContext.setContextClassLoader(getClass().getClassLoader(), + registry.getServiceDiscovery(), + SchemaFactory.class, + TransformerFactory.class, + SAXParserFactory.class, + DocumentBuilderFactory.class + ); + try { + // Create an aggregated validation schemas from all the XSDs + return SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + } finally { + if (cl != null) { + Thread.currentThread().setContextClassLoader(cl); + } + } + } + @Override public XMLEventReader createFilteredReader(XMLEventReader arg0, EventFilter arg1) throws XMLStreamException { return inputFactory.createFilteredReader(arg0, arg1); diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java index 91db32b806..132b7a8858 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java @@ -33,6 +33,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import org.apache.tuscany.sca.assembly.Extension; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; @@ -56,7 +57,6 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob private XMLInputFactory inputFactory; private XMLOutputFactory outputFactory; private StAXArtifactProcessorExtensionPoint processors; - /** * Constructs a new ExtensibleStAXArtifactProcessor. @@ -172,7 +172,6 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob @SuppressWarnings("unchecked") public void write(Object model, XMLStreamWriter outputSource, ProcessorContext context) throws ContributionWriteException, XMLStreamException { - Monitor monitor = context.getMonitor(); // Delegate to the processor associated with the model type if (model != null) { StAXArtifactProcessor processor = processors.getProcessor(model.getClass()); @@ -182,11 +181,8 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob if (logger.isLoggable(Level.WARNING)) { logger.warning("No StAX processor is configured to handle " + model.getClass()); } - if (!XMLStreamReader.class.isInstance(model)) { - warning(monitor, "NoStaxProcessor", processors, model.getClass()); - } StAXArtifactProcessor anyElementProcessor = processors.getProcessor(ANY_ELEMENT); - if (anyElementProcessor != null) { + if ((model instanceof Extension) && anyElementProcessor != null) { anyElementProcessor.write(model, outputSource, context); } } |