Thanks for your anser Koshuke. I'll be waiting for the next RI version....
While this happen, I did my own helper function to do the wrapping and
called just before I try to marshal. This will keep me out of the business
of generating XML myself (That was one of the reasons to use JAXB !! )
private static Object toJaxbElement(Object jaxbObject) throws JAXBException
{
if(jaxbObject == null) {
return jaxbObject;
}
if( jaxbObject instanceof javax.xml.bind.Element ) {
return jaxbObject;
}
Object jaxbElement = jaxbObject;
if( jaxbObject instanceof ClassType ) {
Clazz element = MContext.getObjectFactory().createClazz();
ClassType clazz = (ClassType) jaxbObject;
element.setName( clazz.getName() );
element.setDescription( clazz.getDescription() );
jaxbElement = element;
} else if( jaxbObject instanceof SomeOtherType) {
// Create element
// Copy subelements
// Copy attributes
} ...
}
...
marshal( toJaxbElement(foo) );
...
Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM> wrote on 08/07/2003 08:23:35
PM:
>
> This is a tricky issue. We are returning a type instance because that
> allows you to stick that object to somewhere else where it expects
> another type object.
>
> But as you found out, it doesn't let you print that sub-element out
> easily.
>
> The next version of the RI will let you say something like:
>
> FooType t = ...;
> Foo foo = objectFactory.newFoo();
> foo.setType(t); // wrap into an element
>
> marshal(foo);
>
> Hope that helps. In the short term, you might be able to work around
> this problem by
>
> 1. printing the start element <class>.
> 2. marshal a type object without XML declaration.
> 3. print the end element </class>
>
> Search the archive for how to marshal without the XML declaration. (This
> is another thing we are trying to address in the next release.)
>
>
> regards,
> --
> Kohsuke Kawaguchi 408-276-7063 (x17063)
> 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
>