com.sun.xml.bind.v2.runtime
Class LeafBeanInfoImpl<BeanT>

java.lang.Object
  extended by com.sun.xml.bind.v2.runtime.JaxBeanInfo<BeanT>
      extended by com.sun.xml.bind.v2.runtime.LeafBeanInfoImpl<BeanT>

final class LeafBeanInfoImpl<BeanT>
extends JaxBeanInfo<BeanT>

JaxBeanInfo implementation for immutable leaf classes.

Leaf classes are always bound to a text and they are often immutable. The JAXB spec allows this binding for a few special Java classes plus type-safe enums.

This implementation obtains necessary information from RuntimeLeafInfo.


Field Summary
 
Fields inherited from class com.sun.xml.bind.v2.runtime.JaxBeanInfo
flag, jaxbType
 
Constructor Summary
LeafBeanInfoImpl(JAXBContextImpl grammar, RuntimeLeafInfo li)
           
 
Method Summary
 BeanT createInstance(UnmarshallingContext context)
          Creates a new instance of the bean.
 String getElementLocalName(BeanT _)
          Returns the local name portion of the element name, if the bean that this class represents is mapped from/to an XML element.
 String getElementNamespaceURI(BeanT _)
          Returns the namespace URI portion of the element name, if the bean that this class represents is mapped from/to an XML element.
 String getId(BeanT bean, XMLSerializer target)
          Gets the ID value of the given bean, if it has an ID value.
 Loader getLoader(JAXBContextImpl context, boolean typeSubstitutionCapable)
          Gets the Loader that will unmarshall the given object.
 Transducer<BeanT> getTransducer()
          If the bean's representation in XML is just a text, this method return a Transducer that lets you convert values between the text and the bean.
 QName getTypeName(BeanT instance)
          Returns the XML type name to be used to marshal the specified instance.
 boolean reset(BeanT bean, UnmarshallingContext context)
          Resets the object to the initial state, as if the object is created fresh.
 void serializeAttributes(BeanT bean, XMLSerializer target)
          Serializes attributes into the specified target.
 void serializeBody(BeanT bean, XMLSerializer w)
          Serializes child elements and texts into the specified target.
 void serializeRoot(BeanT bean, XMLSerializer target)
          Serializes the bean as the root element.
 void serializeURIs(BeanT bean, XMLSerializer target)
          Declares all the namespace URIs this object is using at its top-level scope into the specified target.
 
Methods inherited from class com.sun.xml.bind.v2.runtime.JaxBeanInfo
getLifecycleMethods, getTypeNames, hasAfterMarshalMethod, hasAfterUnmarshalMethod, hasBeforeMarshalMethod, hasBeforeUnmarshalMethod, hasElementOnlyContentModel, hasElementOnlyContentModel, invokeAfterUnmarshalMethod, invokeBeforeUnmarshalMethod, isElement, isImmutable, link, lookForLifecycleMethods, setLifecycleFlags, wrapUp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LeafBeanInfoImpl

public LeafBeanInfoImpl(JAXBContextImpl grammar,
                        RuntimeLeafInfo li)
Method Detail

getTypeName

public QName getTypeName(BeanT instance)
Description copied from class: JaxBeanInfo
Returns the XML type name to be used to marshal the specified instance.

Most of the times the type can be determined regardless of the actual instance, but there's a few exceptions (most notably XMLGregorianCalendar), so as a general rule we need an instance to determine it.

Overrides:
getTypeName in class JaxBeanInfo<BeanT>

getElementNamespaceURI

public final String getElementNamespaceURI(BeanT _)
Description copied from class: JaxBeanInfo
Returns the namespace URI portion of the element name, if the bean that this class represents is mapped from/to an XML element.

Specified by:
getElementNamespaceURI in class JaxBeanInfo<BeanT>

getElementLocalName

public final String getElementLocalName(BeanT _)
Description copied from class: JaxBeanInfo
Returns the local name portion of the element name, if the bean that this class represents is mapped from/to an XML element.

Specified by:
getElementLocalName in class JaxBeanInfo<BeanT>

createInstance

