I'm trying to make some (contract first) java libraries with XSD's I cannot change.
So, suppose there are 2 XSD Maven projects:
1) Project A that defines an AttributeGroup, with an attribute entry (enum) set to a fixed value
2) Project B that uses the AttributeGroup
Project B uses project A as episode. Now, project A creates an episode when compiled. This episode maps the enum type to a typeSafeEnum.
The result of the compilation of B is that the binding 'fixedAttributeAsConstantProperty' is ignored. I would have expected:
@XmlAttribute(name = "type", namespace = "http://test.org/attrib")
public final static TypeType TYPE = TypeType.SIMPLE;
Instead I got:
@XmlAttribute(name = "type", namespace = "http://test.org/attrib")
protected TypeType type;
If A and B are build in one compilation unit it works.
I've reduced the problem to the generated episode binding in project A:
<bindings scd="x-schema::tns" xmlns:tns="http://test.org/attrib">
<schemaBindings map="false">
<package name="org.test.attrib"/>
</schemaBindings>
<bindings scd="~tns:typeType">
<typesafeEnumClass ref="org.test.attrib.TypeType"/>
</bindings>
</bindings>
</bindings>
My assumption: at the moment the XJC compiler sees a mapping to a typeSafeEnumClass it does not seem to build an internal representation of the enum type. Therefore it does not 'know' how to set the fixed value of TypeType in project B to constant. I've tried to use a binding . That generates a string mapping i.s.o an enum. In that case project B does set the 'fixed' value to a (string) constant. However, it creates other problems down the line.
Anyone know how to solve this? Am I looking at an XJC bug?
To be complete here is the source code of the example projects:
1) Project A that defines an AttributeGroup with in the group a fixed Attribute.
<xs:attribute name="type" type="attrib:typeType"/>
<xs:simpleType name="typeType">
<xs:restriction base="xs:token">
<xs:enumeration value="simple"/>
<xs:enumeration value="extended"/>
</xs:restriction>
</xs:simpleType>
<xs:attributeGroup name="attribGrp">
<xs:attribute ref="attrib:type" fixed="simple"/>
</xs:attributeGroup>
binding.xjb:
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc">
<jaxb:globalBindings fixedAttributeAsConstantProperty="true"/>
</jaxb:bindings>
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>attrib</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaIncludes>
<include>attrib.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>binding.xjb</include>
</bindingIncludes>
<target>2.1</target>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
</project>
2) And a Project B that uses this AttributeGroup
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test.org/attribUser"
xmlns:attrib="http://test.org/attrib"
xmlns:attribUser="http://test.org/attribUser">
<xs:import namespace="http://test.org/attrib" schemaLocation="http://test.org/attrib/attrib.xsd"/>
<xs:complexType name="userOfTst">
<xs:sequence>
<xs:element name="dontCare" type="xs:string"/>
</xs:sequence>
<xs:attributeGroup ref="attrib:attribGrp"/>
</xs:complexType>
</xs:schema>
binding.xjb:
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc">
<jaxb:globalBindings fixedAttributeAsConstantProperty="true"/>
</jaxb:bindings>
catalog.xml:
<?xml version="1.0" encoding="windows-1252"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<group>
<systemSuffix systemIdSuffix="http://test.org/attrib/attrib.xsd" uri="maven:test:attrib!/attrib.xsd"/>
</group>
</catalog>
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>attribUser</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>attrib</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaIncludes>
<include>attribUser.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>binding.xjb</include>
</bindingIncludes>
<catalog>${project.build.resources[0].directory}/catalog.xml</catalog>
<target>2.1</target>
<verbose>true</verbose>
<useDependenciesAsEpisodes>true</useDependenciesAsEpisodes>
</configuration>
</plugin>
</plugins>
</build>
</project>