tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r801876 - in /tuscany/java/sca/modules/common-xml/src: main/java/org/apache/tuscany/sca/common/xml/dom/ main/java/org/apache/tuscany/sca/common/xml/sax/ main/java/org/apache/tuscany/sca/common/xml/stax/ test/java/org/apache/tuscany/sca/comm...
Date Fri, 07 Aug 2009 04:04:01 GMT
Author: rfeng
Date: Fri Aug  7 04:04:00 2009
New Revision: 801876

URL: http://svn.apache.org/viewvc?rev=801876&view=rev
Log:
Add getInstance helper method

Modified:
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/sax/SAXHelper.java
    tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/StAXHelper.java
    tuscany/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/dom/DOMHelperTestCase.java

Modified: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java?rev=801876&r1=801875&r2=801876&view=diff
==============================================================================
--- tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java
(original)
+++ tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java
Fri Aug  7 04:04:00 2009
@@ -37,6 +37,7 @@
 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 @@
     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);

Modified: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/sax/SAXHelper.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/sax/SAXHelper.java?rev=801876&r1=801875&r2=801876&view=diff
==============================================================================
--- tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/sax/SAXHelper.java
(original)
+++ tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/sax/SAXHelper.java
Fri Aug  7 04:04:00 2009
@@ -28,6 +28,7 @@
 
 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 @@
         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 {

Modified: tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/StAXHelper.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/StAXHelper.java?rev=801876&r1=801875&r2=801876&view=diff
==============================================================================
--- tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/StAXHelper.java
(original)
+++ tuscany/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/stax/StAXHelper.java
Fri Aug  7 04:04:00 2009
@@ -62,6 +62,12 @@
         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

Modified: tuscany/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/dom/DOMHelperTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/dom/DOMHelperTestCase.java?rev=801876&r1=801875&r2=801876&view=diff
==============================================================================
--- tuscany/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/dom/DOMHelperTestCase.java
(original)
+++ tuscany/java/sca/modules/common-xml/src/test/java/org/apache/tuscany/sca/common/xml/dom/DOMHelperTestCase.java
Fri Aug  7 04:04:00 2009
@@ -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 @@
         "<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 @@
         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);
 



Mime
View raw message