users@jaxb.java.net

JAXBElement<? extends AbstractDataRecordType> Java generics questions

From: Peizhao Hu <peizhao_at_itee.uq.edu.au>
Date: Wed, 25 Apr 2007 23:55:14 +1000

Hi All,

I have use JAXB to bind the SensorML schema into java classes.
however, when I used the java classes, some methods asked for
JAXBElement<? extends AbstractDataRecordType>. After some google
searches, I found it is java generic programming that is saying a
JAXBElement of any datatype that extends from the
AbstractDataRecordtype. however, my question is how can I get such
JAXBElement object?

after a few tries I have the following code working, but the output is
not quite right.


===================== example method =============================
public static net.opengis.sensorml._1.Capabilities
createCapabilities(String id, Object[][] properties){
        Capabilities capabilities = new Capabilities();
        DataRecordType drt = new DataRecordType();
        Utility.assignDataComponentPropertyList(properties,drt.getField());
        javax.xml.namespace.QName qname = new
javax.xml.namespace.QName("http://www.opengis.net/swe");
        capabilities.setAbstractDataRecord(new
JAXBElement(qname.valueOf("DataRecord"),DataRecordType.class,drt));
        return capabilities;
    }


======================== output ===============================
    <ns3:capabilities>
        <DataRecord xmlns="">
            <ns4:field name="test1">
                <ns4:Text definition="org:ogc:def:term" fixed="true">
                    <ns4:value>Test String</ns4:value>
                </ns4:Text>
            </ns4:field>
        </DataRecord>
    </ns3:capabilities>



I don't know I need to hard code the DataRecord name in QName variable.
please help!!! thanks.



also, I am looking into how to get rid of the JAXBElement, it looks
complicate in my code. I checked

Kohsuke Kawaguchi's blog, and use the suggested approach, but it didn't work with my schema and reported lots of error messages.



-- 
regards;
Peizhao