|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ch.elca.el4j.util.objectwrapper.ObjectWrapper
public class ObjectWrapper
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.
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. |
|
|
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 |
---|
public ObjectWrapper()
Method Detail |
---|
public Map<Class<? extends Wrappable>,AbstractWrapper> getWrappables()
public void setWrappables(Map<Class<? extends Wrappable>,AbstractWrapper> wrappables)
wrappables
- The new wrappables to set.public void addWrappable(Class<? extends Wrappable> wrappableClass, AbstractWrapper implementation)
wrappableClass
- The wrappable class to register.implementation
- The implementation.public <T extends Wrappable> T wrap(Class<T> wrappable, Object object)
T
- The type parameter. (This eliminates a cast of the return value.)wrappable
- The wrappable to cast the object to.object
- the object.
public boolean wrappablePresent(Class<? extends Wrappable> cls)
cls
- The wrappable class.
true
if the wrappable exists.public boolean wrappablePresent(Class<? extends Wrappable> wrappableClass, Class<?> objectClass)
wrappableClass
- The wrappable class.objectClass
- The object class.
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).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |