You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2018/11/19 15:09:27 UTC

[3/5] tomee git commit: defines a new umarshal, this time, not using the filter

defines a new umarshal, this time, not using the filter


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/0165264d
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/0165264d
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/0165264d

Branch: refs/heads/master
Commit: 0165264d37f9cb6ce6d2585f2f6b0fbd926ad5c4
Parents: f668add
Author: Otavio Santana <ot...@gmail.com>
Authored: Fri Nov 16 19:13:19 2018 -0200
Committer: Otavio Santana <ot...@gmail.com>
Committed: Fri Nov 16 19:13:19 2018 -0200

----------------------------------------------------------------------
 .../apache/openejb/config/ReadDescriptors.java  |  2 +-
 .../java/org/apache/openejb/jee/JaxbJavaee.java | 89 +++++++++++++-------
 2 files changed, 60 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/0165264d/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java b/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
index 171a563..ab482f1 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
@@ -555,7 +555,7 @@ public class ReadDescriptors implements DynamicDeployer {
             if (data instanceof URL) {
                 final URL url = (URL) data;
                 try {
-                    final EntityMappings entitymappings = (EntityMappings) JaxbJavaee.unmarshalJavaee(EntityMappings.class, IO.read(url));
+                    final EntityMappings entitymappings = (EntityMappings) JaxbJavaee.unmarshal(EntityMappings.class, IO.read(url));
                     ejbModule.getAltDDs().put("openejb-cmp-orm.xml", entitymappings);
                 } catch (final SAXException e) {
                     throw new OpenEJBException("Cannot parse the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);

http://git-wip-us.apache.org/repos/asf/tomee/blob/0165264d/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java
----------------------------------------------------------------------
diff --git a/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java b/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java
index 3d79864..a76be06 100644
--- a/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java
+++ b/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java
@@ -5,14 +5,14 @@
  * 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.
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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;
 
@@ -91,18 +91,7 @@ public class JaxbJavaee {
         return jaxbContext;
     }
 
-    /**
-     * Convert the namespaceURI in the input to the javaee URI, do not validate the xml, and read in a T.
-     *
-     * @param type Class of object to be read in
-     * @param in   input stream to read
-     * @param <T>  class of object to be returned
-     * @return a T read from the input stream
-     * @throws ParserConfigurationException is the SAX parser can not be configured
-     * @throws SAXException                 if there is an xml problem
-     * @throws JAXBException                if the xml cannot be marshalled into a T.
-     */
-    public static <T> Object unmarshalJavaee(final Class<T> type, final InputStream in) throws ParserConfigurationException, SAXException, JAXBException {
+    private static <T> Object unmarshalJavaee(final Class<T> type, final InputStream in, boolean filter) throws ParserConfigurationException, SAXException, JAXBException {
 
         final SAXParserFactory factory = SAXParserFactory.newInstance();
         factory.setNamespaceAware(true);
@@ -122,11 +111,16 @@ public class JaxbJavaee {
             }
         });
 
-        final JavaeeNamespaceFilter xmlFilter = new JavaeeNamespaceFilter(parser.getXMLReader());
-        xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
+        SAXSource source = null;
+        if (filter) {
+            final JavaeeNamespaceFilter xmlFilter = new JavaeeNamespaceFilter(parser.getXMLReader());
+            xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
+            // unmarshall
+            source = new SAXSource(xmlFilter, new InputSource(in));
+        } else {
+            source = new SAXSource(new InputSource(in));
+        }
 
-        // unmarshall
-        final SAXSource source = new SAXSource(xmlFilter, new InputSource(in));
 
         currentPublicId.set(new TreeSet<String>());
         try {
@@ -138,6 +132,37 @@ public class JaxbJavaee {
     }
 
     /**
+     *
+     * It unmarshals, but not using the {@link JavaeeNamespaceFilter}
+     *
+     * @param type Class of object to be read in
+     * @param in   input stream to read
+     * @param <T>  class of object to be returned
+     * @return a T read from the input stream
+     * @throws ParserConfigurationException is the SAX parser can not be configured
+     * @throws SAXException                 if there is an xml problem
+     * @throws JAXBException                if the xml cannot be marshalled into a T.
+     */
+    public static <T> Object unmarshal(final Class<T> type, final InputStream in) throws ParserConfigurationException, SAXException, JAXBException {
+        return unmarshalJavaee(type, in, false);
+    }
+
+    /**
+     * Convert the namespaceURI in the input to the javaee URI, do not validate the xml, and read in a T.
+     *
+     * @param type Class of object to be read in
+     * @param in   input stream to read
+     * @param <T>  class of object to be returned
+     * @return a T read from the input stream
+     * @throws ParserConfigurationException is the SAX parser can not be configured
+     * @throws SAXException                 if there is an xml problem
+     * @throws JAXBException                if the xml cannot be marshalled into a T.
+     */
+    public static <T> Object unmarshalJavaee(final Class<T> type, final InputStream in) throws ParserConfigurationException, SAXException, JAXBException {
+        return unmarshalJavaee(type, in, true);
+    }
+
+    /**
      * Read in a T from the input stream.
      *
      * @param type     Class of object to be read in
@@ -290,7 +315,11 @@ public class JaxbJavaee {
             if (uri != null && (uri.startsWith("http://jboss.org") || uri.startsWith("urn:java:"))) { // ignore it to be able to read beans.xml with weld config for instances
                 ignore = true;
             } else {
-                super.startElement("http://java.sun.com/xml/ns/javaee", localName, qname, atts);
+                if ("entity-mappings".equals(localName) && "entity-mappings".equals(localName)) {
+                    super.startElement("http://java.sun.com/xml/ns/javaee", localName, qname, atts);
+                } else {
+                    super.startElement("http://java.sun.com/xml/ns/persistence/orm", localName, qname, atts);
+                }
             }
         }
 
@@ -327,7 +356,7 @@ public class JaxbJavaee {
 
         protected String eeUri(final String uri) {
             // if ee 7 then switch back on ee 6 to not break compatibility - to rework surely when we'll be fully ee 7
-            return "http://xmlns.jcp.org/xml/ns/javaee".equals(uri) ? "http://java.sun.com/xml/ns/javaee": uri;
+            return "http://xmlns.jcp.org/xml/ns/javaee".equals(uri) ? "http://java.sun.com/xml/ns/javaee" : uri;
         }
 
         @Override
@@ -555,10 +584,10 @@ public class JaxbJavaee {
         schemaFactory.setResourceResolver(resourceResolver);
 
         final Schema schema = schemaFactory.newSchema(
-            new Source[]{
-                new StreamSource(xmlSchemaURL.openStream()),
-                new StreamSource(javaeeSchemaURL.openStream())
-            });
+                new Source[]{
+                        new StreamSource(xmlSchemaURL.openStream()),
+                        new StreamSource(javaeeSchemaURL.openStream())
+                });
 
         // validate
         schema.newValidator().validate(sourceForValidate);