Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

problem with binding a choice model with jaxb

Wed Jul 29, 2009 3:59 pm

Hi everybody

I am using Jaxb integrated in netbeans 6.5.1 to generate java classes from my xml Schema.
I have got the classes but the problem that my schema contains an element with choice elements .This element has to be binded with a getter and a setter to every element in choice
in reference to
but i the class contains just this method
Code:
public List<Object> getContent() {
        if (content == null) {
            content = new ArrayList<Object>();
        }
        return this.content;
    }


I tried to use an external binding file to customize the choice model .
Code:
<jxb:bindings version="2.0"
               xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema">
               
<jxb:bindings schemaLocation="bib.xsd" node="/schema">
<jxb:globalBindings bindingStyle="modelGroupBinding"/>
<jxb:schemaBindings>
<jxb:package name="poiuu"/>
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>


I get the following problem when generating java code

cvc-complex-type.3.2.2: Attribute 'bindingStyle' is not allowed to appear in element 'jxb:globalBindings'.

Please help me :beg: :beg:



Re: problem with binding a choice model with jaxb

Wed Jul 29, 2009 11:49 pm

it seems you can't have attributes in the complex type that have the attribute "bindingStyle" . i think you have to remove it ,

am wondering how the generetad java classes has only :
Code:
public List<Object> getContent() {
        if (content == null) {
            content = new ArrayList<Object>();
        }
        return this.content;
    }


Re: problem with binding a choice model with jaxb

Thu Jul 30, 2009 12:19 am

I didn't pay attention but my element is a sequence of elements that one of them is a set of choice .What should i do?

Re: problem with binding a choice model with jaxb

Thu Jul 30, 2009 8:33 am

when you generate java class using JAXB from your XSD which contains choices elements , each element will have a class corresponding to it . Does this happened with you .

Re: problem with binding a choice model with jaxb

Thu Jul 30, 2009 8:55 am

Hello

ALL the elements of the choice have the same type which is access-value that it is a complextype

Code:
<complexType name="access-value"/>


So ,i obtain a class named AccessValue without any attributes or methods

Re: problem with binding a choice model with jaxb

Thu Jul 30, 2009 9:39 am

just generate the JAXB java classes . and GO ON ;)

Re: problem with binding a choice model with jaxb

Thu Jul 30, 2009 9:49 am

i haven't understood

Re: problem with binding a choice model with jaxb

Fri Jul 31, 2009 3:46 pm

I get the class of binded choice :
this is my model choice:
Code:
<element name="ACCESS">
  <complexType>
    <choice>
     <element name="nonident" type="access-value"/>
     <element name="ident-contact" type="access-value"/>
     <element name="other-ident" type="access-value"/>
     <element name="contact-and-other" type="access-value"/>
     <element name="all" type="access-value"/>
     <element name="none" type="access-value"/>
    </choice>
</complexType>
</element>

and access-value is defined in my xsd
Code:
<complexType name="access-value"/>


I get with this 2 classes
Code:
@XmlRootElement(name = "ACCESS")
public class ACCESS {

    protected AccessValue nonident;
    @XmlElement(name = "ident-contact")
    protected AccessValue identContact;
    @XmlElement(name = "other-ident")
    protected AccessValue otherIdent;
    @XmlElement(name = "contact-and-other")
    protected AccessValue contactAndOther;
    protected AccessValue all;
    protected AccessValue none;

    /**
     * Gets the value of the nonident property.
     *
     * @return
     *     possible object is
     *     {@link AccessValue }
     *     
     */
    public AccessValue getNonident() {
        return nonident;
    }

    /**
     * Sets the value of the nonident property.
     *
     * @param value
     *     allowed object is
     *     {@link AccessValue }
     *     
     */
    public void setNonident(AccessValue value) {
        this.nonident = value;
    }

    /**
     * Gets the value of the identContact property.
     *
     * @return
     *     possible object is
     *     {@link AccessValue }
     *     
     */
    public AccessValue getIdentContact() {
        return identContact;
    }

    /**
     * Sets the value of the identContact property.
     *
     * @param value
     *     allowed object is
     *     {@link AccessValue }
     *     
     */
    public void setIdentContact(AccessValue value) {
        this.identContact = value;
    }

    /**
     * Gets the value of the otherIdent property.
     *
     * @return
     *     possible object is
     *     {@link AccessValue }
     *     
     */
    public AccessValue getOtherIdent() {
        return otherIdent;
    }

    /**
     * Sets the value of the otherIdent property.
     *
     * @param value
     *     allowed object is
     *     {@link AccessValue }
     *     
     */
    public void setOtherIdent(AccessValue value) {
        this.otherIdent = value;
    }

    /**
     * Gets the value of the contactAndOther property.
     *
     * @return
     *     possible object is
     *     {@link AccessValue }
     *     
     */
    public AccessValue getContactAndOther() {
        return contactAndOther;
    }

    /**
     * Sets the value of the contactAndOther property.
     *
     * @param value
     *     allowed object is
     *     {@link AccessValue }
     *     
     */
    public void setContactAndOther(AccessValue value) {
        this.contactAndOther = value;
    }

    /**
     * Gets the value of the all property.
     *
     * @return
     *     possible object is
     *     {@link AccessValue }
     *     
     */
    public AccessValue getAll() {
        return all;
    }

    /**
     * Sets the value of the all property.
     *
     * @param value
     *     allowed object is
     *     {@link AccessValue }
     *     
     */
    public void setAll(AccessValue value) {
        this.all = value;
    }

    /**
     * Gets the value of the none property.
     *
     * @return
     *     possible object is
     *     {@link AccessValue }
     *     
     */
    public AccessValue getNone() {
        return none;
    }

    /**
     * Sets the value of the none property.
     *
     * @param value
     *     allowed object is
     *     {@link AccessValue }
     *     
     */
    public void setNone(AccessValue value) {
        this.none = value;
    }

}

and
Code:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "access-value")
public class AccessValue {


}



When I create with my objectFactory an Access element it is ok but i want to attribute the value of one of the access value
I try with all,nonident,none to instanciate an access-value for example:
Code:
AccessValue  all=new  AccessValue();
access. setAll(all);
 

But i can't with ident-contact,other-ident,contact-and-other



Help me

Post a reply
  Related Posts  to : problem with binding a choice model with jaxb
 Choice choiceList popup list of choices     -  
 Unmarshall From XML using JAXB     -  
 XML using JAXB API in java     -  
 insert a namespace in a tag with jaxb     -  
 how to use enum in jaxb unmarshalling     -  
 update an xml file with jaxb     -  
 Re: what is the TCP/IP model?     -  
 update an xml file with jaxb and accessing to its elements     -  
 adding an xmlns attribute xith jaxb     -  
 OSI Model Layers     -  

Topic Tags

Java XML, Java JAXB