468,554 Members | 1,087 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,554 developers. It's quick & easy.

Either I'm doing something wrong or jaxb is crappola

I'm betting it me. Here is the simple schema I'm using:

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
<jaxb:package name="com.some.package.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(
"com.some.package.name" );

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
com.some.package.name.impl.EditableTemplateParamet ersImpl
(com.some.package.name.impl.EditableTemplateParame 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??


Jul 20 '05 #1
0 1365

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by S Mulgund | last post: by
4 posts views Thread by jesper | last post: by
1 post views Thread by Sony Antony | last post: by
reply views Thread by Brett Selleck | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.