geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject cvs commit: incubator-geronimo/specs/schema/src/test-data/j2ee_1_3dtd ejb-jar-21.xml
Date Thu, 17 Jun 2004 06:55:11 GMT
djencks     2004/06/16 23:55:11

  Modified:    specs/schema project.xml
               specs/schema/src/test-data/j2ee_1_3dtd ejb-jar-21.xml
  Added:       specs/schema/src/java/org/apache/geronimo/schema
                        SchemaConversionUtils.java
               specs/schema/src/test/org/apache/geronimo/schema/xsl
                        EJB20To21TransformTest.java
  Removed:     specs/schema/src/test/org/apache/geronimo/schema/xsl
                        EJB20To21XSLTest.java
  Log:
  change from  xsl to xmlbeans for dtd to schema conversion
  
  Revision  Changes    Path
  1.8       +3 -15     incubator-geronimo/specs/schema/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/schema/project.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- project.xml	15 Jun 2004 23:00:28 -0000	1.7
  +++ project.xml	17 Jun 2004 06:55:11 -0000	1.8
  @@ -57,21 +57,9 @@
               <version>1.0-DEV</version>
           </dependency>
   
  -        <!-- xsl testing -->
  -        <dependency>
  -            <groupId>xmlunit</groupId>
  -            <artifactId>xmlunit</artifactId>
  -            <version>1.0</version>
  -        </dependency>
  -        <dependency>
  -            <groupId>junit</groupId>
  -            <artifactId>junit</artifactId>
  -            <version>3.8.1</version>
  -        </dependency>
  -
       </dependencies>
   
  -    <build>
  +    <!--build>
           <sourceDirectory>${basedir}/src</sourceDirectory>
  -    </build>
  +    </build-->
   </project>
  
  
  
  1.1                  incubator-geronimo/specs/schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java
  
  Index: SchemaConversionUtils.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed 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.geronimo.schema;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.ArrayList;
  
  import javax.xml.namespace.QName;
  
  import org.apache.geronimo.xbeans.j2ee.ActivationConfigPropertyType;
  import org.apache.geronimo.xbeans.j2ee.ActivationConfigType;
  import org.apache.geronimo.xbeans.j2ee.EjbJarDocument;
  import org.apache.geronimo.xbeans.j2ee.WebAppDocument;
  import org.apache.xmlbeans.XmlCursor;
  import org.apache.xmlbeans.XmlException;
  import org.apache.xmlbeans.XmlObject;
  import org.apache.xmlbeans.XmlOptions;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/06/17 06:55:11 $
   *
   * */
  public class SchemaConversionUtils {
      private static final String J2EE_NAMESPACE = "http://java.sun.com/xml/ns/j2ee";
  
      private SchemaConversionUtils() {
      }
  
      public static XmlObject parse(InputStream is) throws IOException, XmlException {
          ArrayList errors = new ArrayList();
          XmlOptions options = new XmlOptions();
          options.setLoadLineNumbers();
          options.setErrorListener(errors);
          XmlObject parsed = XmlObject.Factory.parse(is, options);
          if (errors.size() != 0) {
              throw new XmlException(errors.toArray().toString());
          }
          return parsed;
      }
  
      public static EjbJarDocument convertToEJBSchema(XmlObject xmlObject) {
          XmlCursor cursor = xmlObject.newCursor();
          String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";
          String version = "2.1";
          try {
              SchemaConversionUtils.convertToSchema(cursor, schemaLocationURL, version);
              //play with message-driven
              cursor.toStartDoc();
              SchemaConversionUtils.convertToActivationConfig(cursor);
          } finally {
              cursor.dispose();
          }
          XmlObject result = xmlObject.changeType(EjbJarDocument.type);
          if (result != null) {
              return (EjbJarDocument)result;
          }
          return (EjbJarDocument)xmlObject;
      }
  
      public static WebAppDocument convertToServletSchema(XmlObject xmlObject) {
          XmlCursor cursor = xmlObject.newCursor();
          String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
          String version = "2.4";
          try {
              SchemaConversionUtils.convertToSchema(cursor, schemaLocationURL, version);
          } finally {
              cursor.dispose();
          }
          XmlObject result = xmlObject.changeType(WebAppDocument.type);
          if (result != null) {
              return (WebAppDocument)result;
          }
          return (WebAppDocument)xmlObject;
      }
  
      public static boolean convertToSchema(XmlCursor cursor, String schemaLocationURL, String
version) {
          //convert namespace
          boolean isFirstStart = true;
          while (cursor.hasNextToken()) {
              if (cursor.isStart()) {
                  if (J2EE_NAMESPACE.equals(cursor.getName().getNamespaceURI())) {
                      //already has correct schema, exit
                      return false;
                  }
                  cursor.setName(new QName(J2EE_NAMESPACE, cursor.getName().getLocalPart()));
                  cursor.toNextToken();
                  if (isFirstStart) {
                      cursor.insertNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                      cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance",
"schemaLocation", "xsi"), "http://java.sun.com/xml/ns/j2ee " + schemaLocationURL);
                      cursor.insertAttributeWithValue(new QName("version"), version);
                      isFirstStart = false;
                  }
              } else {
                  cursor.toNextToken();
              }
          }
          return true;
      }
  
      public static void convertToActivationConfig(XmlCursor cursor) {
          cursor.toChild(J2EE_NAMESPACE, "ejb-jar");
          cursor.toChild(J2EE_NAMESPACE, "enterprise-beans");
          boolean onMessageDriven = cursor.toChild(J2EE_NAMESPACE, "message-driven");
          while (onMessageDriven) {
              cursor.toChild(J2EE_NAMESPACE, "transaction-type");
              //add messaging-type
              cursor.insertElementWithText("messaging-type", J2EE_NAMESPACE, "javax.jms.MessageListener");
              cursor.toNextSibling();
              //mark activation-config-properties location
              cursor.push();
              ActivationConfigType activationConfig = ActivationConfigType.Factory.newInstance();
              if (cursor.isStart() && cursor.getName().equals(new QName(J2EE_NAMESPACE,
"message-selector"))) {
                  addActivationConfigProperty(activationConfig, cursor, "messageSelector");
                  cursor.removeXml();
              }
              toNextStartToken(cursor);
              if (cursor.isStart() && cursor.getName().equals(new QName(J2EE_NAMESPACE,
"acknowledge-mode"))) {
                  addActivationConfigProperty(activationConfig, cursor, "acknowledgeMode");
                  cursor.removeXml();
              }
              toNextStartToken(cursor);
              if (cursor.isStart() && cursor.getName().equals(new QName(J2EE_NAMESPACE,
"message-driven-destination"))) {
                  cursor.push();
                  if (cursor.toChild(J2EE_NAMESPACE, "destination-type")) {
                      addActivationConfigProperty(activationConfig, cursor, "destinationType");
                  } else {
                      throw new IllegalStateException("no destination-type in message-driven-destination");
                  }
                  if (cursor.toNextSibling(J2EE_NAMESPACE, "subscription-durability")) {
                      addActivationConfigProperty(activationConfig, cursor, "subscriptionDurability");
                  }
                  cursor.pop();
                  cursor.removeXml();
              }
              cursor.pop();
              cursor.insertElement(new QName(J2EE_NAMESPACE, "activation-config"));
              //back up into element we just inserted.
              while (!cursor.isEnd()) {
                  cursor.toPrevToken();
              }
              XmlCursor activationConfigCursor = activationConfig.newCursor();
              //move past the STARTDOC token
              toNextStartToken(activationConfigCursor);
              //add all the activation-config-properties we defined
              while (true) {
                  activationConfigCursor.copyXml(cursor);
                  if (!activationConfigCursor.toNextSibling(J2EE_NAMESPACE, "activation-config-property"))
{
                      break;
                  }
              }
              //out of activation-config element
              cursor.toParent();
              //out of message-driven element
              cursor.toParent();
              //on to next message driven bean, if any.
              onMessageDriven = cursor.toNextSibling(J2EE_NAMESPACE, "message-driven");
          }
      }
  
      private static void toNextStartToken(XmlCursor cursor) {
          while (!cursor.isStart()) {
              cursor.toNextToken();
          }
      }
  
      private static void addActivationConfigProperty(ActivationConfigType activationConfig,
XmlCursor cursor, String activationConfigPropertyName) {
          ActivationConfigPropertyType activationConfigProperty = activationConfig.addNewActivationConfigProperty();
          activationConfigProperty.addNewActivationConfigPropertyName().setStringValue(activationConfigPropertyName);
          activationConfigProperty.addNewActivationConfigPropertyValue().setStringValue(cursor.getTextValue());
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/specs/schema/src/test/org/apache/geronimo/schema/xsl/EJB20To21TransformTest.java
  
  Index: EJB20To21TransformTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed 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.geronimo.schema.xsl;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.geronimo.schema.SchemaConversionUtils;
  import org.apache.xmlbeans.XmlCursor;
  import org.apache.xmlbeans.XmlObject;
  import junit.framework.TestCase;
  
  /**
   * ejb 1.1 dtd appears to be a subset of ejb 2.0 dtd so the same xsl should
   * work for both.
   *
   * @version $Revision: 1.1 $ $Date: 2004/06/17 06:55:11 $
   *
   * */
  public class EJB20To21TransformTest extends TestCase {
  
  //comment on validity of j2ee 1.4 schemas: validation doesn't work...
  //        From: "Radu Preotiuc-Pietro" <radup@bea.com>
  //        Date: Tue Jun 15, 2004  3:37:50 PM US/Pacific
  //        To: <xmlbeans-user@xml.apache.org>
  //        Subject: RE: Problem with validate -- xsb schema file missing/wrong name
  //        Reply-To: xmlbeans-user@xml.apache.org
  //
  //        Unfortunately, there is an issue in XmlBeans v1 having to do with duplicate id
constraints definitions.
  //        XmlBeans v2 does not have this issue.
  //        Also, these ejb Schemas are techically incorrect because they violate the id constraint
uniqueness rule (at least when processed together, you could try and compile each one separately)
  //        So, there are a couple of options:
  //        1. you hand-edit the schemas to rename those problematic id constraints
  //        2. you upgrade to v2
  //        Well, there is a third alternative, which is a fix integrated in XmlBeans v1,
may or may not be feasible
  //
  //        Radu
  
      public void testXMLBeansTransform() throws Exception {
          File srcXml = new File("src/test-data/j2ee_1_3dtd/ejb-jar.xml");
          File expectedOutputXml = new File("src/test-data/j2ee_1_3dtd/ejb-jar-21.xml");
          XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
          xmlObject = SchemaConversionUtils.convertToEJBSchema(xmlObject);
          XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
          List problems = new ArrayList();
          assertTrue("Differences: " + problems, compareXmlObjects(xmlObject, expected, problems));
          //make sure trying to convert twice has no bad effects
          XmlCursor cursor2 = xmlObject.newCursor();
          try {
              String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";
              String version = "2.1";
              assertFalse(SchemaConversionUtils.convertToSchema(cursor2, schemaLocationURL,
version));
          } finally {
              cursor2.dispose();
          }
          assertTrue("Differences after reconverting to schema: " + problems, compareXmlObjects(xmlObject,
expected, problems));
      }
  
  
      private boolean compareXmlObjects(XmlObject xmlObject, XmlObject expectedObject, List
problems) {
          XmlCursor test = xmlObject.newCursor();
          XmlCursor expected = expectedObject.newCursor();
          boolean similar = true;
          int elementCount = 0;
          while (toNextStartToken(test)) {
              elementCount++;
              if (!toNextStartToken(expected)) {
                  problems.add("test longer than expected at element: " + elementCount);
                  return false;
              }
              if (!test.getChars().equals(expected.getChars())) {
                  problems.add("Different elements at elementCount: " + elementCount + ",
test: " + test.getChars() + ", expected: " + expected.getChars());
                  similar = false;
              }
              test.toNextToken();
              expected.toNextToken();
          }
          return similar;
      }
  
      private boolean toNextStartToken(XmlCursor cursor) {
          while (!cursor.isStart()) {
              if (!cursor.hasNextToken()) {
                  return false;
              }
              cursor.toNextToken();
          }
          return true;
      }
  
  }
  
  
  
  1.2       +51 -51    incubator-geronimo/specs/schema/src/test-data/j2ee_1_3dtd/ejb-jar-21.xml
  
  Index: ejb-jar-21.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/schema/src/test-data/j2ee_1_3dtd/ejb-jar-21.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ejb-jar-21.xml	15 Jun 2004 23:00:28 -0000	1.1
  +++ ejb-jar-21.xml	17 Jun 2004 06:55:11 -0000	1.2
  @@ -17,9 +17,9 @@
   -->
   
   <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
  -  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  -  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
  -  version="2.1">
  +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  +    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
  +    version="2.1">
       <enterprise-beans>
           <session>
               <ejb-name>SimpleStatelessSession</ejb-name>
  @@ -76,65 +76,65 @@
               <primkey-field>id</primkey-field>
           </entity>
           <message-driven>
  -<description>hey its a mdb</description>
  -<display-name>some CMT mdb</display-name>
  -<ejb-name>SampleCMTMDB</ejb-name>
  -<ejb-class>org.openejb.test.mdb.CMTMDB</ejb-class>
  -<messaging-type>javax.jms.MessageListener</messaging-type>
  -<transaction-type>Container</transaction-type>
  -<activation-config>
  -<activation-config-property>
  -<activation-config-property-name>messageSelector</activation-config-property-name>
  -<activation-config-property-value>some selector</activation-config-property-value>
  -</activation-config-property>
  -<activation-config-property>
  -<activation-config-property-name>destinationType</activation-config-property-name>
  -<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
  -</activation-config-property>
  -<activation-config-property>
  -<activation-config-property-name>subscriptionDurability</activation-config-property-name>
  -<activation-config-property-value>Durable</activation-config-property-value>
  -</activation-config-property>
  -</activation-config>
  -<env-entry>
  +            <description>hey its a mdb</description>
  +            <display-name>some CMT mdb</display-name>
  +            <ejb-name>SampleCMTMDB</ejb-name>
  +            <ejb-class>org.openejb.test.mdb.CMTMDB</ejb-class>
  +            <messaging-type>javax.jms.MessageListener</messaging-type>
  +            <transaction-type>Container</transaction-type>
  +            <activation-config>
  +                <activation-config-property>
  +                    <activation-config-property-name>messageSelector</activation-config-property-name>
  +                    <activation-config-property-value>some selector</activation-config-property-value>
  +                </activation-config-property>
  +                <activation-config-property>
  +                    <activation-config-property-name>destinationType</activation-config-property-name>
  +                    <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
  +                </activation-config-property>
  +                <activation-config-property>
  +                    <activation-config-property-name>subscriptionDurability</activation-config-property-name>
  +                    <activation-config-property-value>Durable</activation-config-property-value>
  +                </activation-config-property>
  +            </activation-config>
  +            <env-entry>
                   <description>sure, it's like this</description>
                   <env-entry-name>EnvEntry</env-entry-name>
                   <env-entry-type>java.lang.String</env-entry-type>
                   <env-entry-value>value</env-entry-value>
               </env-entry>
  -</message-driven>
  +        </message-driven>
           <message-driven>
  -<description>hey its another mdb</description>
  -<display-name>some BMT mdb</display-name>
  -<ejb-name>SampleBMTMDB</ejb-name>
  -<ejb-class>org.openejb.test.mdb.BMTMDB</ejb-class>
  -<messaging-type>javax.jms.MessageListener</messaging-type>
  -<transaction-type>Bean</transaction-type>
  -<activation-config>
  -<activation-config-property>
  -<activation-config-property-name>acknowledgeMode</activation-config-property-name>
  -<activation-config-property-value>Dups-ok-acknowledge</activation-config-property-value>
  -</activation-config-property>
  -<activation-config-property>
  -<activation-config-property-name>messageSelector</activation-config-property-name>
  -<activation-config-property-value>some selector</activation-config-property-value>
  -</activation-config-property>
  -<activation-config-property>
  -<activation-config-property-name>destinationType</activation-config-property-name>
  -<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
  -</activation-config-property>
  -<activation-config-property>
  -<activation-config-property-name>subscriptionDurability</activation-config-property-name>
  -<activation-config-property-value>Durable</activation-config-property-value>
  -</activation-config-property>
  -</activation-config>
  -<env-entry>
  +            <description>hey its another mdb</description>
  +            <display-name>some BMT mdb</display-name>
  +            <ejb-name>SampleBMTMDB</ejb-name>
  +            <ejb-class>org.openejb.test.mdb.BMTMDB</ejb-class>
  +            <messaging-type>javax.jms.MessageListener</messaging-type>
  +            <transaction-type>Bean</transaction-type>
  +            <activation-config>
  +                <activation-config-property>
  +                    <activation-config-property-name>messageSelector</activation-config-property-name>
  +                    <activation-config-property-value>some selector</activation-config-property-value>
  +                </activation-config-property>
  +                <activation-config-property>
  +                    <activation-config-property-name>acknowledgeMode</activation-config-property-name>
  +                    <activation-config-property-value>Dups-ok-acknowledge</activation-config-property-value>
  +                </activation-config-property>
  +                <activation-config-property>
  +                    <activation-config-property-name>destinationType</activation-config-property-name>
  +                    <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
  +                </activation-config-property>
  +                <activation-config-property>
  +                    <activation-config-property-name>subscriptionDurability</activation-config-property-name>
  +                    <activation-config-property-value>Durable</activation-config-property-value>
  +                </activation-config-property>
  +            </activation-config>
  +            <env-entry>
                   <description>sure, it's like this</description>
                   <env-entry-name>EnvEntry</env-entry-name>
                   <env-entry-type>java.lang.String</env-entry-type>
                   <env-entry-value>value</env-entry-value>
               </env-entry>
  -</message-driven>
  +        </message-driven>
       </enterprise-beans>
       <assembly-descriptor>
           <method-permission>
  
  
  

Mime
View raw message