jochen      2005/07/04 16:59:19

  Modified:    src/test/jaxb Tag: v0_4 types.xsd
               src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg Tag:
                        v0_4 GroupBeanSG.java BeanSGImpl.java
               src/jaxme/org/apache/ws/jaxme/junit Tag: v0_4
                        NestedGroupTest.java
               src/jaxme/org/apache/ws/jaxme/generator/sg/impl Tag: v0_4
                        JAXBComplexTypeSG.java
  Log:
  Use of xs:extension is now mapped to proper Java inheritance (at least for 
the bean classes.)
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.10.2.2  +41 -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.10.2.1
  retrieving revision 1.10.2.2
  diff -u -r1.10.2.1 -r1.10.2.2
  --- types.xsd 28 Apr 2005 23:57:40 -0000      1.10.2.1
  +++ types.xsd 4 Jul 2005 23:59:19 -0000       1.10.2.2
  @@ -234,4 +234,45 @@
          </xs:sequence>
        </xs:complexType>
      </xs:element>
  +
  +   <xs:complexType name="FsNode">
  +     <xs:sequence>
  +       <xs:element ref="ex:acl" minOccurs="0"/>
  +     </xs:sequence>
  +     <xs:attribute name="id" type="xs:long" use="required"/>
  +     <xs:attribute name="name" type="xs:string" use="required"/>
  +     <xs:attribute name="parent" type="xs:long" use="required"/>
  +   </xs:complexType>
  +
  +   <xs:element name="FsFile" type="ex:FsNode"/>
  +
  +   <xs:element name="FsDirectory">
  +     <xs:complexType>
  +       <xs:complexContent>
  +         <xs:extension base="ex:FsNode">
  +           <xs:attribute name="hidden" type="xs:boolean" use="optional" 
