Fwd: Trick sur les interférences wsimport/wsgen et JAXB

Sylvain RICHET <[email protected]> Tue, 27 Sep 2011 16:03:20 +0200
Newsgroups gmane.comp.java.french.general
Message-ID <CAGn21GJikEjk+pbfK79L-tguQ-pyOr9iEvLGFRGvgbsYaSjrww@mail.gmail.com>
--bcaec520eea7f62ea904adecbc74
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Quand je dis* WSIMPORT/WSGEN*, ... en fait il s'agit surtout de
*WSIMPORT*(une task ANT fournit dans le fichierjaxws-tools.jarde la
library JAX-WS)

;-)

---------- Message transf=E9r=E9 ----------
De : Sylvain RICHET <[email protected]>
Date : 27 septembre 2011 14:45
Objet : Trick sur les interf=E9rences wsimport/wsgen et JAXB
=C0 : JAVA_ML_USTRASBG <[email protected]>


Bonjour =E0 Tous,

J'ai un WebService, avec une WSDL qui ne doit plus varier dans sa version
actuelle.
("ne doit plus varier" ? =3D=3D> les signatures de m=E9thodes de ma SEI)

Or je viens de prendre conscience que sur une List d'une de mes classes, il
fallait que j'ajoute une annotation *@XmlElementWrapper* pour satisfaire un
mapping XML =3D=3D> JAVA via JAXB.

# Voici la classe annot=E9e JAXB :

@XmlRootElement
public class DbiLayoutItem {

    @XmlElement(required =3D true)
    protected String label;

    @XmlElementWrapper(name=3D"items")        <=3D=3D ma personnalisation
    @XmlElement(name=3D"dbiLayoutItem")       <=3D=3D "  "
    //@XmlElement(name=3D"items")             <=3D=3D version initiale
    protected List<DbiLayoutItem> items;

    [...]
}

*# WSIMPORT/WSGEN, qui s'appuie sur JAXB, est sensible aux annotations JAXB=
.
*
   Du coup, lors de la g=E9n=E9ration des classes clientes via ces tools, u=
ne
nouvelle inner class "Items" apparait, dans la classe cliente/proxy
"DbiLayoutItem" :

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name =3D "dbiLayoutItem", namespace =3D
"urn:NETIA:schema:SEARCH_LAYOUT", propOrder =3D {
    "label",
    "items",
    [...]
})
public class DbiLayoutItem {

    @XmlElement(required =3D true)
    protected String label;

    protected DbiLayoutItem.Items items;            <=3D=3D !
    [...]


    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name =3D "", propOrder =3D {
        "dbiLayoutItem"
    })
    public static class Items {

        protected List<DbiLayoutItem> dbiLayoutItem;
        [...]
    }
}

*# Ze probl=E8me :*
*=E7a vient p=E9ter mon contrat de WSDL, par rapport =E0 ce qu'il y avait
auparavant sans l'annotation @XmlElementWrapper.*

# D'o=F9 ma question :
*comment faire pour =E9viter la g=E9n=E9ration de cette inner class suppl=
=E9mentaire
?*

En effet, je voudrais que WSIMPORT/WSGEN me garde la d=E9finition initiale =
de
la liste dans ma classe cliente "DbiLayoutItem" :
public class DbiLayoutItem {

    @XmlElement(required =3D true)
    protected String label;

    protected List<DbiLayoutItem> items;            <=3D=3D pas d'inner cla=
ss
    [...]
}


D=E8s =E0 pr=E9sent, je vais fouiller un peu du c=F4t=E9 de la "customisati=
on JAXB"...
mais =E7a n'est pas dit du tout que cela soit possible.

Si l'un d'entre Vous est interpell=E9 (ou a une id=E9e, ou a =E9t=E9 confro=
nt=E9 =E0 une
probl=E8matique similaire)
merci d'avance

--bcaec520eea7f62ea904adecbc74
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Quand je dis<i> WSIMPORT/WSGEN</i>, ... en fait il s&#39;agit surtout de <b=
>WSIMPORT</b> (une task ANT fournit dans le fichier<span style=3D"font-fami=
ly: courier new,monospace;"> jaxws-tools.jar</span> de la library JAX-WS)<b=
r>
<br>;-)<br><br><div class=3D"gmail_quote">---------- Message transf=E9r=E9 =
----------<br>De=A0: <b class=3D"gmail_sendername">Sylvain RICHET</b> <span=
 dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]">akamanouche@gmail=
.com</a>&gt;</span><br>
Date=A0: 27 septembre 2011 14:45<br>Objet=A0: Trick sur les interf=E9rences=
 wsimport/wsgen et JAXB<br>=C0=A0: JAVA_ML_USTRASBG &lt;<a href=3D"mailto:j=
