Trick sur les interférences wsimport/wsgen et JAXB

Sylvain RICHET <[email protected]> Tue, 27 Sep 2011 14:45:30 +0200
Newsgroups gmane.comp.java.french.general
Message-ID <CAGn21GK2UP8rCA=vmTHOM_5DMAv-zOG6W_e40wUD3O4jYWjtGg@mail.gmail.com>
--bcaec520eea79c54a604adeba630
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

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

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

<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: tahoma,sans-serif;">J&#39;ai un W=
ebService, avec une WSDL qui ne doit plus varier dans sa version actuelle.<=
/span><br style=3D"font-family: tahoma,sans-serif;">
<span style=3D"font-family: tahoma,sans-serif;">(&quot;ne doit plus varier&=
quot; ? =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 pren=
dre conscience que sur une List d&#39;une de mes classes, il fallait que j&=
#39;ajoute une annotation <b>@XmlElementWrapper</b> pour satisfaire un mapp=
ing 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;">@XmlRootEl=
ement</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-famil=
y: courier new,monospace;">=A0=A0=A0 @XmlElement(required =3D true)</span><=
br style=3D"font-family: courier new,monospace;"><span style=3D"font-family=
: courier 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 st=
yle=3D"font-family: courier new,monospace;"><span style=3D"font-family: cou=
rier 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"fon=
t-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0 =A0@XmlElement(n=
ame=3D&quot;dbiLayoutItem&quot;)=A0=A0=A0=A0=A0=A0 &lt;=3D=3D &quot;=A0 &qu=
ot;</span><br style=3D"font-family: courier new,monospace;"><span style=3D"=
font-family: courier new,monospace;">=A0=A0 =A0//@XmlElement(name=3D&quot;i=
tems&quot;)=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 Lis=
t&lt;DbiLayoutItem&gt; items;</span><br style=3D"font-family: courier new,m=
onospace;"><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=
: courier new,monospace;">}</span><br><br><b># WSIMPORT/WSGEN, qui s&#39;ap=
puie sur 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: co=
urier 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=
;dbiLayoutItem&quot;, namespace =3D &quot;urn:NETIA:schema:SEARCH_LAYOUT&qu=
ot;, propOrder =3D {</span><br style=3D"font-family: courier new,monospace;=
"><span 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&q=
uot;,</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;">})</span><br style=3D"f=
ont-family: courier new,monospace;"><span style=3D"font-family: courier new=
,monospace;">public class DbiLayoutItem {</span><br style=3D"font-family: c=
ourier new,monospace;">
<br style=3D"font-family: courier new,monospace;"><span style=3D"font-famil=
y: courier new,monospace;">=A0=A0=A0 @XmlElement(required =3D true)</span><=
br style=3D"font-family: courier new,monospace;"><span style=3D"font-family=
: courier 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 st=
yle=3D"font-family: courier new,monospace;"><span style=3D"font-family: cou=
rier 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: co=
urier new,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: =
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 @XmlAccessorT=
ype(XmlAccessType.FIELD)</span><br style=3D"font-family: courier new,monosp=
ace;"><span style=3D"font-family: courier new,monospace;">=A0=A0=A0 @XmlTyp=
e(name =3D &quot;&quot;, propOrder =3D {</span><br style=3D"font-family: co=
urier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0=A0=A0=A0=A0 &=
quot;dbiLayoutItem&quot;</span><br style=3D"font-family: courier new,monosp=
ace;"><span style=3D"font-family: courier new,monospace;">=A0=A0=A0 })</spa=
n><br style=3D"font-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0 public static=
 class Items {</span><br style=3D"font-family: courier new,monospace;"><br =
style=3D"font-family: courier new,monospace;"><span style=3D"font-family: c=
ourier new,monospace;">=A0=A0=A0=A0=A0=A0=A0 protected List&lt;DbiLayoutIte=
m&gt; dbiLayoutItem;</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"f=
ont-family: courier new,monospace;">=A0=A0=A0 }</span><br style=3D"font-fam=
ily: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">}</span><br><br><i><b>#=
 Ze probl=E8me :</b></i><br><i>=E7a vient p=E9ter mon contrat de WSDL, par =
rapport =E0 ce qu&#39;il y avait auparavant sans l&#39;annotation @XmlEleme=
ntWrapper.</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 DbiLayoutI=
tem {</span><br style=3D"font-family: courier new,monospace;"><br style=3D"=
font-family: courier new,monospace;"><span style=3D"font-family: courier ne=
w,monospace;">=A0=A0=A0 @XmlElement(required =3D true)</span><br style=3D"f=
ont-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0 protected Str=
ing label;</span><br style=3D"font-family: courier new,monospace;"><span st=
yle=3D"font-family: courier new,monospace;">=A0=A0=A0 </span><br style=3D"f=
ont-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0 protected Lis=
t&lt;DbiLayoutItem&gt; items;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 &lt;=3D=3D p=
as d&#39;inner class</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;">}</span><br><br><br>D=
=E8s =E0 pr=E9sent, je vais fouiller un peu du c=F4t=E9 de la &quot;customi=
sation JAXB&quot;... mais =E7a n&#39;est pas dit du tout que cela soit poss=
ible.<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>

--bcaec520eea79c54a604adeba630--