Critique my JAXB object wrapper.

Hello Ladies and Gents,
I have a question on wrapping a jaxb created class and would really like to hear your inputs.
My xsd looks a bit like:
<ComplexService>
<ComplexObject1>
<Element1></Element1>
<Parameter></Parameter>
</ComplexObject1>
<ComplexObject2>
<Element2> </Element2>
<Parameter> </Parameter>
</ComplexObject2>
<ComplexObject10>
<Element10> </Element10>
<Parameter> </Parameter>
</ComplexObjec10>The class created after running the above xsd through xjc looks a bit like :
public class ComplexService{
ComplexObject1 object1;
ComplexObject2 object2;
ComplexObject10 object10;
public static class ComplexObject1{
//Accessors and mutators on ComplexObject1
public static class ComplexObject2{
//Accessors and mutators on ComplexObject2
public static class ComplexObject10{
//Accessors and mutators on ComplexObject10
}Now I want to create a wrapper around these CompleObjects as well the ComplexService class.
public class WrappedComplexObject1{
private final ComplexObject1;
public WrappedComplexObject1(){
complexObject1 = new ComplexObject1();
//Delegate calls to the underlying ComplexObject1
public String getServiceName(){
return complexObject1.getServiceName();
}My questions are these:
1. Would the above way be the preferred way to wrap the class? My objectives are to not mess with the underlying classes created by xjc; to provide a better named api (Class as well as method names).
2. I also want to validate the data in these objects. Therefore I am thinking of using the decorator pattern to further wrap WrappedComplexObject1. Would this be a recommended approach?
3. Lastly, the xsd contains the element "Parameter" which is structurally the same (just contains one value field). However, when xjc created the ComplexService class, for every ComplexObject a new Parameter class was created.
Should I worry about just having one wrapper class for "Parameter" or should I simply create one Parameter wrapper classes per ComplexObject?
Any suggestions, ideas, code samples would be most helpful.
Thanks
Edited by: CaptainHastings on Oct 22, 2009 9:44 AM

CaptainHastings wrote:
Hello Ladies and Gents,
I have a question on wrapping a jaxb created class and would really like to hear your inputs.
My xsd looks a bit like:
<ComplexService>
<ComplexObject1>
<Element1></Element1>
<Parameter></Parameter>
</ComplexObject1>
<ComplexObject2>
<Element2> </Element2>
<Parameter> </Parameter>
</ComplexObject2>
<ComplexObject10>
<Element10> </Element10>
<Parameter> </Parameter>
</ComplexObjec10>
that doesn't look at all like xsd. is that your xml, perhaps?
My questions are these:
1. Would the above way be the preferred way to wrap the class? My objectives are to not mess with the underlying classes created by xjc; to provide a better named api (Class as well as method names).why not use xsd annotations to influence the generated classes?
2. I also want to validate the data in these objects. Therefore I am thinking of using the decorator pattern to further wrap WrappedComplexObject1. Would this be a recommended approach?are you talking validation above and beyond schema validation (because jaxb can do the schema validation for you)?
3. Lastly, the xsd contains the element "Parameter" which is structurally the same (just contains one value field). However, when xjc created the ComplexService class, for every ComplexObject a new Parameter class was created.did you define Parameter as a separate complextype which the other types utilize, or did you redefine it in every one?

Similar Messages

  • Converting object wrapper type array into equivalent primary type array

    Hi All!
    My question is how to convert object wrapper type array into equivalent prime type array, e.g. Integer[] -> int[] or Float[] -> float[] etc.
    Is sound like a trivial task however the problem is that I do not know the type I work with. To understand what I mean, please read the following code -
    //Method signature
    Object createArray( Class clazz, String value ) throws Exception;
    //and usage should be as follows:
    Object arr = createArray( Integer.class, "2%%3%%4" );
    //"arr" will be passed as a parameter of a method again via reflection
    public void compute( Object... args ) {
        a = (int[])args[0];
    //or
    Object arr = createArray( Double.class, "2%%3%%4" );
    public void compute( Object... args ) {
        b = (double[])args[0];
    //and the method implementation -
    Object createArray( Class clazz, String value ) throws Exception {
         String[] split = value.split( "%%" );
         //create array, e.g. Integer[] or Double[] etc.
         Object[] o = (Object[])Array.newInstance( clazz, split.length );
         //fill the array with parsed values, on parse error exception will be thrown
         for (int i = 0; i < split.length; i++) {
              Method meth = clazz.getMethod( "valueOf", new Class[]{ String.class });
              o[i] = meth.invoke( null, new Object[]{ split[i] });
         //here convert Object[] to Object of type int[] or double[] etc...
         /* and return that object*/
         //NB!!! I want to avoid the following code:
         if( o instanceof Integer[] ) {
              int[] ar = new int[o.length];
              for (int i = 0; i < o.length; i++) {
                   ar[i] = (Integer)o;
              return ar;
         } else if( o instanceof Double[] ) {
         //...repeat "else if" for all primary types... :(
         return null;
    Unfortunately I was unable to find any useful method in Java API (I work with 1.5).
    Did I make myself clear? :)
    Thanks in advance,
    Pavel Grigorenko

    I think I've found the answer myself ;-)
    Never thought I could use something like int.class or double.class,
    so the next statement holds int[] q = (int[])Array.newInstance( int.class, 2 );
    and the easy solution is the following -
    Object primeArray = Array.newInstance( token.getPrimeClass(), split.length );
    for (int j = 0; j < split.length; j++) {
         Method meth = clazz.getMethod( "valueOf", new Class[]{ String.class });
         Object val = meth.invoke( null, new Object[]{ split[j] });
         Array.set( primeArray, j, val );
    }where "token.getPrimeClass()" return appropriate Class, i.e. int.class, float.class etc.

  • JAXB object creation for common XML

    Hi,
    Does JAXB let us create common Java Objects for common XMLs.
    Consider the following scenirio:
    XML1.xml
    <xsd:schema>
    <xsd:import namespace="Commons" schemaLocation="Commons.xsd"/>
    <xsd:complexType name="ComplexElementType">
    <xsd:sequence>
    <xsd:element name="Commons" type="Commons:CommonsType"/>
    <xsd:element name="field1" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="complexElement1" type="ComplexElementType"/>
    </xsd:schema>
    XML2.xml
    <xsd:schema>
    <xsd:import namespace="Commons" schemaLocation="Commons.xsd"/>
    <xsd:complexType name="ComplexElementType">
    <xsd:sequence>
    <xsd:element name="Commons" type="Commons:CommonsType"/>
    <xsd:element name="field2" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="complexElement2" type="ComplexElementType"/>
    </xsd:schema>
    The above 2 xmls uses common xml commons.xml.
    Now, lets consider the package of creating Java objects are:
    XML1.xml -> com.xml1
    XML2.xml -> com.xml2
    in general, commons java object will be created separately in both the packages.
    So, my question is, is there any way with which the java objects related to commons.xmls be same or related with some interface?
    Regards
    Sandeep Jindal

    Hi,
    Does JAXB let us create common Java Objects for common XMLs.
    Consider the following scenirio:
    XML1.xml
    <xsd:schema>
    <xsd:import namespace="Commons" schemaLocation="Commons.xsd"/>
    <xsd:complexType name="ComplexElementType">
    <xsd:sequence>
    <xsd:element name="Commons" type="Commons:CommonsType"/>
    <xsd:element name="field1" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="complexElement1" type="ComplexElementType"/>
    </xsd:schema>
    XML2.xml
    <xsd:schema>
    <xsd:import namespace="Commons" schemaLocation="Commons.xsd"/>
    <xsd:complexType name="ComplexElementType">
    <xsd:sequence>
    <xsd:element name="Commons" type="Commons:CommonsType"/>
    <xsd:element name="field2" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="complexElement2" type="ComplexElementType"/>
    </xsd:schema>
    The above 2 xmls uses common xml commons.xml.
    Now, lets consider the package of creating Java objects are:
    XML1.xml -> com.xml1
    XML2.xml -> com.xml2
    in general, commons java object will be created separately in both the packages.
    So, my question is, is there any way with which the java objects related to commons.xmls be same or related with some interface?
    Regards
    Sandeep Jindal

  • Help: Bank Statement Program, Objects within Object wrapper, null pointer

    I am trying to create a class to create a list of banking transactions. The list should hold the date and time of the transaction, the type of transaction (either deposit or withdrawal) and the amount of the transaction.
    So I came up with this code:
    import java.util.*;
    import java.text.*;
    import java.util.LinkedList;
    public class Transaction
    class transactionTypeWrapper{
    Date now;
    StringBuffer transactionType = new StringBuffer(8);
    int amount;
    transactionTypeWrapper aTransaction;
    public Transaction()
    LinkedList transactions = new LinkedList();
    public void addTransaction(String transactionType, int amount)
    StringBuffer temp = new StringBuffer(transactionType);
    aTransaction.transactionType.insert(0, "Deposit");
    aTransaction.amount = amount;
    System.out.println("Transaction Successful");
    Whenever I try to execute the addTransaction method however, it throws up a NullPointerException. i think it has problems with my putting a StringBuffer inside the transactionTypeWrapper but I don't know any other way to do what I want to do without doing this?

    transactionTypeWrapper aTransaction;That never gets initialized. So when you call this code in addTransaction():
    aTransaction.transactionType.insert(0, "Deposit");It's really
    null.transactionType.insert(0, "Deposit");Maybe instead of creating a LinkedList in the constructor that disappears as soon as the constructor finishes, you should actually initailize aTransaction there.
    Message was edited by:
    hunter9000

  • Unable to compile the JAXB generated java files

    Hi
    I am using JAXB 2.0 API for binding process.
    I have products.xml file as
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE PRODUCTDATA SYSTEM "products.dtd">
    <PRODUCTDATA>
    <PRODUCT PRODID="P001" CATEGORY="Books">
    <PRODUCTNAME>Gone with the wind</PRODUCTNAME>
    <DESCRIPTION>This is abt American Civil War</DESCRIPTION>
    <PRICE>25.00</PRICE>
    <QUANTITY>3</QUANTITY>
    </PRODUCT>
    </PRODUCTDATA>
    and products.xsd(Schema file) as
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="PRODUCTDATA" type="prdt"/>
    <xsd:complexType name="prdt">
    <xsd:sequence>
    <xsd:element name="PRODUCT" type="prd" maxOccurs="unbounded" />
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="prd">
    <xsd:sequence>
    <xsd:element name="PRODUCTNAME" type="xsd:string"/>
    <xsd:element name="DESCRIPTION" type="xsd:string"/>
    <xsd:element name="PRICE" type="xsd:positiveInteger"/>
    <xsd:element name="QUANTITY" type="xsd:nonNegativeInteger"/>
    </xsd:sequence>
    <xsd:attribute name="PRODID" type="pid" use="required"/>
    <xsd:attribute name="CATEGORY" type="xsd:string" use="optional"/>
    </xsd:complexType>
    <xsd:simpleType name="pid">
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[p]{1}/d{3}"/>
    <xsd:length value="4"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:schema>
    I am converting these schema file to java files by using binding compiler xjc.
    So that three java files are genearated automatically.
    1) ObjectFactory.java
    // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6
    // See http://java.sun.com/xml/jaxb
    // Any modifications to this file will be lost upon recompilation of the source schema.
    // Generated on: 2008.06.23 at 04:09:25 PM IST
    package testing.jaxb;
    import javax.xml.bind.JAXBElement;
    import javax.xml.bind.annotation.XmlElementDecl;
    import javax.xml.bind.annotation.XmlRegistry;
    import javax.xml.namespace.QName;
    * This object contains factory methods for each
    * Java content interface and Java element interface
    * generated in the testing.jaxb package.
    * <p>An ObjectFactory allows you to programatically
    * construct new instances of the Java representation
    * for XML content. The Java representation of XML
    * content can consist of schema derived interfaces
    * and classes representing the binding of schema
    * type definitions, element declarations and model
    * groups. Factory methods for each of these are
    * provided in this class.
    @XmlRegistry
    public class ObjectFactory {
    private final static QName PRODUCTDATAQNAME = new QName("", "PRODUCTDATA");
    * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: testing.jaxb
    public ObjectFactory() {
    * Create an instance of {@link Prd }
    public Prd createPrd() {
    return new Prd();
    * Create an instance of {@link Prdt }
    public Prdt createPrdt() {
    return new Prdt();
    * Create an instance of {@link JAXBElement }{@code <}{@link Prdt }{@code >}}
    @XmlElementDecl(namespace = "", name = "PRODUCTDATA")
    public JAXBElement<Prdt> createPRODUCTDATA(Prdt value) {
    return new JAXBElement<Prdt>(_PRODUCTDATA_QNAME, Prdt.class, null, value);
    2)Prdt.java
    // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6
    // See http://java.sun.com/xml/jaxb
    // Any modifications to this file will be lost upon recompilation of the source schema.
    // Generated on: 2008.06.23 at 04:09:25 PM IST
    package testing.jaxb;
    import java.util.ArrayList;
    import java.util.List;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlType;
    * <p>Java class for prdt complex type.
    * <p>The following schema fragment specifies the expected content contained within this class.
    * <pre>
    * <complexType name="prdt">
    * <complexContent>
    * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    * <sequence>
    * <element name="PRODUCT" type="{}prd" maxOccurs="unbounded"/>
    * </sequence>
    * </restriction>
    * </complexContent>
    * </complexType>
    * </pre>
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "prdt", propOrder = {
    "product"
    public class Prdt {
    @XmlElement(name = "PRODUCT", required = true)
    protected List<Prd> product;
    * Gets the value of the product property.
    * <p>
    * This accessor method returns a reference to the live list,
    * not a snapshot. Therefore any modification you make to the
    * returned list will be present inside the JAXB object.
    * This is why there is not a <CODE>set</CODE> method for the product property.
    * <p>
    * For example, to add a new item, do as follows:
    * <pre>
    * getPRODUCT().add(newItem);
    * </pre>
    * <p>
    * Objects of the following type(s) are allowed in the list
    * {@link Prd }
    public List<Prd> getPRODUCT() {
    if (product == null) {
    product = new ArrayList<Prd>();
    return this.product;
    3) Prd.java
    // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6
    // See http://java.sun.com/xml/jaxb
    // Any modifications to this file will be lost upon recompilation of the source schema.
    // Generated on: 2008.06.23 at 04:09:25 PM IST
    package testing.jaxb;
    import java.math.BigInteger;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlAttribute;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlType;
    * <p>Java class for prd complex type.
    * <p>The following schema fragment specifies the expected content contained within this class.
    * <pre>
    * <complexType name="prd">
    * <complexContent>
    * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    * <sequence>
    * <element name="PRODUCTNAME" type="{http://www.w3.org/2001/XMLSchema}string"/>
    * <element name="DESCRIPTION" type="{http://www.w3.org/2001/XMLSchema}string"/>
    * <element name="PRICE" type="{http://www.w3.org/2001/XMLSchema}positiveInteger"/>
    * <element name="QUANTITY" type="{http://www.w3.org/2001/XMLSchema}nonNegativeInteger"/>
    * </sequence>
    * <attribute name="CATEGORY" type="{http://www.w3.org/2001/XMLSchema}string" />
    * <attribute name="PRODID" use="required" type="{}pid" />
    * </restriction>
    * </complexContent>
    * </complexType>
    * </pre>
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "prd", propOrder = {
    "productname",
    "description",
    "price",
    "quantity"
    public class Prd {
    @XmlElement(name = "PRODUCTNAME", required = true)
    protected String productname;
    @XmlElement(name = "DESCRIPTION", required = true)
    protected String description;
    @XmlElement(name = "PRICE", required = true)
    protected BigInteger price;
    @XmlElement(name = "QUANTITY", required = true)
    protected BigInteger quantity;
    @XmlAttribute(name = "CATEGORY")
    protected String category;
    @XmlAttribute(name = "PRODID", required = true)
    protected String prodid;
    * Gets the value of the productname property.
    * @return
    * possible object is
    * {@link String }
    public String getPRODUCTNAME() {
    return productname;
    * Sets the value of the productname property.
    * @param value
    * allowed object is
    * {@link String }
    public void setPRODUCTNAME(String value) {
    this.productname = value;
    * Gets the value of the description property.
    * @return
    * possible object is
    * {@link String }
    public String getDESCRIPTION() {
    return description;
    * Sets the value of the description property.
    * @param value
    * allowed object is
    * {@link String }
    public void setDESCRIPTION(String value) {
    this.description = value;
    * Gets the value of the price property.
    * @return
    * possible object is
    * {@link BigInteger }
    public BigInteger getPRICE() {
    return price;
    * Sets the value of the price property.
    * @param value
    * allowed object is
    * {@link BigInteger }
    public void setPRICE(BigInteger value) {
    this.price = value;
    * Gets the value of the quantity property.
    * @return
    * possible object is
    * {@link BigInteger }
    public BigInteger getQUANTITY() {
    return quantity;
    * Sets the value of the quantity property.
    * @param value
    * allowed object is
    * {@link BigInteger }
    public void setQUANTITY(BigInteger value) {
    this.quantity = value;
    * Gets the value of the category property.
    * @return
    * possible object is
    * {@link String }
    public String getCATEGORY() {
    return category;
    * Sets the value of the category property.
    * @param value
    * allowed object is
    * {@link String }
    public void setCATEGORY(String value) {
    this.category = value;
    * Gets the value of the prodid property.
    * @return
    * possible object is
    * {@link String }
    public String getPRODID() {
    return prodid;
    * Sets the value of the prodid property.
    * @param value
    * allowed object is
    * {@link String }
    public void setPRODID(String value) {
    this.prodid = value;
    Next step is to compile these three files
    So I am compiling these three files it gives me compiler error as:
    testing/jaxb/ObjectFactory.java:31: illegal character: \64
    @XmlRegistry
    ^
    testing/jaxb/ObjectFactory.java:63: illegal character: \64
    @XmlElementDecl(namespace = "", name = "PRODUCTDATA")
    ^
    testing/jaxb/ObjectFactory.java:65: <identifier> expected
    return new JAXBElement<Prdt>(_PRODUCTDATA_QNAME, Prdt.class, null, value
    ^
    testing/jaxb/ObjectFactory.java:65: <identifier> expected
    return new JAXBElement<Prdt>(_PRODUCTDATA_QNAME, Prdt.class, null, value
    ^
    testing/jaxb/ObjectFactory.java:65: '{' expected
    return new JAXBElement<Prdt>(_PRODUCTDATA_QNAME, Prdt.class, null, value
    ^
    testing/jaxb/Prdt.java:38: illegal character: \64
    @XmlAccessorType(XmlAccessType.FIELD)
    ^
    testing/jaxb/Prdt.java:39: illegal character: \64
    @XmlType(name = "prdt", propOrder = {
    ^
    testing/jaxb/Prdt.java:44: illegal character: \64
    @XmlElement(name = "PRODUCT", required = true)
    ^
    testing/jaxb/Prdt.java:45: <identifier> expected
    protected List<Prd> product;
    ^
    testing/jaxb/Prdt.java:69: <identifier> expected
    public List<Prd> getPRODUCT() {
    ^
    testing/jaxb/Prdt.java:75: ';' expected
    ^
    testing/jaxb/Prd.java:43: illegal character: \64
    @XmlAccessorType(XmlAccessType.FIELD)
    ^
    testing/jaxb/Prd.java:44: illegal character: \64
    @XmlType(name = "prd", propOrder = {
    ^
    testing/jaxb/Prd.java:52: illegal character: \64
    @XmlElement(name = "PRODUCTNAME", required = true)
    ^
    testing/jaxb/Prd.java:53: <identifier> expected
    protected String productname;
    ^
    testing/jaxb/Prd.java:54: illegal character: \64
    @XmlElement(name = "DESCRIPTION", required = true)
    ^
    testing/jaxb/Prd.java:55: <identifier> expected
    protected String description;
    ^
    testing/jaxb/Prd.java:56: illegal character: \64
    @XmlElement(name = "PRICE", required = true)
    ^
    testing/jaxb/Prd.java:57: <identifier> expected
    protected BigInteger price;
    ^
    testing/jaxb/Prd.java:58: illegal character: \64
    @XmlElement(name = "QUANTITY", required = true)
    ^
    testing/jaxb/Prd.java:59: <identifier> expected
    protected BigInteger quantity;
    ^
    testing/jaxb/Prd.java:60: illegal character: \64
    @XmlAttribute(name = "CATEGORY")
    ^
    testing/jaxb/Prd.java:61: <identifier> expected
    protected String category;
    ^
    testing/jaxb/Prd.java:62: illegal character: \64
    @XmlAttribute(name = "PRODID", required = true)
    ^
    testing/jaxb/Prd.java:63: <identifier> expected
    protected String prodid;
    ^
    25 errors
    I want all three files to compiled successfully.If it is compiled only then I will continue on Unmarshalling process

    I suspect you are trying to compile the files one by one. You may also be trying to compile them disregarding the package structure.
    From your post, I gather these files are in the package: com.geindustrial.sqms
    Therefore, if they are not so already, put them under a directory structure:
    com/geindustrial/sqms
    and then compile with:
    javac com/geindustrial/sqms/AddCtq.java com/geindustrial/sqms/Ctq.java com/geindustrial/sqms/VariableData.java
    (The above is all on one line.)
    HTH,
    Manuel Amago.

  • Web services with JAXB

    Hi All,
    I am new to Web services with JAXB in ECLIPS.
    When I tried to unmarshal the XML file, I am getting the following exception.
    javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"order"). Expected elements are <{http://webservices/}read>,<{http://webservices/}readResponse>
         at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent
    xml , schema and java class are in follow.
    Please help me to solve this issue.
    Mohseni Rad.
    ----------------------------------po.xsd-----------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="order" type="OrderType"/>
    <xsd:complexType name="OrderType">
    <xsd:sequence>
    <xsd:element name="shipTo" type="xsd:string"/>
    <xsd:element name="billTo" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:schema>
    ------------------------------------po.xml----------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <order>
    <shipTo>shipto</shipTo>
    <billTo>billto</billTo>
    </order>
    ------------------TestWS.java---------------------
    import java.io.FileInputStream;
    import java.io.IOException;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.JAXBElement;
    import javax.xml.bind.JAXBException;
    import javax.xml.bind.Unmarshaller;
    import wsclient.*;
    public class TestWs {
         public static void main(String[] args) {
              try{
                   SecondWebServices webService = new SecondWebServicesService
    .getSecondWebServicesPort();
                   JAXBContext jctx = JAXBContext.newInstance("wsclient");
                   Unmarshaller unmarshaller = jctx.createUnmarshaller();
                   FileInputStream fl = new FileInputStream( "etc//po.xml" );
         JAXBElement<?> order = (JAXBElement<?>)unmarshaller.unmarshal( fl );
                   OrderType orderType = (OrderType)order.getValue();
                   webService.read( orderType);
              }catch (JAXBException je) {
                   je.printStackTrace();
              catch (IOException ioe) {
                   ioe.printStackTrace();
    }

    Hi,
    When you are using JAX-WS, there is a tool wsimport, with which you are going to generate the artifacts required to implement the web service.
    When you pass the WSDL as a parameter to the wsimport tool, it will be create the required beans also(JAXB Objects).
    So need of any other external implementation of JAXB when you are working with JAXWS
    Thanks,

  • JAXB question

    DB Structure
    Parent Table - Incident --> Child Table - IncidentCharges --> Child Table of IncidentCharges --> IncidentChargeWeapons
    Container
    Oracle Containers for JAVA(OC4J)
    We have a schema (Incident.xsd) which comprises of our entire database structure. We unmarshalled the schema using JAXB to Java classes and interfaces .
    It created 2 .java classes and 2 .java interfaces for each high level tag . for eg for our Incident tag it created a Incident interface and a IncidentType Interface
    and also it created 2 classes IncidentImpl and IncidentTypeImpl . The IncidentTypeImpl has all the get and set properties we require eg. getIncidentType,
    setIncidentType,getIncidentNumber,setIncidentNumber,getOccuranceDate,setOccuranceDate etc.
    Our objective is to create a JSP page which has form fields to enter data which use these JAXB generated classes get and set properties. In other words
    we want to bind the JSP form fields to these JAXB generated classes. And once these JAXB objects are populated we want to marshal it and create a XML file with the data from those JAXB . Our database would then consume the generated XML. We tried creating a simple incident form with just 3 fields IncidentType,Occurance date and Incident Number and tried to bind these fields with the properties from IncidentTypeImpl classes using the <jsp:usebean> tag . When we deployed it to our container and tried to load the Incident.jsp page , it would not load up . Only when we cleared all the bindings it loaded up .
    Then we tried another workaround (just to get it working. Not a preferred approach) . We created another simple JAVA bean(not JAXB generated beans) which has set and get properties for the form fields and bound the form fields to it.
    On submitting the JSP page we called a servlet which takes data from our created bean and transfers it to the JAXB generated IncidentTypeImpl bean. When we deployed this the jsp page loads up and also our bean is filled with data . But the servlet bombs with this error below.
    500 Internal Server Error
    java.lang.NoClassDefFoundError: javax/xml/bind/JAXBContext
    at Servlets.IncidentServlet.doPost(Unknown Source)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:765)
    at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
    at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
    at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
    at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
    at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
    at java.lang.Thread.run(Thread.java:534)
    We have 2 questions .
    1. Can a JSP page be bound directly to this JAXB generated bean in pretty much the same way as we bind it to our own bean ? (We would like to do this so that we dont have to create duplicate classes which mirror the JAXB generated classes.)
    2. Is there something special we have to do to deploy this application to recognize the JAXB classes. Do we have to deploy some jar file for it to recognize those classes ?

    Nevermind, I have then answer to my question - use this flag - use-runtime <pkg> : suppress the generation of the impl.runtime package and simply

  • JSP and JAXB

    DB Structure
    Parent Table - Incident --> Child Table - IncidentCharges --> Child Table of IncidentCharges --> IncidentChargeWeapons
    Container
    Oracle Containers for JAVA(OC4J)
    We have a schema (Incident.xsd) which comprises of our entire database structure. We unmarshalled the schema using JAXB to Java classes and interfaces .
    It created 2 .java classes and 2 .java interfaces for each high level tag . for eg for our Incident tag it created a Incident interface and a IncidentType Interface
    and also it created 2 classes IncidentImpl and IncidentTypeImpl . The IncidentTypeImpl has all the get and set properties we require eg. getIncidentType,
    setIncidentType,getIncidentNumber,setIncidentNumber,getOccuranceDate,setOccuranceDate etc.
    Our objective is to create a JSP page which has form fields to enter data which use these JAXB generated classes get and set properties. In other words
    we want to bind the JSP form fields to these JAXB generated classes. And once these JAXB objects are populated we want to marshal it and create a XML file with the data from those JAXB . Our database would then consume the generated XML. We tried creating a simple incident form with just 3 fields IncidentType,Occurance date and Incident Number and tried to bind these fields with the properties from IncidentTypeImpl classes using the <jsp:usebean> tag . When we deployed it to our container and tried to load the Incident.jsp page , it would not load up . Only when we cleared all the bindings it loaded up .
    Then we tried another workaround (just to get it working. Not a preferred approach) . We created another simple JAVA bean(not JAXB generated beans) which has set and get properties for the form fields and bound the form fields to it.
    On submitting the JSP page we called a servlet which takes data from our created bean and transfers it to the JAXB generated IncidentTypeImpl bean. When we deployed this the jsp page loads up and also our bean is filled with data . But the servlet bombs with this error below.
    500 Internal Server Error
    java.lang.NoClassDefFoundError: javax/xml/bind/JAXBContext
    at Servlets.IncidentServlet.doPost(Unknown Source)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:765)
    at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
    at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
    at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
    at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
    at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
    at java.lang.Thread.run(Thread.java:534)
    We have 2 questions .
    1. Can a JSP page be bound directly to this JAXB generated bean in pretty much the same way as we bind it to our own bean ? (We would like to do this so that we dont have to create duplicate classes which mirror the JAXB generated classes.)
    2. Is there something special we have to do to deploy this application to recognize the JAXB classes. Do we have to deploy some jar file for it to recognize those classes ?

    I've used oracle's xdk to generate both the interfaces and the implementation classes. Next i've implemented a service class with some methods to return java classes as generated by oracle's jaxb. The return types of these service methods are interfaces, not the implementation classes.
    I can generate an adf data control for this service class, but the data control palette doesn't show the attributes for the jaxb generated classes (i have changed the bean class property in the data control description xml file).
    It's not possible to ignore the interfaces and just use the implementation classes, as the implementation classes specify their return types in interfaces. I don't want to rewrite all the generated code.

  • Minimum packaging to deploy JAXB?

    What is the minimum set of jars I should ship to deploy XJC-generated classes?
    I'm trying to decide whether I can use JAXB, and one important factor is deployability. For my project, I can assume that the customer already has Java 1.4, but otherwise the application must be self-contained.
    I cannot ship the entire Web Services Developer Pack: that's far too large and complex for my needs, as I'm not building a web service. All I want is XML <-> Java translation using standardized APIs, and in the case of a known, fixed schema JAXB objects have better programmer convenience and memory efficiency than generic DOM trees.
    Is there an official distribution with a simple "jaxb-runtime.jar" I can use? At the moment, I'm taking individual jars out of the WSDP, trying to find the smallest set that works.
    Here's the minimum set of Jars that seem to work for running XJC generated classes.
    <fileset dir="${jwsdp}/jaxb/lib">
    <include name="jaxb-api.jar"/>
    <include name="jaxb-impl.jar"/>
    <include name="jaxb-libs.jar"/>
    </fileset>
    <fileset dir="${jwsdp}/jwsdp-shared/lib">
    <include name="jax-qname.jar"/>
    <include name="namespace.jar"/>
    <include name="relaxngDatatype.jar"/>
    <include name="xsdlib.jar"/>
    </fileset>
    Notably absent are the jars in jaxp/lib/endorsed. The large "xsdlib.jar" overlaps a lot with xercesImpl, but not enough to use it as a standalone xsd-aware jaxp parser, which I need for other reasons.
    Noteably present is a dependency on Relax NG, which I am not using.
    Unless JAXB packaging improves, I'll be using Xerces-J plus bare DOM. Tell me there's a better way?

    I think we do not have to take the files mentioned in second <fileset/> to the client. At runtime we need:
    jaxb-api.jar, jaxb-ri.jar(jaxb-impl.jar), jaxb-libs.jar, xerces.jar and generated jar for the package. It worked for me.
    Is there an official distribution with a simple
    "jaxb-runtime.jar" I can use? The JAXB system is divided into two main parts that are completely independent.
    1. Generating classes
    2. Creating objects at runtime
    Obviouly first part needs more XML specific jars, but for second part (in which client is interested) we don't need them.
    So there can't be a true "jaxb-runtime.jar".

  • Injest XML (JAXB) with Apache CXF on Weblogic 9.2.3

    I have tried all of the suggestions I can find out there, but still can not get Weblogic and CXF to play along when injesting XML.
    CXF is deployed and working in production.
    Now that I want add a method to XML results, I declared with JAX-RS like this:
    @POST
    @Consumes( "application/xml")
    @Path( "{order_id}/" + ANALYSE_PARAM )
    public void reportResult( @PathParam( "order_id") int orderId, AnalyseResults analyseResults ) {
    // NOTE: AnalyseResults is a JAXB object which we've created (i.e. mappings to Java provided)
    However, when this method is invoked, I get this:
    , I get this:
    2011-10-26 14:02:46,766 WARN org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper - WebApplicationException has been caught : no cause is available
    java.lang.IllegalArgumentException: Unable to access unsupported property javax.xml.stream.supportDTD
    at weblogic.xml.stax.ConfigurationContextBase.check(ConfigurationContextBase.java:60)
    at weblogic.xml.stax.ConfigurationContextBase.setProperty(ConfigurationContextBase.java:54)
    at weblogic.xml.stax.XMLStreamInputFactory.setProperty(XMLStreamInputFactory.java:280)
    at org.apache.cxf.staxutils.StaxUtils.createXMLInputFactory(StaxUtils.java:195)
    at org.apache.cxf.staxutils.StaxUtils.getXMLInputFactory(StaxUtils.java:166)
    at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1164)
    at org.apache.cxf.jaxrs.provider.JAXBElementProvider.unmarshalFromInputStream(JAXBElementProvider.java:214)
    at org.apache.cxf.jaxrs.provider.JAXBElementProvider.doUnmarshal(JAXBElementProvider.java:180)
    at org.apache.cxf.jaxrs.provider.JAXBElementProvider.readFrom(JAXBElementProvider.java:149)
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1013)
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:594)
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:559)
    at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:230)
    at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:88)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:118)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:208)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:166)
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:113)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:184)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:107)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:163)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3244)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2010)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1916)
    I've done all the reading out there and taken all the suggestions:
    - the woodstox and stax2 JARs are on my classpath
    - the weblogic-application.xml file has been modified to include (a number of varieties have been tried):
    <prefer-application-packages>
              <package-name>javax.jws.*</package-name>
              <package-name>javax.xml.*</package-name>
              <package-name>org.apache.*</package-name>
    </prefer-application-packages>
    I understand the root of the issue: the System properties / JAR files which are first read by Weblogic force the loading of the weblogic.xml.stax.XMLStreamInputFactory as "the way" to create StAX InputFactories.
    But ... that Factory (for whatever reason) is incompatible with the way that CXF invokes it.
    So ... is there ANY way to get WebLogic to allow CXF to use an alternate parser?

    A support ticket (SR 3-4866617511) with Oracle has confirmed that the Weblogic StAX parser has a defect. A patch is available for WLS 10mp2 (and possibly for 9.2.4).
    However, it is also possible to work around with a different StAX implementation.
    Our choice was Woodstox and after putting the JARs (Woodstox and StaX2 mentioned below plus the xml-apis.jar and a xerces implementation JAR) in WEB-INF/lib and removing the changes to weblogic-application.xml (below), the magic was changing WEB-INF/weblogic.xml file (as described in http://download.oracle.com/docs/cd/E13222_01/wls/docs92/programming/classloading.html )to include:
    <container-descriptor>
    <servlet-reload-check-secs>-1</servlet-reload-check-secs>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor>
    Why does this work?
    By using the "prefer-web-inf-classes" node, the WL Classloader looks first in the JAR files of the Web Application (rather than it's own classes). In this case it finds the META-INF/services/javax.xml.stream.XMLInputFactory from the Woodstox JAR (rather than the one from weblogic.jar). Note how this is not just about loading classes from the WEB-INF/lib JARs first ... it also affects how Weblogic interacts with the JAR Service Provider Interface (SPI ... http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html).
    However, the XercesImpl.jar is becomes necessary because when running without it, the following error occurs:
    javax.xml.datatype.FactoryFinder:Using context class loader: weblogic.utils.classloaders.ChangeAwareClassLoader@1a3c1d6 finder: weblogic.utils.classloaders.CodeGenClassFinder@488280 annotation: appsdirtbiis_dir@btb-ws/ic
    javax.xml.datatype.FactoryFinder:found null in $java.home/jaxp.properties
    javax.xml.datatype.FactoryFinder:loaded from fallback value: org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl
    <Nov 8, 2011 11:58:41 AM EST> <Error> <HTTP> <BEA-101017> <[weblogic.servlet.internal.WebAppServletContext@e02837 - appName: '_appsdir_tbiis_dir', name: '/btb-ws/ic', context-path: '/btb-ws/ic'] Root cause of ServletException.
    java.lang.Error: javax.xml.datatype.DatatypeConfigurationException: Provider org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl not found
    Truncated. see log file for complete stacktrace
    >
    THAT issue is due to the fact that the javaee-5.0.5-api.jar's implementation of javax.xml.datatype.DatatypeFactory provides org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl (rather than com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl which is the fallback for the JDK 1.5 implementation that ships with WL 9.2) as the fallback value.
    However, this mechanism is only used because none of the JARs (either in my app or in the standard WL distro) contain an file named "META-INF/services/java.xml.datatype.DatatypeFactory" which points to an existing Xerces implementation.
    The xml-apis.jar was necessary because of unit test I was running on the package. YMMV with the xml-apis.jar.

  • JAXB 1.0 Final: jaxb.properties not found when using custom classloader

    JDK 1.3.1 is being used.
    The scenario:
    1) jaxb jar files, jaxb generated files and application files loaded in default class loader works, however
    2) jaxb jar files, jaxb generated files and application files loaded in a custom class loader generate the following exception:
    javax.xml.bind.JAXBException: Unable to locate jaxb.properties for package XXX
    To demonstrate here are two sample applications: a Launcher app whose job it is to start apps and a sample App1 application who needs JAXB.
    If launch is placed into a jar file named launch.jar and App1 is placed into a jar file named app1.jar (with a JAXB generated package), and both jar files are placed in a directory containing all the JAXB 1.0 jar files (dom, sax, namespace, etc) and the system is started with the following:
    jre\bin\java -cp launch.jar; testLaunch.launch
    the exception occurs.
    By way of comparison, if App1 is started directly with the following:
    jre\bin\java -cp app1.jar;jax-qname.jar;jaxb-xjc.jar;jaxb-ri.jar;jaxb-libs.jar;jaxb-api.jar;dom.jar;sax.jar;jaxp-api.jar;xercesImpl.jar;namespace.jar;ant.jar;xalan.jar testApp.app1
    the exception does not occur.
    Any help would be greatly appreciated.
    package testLaunch;
    import java.net.*;
    import java.io.*;
    public class launch extends javax.swing.JFrame
        private static URLClassLoader app1ClassLoader_; 
        private static Class  app1EntryClass_ = null;
        private static final String app1MainClassName_ = "testApp.app1";
        private Object appObj_ = null;
         static public void main(String args[])
              try {
                System.out.println("Launch Main");               
                new launch();          
                  System.exit(0);
              catch (Throwable t) {
                   t.printStackTrace();
                   System.exit(1);
         public launch()
            if (app1ClassLoader_== null)
                loadAppClassLoader();
            try{
                if (app1EntryClass_ == null)
                    app1EntryClass_ = app1ClassLoader_.loadClass(app1MainClassName_);
                if (app1EntryClass_ == null)
                    System.out.println(app1MainClassName_ + " was not found");
                else
                    appObj_ = app1EntryClass_.newInstance();
            catch(ClassNotFoundException x){
                x.printStackTrace();
            catch(Exception x){
                x.printStackTrace();
        private static void loadAppClassLoader()
            String jarPath = jarPath = System.getProperty("user.dir");
            System.out.println("jar path is: " + jarPath);
            try{
                File jarfile1 = new File(jarPath+File.separator+"app1.jar");
                File jarfile2 = new File(jarPath+File.separator+"dom.jar");
                File jarfile3 = new File(jarPath+File.separator+"jaxp-api.jar");
                File jarfile4 = new File(jarPath+File.separator+"jaxb-api.jar");
                File jarfile5 = new File(jarPath+File.separator+"jaxb-xjc.jar");
                File jarfile6 = new File(jarPath+File.separator+"jaxb-ri.jar");
                File jarfile7 = new File(jarPath+File.separator+"jaxb-libs.jar");
                File jarfile8 = new File(jarPath+File.separator+"jax-qname.jar");
                File jarfile9 = new File(jarPath+File.separator+"sax.jar");
                File jarfile10 = new File(jarPath+File.separator+"xercesImpl.jar");
                File jarfile11 = new File(jarPath+File.separator+"namespace.jar");
                File jarfile12 = new File(jarPath+File.separator+"xalan.jar");
                File jarfile13 = new File(jarPath+File.separator+"ant.jar");
                if (!jarfile1.exists())
                    System.out.println("**ERROR " + jarfile1 + " does not exist!");
                app1ClassLoader_ = new URLClassLoader( new URL[]{jarfile1.toURL(),
                                                                jarfile2.toURL(),
                                                                jarfile3.toURL(),
                                                                jarfile4.toURL(),
                                                                jarfile5.toURL(),
                                                                jarfile6.toURL(),
                                                                jarfile7.toURL(),
                                                                jarfile8.toURL(),
                                                                jarfile9.toURL(),
                                                                jarfile10.toURL(),
                                                                jarfile11.toURL(),
                                                                jarfile12.toURL(),
                                                                jarfile13.toURL()} );
            catch(Exception x){
                x.printStackTrace();
                return;
    package testApp;
    import javax.xml.bind.*; // JAXB classes
    import myGeneratedJAXBFiles;
    public class app1 extends javax.swing.JFrame
         static public void main(String args[])
              try {
                System.out.println("App1 Main");               
                new app1();           
                  System.exit(0);
              catch (Throwable t) {
                   t.printStackTrace();
                   System.exit(1);
         public app1()
            try
                JAXBContext jc_ = JAXBContext.newInstance( "myGeneratedJAXBFiles" );
                System.out.println("Successfully loaded JAXB Context");          
            catch (JAXBException jbe)
                jbe.printStackTrace();

    I'm doing something very similar. In fact my launcher is also stored in launcher.jar. It will start any application on the classpath and load dependencies jars located in the specified directory.
    The first thing you must do is specify the classloader when constructing the jaxb context:
    JAXBContext jc = JAXBContext.newInstance(xmlPackage, getClass().getClassLoader());
    After this I was still raning into the "jaxb.properties not found" exception in some situations. Basically if the class using the jaxb files is located in the same jar as jaxb.properties everything worked fine. However if the class using the jaxb objects was located in a different jar it did not work.
    I had to add the following early in the execution of the application that load the plugins to get things working correctly:
    Thread.currentThread().setContextClassLoader(jarDirClassLoader);
    As far as I can tell JAXB using the Context class loader to find the jaxb.properties file.
    I'm using JAXB 1.1
    I hope this helps!

  • JAXB in JDeveloper 11gR1 PS1

    Hello,
    I'm using JDeveloper 11gR1PS1 and I've generated JAXB 2.0 bindings for an XSD I am using (right-click on the XSD and select "Generate JAXB2.0 Content Model").
    In one complex type of the XSD, there's an element of type "xsd:string" whose presence is mandatory when creating an XML document, even if its content is empty. So if I set the field in my JAXB Object to the empty string:
    myJAXBObject.setSomeStringField("");
    myJAXBObject.setSomeOtherStringField("This has a value");I expect to see (after mashalling) this kind of XML:
    <myJAXB>
            <someStringField></someStringField>
            <someOtherStringField>This has a value</someOtherStringField>
    </myJAXB>Instead I get:
    <myJAXB>
            <someOtherStringField>This has a value</someOtherStringField>
    </myJAXB>Why is this happening? How can I fix it?
    Details on my situation can also be found here: http://stackoverflow.com/questions/3186621/jaxb-empty-string-does-not-produce-empty-element

    The bug has been fixed and will be included in the EclipseLink 2.1.1 maintenance release. If you want access to this fix earlier you can pick up the nightly download starting July 8th from:
    - http://www.eclipse.org/eclipselink/downloads/nightly.php
    -Blaise

  • [JAXB 2.0] Unmarshalling error if the XML contains w3c.Element nodes

    Hi!
    I'm using the JAXB 2.0 library to create an XML file according to a XML Schema (XSD).
    I use the JAXB 2.0 classes, that I have previuosly generated, to fill the data and finally I execute the marshal method to store a XML file with the object's info.
    The second step is unmarshalling the file. Alright in my first attempt: I get all the JAXB objects filled with the data of the file.
    Now I try to add w3c.dom.Element nodes underneath a JAXB object that accepts a list of w3c.dom.Elements:
    org.w3c.dom.Element cip = (org.w3c.dom.Element) doc.createElement("CIP");
    root.appendChild(cip);
    t = doc.createTextNode("CIP");
    t.setData("TEST");
    cip.appendChild(t);
    qpd3.getAny().add(cip);
    And the resulting XML file is marshalled correctly again. Moreover, the node QPD contains a list of simple nodes like 'CIP' (the w3c.dom.Element of the example).
    The second step, to try unmarshalling the XML file I just have generated:
    Using a main method in my class the file is unmarshalled with no problems.
    It's now, when I deploy the web service that calls the unmarshall method (sending the same XML file to the same function), I receive a parsing error!!
    2007-01-30 20:00:08.221 ERROR caught exception while handling request: java.lang.IllegalAccessError: void oracle.xml.parser.schema.XSDNode.<init>()
    Why does this error appear??? I supose JDeveloper tries to parser the w3c.dom.Element nodes like a XSDNode and therefore it fails (what is a XSDNode...?). But if I execute the same method from the "main" of my class it works! Maybe the problem is related with the libraries that OC4J loads when it starts...
    Can anyone help me?? Thanks in advance!
    Sergi

    Hi Blaise,
    The Document class I use to generate the w3c.dom.Element nodes in the marshaling procedure belongs to oracle.xml.parser.v2.XMLDocument class. And it is located in the jar file: file:/C:/Oracle/jdeveloper/jdk/jre/lib/rt.jar!/org/w3c/dom/Document.class
    I have also checked if the unmarshal method of my class has linked the same library, althought is not used in the unmarshalling process (but maybe is implicit...) and it's OK.
    Have you seen something wrong?
    Thank you!
    Sergi

  • Can't generate setters for array or collection classes with JAXB

    I am trying to use JAXB to generate the required setters for Spring beans. Although according to the book Java & XML Data Binding
    Chapter 3 page 42 by Brett McLaughlin it was possible with DTD's using
    <?xml version="1.0"?>
    <xml-java-binding-schema version="1.0-ea">
    <options package="javajaxb.generated.movies" default-reference-collection-type="array" />
    <element name="movies" type="class" root="true"/>
    </xml-java-binding-schema>
    to generate an array as in
    public Movie[] getMovie( ) {
    // implementation
    public void setMovie(Movie[] _Movie) {
    it doesn't look like that capability exists with JAXB 2.0 and XML Schemas. In their wisdom they just generate getters on Lists and tell you:
    <p>
    * This accessor method returns a reference to the live list,
    * not a snapshot. Therefore any modification you make to the
    * returned list will be present inside the JAXB object.
    * This is why there is not a <CODE>set</CODE> method for the filingForm property.
    * <p>
    * For example, to add a new item, do as follows:
    * <pre>
    * getFilingForm().add(newItem);
    * </pre>
    Of course this doesn't work for Spring injection where setters are needed.
    Does anyone know different or is there a way of getting around this ?
    I've tried constructor injection in Spring but it's not as convenient and involves extensive coding of generated code (not nice).
    Edited by: user3806112 on Mar 15, 2011 11:13 AM

    Oh I found it on this post
    http://cxf.547215.n5.nabble.com/NPE-in-generated-setter-method-when-collectionType-quot-indexed-quot-and-a-null-array-is-used-td3323012.html
    collectionType="indexed" in the globalBindings-tag
    it works in schema internal global bindings as well
    <jaxb:globalBindings collectionType="indexed" >

  • JAXB Unnecessary encoding of reserved XML chars?

    Hello all.
    Hopefully what I'm experiencing is a simple problem to fix. I've got an XML document that has the ampersand char encoded as such:
    When I parse this document into a JAXB object, it is getting encoded to:
    &amp;
    I can't figure out how or why or how to make this not happen. Has anyone run into this and figured out why?
    Thanks for you time and help.
    chris

    If you have a string that happens to contain XML data, and you want to treat that data as text contents of a containing XML file instead of treating it as markup, then there are two ways to do that. One is to enclose it in a CDATA section:
    <![CDATA[...your data goes here...]]>
    The other is to escape the XML markup characters: & becomes &amp;, > becomes &gt;, < becomes &lt;, ' becomes &apos;, and " becomes &quot;.
    If that wasn't what you meant, try asking a different version of the question.

Maybe you are looking for

  • Oracle Provider for OLE DB on Vista SSIS Unicode Problem

    I wrote a few SSIS packages on my XP computer using the 10.2.0.2 OLE DB Provider which work fine. Now I'm trying to migrate to a Vista computer... I loaded the Vista certified 10.2.0.3 client and can connect to Oracle databases no problem. The proble

  • How to make custom ecards

    Hey, anyone have suggestions for how to make a custom ecard with my photos? I tried 3 services found (one free, two not) online, but they wouldn't edit the photo to fit the card, one imports it with the wrong orientation, (vertical instead of horiz).

  • Update statement issue

    Whenever I join two tables in update statement following error occures ,However all columns exist update bio1 set appl_uid = demdata.appl_uid where bio1.cnic = demdata.cnic ora-00904 demdataid.cnic invalid indentifier

  • I cant import and export MPEG2 file

    i cant import and exportt file mpeg2 format in premier pro CS6. can u help me....

  • Calendar crashes at startup on iPAD 2 - what to do?

    Calendar crashes at startup on iPAD 2 after approx 1 second (iOS 5.0). Since my iPAD is now older than 6 month, I am apparently not entitled to ask Apple for help and I hope to get some suggestions from the community! Thank you!