Here's the way I create the objects
JAXBContext jaxbContext= JAXBContext.newInstance(contextPath);
ObjectFactory objectFactory = new ObjectFactory();
financing.ifservices.xml.generated.oagis.ObjectFactory
oagisObjectFactory = new
financing.ifservices.xml.generated.oagis.ObjectFactory();
ShowLeaseQuote showLeaseQuote = objectFactory.createShowLeaseQuote();
showLeaseQuote.setApplicationArea(getLeaseQuote.getApplicationArea());
ShowLeaseQuoteDataArea showLeaseQuoteDataArea =
objectFactory.createShowLeaseQuoteDataArea();
Show show = oagisObjectFactory.createShow();
String verb = getLeaseQuote.getDataArea().getGet().getShow();
show.setConfirm(verb);
showLeaseQuoteDataArea.getLeaseQuote().addAll(getLeaseQuote.getDataArea().getLeaseQuote());
showLeaseQuoteDataArea.setShow(show);
showLeaseQuote.setDataArea(showLeaseQuoteDataArea);
where the the contextPath is similar to "package.a:package.b" (a member
variable) and the object GetLeaseQuote is passed in as an instance of
another JAXBObject that has many of the shared fields from package.b
This is the stack trace
org.w3c.dom.DOMException: DOM006 Hierarchy request error
at
org.apache.xerces.dom.DocumentImpl.insertBefore(DocumentImpl.java:405)
at org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:226)
at
com.sun.xml.bind.marshaller.SAX2DOMEx.startElement(SAX2DOMEx.java:121)
at
financing.ifservices.xml.generated.impl.runtime.SAXMarshaller.endAttributes(SAXMarshaller.java:188)
at
financing.ifservices.xml.generated.impl.ShowLeaseQuoteImpl.serializeBody(ShowLeaseQuoteImpl.java:62)
at
financing.ifservices.xml.generated.impl.runtime.MarshallerImpl.write(MarshallerImpl.java:174)
at
financing.ifservices.xml.generated.impl.runtime.MarshallerImpl.marshal(MarshallerImpl.java:114)
at
javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:87)
at
financing.ifservices.webservice.domain.jaxb.LeaseQuoteFactory_jaxb.getLeaseQuoteXml(LeaseQuoteFactory_jaxb.java:166)
at
financing.ifservices.webservice.domain.junit.LeaseQuoteTestCase.testConversionToXML(LeaseQuoteTestCase.java:139)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
Notice that it occurs during marshalling. The marshalling code looks like
this:
JAXBContext jaxbContext =
JAXBContext.newInstance(contextPath);
Marshaller marshaller = jaxbContext.createMarshaller();
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder =
documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
marshaller.marshal(jaxbObject, document);
The test case basically does this
LeaseQuoteFactory factory = LeaseQuoteFactory.singleton();
assertTrue("LeaseQuoteFactory instanceof
LeaseQuoteFactory_jaxb", factory instanceof LeaseQuoteFactory_jaxb);
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder =
documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(new File(pathName +
"getLeaseQuotenew.xml"));
LeaseQuote leaseQuote = factory.getLeaseQuote(document);
assertEquals("Checking orignal lease quote size", 1,
leaseQuote.getQuoteLines().size());
int size = leaseQuote.getQuoteLines().size();
LeaseQuote convertedLeaseQuote =
LeaseQuoteFactory.singleton().convertLeaseQuote(leaseQuote);
int newSize = convertedLeaseQuote.getQuoteLines().size();
assertEquals("Checking converted lease qutoe size", size,
newSize);
The LeaseQuote object is a facade that has a member variable for the
JAXBObject and uses specific JAXB calls.
Regards,
Greg T. Robertson
Kohsuke Kawaguchi
<Kohsuke.Kawaguch To: users_at_jaxb.dev.java.net
i_at_Sun.COM> cc:
Subject: Re: oddity in creating and then marhsalling
10/27/2003 11:12
AM
Please respond to
users
> Can anyone explain to me why doing the unmarshalling first to create the
> object, instead of using the ObjectFactory methods, would give allow me
to
> marshall succesfully? Perhaps there are some properties that need to be
> set?
No, not really. Using ObjectFactory should be OK.
Could you show me how you are creating new objects, when you get that
exception, and the stack trace. I need more information to help you.
regards,
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net