[email protected]">[email protected]</a>&gt;<br><br><br><span style=3D"font-=
family:tahoma,sans-serif">Bonjour =E0 Tous,</span><br style=3D"font-family:=
tahoma,sans-serif">
<br style=3D"font-family:tahoma,sans-serif"><span style=3D"font-family:taho=
ma,sans-serif">J&#39;ai un WebService, avec une WSDL qui ne doit plus varie=
r dans sa version actuelle.</span><br style=3D"font-family:tahoma,sans-seri=
f">

<span style=3D"font-family:tahoma,sans-serif">(&quot;ne doit plus varier&qu=
ot; ? =3D=3D&gt; les signatures de m=E9thodes de ma SEI)</span><br style=3D=
"font-family:tahoma,sans-serif"><br style=3D"font-family:tahoma,sans-serif"=
><span style=3D"font-family:tahoma,sans-serif">Or je viens de prendre consc=
ience que sur une List d&#39;une de mes classes, il fallait que j&#39;ajout=
e une annotation <b>@XmlElementWrapper</b> pour satisfaire un mapping XML =
=3D=3D&gt; JAVA via JAXB.</span><br>

<br># Voici la classe annot=E9e JAXB :<br style=3D"font-family:tahoma,sans-=
serif"><br><span style=3D"font-family:courier new,monospace">@XmlRootElemen=
t</span><br style=3D"font-family:courier new,monospace"><span style=3D"font=
-family:courier new,monospace">public class DbiLayoutItem {</span><br style=
=3D"font-family:courier new,monospace">

<br style=3D"font-family:courier new,monospace"><span style=3D"font-family:=
courier new,monospace">=A0=A0=A0 @XmlElement(required =3D true)</span><br s=
tyle=3D"font-family:courier new,monospace"><span style=3D"font-family:couri=
er new,monospace">=A0=A0=A0 protected String label;</span><br style=3D"font=
-family:courier new,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0 =A0</span><br styl=
e=3D"font-family:courier new,monospace"><span style=3D"font-family:courier =
new,monospace">=A0=A0 =A0@XmlElementWrapper(name=3D&quot;items&quot;)=A0=A0=
=A0=A0=A0=A0=A0 &lt;=3D=3D ma personnalisation</span><br style=3D"font-fami=
ly:courier new,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0 =A0@XmlElement(nam=
e=3D&quot;dbiLayoutItem&quot;)=A0=A0=A0=A0=A0=A0 &lt;=3D=3D &quot;=A0 &quot=
;</span><br style=3D"font-family:courier new,monospace"><span style=3D"font=
-family:courier new,monospace">=A0=A0 =A0//@XmlElement(name=3D&quot;items&q=
uot;)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 &lt;=3D=3D version initiale</span=
><br style=3D"font-family:courier new,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0=A0 protected List&=
lt;DbiLayoutItem&gt; items;</span><br style=3D"font-family:courier new,mono=
space"><span style=3D"font-family:courier new,monospace">=A0=A0 =A0</span><=
br style=3D"font-family:courier new,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0 =A0[...]</span><br=
 style=3D"font-family:courier new,monospace"><span style=3D"font-family:cou=
rier new,monospace">}</span><br><br><b># WSIMPORT/WSGEN, qui s&#39;appuie s=
ur JAXB, est sensible aux annotations JAXB.</b><br>

=A0=A0 Du coup, lors de la g=E9n=E9ration des classes clientes via ces tool=
s, une nouvelle inner class &quot;Items&quot; apparait, dans la classe clie=
nte/proxy &quot;DbiLayoutItem&quot; :<br><br><span style=3D"font-family:cou=
rier new,monospace">@XmlAccessorType(XmlAccessType.FIELD)</span><br style=
=3D"font-family:courier new,monospace">

<span style=3D"font-family:courier new,monospace">@XmlType(name =3D &quot;d=
biLayoutItem&quot;, namespace =3D &quot;urn:NETIA:schema:SEARCH_LAYOUT&quot=
;, propOrder =3D {</span><br style=3D"font-family:courier new,monospace"><s=
pan style=3D"font-family:courier new,monospace">=A0=A0=A0 &quot;label&quot;=
,</span><br style=3D"font-family:courier new,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0=A0 &quot;items&quo=
t;,</span><br style=3D"font-family:courier new,monospace"><span style=3D"fo=
nt-family:courier new,monospace">=A0=A0=A0 [...]</span><br style=3D"font-fa=
mily:courier new,monospace">

<span style=3D"font-family:courier new,monospace">})</span><br style=3D"fon=
t-family:courier new,monospace"><span style=3D"font-family:courier new,mono=
space">public class DbiLayoutItem {</span><br style=3D"font-family:courier =
new,monospace">

