users@jaxb.java.net

Re: Can I apply bindings to included schemas?

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Thu, 28 Jun 2012 09:02:25 +0200

Sorry Peter,

I'm not sure where and when xjc accepts elements provided for plugins.
I tried to look at the annox site confluence.highsource.org, but it
says 502, maybe later.

The documentation describing "global scope" is in the JAXB
Specification, Section 7.4 Customization Overview, Subsection 7.4.1
Scope:

  global scope: A customization value defined in <globalBindings>
  has global scope. A global scope covers all the schema elements in the
  source schema and (recursively) any schemas that are included or
  imported by the source schema.

Regards
Wolfgang


On 27/06/2012, Peter <peter.follo+javadev_at_foi.se> wrote:
> Thanks for the tip Wolfgang! I've tried several variants in vail, this
> is one of them:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns="http://www.citygml.org/citygml/profiles/base/1.0"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
> xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:annox="http://annox.dev.java.net"
> xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb
> http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
> jaxb:extensionBindingPrefixes="xjc annox"
> jaxb:version="2.1"
> elementFormDefault="qualified"
> attributeFormDefault="unqualified"
> targetNamespace="http://www.citygml.org/citygml/profiles/base/1.0">
> <xs:include
> schemaLocation="http://schemas.opengis.net/citygml/profiles/base/1.0/CityGML.xsd"/>
> <xs:annotation>
> <xs:appinfo>
> <jaxb:globalBindings>
> <annox:annotate>
> <annox:annotate annox:class="java.lang.SuppressWarnings"
> value="unused"/>
> </annox:annotate>
> </jaxb:globalBindings>
> </xs:appinfo>
> </xs:annotation>
> </xs:schema>
>
> The output running xjc often looks somethning like this:
> [ERROR] cvc-complex-type.2.4.a: Invalid content was found starting with
> element 'annox:annotate'. One of
> '{"http://java.sun.com/xml/ns/jaxb":javaType,
> "http://java.sun.com/xml/ns/jaxb":serializable,
> "http://java.sun.com/xml/ns/jaxb/xjc":serializable,
> "http://java.sun.com/xml/ns/jaxb/xjc":superClass,
> "http://java.sun.com/xml/ns/jaxb/xjc":superInterface,
> "http://java.sun.com/xml/ns/jaxb/xjc":typeSubstitution,
> "http://java.sun.com/xml/ns/jaxb/xjc":smartWildcardDefaultBinding,
> "http://java.sun.com/xml/ns/jaxb/xjc":simple,
> "http://java.sun.com/xml/ns/jaxb/xjc":treatRestrictionLikeNewType,
> "http://java.sun.com/xml/ns/jaxb/xjc":javaType,
> "http://java.sun.com/xml/ns/jaxb/xjc":generateElementProperty,
> "http://java.sun.com/xml/ns/jaxb/xjc":noMarshaller,
> "http://java.sun.com/xml/ns/jaxb/xjc":noUnmarshaller,
> "http://java.sun.com/xml/ns/jaxb/xjc":noValidator,
> "http://java.sun.com/xml/ns/jaxb/xjc":noValidatingUnmarshaller}' is
> expected.
> line 18 of file:/home/follo/CityGML-jaxb/myCityGML-schema.xsd
>
> Which makes sense I guess.
>
> I have also tried using component designators. This went without errors
> but also without wanted annotations. :-P
>
>
> PS
> I didn't find any doc about globalBindings being recursive in inline
> declarations. Maybe I'm missing some essential piece of documentation,
> can you point me to where you found it? I did find doc about
> restrictions in external bindings that may imply that it is not
> recursive in that case though.
> DS
>
>
> On 06/27/2012 01:57 PM, Wolfgang Laun wrote:
>> The inline binding element<globalBindings> is documented as acting
>> recursively into included and imported schemas.
>>
>> If you don't want to modify your top level XML schema, write another
>> one<include>ing that one.
>>
>> Untried.
>> -W
>>
>> On 27/06/2012, peter.follo+javadev_at_foi.se<peter.follo+javadev_at_foi.se>
>> wrote:
>>> If one wants to annotate every 'complexType' in the generated code with
>>> say a 'SuppressWarnings' annotation one could use a binding file
>>> looking something like this:
>>>
>>> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
>>> <jaxb:bindings
>>> 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"
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xmlns:annox="http://annox.dev.java.net"
>>> xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb
>>> http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
>>> jaxb:extensionBindingPrefixes="xjc annox"
>>> version="2.1">
>>>
>>> <jaxb:bindings
>>> schemaLocation="http://schemas.opengis.net/gml/3.1.1/base/gmlBase.xsd"
>>> node="/xs:schema">
>>> <jaxb:bindings node="xs:complexType" multiple="true"
>>> required="false">
>>> <annox:annotate>
>>> <annox:annotate annox:class="java.lang.SuppressWarnings"
>>> value="unused"/>
>>> </annox:annotate>
>>> </jaxb:bindings>
>>> </jaxb:bindings>
>>>
>>> </jaxb:bindings>
>>>
>>> And it works all fine :-)
>>>
>>> However, if the schema imports other schemas, such as
>>> http://schemas.opengis.net/citygml/profiles/base/1.0/CityGML.xsd do,
>>> this binding rule won't traverse recursively to the imported schemas.
>>> Is there a way to make this rule traverse imported schemas? Can I use
>>> some sort of global binding instead? Can I use some kind of wildcard as
>>> a value to schemaLocation? Ideas anyone?
>>>
>