You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2007/01/22 07:23:55 UTC

svn commit: r498544 - in /incubator/openejb/trunk/openejb3/container/openejb-jee/src: main/java/org/apache/openejb/jee/oej2/ test/java/org/apache/openejb/jee/oej2/ test/resources/

Author: dblevins
Date: Sun Jan 21 22:23:54 2007
New Revision: 498544

URL: http://svn.apache.org/viewvc?view=rev&rev=498544
Log:
The very minimal beginning of a conversion tool.  doesn't really work yet.

Added:
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EnterpriseBean.java
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EnterpriseBeanFoo.java
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/JaxbUtil.java
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EntityBeanType.java
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/MessageDrivenBeanType.java
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/ObjectFactory.java
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/OpenejbJarType.java
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/SessionBeanType.java
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/oej2/ConversionTest.java
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/oej2/OpenejbJarTest.java
    incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/resources/openejb-jar-2-full.xml

Added: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EnterpriseBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EnterpriseBean.java?view=auto&rev=498544
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EnterpriseBean.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EnterpriseBean.java Sun Jan 21 22:23:54 2007
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.jee.oej2;
+
+import javax.xml.bind.JAXBElement;
+import java.lang.*;
+import java.util.List;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface EnterpriseBean {
+    java.lang.String getEjbName();
+
+    void setEjbName(java.lang.String value);
+
+    List<java.lang.String> getJndiName();
+
+    List<java.lang.String> getLocalJndiName();
+
+    List<JAXBElement<? extends AbstractNamingEntryType>> getAbstractNamingEntry();
+
+    List<EjbRefType> getEjbRef();
+
+    List<EjbLocalRefType> getEjbLocalRef();
+
+    List<ServiceRefType> getServiceRef();
+
+    List<ResourceRefType> getResourceRef();
+
+    List<ResourceEnvRefType> getResourceEnvRef();
+}

Added: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EnterpriseBeanFoo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EnterpriseBeanFoo.java?view=auto&rev=498544
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EnterpriseBeanFoo.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EnterpriseBeanFoo.java Sun Jan 21 22:23:54 2007
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.jee.oej2;
+
+import java.lang.String;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface EnterpriseBeanFoo {
+}

Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EntityBeanType.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EntityBeanType.java?view=diff&rev=498544&r1=498543&r2=498544
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EntityBeanType.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/EntityBeanType.java Sun Jan 21 22:23:54 2007
@@ -135,7 +135,7 @@
     "resourceEnvRef",
     "query"
 })
-public class EntityBeanType {
+public class EntityBeanType implements EnterpriseBean {
 
     @XmlElement(name = "ejb-name", required = true)
     protected java.lang.String ejbName;

Added: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/JaxbUtil.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/JaxbUtil.java?view=auto&rev=498544
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/JaxbUtil.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/JaxbUtil.java Sun Jan 21 22:23:54 2007
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.jee.oej2;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.JAXBElement;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.SAXParser;
+import javax.xml.transform.sax.SAXSource;
+import java.lang.*;
+import java.lang.String;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JaxbUtil {
+
+    public static <T>java.lang.String marshal(Class<T> type, Object object) throws JAXBException {
+        JAXBContext ctx2 = JAXBContext.newInstance(type);
+        Marshaller marshaller = ctx2.createMarshaller();
+
+        marshaller.setProperty("jaxb.formatted.output", true);
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        marshaller.marshal(object, baos);
+
+        return new String(baos.toByteArray());
+    }
+
+    public static <T>Object unmarshal(Class<T> type, InputStream in) throws ParserConfigurationException, SAXException, JAXBException {
+        InputSource inputSource = new InputSource(in);
+
+        SAXParserFactory factory = SAXParserFactory.newInstance();
+        factory.setNamespaceAware(true);
+        factory.setValidating(false);
+        SAXParser parser = factory.newSAXParser();
+
+        JAXBContext ctx = JAXBContext.newInstance(type);
+        Unmarshaller unmarshaller = ctx.createUnmarshaller();
+
+        NamespaceFilter xmlFilter = new NamespaceFilter(parser.getXMLReader());
+        xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
+
+        SAXSource source = new SAXSource(xmlFilter, inputSource);
+
+        return unmarshaller.unmarshal(source);
+    }
+}

Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/MessageDrivenBeanType.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/MessageDrivenBeanType.java?view=diff&rev=498544&r1=498543&r2=498544
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/MessageDrivenBeanType.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/MessageDrivenBeanType.java Sun Jan 21 22:23:54 2007
@@ -19,6 +19,8 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.lang.*;
+import java.lang.String;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -27,6 +29,7 @@
 import javax.xml.bind.annotation.XmlElementRef;
 import javax.xml.bind.annotation.XmlID;
 import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlTransient;
 import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
@@ -66,7 +69,7 @@
     "resourceRef",
     "resourceEnvRef"
 })
