diff options
Diffstat (limited to '')
4 files changed, 41 insertions, 3 deletions
diff --git a/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java b/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java index 90b49b9f5b..4f6af5e791 100644 --- a/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java +++ b/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java @@ -37,6 +37,7 @@ import javax.xml.transform.stream.StreamResult; import org.apache.tuscany.sca.common.xml.dom.impl.SAX2DOMAdapter; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -56,6 +57,11 @@ public class DOMHelper { private DocumentBuilderFactory documentBuilderFactory; private TransformerFactory transformerFactory; + public static DOMHelper getInstance(ExtensionPointRegistry registry) { + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + return utilities.getUtility(DOMHelper.class); + } + public DOMHelper(ExtensionPointRegistry registry) { FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); documentBuilderFactory = factories.getFactory(DocumentBuilderFactory.class); diff --git a/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/sax/SAXHelper.java b/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/sax/SAXHelper.java index e8aa9605c9..dd22912b17 100644 --- a/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/sax/SAXHelper.java +++ b/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/sax/SAXHelper.java @@ -28,6 +28,7 @@ import javax.xml.parsers.SAXParserFactory; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -46,12 +47,17 @@ public class SAXHelper { super(); this.saxParserFactory = saxParserFactory; } - + public SAXHelper(ExtensionPointRegistry registry) { FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); saxParserFactory = factories.getFactory(SAXParserFactory.class); saxParserFactory.setNamespaceAware(true); } + + public SAXHelper getInstance(ExtensionPointRegistry registry) { + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + return utilities.getUtility(SAXHelper.class); + } public SAXParser newSAXParser() throws SAXException { try { diff --git a/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/StAXHelper.java b/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/StAXHelper.java index e5bf05a657..8fa91ee8a3 100644 --- a/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/StAXHelper.java +++ b/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/StAXHelper.java @@ -62,6 +62,12 @@ public class StAXHelper { UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); domHelper = utilities.getUtility(DOMHelper.class); } + + public static StAXHelper getInstance(ExtensionPointRegistry registry) { + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + return utilities.getUtility(StAXHelper.class); + } + /** * @param inputFactory diff --git a/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/dom/DOMHelperTestCase.java b/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/dom/DOMHelperTestCase.java index 5b4cb701d8..176ea35c1c 100644 --- a/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/dom/DOMHelperTestCase.java +++ b/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/dom/DOMHelperTestCase.java @@ -20,11 +20,14 @@ package org.apache.tuscany.sca.common.xml.dom; import static org.junit.Assert.assertNotNull; +import junit.framework.Assert; import org.apache.tuscany.sca.common.xml.sax.SAXHelper; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.custommonkey.xmlunit.XMLAssert; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import org.w3c.dom.Document; import org.xml.sax.ContentHandler; @@ -39,10 +42,24 @@ public class DOMHelperTestCase { "<a:foo xmlns:a='http://a' name='foo'><bar name='bar'>" + "<doo a:name='doo' xmlns:a='http://doo'/>" + "</bar></a:foo>"; + private static ExtensionPointRegistry registry; + + @BeforeClass + public static void init() { + registry = new DefaultExtensionPointRegistry(); + registry.start(); + } + + @AfterClass + public static void destroy() { + if (registry != null) { + registry.stop(); + } + } + @Test public void testHelper() throws Exception { - ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); - DOMHelper helper = new DOMHelper(registry); + DOMHelper helper = DOMHelper.getInstance(registry); Document document = helper.load(XML); String xml = helper.saveAsString(document); XMLAssert.assertXMLEqual(XML, xml); @@ -50,6 +67,9 @@ public class DOMHelperTestCase { Document root = helper.newDocument(); ContentHandler handler = helper.createContentHandler(root); + DOMHelper helper2 = DOMHelper.getInstance(registry); + Assert.assertSame(helper, helper2); + SAXHelper saxHelper = new SAXHelper(registry); saxHelper.parse(XML, handler); |