Might need to write a custom plugin

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Might need to write a custom plugin

Pablo Ghiglino
Hi all,

I have an schema with the following element:

...
  <xsd:complexType name="AggregationNode">
    <xsd:complexContent>
      <xsd:extension base="avqsq:Item">
        <xsd:sequence>
          <xsd:maxOccurs="unbounded" minOccurs="0" name="positions"
type="xsd:IDREF"/>
        </xsd:sequence>
....
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
...

Which the jaxb code generator converts into:

public class AggregationNode
...
    @XmlElementRef(name = "positions", type = JAXBElement.class,
required = false)
    protected List<JAXBElement<Object>> positions;

while I want this:

public class AggregationNode
..
    @XmlIDREF
    protected List<Position> positions;

I haven't found a way to do this with bindings, so I thought that maybe
the way to go is to build a plugin.

Before, I embark into this task, I thought it would be good check here
first as suggested in the main plugin development main page.

Thanks,

Pablo.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Might need to write a custom plugin

Mirko Klemm
Hi Pablo,
there is an error in your XSD syntax…
I’m sure you mean
<xsd:element maxOccurs….

Plus, if you are using the JAXB reference implementation, you should be able to force XJC into generating the property with the correct type by adding an annotation (binding cutomization):

<xsd:element maxOccurs='unbounded' minOccurs="0“ name="positions“ type="xsd:IDREF“>
        <xsd:annotation>
                <xsd:appInfo>
                        <jaxb:property>
                              <jaxb:baseType name="AuthorBio "/>
                         </jaxb:property>
                </xsd:appInfo>
        <xsd:annotation>
<xsd:element>

You need to make sure that the JAXB namespace  xmlns:jaxb="http://java.sun.com/xml/ns/jaxb“ is properly imported and that the jaxb:version and extensionElementPrefixes=„jaxb“ properties are present.

Regards, Mirko

> Am 2015-09-02 um 13:42 schrieb <[hidden email]> <[hidden email]>:
>
> Hi all,
>
> I have an schema with the following element:
>
> ...
>  <xsd:complexType name="AggregationNode">
>    <xsd:complexContent>
>      <xsd:extension base="avqsq:Item">
> <xsd:sequence>
>  <xsd:maxOccurs="unbounded" minOccurs="0" name="positions"
> type="xsd:IDREF"/>
> </xsd:sequence>
> ....
>      </xsd:extension>
>    </xsd:complexContent>
>  </xsd:complexType>
> ...
>
> Which the jaxb code generator converts into:
>
> public class AggregationNode
> ...
>    @XmlElementRef(name = "positions", type = JAXBElement.class,
> required = false)
>    protected List<JAXBElement<Object>> positions;
>
> while I want this:
>
> public class AggregationNode
> ..
>    @XmlIDREF
>    protected List<Position> positions;
>
> I haven't found a way to do this with bindings, so I thought that maybe
> the way to go is to build a plugin.
>
> Before, I embark into this task, I thought it would be good check here
> first as suggested in the main plugin development main page.
>
> Thanks,
>
> Pablo.


smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Might need to write a custom plugin

Mirko Klemm
In reply to this post by Pablo Ghiglino
Of course, instead of „AuthorBio“, you will have to enter your desired class name...

> Am 2015-09-02 um 13:42 schrieb <[hidden email]> <[hidden email]>:
>
> Hi all,
>
> I have an schema with the following element:
>
> ...
>  <xsd:complexType name="AggregationNode">
>    <xsd:complexContent>
>      <xsd:extension base="avqsq:Item">
> <xsd:sequence>
>  <xsd:maxOccurs="unbounded" minOccurs="0" name="positions"
> type="xsd:IDREF"/>
> </xsd:sequence>
> ....
>      </xsd:extension>
>    </xsd:complexContent>
>  </xsd:complexType>
> ...
>
> Which the jaxb code generator converts into:
>
> public class AggregationNode
> ...
>    @XmlElementRef(name = "positions", type = JAXBElement.class,
> required = false)
>    protected List<JAXBElement<Object>> positions;
>
> while I want this:
>
> public class AggregationNode
> ..
>    @XmlIDREF
>    protected List<Position> positions;
>
> I haven't found a way to do this with bindings, so I thought that maybe
> the way to go is to build a plugin.
>
> Before, I embark into this task, I thought it would be good check here
> first as suggested in the main plugin development main page.
>
> Thanks,
>
> Pablo.


smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Might need to write a custom plugin

Pablo Ghiglino
Dear Mirko,

Thank you very much for your prompt response.
I have indeed tried out what you suggest. I also just tried now again to double check that I did not miss anything.
Unfortunately, the generated code is not good:
@XmlElementRef(name = "positions", type = JAXBElement.class, required = false)
protected List<Position> positions;

The problem is that I get a ClassCastException because at runtime the position list is of type JAXBElement and not of type position.

Does the @XmlElementRef annotation look correct? Or do you think that I should expect a @XmlIDREF instead?

Thanks,

Pablo.

> From: [hidden email]

> Subject: Re: Might need to write a custom plugin
> Date: Wed, 2 Sep 2015 13:55:35 +0200
> To: [hidden email]
>
> Of course, instead of „AuthorBio“, you will have to enter your desired class name...
> > Am 2015-09-02 um 13:42 schrieb <[hidden email]> <[hidden email]>:
> >
> > Hi all,
> >
> > I have an schema with the following element:
> >
> > ...
> > <xsd:complexType name="AggregationNode">
> > <xsd:complexContent>
> > <xsd:extension base="avqsq:Item">
> > <xsd:sequence>
> > <xsd:maxOccurs="unbounded" minOccurs="0" name="positions"
> > type="xsd:IDREF"/>
> > </xsd:sequence>
> > ....
> > </xsd:extension>
> > </xsd:complexContent>
> > </xsd:complexType>
> > ...
> >
> > Which the jaxb code generator converts into:
> >
> > public class AggregationNode
> > ...
> > @XmlElementRef(name = "positions", type = JAXBElement.class,
> > required = false)
> > protected List<JAXBElement<Object>> positions;
> >
> > while I want this:
> >
> > public class AggregationNode
> > ..
> > @XmlIDREF
> > protected List<Position> positions;
> >
> > I haven't found a way to do this with bindings, so I thought that maybe
> > the way to go is to build a plugin.
> >
> > Before, I embark into this task, I thought it would be good check here
> > first as suggested in the main plugin development main page.
> >
> > Thanks,
> >
> > Pablo.
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Might need to write a custom plugin

Aleksei Valikov
In reply to this post by Pablo Ghiglino

On Wed, Sep 2, 2015 at 1:42 PM, <[hidden email]> wrote:
Hi all,

I have an schema with the following element:

...
  <xsd:complexType name="AggregationNode">
    <xsd:complexContent>
      <xsd:extension base="avqsq:Item">
        <xsd:sequence>
          <xsd:maxOccurs="unbounded" minOccurs="0" name="positions"
type="xsd:IDREF"/>
        </xsd:sequence>
....
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
...

Which the jaxb code generator converts into:

public class AggregationNode
...
    @XmlElementRef(name = "positions", type = JAXBElement.class,
required = false)
    protected List<JAXBElement<Object>> positions;

while I want this:

public class AggregationNode
..
    @XmlIDREF
    protected List<Position> positions;

I haven't found a way to do this with bindings, so I thought that maybe
the way to go is to build a plugin.

Before, I embark into this task, I thought it would be good check here
first as suggested in the main plugin development main page.

Thanks,

Pablo.

Loading...