472,795 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,795 software developers and data experts.

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"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:version="1.0">
<xs:annotation>
<xs:appinfo>
<jaxb:schemaBindings>
<jaxb:package name="com.some.package.name"/>
</jaxb:schemaBindings>
</xs:appinfo>
</xs:annotation>
<xs:element name="editableTemplateParameters">
<xs:complexType>
<xs:sequence>
<xs:element ref="parameter" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element ref="interface" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="parameter" type="xs:string"/>
<xs:element name="interface">
<xs:complexType>
<xs:sequence>
<xs:element name="interfaceType" type="xs:string"/>
<xs:element ref="parameter" minOccurs="1"
maxOccurs="unbounded"/>
<xs:element ref="parameterBlock" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="parameterBlock">
<xs:complexType>
<xs:sequence>
<xs:element name="blockName" type="xs:string"/>
<xs:element ref="parameter" minOccurs="2"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
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 );
try
{
javax.xml.bind.ValidationEventHandler veh = new
javax.xml.bind.ValidationEventHandler()
{
public boolean handleEvent( javax.xml.bind.ValidationEvent ve
)
{
com.some.package.name.impl.EditableTemplateParamet ersImpl
etp=
(com.some.package.name.impl.EditableTemplateParame tersImpl)
ve.getLocator().getObject();
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,
context);
}
context.endAttributes();
try
{ <b> vvvvvv Why isn't this a Parameter
object
context.text(((java.lang.String) _Parameter.get(idx2
++)));
} catch (java.lang.Exception e) {
com.......handlePrintConversionException(this, e,
context);
}
context.endElement();
}
.............. 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??

Thanks,

Mark
Jul 20 '05 #1
0 1498

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: S Mulgund | last post by:
I have some legacy data that I want to convert to XML. I've designed a schema to represent the data in XML form, and I'm trying to figure out how best to perform the raw->XML conversion. The Java...
4
by: jesper | last post by:
Hi I am currently following the tutorial from IBM (http://www-106.ibm.com/developerworks/xml/edu/x-dw-xjaxb-i.html) I have three problems at the moment. 1. It says else where that when the...
0
by: Mark | last post by:
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" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"...
1
by: Sony Antony | last post by:
We have a situation wherin we should translate the incoming XML based on one schema to the outgoing XML that is based on another schema. Since both input and output are both XML, XSLT was the...
13
by: Christoph Brunner | last post by:
Hi, on the sun homepage i had submit to the bugparade a request for feature enhancement for the JAXB API. After a period of time sun called me to post my request to a newsgroup an get comments...
0
by: Brett Selleck | last post by:
We have an issue where the JAXB generated classes are creating an interface which references itself. The Schema is valid, and I have not seen this ran into before. The code is below. What is...
0
by: ciaran.mchale | last post by:
I used Google to find information about JAXB 2.0 and I ended up downloading a document called "The Java Architecture for XML Binding (JAXB) 2.0: Proposed Final Draft September 30, 2005". ...
0
by: mnsh | last post by:
Hello, I am new to JAXB. So I would like somebody to help me solve this problem. I have a class say Test which contains only a List which has some 6 to 7 user defined objects. I am able to...
0
by: malsh1358 | last post by:
Hi I need check required elements and attributes in JAXB java classes , if there are any value for them place it , otherwise place default value in xml file , because of it I upgrade JAXB2.0 to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.