ch.elca.el4j.util.objectwrapper
Class ObjectWrapper

java.lang.Object
  extended by ch.elca.el4j.util.objectwrapper.ObjectWrapper

public class ObjectWrapper
extends Object

Main class of the object wrapper package. The purpose of this package is to treat objects of different classes as if they implemented exactly the utility interfaces we want to use. This prevents us from having to include the interfaces in every domain class.

For example, Keyed is an interface indicating an object has a key. But domain classes may have keys without implementing the keyed interface. As long as we have an algorithm to get/set keys on an object, we can pretend it does actually implement Keyed.

All methods and the interfaces they create throw ObjectWrapperRTException if an object does not have the interface we want and we cannot emulate it either. As it is a RuntimeException it is not always declared; getting such an exception is under most circumstances non-recoverable anyway.

Author:
David Bernhard (DBD)
File-location:
ObjectWrapper
Last check-in date:
2010-01-08 13:32:17 +0100 (Fr, 08. Jan 2010) by jonasha for revision 4083

Constructor Summary
ObjectWrapper()
          Set up the apsects object.
 
Method Summary
 void addWrappable(Class<? extends Wrappable> wrappableClass, AbstractWrapper implementation)
          Register a wrappable.
 Map<Class<? extends Wrappable>,AbstractWrapper> getWrappables()
          Get the wrappables.
 void setWrappables(Map<Class<? extends Wrappable>,AbstractWrapper> wrappables)
          Setter for wrappabless.
<T extends Wrappable>
T
wrap(Class<T> wrappable, Object object)
          Cast an object to a wrapper.
 boolean wrappablePresent(Class<? extends Wrappable> cls)
          Check if a wrappable is registered.
 boolean wrappablePresent(Class<? extends Wrappable> wrappableClass, Class<?> objectClass)
          Check if a call to wrap() has a chance of creating a wrapper on an object class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectWrapper

public ObjectWrapper()
Set up the apsects object.

Method Detail

getWrappables

public Map<Class<? extends Wrappable>,AbstractWrapper> getWrappables()
Get the wrappables.

Returns:
The wrappables.

setWrappables

public void setWrappables(Map<Class<? extends Wrappable>,AbstractWrapper> wrappables)
Setter for wrappabless.

Parameters:
wrappables - The new wrappables to set.

addWrappable

public void addWrappable(Class<? extends Wrappable> wrappableClass,
                         AbstractWrapper implementation)
Register a wrappable.

Parameters:
wrappableClass - The wrappable class to register.
implementation - The implementation.

wrap

public <T extends Wrappable> T wrap(Class<T> wrappable,
                                    Object object)
Cast an object to a wrapper.

Type Parameters:
T - The type parameter. (This eliminates a cast of the return value.)
Parameters:
wrappable - The wrappable to cast the object to.
object - the object.
Returns:
The wrapped object.

wrappablePresent

public boolean wrappablePresent(Class<? extends Wrappable> cls)
Check if a wrappable is registered. Note that even if it is not, an object might implement the interface already in which case wrap() will succeed on it. To be sure of this, use wrappablePresent(wrappableClass, objectClass).

Parameters:
cls - The wrappable class.
Returns:
true if the wrappable exists.

wrappablePresent

public boolean wrappablePresent(Class<? extends Wrappable> wrappableClass,
                                Class<?> objectClass)
Check if a call to wrap() has a chance of creating a wrapper on an object class. This is the case if a) the object implements the interface or b) the wrappable is registered. Note that even if this returns true, the wrapper implementation may throw an expection in create(). This can happen if the wrapper is present but does not apply to this class.

Parameters:
wrappableClass - The wrappable class.
objectClass - The object class.
Returns:
false if there is definitely no way to create the wrapper for this class, true if it can be tried (and will only fail if the implementation does).


Copyright © 2005-2011 ELCA. All Rights Reserved.