jochen      2005/07/20 13:48:30

  Modified:    src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg
                        GroupHandlerSG.java BeanGeneratingVisitor.java
                        SequenceHandlerSG.java
               src/test/jaxb types.xsd
               .        status.xml
               src/jaxme/org/apache/ws/jaxme/junit MarshallerTest.java
  Log:
  Added a unit test for mixed content handling. Fixed the handling of
  complex child elements in mixed content types.
  
  Revision  Changes    Path
  1.8       +26 -2     
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/GroupHandlerSG.java
  
  Index: GroupHandlerSG.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/GroupHandlerSG.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- GroupHandlerSG.java       8 Jul 2005 20:43:57 -0000       1.7
  +++ GroupHandlerSG.java       20 Jul 2005 20:48:29 -0000      1.8
  @@ -164,8 +164,32 @@
                }
        }
   
  -     protected boolean isRequiredParticle(ParticleSG particleSG) {
  -             return particleSG.getMinOccurs() > 0;
  +     protected boolean isRequiredParticle(ParticleSG particleSG) throws 
SAXException {
  +             if (particleSG.getMinOccurs() == 0) {
  +                     return false;
  +             } else {
  +                     if (particleSG.isGroup()) {
  +                             GroupSG group = particleSG.getGroupSG();
  +                             ParticleSG[] particles = group.getParticles();
  +                             if (group.isChoice()) {
  +                                     for (int i = 0;  i < particles.length;  
i++) {
  +                                             if 
(!isRequiredParticle(particles[i])) {
  +                                                     return false;
  +                                             }
  +                                     }
  +                                     return true;
  +                             } else {
  +                                     for (int i = 0;  i < particles.length;  
i++) {
  +                                             if 
(isRequiredParticle(particles[i])) {
  +                                                     return true;
  +                                             }
  +                                     }
  +                                     return false;
  +                             }
  +                     } else {
  +                             return true;
  +                     }
  +             }
        }
   
        protected void handleStartOfChildElement(Object pUnmarshallerHandler,
  
  
  
  1.5       +26 -24    
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/BeanGeneratingVisitor.java
  
  Index: BeanGeneratingVisitor.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/BeanGeneratingVisitor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BeanGeneratingVisitor.java        13 Jul 2005 19:58:16 -0000      1.4
  +++ BeanGeneratingVisitor.java        20 Jul 2005 20:48:29 -0000      1.5
  @@ -128,32 +128,34 @@
                final JavaSource pJs = this.js;
                final PropertySG elementSG = pParticle.getPropertySG();
                if (isMixed) {
  -                     JavaQName qName = GroupUtil.getContentClass(pGroupSG, 
pParticle, pJs.getQName());
  -                     JavaSource js;
  -                     if (qName.isInnerClass()) {
  -                             js = 
pJs.newJavaInnerClass(qName.getInnerClassName(), JavaSource.PUBLIC);
  -                             if (!pJs.isInterface()) {
  -                                     js.setStatic(true);
  +                     if (!pParticle.getObjectSG().getTypeSG().isComplex()) {
  +                             JavaQName qName = 
GroupUtil.getContentClass(pGroupSG, pParticle, pJs.getQName());
  +                             JavaSource js;
  +                             if (qName.isInnerClass()) {
  +                                     js = 
pJs.newJavaInnerClass(qName.getInnerClassName(), JavaSource.PUBLIC);
  +                                     if (!pJs.isInterface()) {
  +                                             js.setStatic(true);
  +                                     }
  +                             } else {
  +                                     js = 
pJs.getFactory().newJavaSource(qName, JavaSource.PUBLIC);
                                }
  -                     } else {
  -                             js = pJs.getFactory().newJavaSource(qName, 
JavaSource.PUBLIC);
  -                     }
  -                     if (pJs.isInterface()) {
  -                             js.setType(JavaSource.INTERFACE);
  -                     } else {
  -                             
js.addImplements(GroupUtil.getContentClass(pGroupSG, pParticle, 
ct.getClassContext().getXMLInterfaceName()));
  -                     }
  -                     PropertySGChain chain = ((PropertySGImpl) 
elementSG).getHeadOfChain();
  -                     PropertySGChain head = new PropertySGChainImpl(chain){
  -                             public String getXMLFieldName(PropertySG 
pController) throws SAXException {
  -                                     return "_value";
  -                             }
  -                             public String getPropertyName(PropertySG 
pController) throws SAXException {
  -                                     return "value";
  +                             if (pJs.isInterface()) {
  +                                     js.setType(JavaSource.INTERFACE);
  +                             } else {
  +                                     
js.addImplements(GroupUtil.getContentClass(pGroupSG, pParticle, 
ct.getClassContext().getXMLInterfaceName()));
                                }
  -                     };
  -                     PropertySGImpl pSG = new PropertySGImpl(head);
  -                     pSG.generate(js);
  +                             PropertySGChain chain = ((PropertySGImpl) 
elementSG).getHeadOfChain();
  +                             PropertySGChain head = new 
PropertySGChainImpl(chain){
  +                                     public String 
getXMLFieldName(PropertySG pController) throws SAXException {
  +                                             return "_value";
  +                                     }
  +                                     public String 
getPropertyName(PropertySG pController) throws SAXException {
  +                                             return "value";
  +                                     }
  +                             };
  +                             PropertySGImpl pSG = new PropertySGImpl(head);
  +                             pSG.generate(js);
  +                     }
                } else {
                        elementSG.generate(pJs);
                }
  
  
  
  1.5       +1 -1      
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/SequenceHandlerSG.java
  
  Index: SequenceHandlerSG.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/SequenceHandlerSG.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SequenceHandlerSG.java    24 Apr 2005 20:16:48 -0000      1.4
  +++ SequenceHandlerSG.java    20 Jul 2005 20:48:29 -0000      1.5
  @@ -143,7 +143,7 @@
         * returns the index of the last valid particle. Returns
         * -1, if there is no valid particle.
         */
  -     private int getLastValidParticle(int pState) {
  +     private int getLastValidParticle(int pState) throws SAXException {
                int lastParticle;
                if (pState == 0) {
                        lastParticle = 0;
  
  
  
  1.13      +24 -0     ws-jaxme/src/test/jaxb/types.xsd
  
  Index: types.xsd
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/test/jaxb/types.xsd,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- types.xsd 6 Jul 2005 21:34:14 -0000       1.12
  +++ types.xsd 20 Jul 2005 20:48:30 -0000      1.13
  @@ -275,4 +275,28 @@
          </xs:sequence>
        </xs:complexType>
      </xs:element>
  +
  +    <xs:element name="html">
  +      <xs:complexType mixed="true">
  +        <xs:sequence>
  +          <xs:element name="dummy" type="xs:string"/>
  +          <xs:element name="head">
  +            <xs:complexType>
  +              <xs:sequence>
  +                <xs:element name="title" type="xs:string"/>
  +              </xs:sequence>
  +            </xs:complexType>
  +          </xs:element>
  +          <xs:element name="body">
  +            <xs:complexType>
  +              <xs:sequence>
  +                         <xs:element name="p" maxOccurs="unbounded">
  +                  <xs:complexType/>
  +                </xs:element>
  +              </xs:sequence>
  +            </xs:complexType>
  +          </xs:element>
  +        </xs:sequence>
  +      </xs:complexType>
  +    </xs:element>
   </xs:schema>
  
  
  
  1.65      +5 -0      ws-jaxme/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/status.xml,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- status.xml        19 Jul 2005 21:01:59 -0000      1.64
  +++ status.xml        20 Jul 2005 20:48:30 -0000      1.65
  @@ -44,6 +44,11 @@
                A sequence was always treated as a required group,
                even if all particles were optional.
         </action>
  +      <action dev="JW" type="fix" content="generator">
  +        Added a unit test for mixed content handling. Fixed
  +        the handling of complex child elements in mixed
  +        content types.
  +      </action>
        </release>
        <release version="0.5beta" date="2005-Jul-13">
          <action dev="JW" type="enhancement" context="generator">
  
  
  
  1.24      +24 -4     
ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/MarshallerTest.java
  
  Index: MarshallerTest.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/MarshallerTest.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- MarshallerTest.java       30 Jun 2005 08:16:14 -0000      1.23
  +++ MarshallerTest.java       20 Jul 2005 20:48:30 -0000      1.24
  @@ -33,7 +33,6 @@
   import javax.xml.bind.Marshaller;
   import javax.xml.bind.UnmarshalException;
   import javax.xml.bind.Unmarshaller;
  -import javax.xml.bind.ValidationException;
   import javax.xml.namespace.QName;
   import javax.xml.parsers.ParserConfigurationException;
   import javax.xml.parsers.SAXParser;
  @@ -51,6 +50,7 @@
   import org.apache.ws.jaxme.test.misc.types.AllSimpleTypes;
   import org.apache.ws.jaxme.test.misc.types.AllTypesElement;
   import org.apache.ws.jaxme.test.misc.types.Author;
  +import org.apache.ws.jaxme.test.misc.types.Html;
   import org.apache.ws.jaxme.test.misc.types.ObjectFactory;
   import org.apache.ws.jaxme.test.misc.types.impl.AllElementImpl;
   import org.apache.ws.jaxme.test.misc.types.impl.AllSimpleTypesImpl;
  @@ -64,8 +64,6 @@
   import org.xml.sax.XMLReader;
   import org.xml.sax.helpers.DefaultHandler;
   
  -import sun.security.validator.ValidatorException;
  -
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]">Jochen Wiedmann</a>
  @@ -619,4 +617,26 @@
                        fail("Unexpected throwable " + t);
                }
        }
  +
  +     /** Tests marshalling and unmarshalling of a mixed content element.
  +      */
  +     public void testMixedContent() throws Exception {
  +             final String html =
  +                     "<ex:html 
xmlns:ex=\"http://ws.apache.org/jaxme/test/misc/types\";>\n" +
  +                     "  xyz<ex:dummy>012</ex:dummy>\n" +
  +                     "  <ex:head><ex:title>foo bar</ex:title></ex:head>\n" +
  +                     "  <ex:body><ex:p/></ex:body>\n" +
  +                     "</ex:html>";
  +             InputSource isource = new InputSource(new StringReader(html));
  +             isource.setSystemId("mixedContent.xml");
  +             JAXBContext ctx = getJAXBContext(Html.class);
  +             Html htmlElem = (Html) 
ctx.createUnmarshaller().unmarshal(isource);
  +             StringWriter sw = new StringWriter();
  +             Marshaller m = ctx.createMarshaller();
  +             m.setProperty(JMMarshallerImpl.JAXME_XML_DECLARATION, 
Boolean.FALSE);
  +             m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
  +             m.marshal(htmlElem, sw);
  +             String got = sw.toString();
  +             assertEquals(html, got);
  +     }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to