users@jaxb.java.net

Re: Question about ObjectFactory

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Wed, 10 Dec 2008 09:12:57 +0100

On Wed, Dec 10, 2008 at 5:08 AM, yankings <yankings_at_hotmail.com> wrote:

>
> Hi,
>
> I would like to know what is the different between the following two
> declaration:
>
> 1 Create element class through Object Factory:
> ObjectFactory of = new ObjectFactory();
> CatalogType catalog=factory.createCatalogType();
>
> &
> 2 Create element class through new object:
> CatalogType catalog= new CatalogType();
>
> ??As i try to create all element class through 2 and then call the
> mashaller
> to generate the xml file, it works fine. What is the reason to use
> ObjectFactory to get new element class?
>

Many of the createXyz methods of the ObjectFactory are just wrappers
for a call to the constructor Xyz(). But you may also find methods such as

  JAXBElement<Xyz> createXyz( Xyz xyz )

where the element is embedded into a JAXBElement wrapper, and this
object is the one that has to go into its parent.

JAXB uses the ObjectFactory for looking up how to build the content tree
from the unmarshalled document.

I prefer using the "create" methods from the ObjectFactory to calling the
constructor since this will tell me immediately whenever a content
tree node changes from a "plain" object to a "wrapped" object or vice versa.
(This is possible due to changes in the XML schema.)




>
> Thanks a lot!!
> --
> View this message in context:
> http://www.nabble.com/Question-about-ObjectFactory-tp20928806p20928806.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>