public BeanT createInstance(UnmarshallingContext context)
Description copied from class: JaxBeanInfo
Creates a new instance of the bean.

This operation is only supported when JaxBeanInfo.isImmutable() is false.

Specified by:
createInstance in class JaxBeanInfo<BeanT>
Parameters:
context - Sometimes the created bean remembers the corresponding source location,

reset

public final boolean reset(BeanT bean,
                           UnmarshallingContext context)
Description copied from class: JaxBeanInfo
Resets the object to the initial state, as if the object is created fresh.

This is used to reuse an existing object for unmarshalling.

Specified by:
reset in class JaxBeanInfo<BeanT>
context - used for reporting any errors.
Returns:
true if the object was successfuly resetted. False if the object is not resettable, in which case the object will be discarded and new one will be created.

If the object is resettable but failed by an error, it should be reported to the context, then return false. If the object is not resettable to begin with, do not report an error.


getId

public final String getId(BeanT bean,
                          XMLSerializer target)
Description copied from class: JaxBeanInfo
Gets the ID value of the given bean, if it has an ID value. Otherwise return null.

Specified by:
getId in class JaxBeanInfo<BeanT>

serializeBody

public final void serializeBody(BeanT bean,
                                XMLSerializer w)
                         throws SAXException,
                                IOException,
                                javax.xml.stream.XMLStreamException
Description copied from class: JaxBeanInfo
Serializes child elements and texts into the specified target.

Specified by:
serializeBody in class JaxBeanInfo<BeanT>
Throws:
SAXException
IOException
javax.xml.stream.XMLStreamException

serializeAttributes

public final void serializeAttributes(BeanT bean,
                                      XMLSerializer target)
Description copied from class: JaxBeanInfo
Serializes attributes into the specified target.

Specified by:
serializeAttributes in class JaxBeanInfo<BeanT>

serializeRoot

public final void serializeRoot(BeanT bean,
                                XMLSerializer target)
                         throws SAXException,
                                IOException,
                                javax.xml.stream.XMLStreamException
Description copied from class: JaxBeanInfo
Serializes the bean as the root element.

In the java-to-schema binding, an object might marshal in two different ways depending on whether it is used as the root of the graph or not. In the former case, an object could marshal as an element, whereas in the latter case, it marshals as a type.

This method is used to marshal the root of the object graph to allow this semantics to be implemented.

It is doubtful to me if it's a good idea for an object to marshal in two ways depending on the context.

For schema-to-java, this is equivalent to JaxBeanInfo.serializeBody(Object, XMLSerializer).

Specified by:
serializeRoot in class JaxBeanInfo<BeanT>
Throws:
SAXException
IOException
javax.xml.stream.XMLStreamException

serializeURIs

public final void serializeURIs(BeanT bean,
                                XMLSerializer target)
                         throws SAXException
Description copied from class: JaxBeanInfo
Declares all the namespace URIs this object is using at its top-level scope into the specified target.

Specified by:
serializeURIs in class JaxBeanInfo<BeanT>
Throws:
SAXException

getLoader

public final Loader getLoader(JAXBContextImpl context,
                              boolean typeSubstitutionCapable)
Description copied from class: JaxBeanInfo
Gets the Loader that will unmarshall the given object.

Specified by:
getLoader in class JaxBeanInfo<BeanT>
Parameters:
context - The JAXBContextImpl object that governs this object. This object is taken as a parameter so that JaxBeanInfo doesn't have to store them on its own. When this method is invoked from within the unmarshaller, tihs parameter can be null (because the loader is constructed already.)
typeSubstitutionCapable - If true, the returned Loader is capable of recognizing @xsi:type (if necessary) and unmarshals a subtype. This allowes an optimization where this bean info is guaranteed not to have a type substitution. If false, the returned Loader doesn't look for @xsi:type.
Returns:
must return non-null valid object

getTransducer

public Transducer<BeanT> getTransducer()
Description copied from class: JaxBeanInfo
If the bean's representation in XML is just a text, this method return a Transducer that lets you convert values between the text and the bean.

Specified by:
getTransducer in class JaxBeanInfo<BeanT>