users@jaxb.java.net

Stumped by JAXBIntrospector

From: geo55 <owenge_at_us.ibm.com>
Date: Wed, 6 Aug 2008 05:49:51 -0700 (PDT)

Have just been working with JAXB for a week or so. Feel free to suggest
changes to architecture.

Am developing a generic conversion class that provides functions to:
1. Convert SCA-based data object to XML (BOXMLSerializer API) and back again
2. Convert XML to Java class (JAXB) and back again
3. Convert data object to Java class and back again (combine #1 and #2)

I can go from data object to java class, but creating the XML from a Java
class is not working due to namespace problems. Option #1 works roundtrip.
Option #2 works roundtrip, but the namespace doesn't match what the data
object expects.

Data object's namespace = www.pgh.com/java
Java class's package = com.pgh.java

(The schema describing the Java classes is not available, as it conflicts
with the defined data objects.)

When converting from Java to XML, the code does this with input 'Object
inObj':

String localPart = inObj.getClass().getSimpleName();
String namespaceURI = inObj.getClass().getPackage().getName();

jc = JAXBContext.newInstance(inObj.getClass().getPackage().getName());
JAXBIntrospector introspector = jc.createJAXBIntrospector();
QName qName = new QName(namespaceURI, localPart);
JAXBElement jaxbElement = new JAXBElement(qName, inObj.getClass(), inObj);
if (introspector.isElement(jaxbElement)) {
  QName jaxQname = introspector.getElementName(jaxbElement);
  jaxbElement = new JAXBElement(jaxQname, inObj.getClass(), inObj);
}

This may be convoluted, but it's a bit of desperation. The marshalled XML
file is valid, such as it is, but its namespace is wrong:

<ns3:TestDataObject
   xmlns:ns2="http://www.pgh.com/java"
   xmlns:ns3="com.pgh.java">
      <testDataField>twisted results</testDataField>
</ns3:TestDataObject>

Debugging into the introspector object I find a QName object with the
correct namespace but can't seem to access it.

Any suggestions on whether or not this schema will even work? If so, any
corrections to my approach?
-- 
View this message in context: http://www.nabble.com/Stumped-by-JAXBIntrospector-tp18850474p18850474.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.