473,395 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1526

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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.