473,689 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="htt p://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http ://java.sun.com/xml/ns/jaxb/xjc"
jaxb:version="1 .0">
<xs:annotatio n>
<jaxb:schemaBin dings>
<jaxb:package name="com.some. package.name"/>
</jaxb:schemaBind ings>
<xs:element name="editableT emplateParamete rs">
<xs:complexType >
<xs:element ref="parameter" minOccurs="0"
maxOccurs="unbo unded"/>
<xs:element ref="interface" minOccurs="0"
maxOccurs="unbo unded"/>
<xs:element name="parameter " type="xs:string "/>
<xs:element name="interface ">
<xs:complexType >
<xs:element name="interface Type" type="xs:string "/>
<xs:element ref="parameter" minOccurs="1"
maxOccurs="unbo unded"/>
<xs:element ref="parameterB lock" minOccurs="0"
maxOccurs="unbo unded"/>
<xs:element name="parameter Block">
<xs:complexType >
<xs:element name="blockName " type="xs:string "/>
<xs:element ref="parameter" minOccurs="2"
maxOccurs="unbo unded"/>
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.new Instance(
"com.some.packa ge.name" );

ObjectFactory templateObjFact ory = new ObjectFactory() ;
EditableTemplat eParameters editableTemplat eParams =
templateObjFact ory.createEdita bleTemplatePara meters();

List currentParamLis t = editableTemplat eParams.getPara meter();
Parameter newParam = templateObjFact ory.createParam eter();
newParam.setVal ue( "jaxbSUX!!! " );
currentParamLis t.add( newParam );

StringWriter sw = new StringWriter();
Marshaller m = jaxbContext.cre ateMarshaller() ;
m.setProperty( Marshaller.JAXB _FORMATTED_OUTP UT, Boolean.TRUE );
javax.xml.bind. ValidationEvent Handler veh = new
javax.xml.bind. ValidationEvent Handler()
public boolean handleEvent( javax.xml.bind. ValidationEvent ve
com.some.packag e.name.impl.Edi tableTemplatePa rametersImpl
(com.some.packa ge.name.impl.Ed itableTemplateP arametersImpl)
ve.getLocator() .getObject();
Parameter p = (Parameter) etp.getParamete r().get(0);
StringBuffer locBuff = new StringBuffer( "Locator : Col
Num :"
+ ve.getLocator() .getColumnNumbe r() + "\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().ge tClass().getNam e() + "\n");
locBuff.append( "Locator : param list size :"
+ etp.getParamete r().size() + "\n");
locBuff.append( "Locator : list object :"
+ etp.getParamete r().get(0).getC lass().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(m ethod + "Validation Event: Linked
Exception: "
+ ve.getLinkedExc eption() );
_logger.debug(m ethod + "Validation Event : Locator "
+ locBuff.toStrin g() );
_logger.debug(m ethod + "Validation Event : Message "
+ ve.getMessage() );
_logger.debug(m ethod + "Validation Event : Severity "
+ ve.getSeverity( ) );
return true;
m.setEventHandl er( veh );
m.marshal( editableTemplat eParams, sw );
catch(JAXBExcep tion 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 serializeElemen ts(.....)
throws org.xml.sax.SAX Exception
int idx1 = 0;
final int len1 = _Interface.size ();
int idx2 = 0;
final int len2 = _Parameter.size ();
while (idx2 != len2) {
context.startEl ement("", "parameter" );
int idx_0 = idx2;
try {
idx_0 += 1;
} catch (java.lang.Exce ption e) {
com........hand lePrintConversi onException(thi s, e,
context.endAttr ibutes();
{ <b> vvvvvv Why isn't this a Parameter
context.text((( java.lang.Strin g) _Parameter.get( idx2
} catch (java.lang.Exce ption e) {
com.......handl ePrintConversio nException(this , e,
context.endElem ent();
.............. 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 1543

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

Similar topics

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 web services tutorial shows how to use Transformers and SAXSource objects to perform the conversion in a memory-efficient way, but it requires that I take responsibility for adherence to the schema myself in how I generate the XML output. So I...
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 source code files are generated using the XJC, it is possible to compile the generated source code using javac generated\*.java generated\impl\*.java , but this only gives me 97 errors.?
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" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:version="1.0"> <xs:annotation> <xs:appinfo>
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 natural preference. But there was a requirement that demanded a part of the generated XML to be different depending on whether an element was present or not in the incoming XML. Since we were only beginning with XML, we couldn t find the Xpath...
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 from other java developers. So please comment my following request for feature enhancement: If i unmarshall an invalid xml document i got a javax.xml.bind.UnmarshalException: Unexpected end of element
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 interesting, is if I change the name of ErrorType to Error the issue goes away. Has anyone else ran into this issue? Do you have a solution? The pertanant part of the schema: <snip>
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". Section D.2 (pages 331 to 334) gives an unambiguous explanation of the mapping from an XML name into a Java identifier *if* the underscoreHandling is "asWordSeparator" (which is the default). In particular, Table D-1 uses regular expressions to clearly...
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 marshal the Test object to an xml file. But while unmarshalling back to the java object, I am getting a NullPointerException and a part of the trace is pasted below java.lang.NullPointerException at...
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 JAXB 2.1 to support "required" in "XmlElement" , I read in "JavaWS(JAXB)Tutorial.pdf" that JAXB itself check required elements and attributes , if there are any value for them place it , otherwise place default value in xml file , the exact part of...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.