users@jaxb.java.net

Re: Nested anonymous complex types

From: Giuseppe Serra <beppe_serra_at_mail.com>
Date: Mon, 25 Aug 2003 10:08:36 -0500

I'm using JAXB with a number of xsd schemas (which are not under my
control, hence I'd like not have to modify them) where extensive
usage of anonymous complex types is made.
Like someone else here in this forum, I came across Windows' 256 characters
maximum length limit, thus I tried to customize my bindings to have
shorter names for Java classes and interfaces.
My problem is that as soon as I customize the anonymous complex type
binding for a given schema element (say anElement), both the
element type interface (anElementType) and the element type implementation
(anElementTypeImpl) are not generated in separate
.java files.
Instead, they are generated as sub-inteface and sub-class for the element
interface (anElement) and element implementation
(anElementImpl), respectively.
For example:

(excerpt from anElement.java)

package com.foo.valueobjs.MyStuff;

public interface anElement
    extends javax.xml.bind.Element,
    com.foo.valueobjs.MyStuff.anElement.anElementType // (1)
{
...
    public interface anElementType {
...
    }
}

(excerpt from anElementImpl.java)

package com.foo.valueobjs.MyStuff.impl;

public class anElementImpl
    extends com.foo.valueobjs.MyStuff.impl.anElementImpl.anElementTypeImpl
 // (2)
    implements com.foo.valueobjs.MyStuff.anElement,
    com.sun.xml.bind.RIElement, java.io.Serializable,
    com.sun.xml.bind.unmarshaller.UnmarshallableObject,
    com.sun.xml.bind.serializer.XMLSerializable,
    com.sun.xml.bind.validator.ValidatableObject
{
...
    public static class anElementTypeImpl
    implements com.foo.valueobjs.MyStuff.anElement.anElementType,

    java.io.Serializable,
com.sun.xml.bind.unmarshaller.UnmarshallableObject,
    com.sun.xml.bind.serializer.XMLSerializable,
com.sun.xml.bind.validator.ValidatableObject
    {
    ...
    }
}

Lines (1) and (2) result in compilation errors ("cannot extend/implement
itself or one of its own member types").

Am I doing anything wrong ?
Following is all you need to reproduce the problem.

a) Command line
---------------

xjc -b MyStuff.xjb -d C:\Temp -p com.foo.valueobjs.MyStuff MyStuff.xsd


b) MyStuff.xsd
--------------

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xs:element name="My2Numbers">
   <xs:complexType>
    <xs:sequence>
     <xs:element name="firstNumber">
      <xs:simpleType>
       <xs:restriction
base="xs:decimal">
       </xs:restriction>
      </xs:simpleType>
     </xs:element>
     <xs:element name="secondNumber">
      <xs:simpleType>
       <xs:restriction
base="xs:decimal"/>
      </xs:simpleType>
     </xs:element>
    </xs:sequence>
   </xs:complexType>
 </xs:element>
 <xs:element name="My2Names">
   <xs:complexType>
    <xs:sequence>
     <xs:element name="firstName">
      <xs:simpleType>
       <xs:restriction
base="xs:string">
       </xs:restriction>
      </xs:simpleType>
     </xs:element>
     <xs:element name="secondName">
      <xs:simpleType>
       <xs:restriction
base="xs:string"/>
      </xs:simpleType>
     </xs:element>
    </xs:sequence>
   </xs:complexType>
 </xs:element>
</xs:schema>


c) MyStuff.xjb
--------------

<jxb:bindings version="1.0"
               xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <jxb:bindings schemaLocation="MyStuff.xsd" node="/xs:schema">

    <jxb:bindings node="//xs:element[@name='My2Numbers']">
      <jxb:class name="Num"/>
      <jxb:property name="Num"/>
    </jxb:bindings>

    <jxb:bindings node="//xs:element[@name='My2Numbers']/xs:complexType">
      <jxb:class name="NumType"/>
      <jxb:property name="NumType"/>
    </jxb:bindings>

    <jxb:bindings node="//xs:element[@name='My2Names']">
      <jxb:class name="Name"/>
      <jxb:property name="Name"/>
    </jxb:bindings>

    <jxb:bindings node="//xs:element[@name='My2Names']/xs:complexType">
      <jxb:class name="NameType"/>
      <jxb:property name="NameType"/>
    </jxb:bindings>
  </jxb:bindings>

</jxb:bindings>


-- 
__________________________________________________________
Sign-up for your own personalized E-mail at Mail.com
http://www.mail.com/?sr=signup
CareerBuilder.com has over 400,000 jobs. Be smarter about your job search
http://corp.mail.com/careers
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net