<br style=3D"font-family:courier new,monospace"><span style=3D"font-family:=
courier new,monospace">=A0=A0=A0 @XmlElement(required =3D true)</span><br s=
tyle=3D"font-family:courier new,monospace"><span style=3D"font-family:couri=
er new,monospace">=A0=A0=A0 protected String label;</span><br style=3D"font=
-family:courier new,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0=A0 </span><br styl=
e=3D"font-family:courier new,monospace"><span style=3D"font-family:courier =
new,monospace">=A0=A0=A0 protected DbiLayoutItem.Items items;=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0 &lt;=3D=3D !</span><br style=3D"font-family:courier n=
ew,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0=A0 [...]</span><br=
 style=3D"font-family:courier new,monospace"><br style=3D"font-family:couri=
er new,monospace"><span style=3D"font-family:courier new,monospace">=A0=A0=
=A0 </span><br style=3D"font-family:courier new,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0=A0 @XmlAccessorTyp=
e(XmlAccessType.FIELD)</span><br style=3D"font-family:courier new,monospace=
"><span style=3D"font-family:courier new,monospace">=A0=A0=A0 @XmlType(name=
 =3D &quot;&quot;, propOrder =3D {</span><br style=3D"font-family:courier n=
ew,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0=A0=A0=A0=A0=A0 &qu=
ot;dbiLayoutItem&quot;</span><br style=3D"font-family:courier new,monospace=
"><span style=3D"font-family:courier new,monospace">=A0=A0=A0 })</span><br =
style=3D"font-family:courier new,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0=A0 public static c=
lass Items {</span><br style=3D"font-family:courier new,monospace"><br styl=
e=3D"font-family:courier new,monospace"><span style=3D"font-family:courier =
new,monospace">=A0=A0=A0=A0=A0=A0=A0 protected List&lt;DbiLayoutItem&gt; db=
iLayoutItem;</span><br style=3D"font-family:courier new,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0=A0 =A0=A0=A0 [...]=
</span><br style=3D"font-family:courier new,monospace"><span style=3D"font-=
family:courier new,monospace">=A0=A0=A0 }</span><br style=3D"font-family:co=
urier new,monospace">

<span style=3D"font-family:courier new,monospace">}</span><br><br><i><b># Z=
e probl=E8me :</b></i><br><i>=E7a vient p=E9ter mon contrat de WSDL, par ra=
pport =E0 ce qu&#39;il y avait auparavant sans l&#39;annotation @XmlElement=
Wrapper.</i><br>

=A0=A0=A0 <br># D&#39;o=F9 ma question :<br><i>comment faire pour =E9viter =
la g=E9n=E9ration de cette inner class suppl=E9mentaire ?</i><br><br>En eff=
et, je voudrais que WSIMPORT/WSGEN me garde la d=E9finition initiale de la =
liste dans ma classe cliente &quot;DbiLayoutItem&quot; :<br>

<span style=3D"font-family:courier new,monospace">public class DbiLayoutIte=
m {</span><br style=3D"font-family:courier new,monospace"><br style=3D"font=
-family:courier new,monospace"><span style=3D"font-family:courier new,monos=
pace">=A0=A0=A0 @XmlElement(required =3D true)</span><br style=3D"font-fami=
ly:courier new,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0=A0 protected Strin=
g label;</span><br style=3D"font-family:courier new,monospace"><span style=
=3D"font-family:courier new,monospace">=A0=A0=A0 </span><br style=3D"font-f=
amily:courier new,monospace">

<span style=3D"font-family:courier new,monospace">=A0=A0=A0 protected List&=
lt;DbiLayoutItem&gt; items;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 &lt;=3D=3D pas=
 d&#39;inner class</span><br style=3D"font-family:courier new,monospace"><s=
pan style=3D"font-family:courier new,monospace">=A0=A0=A0 [...]</span><br s=
tyle=3D"font-family:courier new,monospace">

<span style=3D"font-family:courier new,monospace">}</span><br><br><br>D=E8s=
 =E0 pr=E9sent, je vais fouiller un peu du c=F4t=E9 de la &quot;customisati=
on JAXB&quot;... mais =E7a n&#39;est pas dit du tout que cela soit possible=
.<br><br>

Si l&#39;un d&#39;entre Vous est interpell=E9 (ou a une id=E9e, ou a =E9t=
=E9 confront=E9 =E0 une probl=E8matique similaire)<br>merci d&#39;avance<br=
><br><br>
</div><br>

--bcaec520eea7f62ea904adecbc74--