com.sun.xml.bind.v2.runtime.reflect
Class Accessor<BeanT,ValueT>

java.lang.Object
  extended by com.sun.xml.bind.v2.runtime.reflect.Accessor<BeanT,ValueT>
All Implemented Interfaces:
Receiver
Direct Known Subclasses:
Accessor.FieldReflection, Accessor.GetterSetterReflection, AdaptedAccessor, FieldAccessor_Byte, FieldAccessor_Ref, MethodAccessor_Byte, MethodAccessor_Ref, NullSafeAccessor

public abstract class Accessor<BeanT,ValueT>
extends java.lang.Object
implements Receiver

Accesses a particular property of a bean.

This interface encapsulates the access to the actual data store. The intention is to generate implementations for a particular bean and a property to improve the performance.

Accessor can be used as a receiver. Upon receiving an object it sets that to the field.

See Also:
Accessor.FieldReflection, TransducedAccessor

Nested Class Summary
static class Accessor.FieldReflection<BeanT,ValueT>
          Accessor that uses Java reflection to access a field.
static class Accessor.GetterSetterReflection<BeanT,ValueT>
          Accessor that uses Java reflection to access a getter and a setter.
static class Accessor.ReadOnlyFieldReflection<BeanT,ValueT>
          Read-only access to Field.
 
Field Summary
static Accessor ERROR
          Special Accessor used to recover from errors.
static Accessor<javax.xml.bind.JAXBElement,java.lang.Object> JAXB_ELEMENT_VALUE
          Accessor for JAXBElement.getValue().
 java.lang.Class<ValueT> valueType
           
 
Constructor Summary
protected Accessor(java.lang.Class<ValueT> valueType)
           
 
Method Summary
<T> Accessor<BeanT,T>
adapt(Adapter<java.lang.reflect.Type,java.lang.Class> adapter)
           
<T> Accessor<BeanT,T>
adapt(java.lang.Class<T> targetType, java.lang.Class<? extends javax.xml.bind.annotation.adapters.XmlAdapter<T,ValueT>> adapter)
          Wraps this Accessor into another Accessor and performs the type adaption as necessary.
abstract  ValueT get(BeanT bean)
          Gets the value of the property of the given bean object.
 java.lang.Object getUnadapted(BeanT bean)
          Sets the value without adapting the value.
 java.lang.Class<ValueT> getValueType()
           
 Accessor<BeanT,ValueT> optimize()
          Returns the optimized version of the same accessor.
 void receive(UnmarshallingContext.State state, java.lang.Object o)
          Called when the child loader is deactivated.
abstract  void set(BeanT bean, ValueT value)
          Sets the value of the property of the given bean object.
 void setUnadapted(BeanT bean, java.lang.Object value)
          Sets the value without adapting the value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

valueType

public final java.lang.Class<ValueT> valueType

ERROR

public static final Accessor ERROR
Special Accessor used to recover from errors.


JAXB_ELEMENT_VALUE

public static final Accessor<javax.xml.bind.JAXBElement,java.lang.Object> JAXB_ELEMENT_VALUE
Accessor for JAXBElement.getValue().

Constructor Detail

Accessor

protected Accessor(java.lang.Class<ValueT> valueType)
Method Detail

getValueType

public java.lang.Class<ValueT> getValueType()

optimize

public Accessor<BeanT,ValueT> optimize()
Returns the optimized version of the same accessor.

Returns:
At least the implementation can return this.

get

public abstract ValueT get(BeanT bean)
                    throws AccessorException
Gets the value of the property of the given bean object.

Parameters:
bean - must not be null.
Throws:
AccessorException - if failed to set a value. For example, the getter method may throw an exception.
Since:
2.0 EA1

set

public abstract void set(BeanT bean,
                         ValueT value)
                  throws AccessorException
Sets the value of the property of the given bean object.

Parameters:
bean - must not be null.
value - the value to be set. Setting value to null means resetting to the VM default value (even for primitive properties.)
Throws:
AccessorException - if failed to set a value. For example, the setter method may throw an exception.
Since:
2.0 EA1

getUnadapted

public java.lang.Object getUnadapted(BeanT bean)
                              throws AccessorException
Sets the value without adapting the value. This ugly entry point is only used by JAX-WS. See JAXBRIContext.getElementPropertyAccessor(java.lang.Class, java.lang.String, java.lang.String)

Throws:
AccessorException

setUnadapted

public void setUnadapted(BeanT bean,
                         java.lang.Object value)
                  throws AccessorException
Sets the value without adapting the value. This ugly entry point is only used by JAX-WS. See JAXBRIContext.getElementPropertyAccessor(java.lang.Class, java.lang.String, java.lang.String)

Throws:
AccessorException

receive

public void receive(UnmarshallingContext.State state,
                    java.lang.Object o)
             throws org.xml.sax.SAXException
Description copied from interface: Receiver
Called when the child loader is deactivated.

Specified by:
receive in interface Receiver
Parameters:
state - points to the parent's current state.
o - object that was loaded. may be null.
Throws:
org.xml.sax.SAXException

adapt

public final <T> Accessor<BeanT,T> adapt(java.lang.Class<T> targetType,
                                         java.lang.Class<? extends javax.xml.bind.annotation.adapters.XmlAdapter<T,ValueT>> adapter)
Wraps this Accessor into another Accessor and performs the type adaption as necessary.


adapt

public final <T> Accessor<BeanT,T> adapt(Adapter<java.lang.reflect.Type,java.lang.Class> adapter)