org.openpermis.editor.policy.adapter
Class AbstractAdapter

java.lang.Object
  extended by org.openpermis.editor.policy.adapter.AbstractAdapter
All Implemented Interfaces:
Serializable, Adapter
Direct Known Subclasses:
PartBeanAdapter

public abstract class AbstractAdapter
extends Object
implements Adapter

Abstract base class of an adapter that uses a pico container to manage Adaptees.

The Adaptees are stored in a pico container with a string description key that contains the (source) object type and the (target) adaptee type. Once an object should be adapted a new adaptee is created using the pico container. All parameters necessary to instantiate the adaptee are injected by the pico container, i.e. construction of the adaptee is done using the source object.

See Also:
Serialized Form
Since:
0.9.0

Constructor Summary
AbstractAdapter()
          Creates an abstract adapter.
 
Method Summary
<T extends Adaptee<?>>
T
adaptTo(Object object, Class<T> adapteeType)
          Adapts an object to the adaptee type.
protected abstract  org.picocontainer.MutablePicoContainer createContainer()
          Creates and initializes the pico container used by this adapter.
protected  String getKey(Class<?> adapteeType, Class<?> objectType)
          Determines the unique key that identifies an adapter/object type pair.
protected  Class<?> getObjectType(Object object)
          Determines the object type of the specified object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractAdapter

public AbstractAdapter()
Creates an abstract adapter.

The underlying pico container is initialized using createContainer().

Since:
0.9.0
Method Detail

createContainer

protected abstract org.picocontainer.MutablePicoContainer createContainer()
Creates and initializes the pico container used by this adapter.

Concrete implementations are expected to provide a fully configured pico here.

Adaptees should be registered at the pico with keys of the same type as returned by getKey(Class, Class).

Returns:
the pico container used to create Adaptees.
Since:
0.9.0

getObjectType

protected Class<?> getObjectType(Object object)
Determines the object type of the specified object.

The default implementation returns the implementation class of the object.

Parameters:
object - the object for which to determine the type in the context of this trader.
Returns:
the class requested.
Since:
0.9.0

getKey

protected String getKey(Class<?> adapteeType,
                        Class<?> objectType)
Determines the unique key that identifies an adapter/object type pair.

The key returned consists of the canonical adaptee type name followed by a colon and the canonical object type name.

Example: For adaptee type org.openpermis.policy.adapter.overview.Overview and object type org.openpermis.policy.Action the resulting string key will be org.openpermis.policy.adapter.overview.Overview:org.openpermis.policy.Action.

Note: Take care when dealing with object types that can be extended, always use interfaces or base types to identify an object type!

Parameters:
adapteeType - the type of adapter for which to retrieve the key.
objectType - the object type for which to retrieve the key.
Returns:
the key requested, never null.
Since:
0.9.0

adaptTo

public <T extends Adaptee<?>> T adaptTo(Object object,
                                        Class<T> adapteeType)
Description copied from interface: Adapter
Adapts an object to the adaptee type.

Specified by:
adaptTo in interface Adapter
Parameters:
object - the object to adapt.
adapteeType - the type to adapt to.
Since:
0.9.0


OpenPermis Role Based Access Control 0.9.0 (Build 16)
2009/08/13 07:17:21
Copyright (c) 2002-2007 Ergon Informatik AG