users@jaxb.java.net

Re: Customization namespaces and "vendor extensions"

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Wed, 19 Jan 2005 17:52:32 +0100

Hi.

In HyperJAXB annotations could be used to customize mapping, i.e.
provide additional metadata for code augmentation. Currently I'm using
javadoc annotation + xdoclets for this purpose, but it is an ugly
solution, to be honest.

>> I'm currently interested in "triggering" some customized code generation
>> when an element is annotated. Consider, for example, the following
>> annotation:
>>
>> <xsd:element name="configFile" type="xsd:string">
>> <xsd:annotation>
>> <xsd:appinfo>
>> <myns:file>
>> <myns:validateExistence />
>> </myns:file>
>> </xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>>
>> The 'configFile' element should be a java.util.File element, which is
>> validated for existence when parsed. Again, I know this can be achieved
>> using the jaxb:javaType annotation, but this is just an example.
>
>
> Perhaps I wasn't clear.
>
> Suppose we parse this sample. We call your extension with <myns:file>
> and you give us back an object that represents the parsed annotation.
> Maybe an instance of the MYNSFile class.

I would suggest that annotations are parsed into DOM nodes, class
instantiation is a bit of overkill.

> Internally, we first attach it to XSOM's XSElementDecl. Then our
> compiler front-end runs, which creates a ClassItem for this element.
> Because extensions can only run after we've finished the basic code
> generation, we have to somehow attach your MYNSFile instance to one of
> the model objects the front-end creates. But exactly which model object
> we should attach your annotations isn't quite clear to me.
>
> For example, in your MYNSFile case, you'd almost want it on FieldItem,
> not on ClassItem. But how the JAXB RI, without knowing the semantics of
> your annotations, can determine whether it should put yours on a
> ClassItem or a FieldItem? If I more or less randomly pick which
> annotation goes to where, does that work for you?

jaxb:property and jaxb:class solve the same problem for JAXB, don't
they? The same approach could be used for custom annotations.

Bye.
/lexi



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net