users@jaxb.java.net

Re: Question about ObjectFactory

From: gmenguy <guillaume.menguy_at_ext.ec.europa.eu>
Date: Fri, 26 Dec 2008 06:01:49 -0800 (PST)

To be complete, if you want to use like me the JAXB interfaces/classes model

( use <globalBindings generateValueClass="false"> in your external bindings
file or
<xs:annotation>
   <xs:appinfo>
      <jaxb:globalBindings generateValueClass="false">
   </xs:appinfo>
</xs:annotation> in your XSD )

you cannot write anymore

CatalogType catalog= new CatalogType();

because CatalogType is now a generated interface, the implementation
classes are, by default, in the impl subpackage and are all suffixed by
Impl, so you should write

CatalogType catalog= new CatalogTypeImpl();

and so you inderstand that

CatalogType catalog=factory.createCatalogType();

works in both cases !! and is much cleaner ...



which

Wolfgang Laun-2 wrote:
>
> 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
>>
>>
>
>

-- 
View this message in context: http://www.nabble.com/Question-about-ObjectFactory-tp20928806p21174571.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.