users@jaxb.java.net

Re: ObjectFactory vs Constructor; package name vs class

From: Sekhar Vajjhala <Sekhar.Vajjhala_at_Sun.COM>
Date: Mon, 31 Oct 2005 13:15:29 -0500

William Simons wrote:

>I'm migrating from JAXB 1 to JAXB 2.0 and I want to make sure that I'm
>sticking to the newest coding conventions. Which is the preferred manner of
>constructing objects? Using the ObjectFactory.createX() method or new X()
>constructor?
>
There is no single preferred mechanism that works for all JAXB usage
scenarios.
Our general thinking was:

a. If interace/impl classes then the ObjectFactory method is used.
b. if value classses are generated (default for JAXB 2.0), then either the
    ObjectFactory method or new X() may be used.
    JAXB 1.0 applications being migrated to JAXB 2.0 and may prefer to
continue
    to use the ObjectFactory method while new applications written for
JAXB 2.0
    would prefer to use the new X() constructor.

>
>Also, which is the preferred way to initialize the JAXBContext? Using the
>string package name or the Class of the object that you want to
>marshal/unmarshal?
>
If you start from schema, it might be more convenient to initialize
JAXBContext with a context
path that takes a list of packages names derived from schema.

If you start from java, it might be more convenient to initialize
JAXBContext with a list
of classes.

See section 4.2, "JAXBContext" in the JAXB 2.0 Proposed Final Draft
specification
for an overview. You can obtain a copy of the specification from
http://jcp.org/en/jsr/detail?id=222 .
Regards,
Sekhar

>
>Thanks,
>Bill
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>