users@jaxb.java.net

Re: complexType extend an external Java class

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Sun, 4 Oct 2009 09:17:00 +0200

Hi Eric,

there are two ways to achieve what you want.

(1) Modify your xjc compilation process to run twice, once without the
vendor specific customization, and once, in some other working directory,
with the <xjc:superClass>. (Putting the customization into a separate
bindings file will make this a matter of using and not using xjc's -b
option).
Then, simply copy the class with the suitable "extends" onto the sibling
one.
Of course, if you have several such classes, it's going to be a mess.

(2) Check how far it is possible to obtain the base class com.test.Template
via xjc compilation and define a complex schema type accordingly, and
use the extension mechanism of XML Schema to define template-transportable
as a subclass of Template. For missing methods and stuff you can use a
(standard)
plugin for xjc, to inject arbitrary Java code into a class body:
   xjc -extension -Xinject-code ...
which lets you add arbitrary code to any class:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
            xmlns:ci="http://jaxb.dev.java.net/plugin/code-injector"

            jxb:extensionBindingPrefixes="ci"
            jxb:version="2.0">

<xsd:complexType name="...">
  <xsd:annotation><xsd:appinfo><ci:code><![CDATA[
    public int hashCode()...
]]></ci:code></xsd:appinfo></xsd:annotation>

-W

On Wed, Sep 30, 2009 at 8:30 PM, Eric C. <coureux.eric_at_free.fr> wrote:

>
> I would share my problem :
>
> In my schema file I declare this :
>
>
> ----------------------------------------------------------------------------------
> <xsd:schema ...
> ...
> <xsd:complexType name="template-transportable">
> <xsd:sequence>
> <xsd:element name="title" type="xsd:string" />
> <xsd:element name="content" type="xsd:base64Binary"
> xmime:expectedContentTypes="application/octet-stream" />
> </xsd:sequence>
> </xsd:complexType>
> ...
> </xsd:schema>
>
> ----------------------------------------------------------------------------------
>
> When I generate the class TemplateTransportable.java all is ok; but now I
> would like this last one inherits from an existing java class (which is not
> generated by Jaxb).
> For exemple I have a class com.test.Template somewhere, and I would like my
> generated class TemplateTransportable extends com.test.Template.
>
> I have seen when can declare something
>
> ----------------------------------------------------------------------------------
> <xsd:schema ...
> ...
> <xsd:annotation>
> <xsd:appinfo>
> <jaxb:globalBindings>
> <xjc:superClass name="com.test.Template"/>
> </jaxb:globalBindings>
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:schema>
>
> ----------------------------------------------------------------------------------
> But it's not good because all my compexType in the schema file will inherit
> from this com.test.Template, it's not my goal, I would to apply on only one
> of my complexType nodes.
>
> Anyone has any idea to resolve my problem ?
>
> Thanks a lot everybody
>
> --
> View this message in context:
> http://www.nabble.com/complexType-extend-an-external-Java-class-tp25686486p25686486.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
>
>