Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Either I'm doing something wrong or jaxb is crappola

Thread Tools

Either I'm doing something wrong or jaxb is crappola

Posts: n/a
I'm betting it me. Here is the simple schema I'm using:

<?xml version="1.0"?>

<xs:schema xmlnss=""
<jaxbackage name=""/>
<xs:element name="editableTemplateParameters">
<xs:element ref="parameter" minOccurs="0"
<xs:element ref="interface" minOccurs="0"
<xs:element name="parameter" type="xs:string"/>
<xs:element name="interface">
<xs:element name="interfaceType" type="xs:string"/>
<xs:element ref="parameter" minOccurs="1"
<xs:element ref="parameterBlock" minOccurs="0"
<xs:element name="parameterBlock">
<xs:element name="blockName" type="xs:string"/>
<xs:element ref="parameter" minOccurs="2"

The compiler handles this just fine. It generates the classes & they
compile. The problem shows up when I try to create a doc from java
classes. Here's the java code that does this....

// Create jaxb containers for XML data
JAXBContext jaxbContext = JAXBContext.newInstance(
"" );

ObjectFactory templateObjFactory = new ObjectFactory();
EditableTemplateParameters editableTemplateParams =
templateObjFactory.createEditableTemplateParameter s();

List currentParamList = editableTemplateParams.getParameter();
Parameter newParam = templateObjFactory.createParameter();
newParam.setValue( "jaxbSUX!!!" );
currentParamList.add( newParam );

StringWriter sw = new StringWriter();
Marshaller m = jaxbContext.createMarshaller();
m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
javax.xml.bind.ValidationEventHandler veh = new
public boolean handleEvent( javax.xml.bind.ValidationEvent ve
{ ersImpl
( tersImpl)
Parameter p = (Parameter) etp.getParameter().get(0);
StringBuffer locBuff = new StringBuffer( "Locator : Col
Num :"
+ ve.getLocator().getColumnNumber() + "\n");
locBuff.append( "Locator : Line Num :"
+ ve.getLocator().getLineNumber() + "\n");
locBuff.append( "Locator : Node :"
+ ve.getLocator().getNode() + "\n");
locBuff.append( "Locator : Object :"
+ ve.getLocator().getObject().getClass().getName() + "\n");
locBuff.append( "Locator : param list size :"
+ etp.getParameter().size() + "\n");
locBuff.append( "Locator : list object :"
+ etp.getParameter().get(0).getClass().getName() + "\n");
locBuff.append( "Locator : list object data:"
+ p.getValue() + "\n");
locBuff.append( "Locator : Offset :"
+ ve.getLocator().getOffset() + "\n");
locBuff.append( "Locator : URL :"
+ ve.getLocator().getURL() + "\n");

_logger.debug(method + "Validation Event: Linked
Exception: "
+ ve.getLinkedException() );
_logger.debug(method + "Validation Event : Locator "
+ locBuff.toString() );
_logger.debug(method + "Validation Event : Message "
+ ve.getMessage() );
_logger.debug(method + "Validation Event : Severity "
+ ve.getSeverity() );
return true;
m.setEventHandler( veh );
m.marshal( editableTemplateParams, sw );
catch(JAXBException je)
_logger.warning( method + " JAXB Exception message: " +
je.getMessage() );

...... End of relevant code snippet

I added the bogus event handler to gather up some details as to what
was going on. Without it the code throws a Serializer exception when
I marshal the code. The problem is in how one of the ipml classes
pulls the "Parameter" data from the list object. Note that I create a
Parameter object using the ObjectFactory, then set the value
(jaxbSUX!!!) then add the Parameter to the list. In the serialization
method generated by xjc the object pulled from the list is cast as a
string. Here is a snippet from the method....

public void serializeElements(.....)
throws org.xml.sax.SAXException
int idx1 = 0;
final int len1 = _Interface.size();
int idx2 = 0;
final int len2 = _Parameter.size();
while (idx2 != len2) {
context.startElement("", "parameter");
int idx_0 = idx2;
try {
idx_0 += 1;
} catch (java.lang.Exception e) {
com........handlePrintConversionException(this, e,
{ <b> vvvvvv Why isn't this a Parameter
context.text(((java.lang.String) _Parameter.get(idx2
} catch (java.lang.Exception e) {
com.......handlePrintConversionException(this, e,
.............. End of snippet

So obviously, if I put the string directly into the list all is well.
But why create a Parameter object if we cant use it. Is there a
problem with the schema that is causing this apparently strange/buggy
behavior or is jaxb really this dumb. I tried using the current
version of the jwsdk (1.3) but we have some dependencies on java 1.3.1
and even when I generated the newer jaxb code the generated class
still cast the object returned from the list to a string.

What am I doing wrong??


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL: I'm doing something wrong, and I can't see it! Simon Brooke XML 5 02-27-2007 08:34 AM
Crypto.Cipher.ARC4, bust or me doing something wrong? Michael Sparks Python 6 09-21-2005 07:54 PM
Re: Crypto.Cipher.ARC4, bust or me doing something wrong? Jp Calderone Python 1 09-20-2005 05:20 PM
Doing something wrong Chiller C++ 1 04-12-2004 11:57 AM
Re: Testing magnification. Am I doing something wrong? Mark M Digital Photography 14 08-20-2003 12:43 PM