Generating one java class for subnodes with the same structure

View: New views
2 Messages — Rating Filter:   Alert me  

Generating one java class for subnodes with the same structure

by yauhen p :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi.

I m novice on JAXB and I ve faced with next problem. I generate java classes from schema. Used jaxb transformation as follows:

<jaxb:bindings node="xsd:complexType[@name='Contract']/xsd:complexContent/xsd:extension/xsd:sequence/xsd:element[@name='Terms']/xsd:simpleType">
                        <jaxb:typesafeEnumClass name ="Terms"/>
    </jaxb:bindings>
<jaxb:bindings node="xsd:complexType[@name='Task']/xsd:complexContent/xsd:extension/xsd:sequence/xsd:element[@name='Terms']/xsd:simpleType">
                        <jaxb:typesafeEnumClass name ="Terms"/>
    </jaxb:bindings>

Contract and Task classes are generated and in each one inner class Terms is generated . I want to have just one inner class Terms in one of the classes. And in another this class Terms should be used. Is it possible to do with JAXB?

Thanks
Yauhen

Re: Generating one java class for subnodes with the same structure

by Wolfgang Laun-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Defining the same schema type twice is evil. If you can change the schema, create a named
simple type and use it in both elements. No customization will be required any more.

If you can't do that, then you could use a more complicated customization on the
second element:

  <jaxb:bindings node="xsd:complexType[@name='Task']/.../xsd:simpleType">
    <jaxb:javaType name ="generated.Contract.Terms"
                   parseMethod="util.Helper.parseStr2Terms"
                   printMethod="util.Helper.printTerms2Str"/>
  </jaxb:bindings>

and implement util.Helper:

package util;

import generated.Contract.Terms;

public class Helper {

    public static Terms parseStr2Terms( String value ){
        return Enum.valueOf(Terms.class, value );
    }
    public static String printTerms2Str( Terms value ){
    return value.toString();
    }
}

And, if possible, tell the schema author(s) to change their ways ;-)

-W


On Tue, Oct 6, 2009 at 12:33 PM, yauhen p <yauhen_p@...> wrote:

Hi.

I m novice on JAXB and I ve faced with next problem. I generate java classes
from schema. Used jaxb transformation as follows:

<jaxb:bindings
node="xsd:complexType[@name='Contract']/xsd:complexContent/xsd:extension/xsd:sequence/xsd:element[@name='Terms']/xsd:simpleType">
                       <jaxb:typesafeEnumClass name ="Terms"/>
       </jaxb:bindings>
<jaxb:bindings
node="xsd:complexType[@name='Task']/xsd:complexContent/xsd:extension/xsd:sequence/xsd:element[@name='Terms']/xsd:simpleType">
                       <jaxb:typesafeEnumClass name ="Terms"/>
       </jaxb:bindings>

Contract and Task classes are generated and in each one inner class Terms is
generated . I want to have just one inner class Terms in one of the classes.
And in another this class Terms should be used. Is it possible to do with
JAXB?

Thanks
Yauhen
--
View this message in context: http://www.nabble.com/Generating-one-java-class-for-subnodes-with-the-same-structure-tp25766355p25766355.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...