default="false"/>
  +         </xs:extension>
  +       </xs:complexContent>
  +     </xs:complexType>
  +   </xs:element>
  +
  +   <xs:element name="acl">
  +     <xs:complexType>
  +       <xs:sequence>
  +         <xs:element name="rule" minOccurs="0" maxOccurs="unbounded">
  +           <xs:complexType>
  +             <xs:attribute name="principal" type="xs:string" use="required"/>
  +             <xs:attribute name="mode">
  +               <xs:simpleType>
  +                 <xs:restriction base="xs:string">
  +                   <xs:enumeration value="allow"/>
  +                   <xs:enumeration value="deny"/>
  +                 </xs:restriction>
  +               </xs:simpleType>
  +             </xs:attribute>
  +           </xs:complexType>
  +         </xs:element>
  +       </xs:sequence>
  +     </xs:complexType>
  +   </xs:element>
   </xs:schema>
  
  
  
  No                   revision
  No                   revision
  1.1.2.1   +28 -31    
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/Attic/GroupBeanSG.java
  
  Index: GroupBeanSG.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/Attic/GroupBeanSG.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- GroupBeanSG.java  14 Mar 2005 02:16:09 -0000      1.1
  +++ GroupBeanSG.java  4 Jul 2005 23:59:19 -0000       1.1.2.1
  @@ -36,47 +36,44 @@
                particles = group.getParticles();
        }
   
  -     private GroupBeanSG newBeanSG(GroupSG pGroup) throws SAXException {
  -             if (pGroup.isSequence()) {
  -                     return new SequenceBeanSG(ctSG, pGroup, null);
  -             } else if (pGroup.isChoice()) {
  -                     return new ChoiceBeanSG(ctSG, pGroup, null);
  -             } else if (pGroup.isAll()) {
  -                     return new AllBeanSG(ctSG, pGroup, null);
  -             } else {
  -                     throw new IllegalStateException("Invalid group type");
  +     private boolean isInheritedParticle(ParticleSG pParticle, ParticleSG[] 
pInheritedParticles) throws SAXException {
  +             if (pInheritedParticles != null) {
  +                     String p = pParticle.getPropertySG().getPropertyName();
  +                     for (int i = 0;  i < pInheritedParticles.length;  i++) {
  +                             if 
(pParticle.getPropertySG().getPropertyName().equals(p)) {
  +                                     return true;
  +                             }
  +                     }
                }
  +             return false;
        }
   
  -     private void generateSubclasses(JavaSource pJs) throws SAXException {
  -             for (int i = 0;  i < particles.length;  i++) {
  -                     ParticleSG particle = particles[i];
  -                     if (particle.isElement()) {
  +     public void generate() throws SAXException {
  +             super.generate();
  +             JavaSource js = getJavaSource();
  +             ParticleSG[] elementParticles = ccSG.getElementParticles();
  +             ParticleSG[] inheritedParticles = null;
  +             if (ctSG.getTypeSG().isExtension()) {
  +                     TypeSG extTSG = ctSG.getTypeSG().getExtendedType();
  +                     if (extTSG.isComplex()  &&  
!extTSG.getComplexTypeSG().hasSimpleContent()) {
  +                             inheritedParticles = 
extTSG.getComplexTypeSG().getComplexContentSG().getElementParticles();
  +                     }
  +             }
  +             for (int i = 0;  i < elementParticles.length;  i++) {
  +                     ParticleSG particle = elementParticles[i];
  +                     if (!isInheritedParticle(particle, inheritedParticles)) 
{
                                ObjectSG elementSG = particle.getObjectSG();
                                TypeSG typeSG = elementSG.getTypeSG();
                                if (!typeSG.isGlobalType()  &&  
!typeSG.isGlobalClass()  &&  typeSG.isComplex()) {
                                        ComplexTypeSG complexTypeSG = 
typeSG.getComplexTypeSG();
  -                                     if (pJs.isInterface()) {
  -                                             
complexTypeSG.getXMLInterface(pJs);
  +                                     if (js.isInterface()) {
  +                                             
complexTypeSG.getXMLInterface(js);
                                        } else {
  -                                             
complexTypeSG.getXMLImplementation(pJs);
  +                                             
complexTypeSG.getXMLImplementation(js);
                                        }
  -                     }
  -                     } else if (particle.isGroup()) {
  -                             GroupBeanSG beanSG = 
newBeanSG(particle.getGroupSG());
  -                             beanSG.generateSubclasses(pJs);
  -                     } else if (particle.isWildcard()) {
  -                             throw new IllegalStateException("TODO: Add 
support for wildcards");
  -                     } else {
  -                             throw new IllegalStateException("Unknown 
particle type: Neither of element, group, or wildcard");
  +                         }
  +                             particle.getPropertySG().generate(js);
                        }
                }
        }
  -
  -     public void generate() throws SAXException {
  -             super.generate();
  -             JavaSource js = getJavaSource();
  -             generateSubclasses(js);
  -             ctSG.getComplexContentSG().generateProperties(js);
  -     }
   }
  
  
  
  1.1.2.1   +24 -1     
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/Attic/BeanSGImpl.java
  
  Index: BeanSGImpl.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/Attic/BeanSGImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- BeanSGImpl.java   14 Mar 2005 02:16:09 -0000      1.1
  +++ BeanSGImpl.java   4 Jul 2005 23:59:19 -0000       1.1.2.1
  @@ -2,6 +2,7 @@
   
   import org.apache.ws.jaxme.generator.sg.AttributeSG;
   import org.apache.ws.jaxme.generator.sg.ComplexTypeSG;
  +import org.apache.ws.jaxme.generator.sg.TypeSG;
   import org.apache.ws.jaxme.js.JavaSource;
   import org.xml.sax.SAXException;
   
  @@ -22,11 +23,33 @@
         */
        public JavaSource getJavaSource() { return js; }
   
  +     private boolean isInheritedAttribute(AttributeSG pAttr, AttributeSG[] 
pInheritedAttributes) throws SAXException {
  +             if (pInheritedAttributes != null) {
  +                     String p = pAttr.getPropertySG().getPropertyName();
  +                     for (int i = 0;  i < pInheritedAttributes.length;  i++) 
{
  +                             if 
(pInheritedAttributes[i].getPropertySG().getPropertyName().equals(p)) {
  +                                     return true;
  +                             }
  +                     }
  +             }
  +             return false;
  +     }
  +
        public void generate() throws SAXException {
                JavaSource js = getJavaSource();
                AttributeSG[] myAttributes = ctSG.getAttributes();
  +             AttributeSG[] inheritedAttributes = null;
  +             if (ctSG.getTypeSG().isExtension()) {
  +                     TypeSG tSG = ctSG.getTypeSG().getExtendedType();
  +                     if (tSG.isComplex()) {
  +                             inheritedAttributes = 
tSG.getComplexTypeSG().getAttributes();
  +                     }
  +             }
                for (int i = 0;  i < myAttributes.length;  i++) {
  -                     myAttributes[i].getPropertySG().generate(js);
  +                     AttributeSG attr = myAttributes[i];
  +                     if (!isInheritedAttribute(attr, inheritedAttributes)) {
  +                             myAttributes[i].getPropertySG().generate(js);
  +                     }
                }
        }
   }
  
  
  
  No                   revision
  No                   revision
  1.4.2.2   +12 -1     
ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/NestedGroupTest.java
  
  Index: NestedGroupTest.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/NestedGroupTest.java,v
  retrieving revision 1.4.2.1
  retrieving revision 1.4.2.2
  diff -u -r1.4.2.1 -r1.4.2.2
  --- NestedGroupTest.java      18 Apr 2005 20:31:49 -0000      1.4.2.1
  +++ NestedGroupTest.java      4 Jul 2005 23:59:19 -0000       1.4.2.2
  @@ -18,7 +18,6 @@
   import java.io.StringReader;
   
   import javax.xml.bind.JAXBContext;
  -import javax.xml.bind.UnmarshalException;
   import javax.xml.bind.Unmarshaller;
   import javax.xml.bind.ValidationEvent;
   import javax.xml.bind.ValidationEventHandler;
  @@ -26,6 +25,10 @@
   import org.apache.ws.jaxme.ValidationEvents;
   import org.apache.ws.jaxme.impl.ValidationEventImpl;
   import org.apache.ws.jaxme.test.misc.group.impl.PersonsImpl;
  +import org.apache.ws.jaxme.test.misc.types.FsDirectory;
  +import org.apache.ws.jaxme.test.misc.types.FsDirectoryType;
  +import org.apache.ws.jaxme.test.misc.types.FsFile;
  +import org.apache.ws.jaxme.test.misc.types.FsNode;
   import org.apache.ws.jaxme.test.nestedgroups.MailTemplate;
   import org.apache.ws.jaxme.test.nestedgroups.impl.MailTemplateImpl;
   import org.xml.sax.InputSource;
  @@ -123,4 +126,12 @@
                }
                assertTrue(h.ok);
        }
  +
  +     /** Tests proper inheritance of xs:extension.
  +      */
  +     public void testInheritance() throws Exception {
  +             assertTrue(FsNode.class.isAssignableFrom(FsFile.class));
  +             assertTrue(FsNode.class.isAssignableFrom(FsDirectory.class));
  +             
assertTrue(FsNode.class.isAssignableFrom(FsDirectoryType.class));
  +     }
   }
  
  
  
  No                   revision
  No                   revision
  1.17.2.1  +15 -2     
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBComplexTypeSG.java
  
  Index: JAXBComplexTypeSG.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBComplexTypeSG.java,v
  retrieving revision 1.17
  retrieving revision 1.17.2.1
  diff -u -r1.17 -r1.17.2.1
  --- JAXBComplexTypeSG.java    14 Mar 2005 02:16:09 -0000      1.17
  +++ JAXBComplexTypeSG.java    4 Jul 2005 23:59:19 -0000       1.17.2.1
  @@ -89,7 +89,7 @@
                classContext = new GlobalContext(pTypeSG.getName(), pType, 
null, suffix, pTypeSG.getSchema());
                log.finest(mName, "<-", classContext);
        }
  -     
  +
        /** <p>Constructor for a local type, which is embedded into the 
enclosing
         * <code>pContext</code>.</p>
         */
  @@ -194,8 +194,21 @@
        private void createXMLBean(ComplexTypeSG pController, JavaSource pJs)
                        throws SAXException {
                BeanSG beanSG = newBeanSG(pController, pJs);
  -             if (!pJs.isInterface()) {
  +             if (pJs.isInterface()) {
  +                     if (pController.getTypeSG().isExtension()) {
  +                             TypeSG extType = 
pController.getTypeSG().getExtendedType();
  +                             if (extType.isComplex()) {
  +                                     
pJs.addExtends(extType.getComplexTypeSG().getClassContext().getXMLInterfaceName());
  +                             }
  +                     }
  +             } else {
                        
SerializableSG.makeSerializable(pController.getTypeSG().getSchema(), pJs);
  +                     if (pController.getTypeSG().isExtension()) {
  +                             TypeSG extType = 
pController.getTypeSG().getExtendedType();
  +                             if (extType.isComplex()) {
  +                                     
pJs.addExtends(extType.getComplexTypeSG().getClassContext().getXMLImplementationName());
  +                             }
  +                     }
                }
                beanSG.generate();
        }
  
  
  

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

Reply via email to