tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r643485 - in /incubator/tuscany/java/sca/modules/databinding-jaxb/src: main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java test/java/org/apache/tuscany/databinding/jaxb/JAXBReflectionTestCase.java
Date Tue, 01 Apr 2008 17:52:06 GMT
Author: rfeng
Date: Tue Apr  1 10:52:03 2008
New Revision: 643485

URL: http://svn.apache.org/viewvc?rev=643485&view=rev
Log:
Refactor the xsd generation into JAXBContextHelper

Modified:
    incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
    incubator/tuscany/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBReflectionTestCase.java

Modified: incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java?rev=643485&r1=643484&r2=643485&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
(original)
+++ incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
Tue Apr  1 10:52:03 2008
@@ -19,21 +19,26 @@
 package org.apache.tuscany.sca.databinding.jaxb;
 
 import java.beans.Introspector;
+import java.io.IOException;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
+import javax.xml.bind.SchemaOutputResolver;
 import javax.xml.bind.annotation.XmlEnum;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlSchema;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.namespace.QName;
+import javax.xml.transform.Result;
+import javax.xml.transform.dom.DOMResult;
 
 import org.apache.tuscany.sca.databinding.TransformationContext;
 import org.apache.tuscany.sca.databinding.TransformationException;
 import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
 import org.apache.tuscany.sca.interfacedef.DataType;
 import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.w3c.dom.Node;
 
 public class JAXBContextHelper {
     // TODO: Do we need to set them for source and target?
@@ -178,5 +183,27 @@
         }
         return new XMLType(elementQName, typeQName);
     }
+    
+    public static Node generateSchema(JAXBContext context) throws Exception {
+        SchemaOutputResolverImpl resolver = new SchemaOutputResolverImpl();
+        context.generateSchema(resolver);
+        return resolver.getSchema();
+    }
+
+    public static class SchemaOutputResolverImpl extends SchemaOutputResolver {
+        private DOMResult result = new DOMResult();
+
+        @Override
+        public Result createOutput(String ns, String file) throws IOException {
+            result.setSystemId("sca:dom");
+            return result;
+        }
+
+        public Node getSchema() {
+            return result != null ? result.getNode() : null;
+        }
+
+    }
+    
 
 }

Modified: incubator/tuscany/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBReflectionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBReflectionTestCase.java?rev=643485&r1=643484&r2=643485&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBReflectionTestCase.java
(original)
+++ incubator/tuscany/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBReflectionTestCase.java
Tue Apr  1 10:52:03 2008
@@ -19,19 +19,16 @@
 
 package org.apache.tuscany.databinding.jaxb;
 
-import java.io.IOException;
 import java.lang.reflect.Type;
 import java.util.Collections;
 
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.SchemaOutputResolver;
 import javax.xml.namespace.QName;
-import javax.xml.transform.Result;
-import javax.xml.transform.dom.DOMResult;
 
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
+import org.apache.tuscany.sca.databinding.jaxb.JAXBContextHelper;
 import org.apache.tuscany.sca.databinding.xml.Node2String;
 import org.jvnet.jaxb.reflection.model.annotation.RuntimeInlineAnnotationReader;
 import org.jvnet.jaxb.reflection.model.core.Ref;
@@ -53,28 +50,10 @@
 
     public void testGenerateSchema() throws Exception {
         JAXBContext context = JAXBContext.newInstance("com.example.ipo.jaxb");
-        SchemaOutputResolverImpl resolver = new SchemaOutputResolverImpl();
-        context.generateSchema(resolver);
-        System.out.println(new Node2String().transform(resolver.getSchema(), null));
+        Node schema = JAXBContextHelper.generateSchema(context);
+        System.out.println(new Node2String().transform(schema, null));
     }
-
-    public static class SchemaOutputResolverImpl extends SchemaOutputResolver {
-        private DOMResult result = new DOMResult();
-
-        @Override
-        public Result createOutput(String ns, String file) throws IOException {
-            System.out.println(ns);
-            System.out.println(file);
-            result.setSystemId("sca:dom");
-            return result;
-        }
-
-        public Node getSchema() {
-            return result != null ? result.getNode() : null;
-        }
-
-    }
-    
+  
     /**
      * This is a workaround for the NPE bug in jaxb-reflection
      * @param classes



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message