velosurf.context
Class ExternalObjectWrapper

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.TreeMap
          extended by velosurf.context.Instance
              extended by velosurf.context.ExternalObjectWrapper
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map, java.util.SortedMap, ReadOnlyMap

public class ExternalObjectWrapper
extends Instance

This wrapper allows one to specify custom mapping objects that don't inherit from Instance.

For now, the introspection is rather basic but may work for standard getters without ambiguity.

Author:
Claude Brisson
See Also:
Serialized Form

Nested Class Summary
private static class ExternalObjectWrapper.ClassInfo
           
 
Field Summary
(package private)  ExternalObjectWrapper.ClassInfo classInfo
          info on the wrapped object class
(package private) static java.util.Map<java.lang.String,ExternalObjectWrapper.ClassInfo> classInfoMap
          a map of class infos
(package private)  java.util.Map getterCache
          a cache for the wrapped object getter methods
(package private)  java.util.Map setterCache
          a cache for the wrapped object setter methods
(package private)  java.lang.Object wrapped
          the wrapped object
 
Fields inherited from class velosurf.context.Instance
db, entity, localized, userContext
 
Constructor Summary
ExternalObjectWrapper(Entity entity, java.lang.Object object)
          Builds a new PlaiObjectWrapper
 
Method Summary
 boolean delete()
          Tries to delete the row associated with this Instance using a delete() method in the external object.
protected  java.lang.reflect.Method findMethod(java.lang.String name, java.lang.Class[] args)
          Tries to find a named method in the external object
 java.lang.Object get(java.lang.Object key)
          Wrapper generic getter: tries first to get the property from the wrapped object, and falls back to the superclass if not found.
 java.lang.Object getExternal(java.lang.Object key)
          External getter: get a value on the external object
 boolean insert()
          Tries to insert a new row corresponding to this Instance using an insert() method in the external object.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Wrapper generic setter: tries first to set the property into the wrapped object, and falls back to the superclass if not found.
 java.lang.Object unwrap()
          Returns the underlying external object
 boolean update()
          Try to update the row associated with this Instance using an update() method in the external object.
 boolean update(java.util.Map values)
          Try to update the row associated with this Instance using an update(map) method in the external object.
 
Methods inherited from class velosurf.context.Instance
equals, getEntity, getInternal, getKeys, getPrimaryKey, handleSQLException, initialize, setUserContext, validate
 
Methods inherited from class java.util.TreeMap
clear, clone, comparator, containsKey, containsValue, entrySet, firstKey, headMap, keySet, lastKey, putAll, remove, size, subMap, tailMap, values
 
Methods inherited from class java.util.AbstractMap
hashCode, isEmpty, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface velosurf.sql.ReadOnlyMap
keySet
 
Methods inherited from interface java.util.Map
hashCode, isEmpty
 

Field Detail

wrapped

java.lang.Object wrapped
the wrapped object


classInfo

ExternalObjectWrapper.ClassInfo classInfo
info on the wrapped object class


classInfoMap

static java.util.Map<java.lang.String,ExternalObjectWrapper.ClassInfo> classInfoMap
a map of class infos


getterCache

java.util.Map getterCache
a cache for the wrapped object getter methods


setterCache

java.util.Map setterCache
a cache for the wrapped object setter methods

Constructor Detail

ExternalObjectWrapper

public ExternalObjectWrapper(Entity entity,
                             java.lang.Object object)
Builds a new PlaiObjectWrapper

Parameters:
entity - the related entity
object - target object
Method Detail

get

public java.lang.Object get(java.lang.Object key)
Wrapper generic getter: tries first to get the property from the wrapped object, and falls back to the superclass if not found.

Specified by:
get in interface java.util.Map
Specified by:
get in interface ReadOnlyMap
Overrides:
get in class Instance
Parameters:
key - key of the property to be returned
Returns:
a String, an Instance, an AttributeReference or null if not found or if an error occurs

getExternal

public java.lang.Object getExternal(java.lang.Object key)
External getter: get a value on the external object

Overrides:
getExternal in class Instance
Parameters:
key - key of the property to be returned
Returns:
a String, an Instance, an AttributeReference or null if not found or if an error occurs

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Wrapper generic setter: tries first to set the property into the wrapped object, and falls back to the superclass if not found.

Specified by:
put in interface java.util.Map
Overrides:
put in class Instance
Parameters:
key - key of the property to be set
value - corresponding value
Returns:
previous value, or null

update

public boolean update()

Try to update the row associated with this Instance using an update() method in the external object.

Overrides:
update in class Instance
Returns:
true if successfull, false if an error occurs (in which case $db.lastError can be checked).

update

public boolean update(java.util.Map values)

Try to update the row associated with this Instance using an update(map) method in the external object.

Overrides:
update in class Instance
Parameters:
values - values to be used for the update
Returns:
true if successfull, false if an error occurs (in which case $db.lastError can be checked).

delete

public boolean delete()
Tries to delete the row associated with this Instance using a delete() method in the external object.

Velosurf will ensure all key columns are specified, to avoid an accidental massive update.

Overrides:
delete in class Instance
Returns:
true if successfull, false if an error occurs (in which case $db.lastError can be checked).

insert

public boolean insert()
Tries to insert a new row corresponding to this Instance using an insert() method in the external object.

Overrides:
insert in class Instance
Returns:
true if successfull, false if an error occurs (in which case $db.lastError can be checked).

unwrap

public java.lang.Object unwrap()
Returns the underlying external object

Returns:
the external object

findMethod

protected java.lang.reflect.Method findMethod(java.lang.String name,
                                              java.lang.Class[] args)
Tries to find a named method in the external object

Parameters:
name - the name of the method
args - the types of the arguments


~ooOoo~