users@jaxb.java.net

Re: Generating Java bindings in different packages

From: Jean_at_Eastcode <jean.eastcode_at_gmail.com>
Date: Tue, 26 Oct 2010 05:23:52 -0700 (PDT)

Hi Wolfgang,

very good piece of example, highly helpful for me.

I finally made it with my enums in a specific "model" package, and with one
invocation of XJC only.
Somehow, I get two ObjectFactory.java generated, one per package/namespace.
But the one for the "model" is just empty. Isn't there a way to generate one
only?

I've got a bigger problem though, hopefully easy to solve through some
configuration that I can't find:

I've got an Enum that has a value BETA2, containing a number. This triggers
the generation of a specific Java enum class, as follow:

public enum TrainingOrigin {

    EXTRANET("EXTRANET"),
    INTRANET("INTRANET"),
    @XmlEnumValue("BETA2")
    BETA_2("BETA2");
    private final String value;

    TrainingOrigin(String v) {
        value = v;
    }

    public String value() {
        return value;
    }

    public static TrainingOrigin fromValue(String v) {
        for (TrainingOrigin c: TrainingOrigin.values()) {
            if (c.value.equals(v)) {
                return c;
            }
        }
        throw new IllegalArgumentException(v);
    }
}

I need to keep the value as BETA2, and not BETA_2.

Would you happen to know how to control this in the generation?

cheers
-jean


Wolfgang Laun-2 wrote:
>
> You just put the simple type into another schema with another namespace.
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
> targetNamespace="model"
> version="2.0">
>
> <xs:simpleType name="psType">
> <xs:restriction base="xs:string">
> <xs:enumeration value="one"/>
> <xs:enumeration value="two"/>
> </xs:restriction>
> </xs:simpleType>
>
> </xs:schema>
>
> This is imported from the other schema:
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
> targetNamespace="package"
> xmlns:m="model"
> xmlns:p="package"
> version="2.0">
>
> <xs:import namespace="model" schemaLocation="enum.xsd"/>
>
> <xs:element name="doc" type="p:DocType"/>
>
> <xs:complexType name="DocType">
> <xs:sequence>
> <xs:element name="Topo" type="m:psType"/>
> <xs:element name="Count" type="xs:int" default="1" minOccurs="0"/>
> </xs:sequence>
> </xs:complexType>
>
> </xs:schema>
>
> -W
>
>
>
>
>
>
> On 26 October 2010 09:37, Jean_at_Eastcode <jean.eastcode_at_gmail.com> wrote:
>
>>
>> Actually, the Enum XJC generates are fine.
>> I just want to be able to specify their package, as I don't want it to be
>> the same as the other generated classes.
>>
>> Is this at all possible?
>>
>> -jean
>>
>>
>> Wolfgang Laun-2 wrote:
>> >
>> > xjc generates enum types from xs:string with restriction/enumeration.
>> It
>> > should, however, be possible to use an Adapter to map the Schema type
>> > to your model enum types.
>> > -W
>> >
>> > On 25 October 2010 12:20, Jean_at_Eastcode <jean.eastcode_at_gmail.com>
>> wrote:
>> >
>> >>
>> >> Hi,
>> >>
>> >> I'm using jaxb2-maven-plugin to get automatic generation of my Java
>> >> bindings
>> >> from XSDs.
>> >>
>> >> I'm introducing the use of Enums, hence I have to create simpleTypes
>> that
>> >> maps the Java Enum values.
>> >>
>> >> The XSD as well as the generated classes are all in a binding
>> "package"
>> >>
>> >> The enums are in a different package since they are not autogenerated,
>> >> called "model".
>> >>
>> >> I want the generated classes to use the original Java "model" enum,
>> but
>> >> jaxb
>> >> keep generating them into "binding".
>> >>
>> >> I've split all the simpleType corresponding to the Java enums in a
>> >> EnumTypes.xsd that I put in "model" but still, corresponding Java
>> enums
>> >> are
>> >> always created in "binding".
>> >>
>> >> Is there a way to generate EnumsTypes.xsd classes in "model", and to
>> have
>> >> classes generated into "binding" be linked to them?
>> >>
>> >> FYI, here's my plugin config:
>> >>
>> >> <plugin>
>> >> <groupId>org.codehaus.mojo</groupId>
>> >> <artifactId>jaxb2-maven-plugin</artifactId>
>> >> <version>1.3</version>
>> >> <executions>
>> >> <execution>
>> >> <id>binding</id>
>> >> <goals>
>> >> <goal>xjc</goal>
>> >> </goals>
>> >> <configuration>
>> >>
>> >>
>> >>
>> <schemaDirectory>src/main/resources/com//comp/project/app/common/binding</schemaDirectory>
>> >>
>> >> <packageName>com.comp.project.app.common.binding</packageName>
>> >>
>> >> <outputDirectory>src/main/generated</outputDirectory>
>> >> <clearOutputDir>false</clearOutputDir>
>> >> </configuration>
>> >> </execution>
>> >> <execution>
>> >> <id>model</id>
>> >> <goals>
>> >> <goal>xjc</goal>
>> >> </goals>
>> >> <configuration>
>> >>
>> >>
>> >>
>> <schemaDirectory>src/main/resources/com/comp/project/app/common/model</schemaDirectory>
>> >>
>> >> <packageName>com.comp.project.app.common.model</packageName>
>> >>
>> >> <outputDirectory>src/main/generated</outputDirectory>
>> >> <clearOutputDir>false</clearOutputDir>
>> >> </configuration>
>> >> </execution>
>> >> </executions>
>> >>
>> >> cheers
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://old.nabble.com/Generating-Java-bindings-in-different-packages-tp30046469p30046469.html
>> >> Sent from the java.net - jaxb users mailing list archive at
>> Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> >> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Generating-Java-bindings-in-different-packages-tp30046469p30054965.html
>> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>>
>>
>
>

-- 
View this message in context: http://old.nabble.com/Generating-Java-bindings-in-different-packages-tp30046469p30056982.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.