-public class MessageDrivenBeanType {
+public class MessageDrivenBeanType implements EnterpriseBean {
 
     @XmlElement(name = "ejb-name", required = true)
     protected java.lang.String ejbName;
@@ -99,6 +102,16 @@
     @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
     @XmlID
     protected java.lang.String id;
+
+    @XmlTransient
+    public List<String> getJndiName() {
+        return null;
+    }
+
+    @XmlTransient
+    public List<String> getLocalJndiName() {
+        return null;
+    }
 
     /**
      * Gets the value of the ejbName property.

Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/ObjectFactory.java?view=diff&rev=498544&r1=498543&r2=498544
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/ObjectFactory.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/ObjectFactory.java Sun Jan 21 22:23:54 2007
@@ -384,13 +384,13 @@
         return new RelationshipsType();
     }
 
-    /**
-     * Create an instance of {@link OpenejbJarType.EnterpriseBeans }
-     * 
-     */
-    public OpenejbJarType.EnterpriseBeans createOpenejbJarTypeEnterpriseBeans() {
-        return new OpenejbJarType.EnterpriseBeans();
-    }
+//    /**
+//     * Create an instance of {@link OpenejbJarType.EnterpriseBeans }
+//     *
+//     */
+//    public OpenejbJarType.EnterpriseBeans createOpenejbJarTypeEnterpriseBeans() {
+//        return new OpenejbJarType.EnterpriseBeans();
+//    }
 
     /**
      * Create an instance of {@link OpenejbJarType }

Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/OpenejbJarType.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/OpenejbJarType.java?view=diff&rev=498544&r1=498543&r2=498544
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/OpenejbJarType.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/OpenejbJarType.java Sun Jan 21 22:23:54 2007
@@ -17,14 +17,10 @@
 
 package org.apache.openejb.jee.oej2;
 
-import org.xml.sax.helpers.XMLFilterImpl;
-import org.xml.sax.XMLReader;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
 import java.util.ArrayList;
 import java.util.List;
-import java.lang.*;
+import java.util.Map;
+import java.util.LinkedHashMap;
 import java.lang.String;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.annotation.XmlAccessType;
@@ -33,6 +29,8 @@
 import javax.xml.bind.annotation.XmlElementRef;
 import javax.xml.bind.annotation.XmlElements;
 import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlElementWrapper;
 
 
 /**
@@ -105,8 +103,12 @@
     @XmlElement(name = "enforce-foreign-key-constraints")
     protected EmptyType enforceForeignKeyConstraints;
 
-    @XmlElement(name = "enterprise-beans", required = true)
-    protected OpenejbJarType.EnterpriseBeans enterpriseBeans;
+    @XmlElementWrapper(name = "enterprise-beans")
+    @XmlElements({
+    @XmlElement(name = "message-driven", required = true, type = MessageDrivenBeanType.class),
+    @XmlElement(name = "session", required = true, type = SessionBeanType.class),
+    @XmlElement(name = "entity", required = true, type = EntityBeanType.class)})
+    protected List<EnterpriseBean> enterpriseBeans = new ArrayList<EnterpriseBean>();
 
     @XmlElement()
     protected RelationshipsType relationships;
@@ -240,31 +242,11 @@
         this.enforceForeignKeyConstraints = value;
     }
 
-    /**
-     * Gets the value of the enterpriseBeans property.
-     * 
-     * @return
-     *     possible object is
-     *     {@link OpenejbJarType.EnterpriseBeans }
-     *     
-     */
-    public OpenejbJarType.EnterpriseBeans getEnterpriseBeans() {
+    public List<EnterpriseBean> getEnterpriseBeans() {
         return enterpriseBeans;
     }
 
     /**
-     * Sets the value of the enterpriseBeans property.
-     * 
-     * @param value
-     *     allowed object is
-     *     {@link OpenejbJarType.EnterpriseBeans }
-     *     
-     */
-    public void setEnterpriseBeans(OpenejbJarType.EnterpriseBeans value) {
-        this.enterpriseBeans = value;
-    }
-
-    /**
      * Gets the value of the relationships property.
      * 
      * @return
@@ -369,74 +351,6 @@
             service = new ArrayList<JAXBElement<? extends AbstractServiceType>>();
         }
         return this.service;
-    }
-
-
-    /**
-     * <p>Java class for anonymous complex type.
-     * 
-     * <p>The following schema fragment specifies the expected content contained within this class.
-     * 
-     * <pre>
-     * &lt;complexType>
-     *   &lt;complexContent>
-     *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *       &lt;choice maxOccurs="unbounded" minOccurs="0">
-     *         &lt;element name="session" type="{http://openejb.apache.org/xml/ns/openejb-jar-2.2}session-beanType"/>
-     *         &lt;element name="entity" type="{http://openejb.apache.org/xml/ns/openejb-jar-2.2}entity-beanType"/>
-     *         &lt;element name="message-driven" type="{http://openejb.apache.org/xml/ns/openejb-jar-2.2}message-driven-beanType"/>
-     *       &lt;/choice>
-     *     &lt;/restriction>
-     *   &lt;/complexContent>
-     * &lt;/complexType>
-     * </pre>
-     * 
-     * 
-     */
-    @XmlAccessorType(XmlAccessType.FIELD)
-    @XmlType(name = "", propOrder = {
-        "sessionOrEntityOrMessageDriven"
-    })
-    public static class EnterpriseBeans {
-
-        @XmlElements({
-            @XmlElement(name = "entity", type = EntityBeanType.class),
-            @XmlElement(name = "session", type = SessionBeanType.class),
-            @XmlElement(name = "message-driven", type = MessageDrivenBeanType.class)
-        })
-        protected List<Object> sessionOrEntityOrMessageDriven;
-
-        /**
-         * Gets the value of the sessionOrEntityOrMessageDriven property.
-         * 
-         * <p>
-         * This accessor method returns a reference to the live list,
-         * not a snapshot. Therefore any modification you make to the
-         * returned list will be present inside the JAXB object.
-         * This is why there is not a <CODE>set</CODE> method for the sessionOrEntityOrMessageDriven property.
-         * 
-         * <p>
-         * For example, to add a new item, do as follows:
-         * <pre>
-         *    getSessionOrEntityOrMessageDriven().add(newItem);
-         * </pre>
-         * 
-         * 
-         * <p>
-         * Objects of the following type(s) are allowed in the list
-         * {@link EntityBeanType }
-         * {@link SessionBeanType }
-         * {@link MessageDrivenBeanType }
-         * 
-         * 
-         */
-        public List<Object> getSessionOrEntityOrMessageDriven() {
-            if (sessionOrEntityOrMessageDriven == null) {
-                sessionOrEntityOrMessageDriven = new ArrayList<Object>();
-            }
-            return this.sessionOrEntityOrMessageDriven;
-        }
-
     }
 
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/SessionBeanType.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/SessionBeanType.java?view=diff&rev=498544&r1=498543&r2=498544
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/SessionBeanType.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oej2/SessionBeanType.java Sun Jan 21 22:23:54 2007
@@ -77,7 +77,7 @@
     "webServiceVirtualHost",
     "webServiceSecurity"
 })
-public class SessionBeanType {
+public class SessionBeanType implements EnterpriseBean {
 
     @XmlElement(name = "ejb-name", required = true)
     protected java.lang.String ejbName;

Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/oej2/ConversionTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/oej2/ConversionTest.java?view=diff&rev=498544&r1=498543&r2=498544
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/oej2/ConversionTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/oej2/ConversionTest.java Sun Jan 21 22:23:54 2007
@@ -16,9 +16,66 @@
  */
 package org.apache.openejb.jee.oej2;
 
+import junit.framework.TestCase;
+
+import javax.xml.bind.JAXBElement;
+import java.lang.*;
+import java.lang.String;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.BufferedInputStream;
+import java.util.List;
+
 /**
  * @version $Rev$ $Date$
  */
-public class ConversionTest {
-    
+public class ConversionTest extends TestCase {
+
+    public void testConversion() throws Exception {
+        JAXBElement element = (JAXBElement) JaxbUtil.unmarshal(OpenejbJarType.class, getInputStream("openejb-jar-2-full.xml"));
+        OpenejbJarType o2 = (OpenejbJarType) element.getValue();
+
+        GeronimoEjbJarType g2 = new GeronimoEjbJarType();
+
+        g2.setEnvironment(o2.getEnvironment());
+        g2.setSecurity(o2.getSecurity());
+        g2.getService().addAll(o2.getService());
+        g2.getMessageDestination().addAll(o2.getMessageDestination());
+
+        for (EnterpriseBean bean : o2.getEnterpriseBeans()) {
+            //
+        }
+
+    }
+
+    private <T> void unmarshalAndMarshal(Class<T> type, java.lang.String xmlFileName, java.lang.String expectedFile) throws Exception {
+
+        Object object = JaxbUtil.unmarshal(type, getInputStream(xmlFileName));
+
+        java.lang.String actual = JaxbUtil.marshal(type, object);
+
+        if (xmlFileName.equals(expectedFile)) {
+            String sourceXml = readContent(getInputStream(xmlFileName));
+            assertEquals(sourceXml, actual);
+        } else {
+            String expected = readContent(getInputStream(expectedFile));
+            assertEquals(expected, actual);
+        }
+    }
+
+    private <T>InputStream getInputStream(String xmlFileName) {
+        return getClass().getClassLoader().getResourceAsStream(xmlFileName);
+    }
+
+    private String readContent(InputStream in) throws IOException {
+        StringBuffer sb = new StringBuffer();
+        in = new BufferedInputStream(in);
+        int i = in.read();
+        while (i != -1) {
+            sb.append((char) i);
+            i = in.read();
+        }
+        return sb.toString();
+    }
+
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/oej2/OpenejbJarTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/oej2/OpenejbJarTest.java?view=diff&rev=498544&r1=498543&r2=498544
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/oej2/OpenejbJarTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/oej2/OpenejbJarTest.java Sun Jan 21 22:23:54 2007
@@ -17,31 +17,20 @@
 package org.apache.openejb.jee.oej2;
 
 import junit.framework.TestCase;
-import org.xml.sax.InputSource;
-import org.apache.openejb.jee.oej2.GeronimoEjbJarType;
 
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.ValidationEventHandler;
-import javax.xml.bind.ValidationEvent;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.parsers.SAXParser;
-import javax.xml.transform.sax.SAXSource;
-import java.lang.*;
-import java.lang.String;
+import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.BufferedInputStream;
-import java.io.StringReader;
+import java.lang.String;
 
 /**
  * @version $Revision: 471447 $ $Date: 2006-11-05 07:42:50 -0800 (Sun, 05 Nov 2006) $
  */
 public class OpenejbJarTest extends TestCase {
 
-    public void testNothing(){}
+    public void testNothing() {
+    }
+
     /**
      * @throws Exception
      */
@@ -62,52 +51,22 @@
     }
 
     private <T> void unmarshalAndMarshal(Class<T> type, java.lang.String xmlFileName, java.lang.String expectedFile) throws Exception {
-        JAXBContext ctx = JAXBContext.newInstance(type);
-        Unmarshaller unmarshaller = ctx.createUnmarshaller();
-
-        String sourceXml = readContent(xmlFileName);
-
-        SAXParserFactory factory = SAXParserFactory.newInstance();
-        factory.setNamespaceAware(true);
-        factory.setValidating(false);
-        SAXParser parser = factory.newSAXParser();
-
-        // Create a filter to intercept events
-        NamespaceFilter xmlFilter = new NamespaceFilter(parser.getXMLReader());
 
-        // Be sure the filter has the JAXB content handler set (or it wont
-        // work)
-        xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
+        Object object = JaxbUtil.unmarshal(type, getInputStream(xmlFileName));
 
-        SAXSource source = new SAXSource(xmlFilter, new InputSource(new StringReader(sourceXml)));
+        String actual = JaxbUtil.marshal(type, object);
 
-        Object object = unmarshaller.unmarshal(source);
-//        JAXBElement element =  (JAXBElement) object;
-        unmarshaller.setEventHandler(new OpenejbJarTest.TestValidationEventHandler());
-//        T app = (T) element.getValue();
-//        System.out.println("unmarshalled");
-
-        Marshaller marshaller = ctx.createMarshaller();
-
-        marshaller.setProperty("jaxb.formatted.output", true);
-
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        marshaller.marshal(object, baos);
-
-        String actual = new String(baos.toByteArray());
-
-        if (xmlFileName.equals(expectedFile)){
+        if (xmlFileName.equals(expectedFile)) {
+            String sourceXml = readContent(getInputStream(xmlFileName));
             assertEquals(sourceXml, actual);
         } else {
-            String expected = readContent(expectedFile);
+            String expected = readContent(getInputStream(expectedFile));
             assertEquals(expected, actual);
         }
     }
 
-    private <T>String readContent(String xmlFileName) throws IOException {
-        InputStream in = this.getClass().getClassLoader().getResourceAsStream(xmlFileName);
-        String sourceXml = readContent(in);
-        return sourceXml;
+    private <T>InputStream getInputStream(String xmlFileName) {
+        return getClass().getClassLoader().getResourceAsStream(xmlFileName);
     }
 
     private String readContent(InputStream in) throws IOException {
@@ -118,14 +77,6 @@
             sb.append((char) i);
             i = in.read();
         }
-        String content = sb.toString();
-        return content;
-    }
-
-    private static class TestValidationEventHandler implements ValidationEventHandler {
-        public boolean handleEvent(ValidationEvent validationEvent) {
-            System.out.println(validationEvent.getMessage());
-            return true;
-        }
+        return sb.toString();
     }
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/resources/openejb-jar-2-full.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/resources/openejb-jar-2-full.xml?view=diff&rev=498544&r1=498543&r2=498544
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/resources/openejb-jar-2-full.xml (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/resources/openejb-jar-2-full.xml Sun Jan 21 22:23:54 2007
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<ns3:openejb-jar xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:ns2="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:ns3="http://openejb.apache.org/xml/ns/openejb-jar-2.2" xmlns:ns4="http://openejb.apache.org/xml/ns/pkgen-2.1" xmlns:ns5="http://geronimo.apache.org/xml/ns/j2ee/application-1.2">
+<ns3:openejb-jar xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:ns2="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:ns3="http://openejb.apache.org/xml/ns/openejb-jar-2.2" xmlns:ns4="http://openejb.apache.org/xml/ns/pkgen-2.1" xmlns:ns5="http://geronimo.apache.org/xml/ns/j2ee/application-1.2" xmlns:ns6="http://geronimo.apache.org/xml/ns/j2ee/ejb/openejb-2.0">
     <environment>
         <moduleId>
             <groupId>String</groupId>