org.apache.commons.betwixt.strategy
Class DefaultIdStoringStrategy

java.lang.Object
  extended byorg.apache.commons.betwixt.strategy.IdStoringStrategy
      extended byorg.apache.commons.betwixt.strategy.DefaultIdStoringStrategy

public class DefaultIdStoringStrategy
extends IdStoringStrategy

Stores every ID that given to it into an internal HashMap and returns it on request.

Since:
0.7
Author:
Christian Aust

Field Summary
private  java.util.Map beanByIdMap
           
private  java.util.Map idByBeanMap
           
 
Fields inherited from class org.apache.commons.betwixt.strategy.IdStoringStrategy
DEFAULT
 
Constructor Summary
DefaultIdStoringStrategy()
          Constructs a IdStoringStrategyusing a HashMap for storage.
 
Method Summary
 java.lang.Object getReferenced(Context context, java.lang.String id)
          Gets an object matching the given reference.
 java.lang.String getReferenceFor(Context context, java.lang.Object bean)
          Returns a String id for the given bean if it has been stored previously.
 void reset()
          Clears all beans.
 void setReference(Context context, java.lang.Object bean, java.lang.String id)
          Stores an ID for the given instance and context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

idByBeanMap

private java.util.Map idByBeanMap

beanByIdMap

private java.util.Map beanByIdMap
Constructor Detail

DefaultIdStoringStrategy

public DefaultIdStoringStrategy()
Constructs a IdStoringStrategyusing a HashMap for storage.

Method Detail

getReferenceFor

public java.lang.String getReferenceFor(Context context,
                                        java.lang.Object bean)
Returns a String id for the given bean if it has been stored previously. Otherwise returns null.

Specified by:
getReferenceFor in class IdStoringStrategy
Parameters:
context - current context, not null
bean - the instance, not null
Returns:
id as String, or null if not found
See Also:
IdStoringStrategy.getReferenceFor(org.apache.commons.betwixt.expression.Context, java.lang.Object)

setReference

public void setReference(Context context,
                         java.lang.Object bean,
                         java.lang.String id)
Stores an ID for the given instance and context. It will check first if this ID has been previously stored and will do nothing in that case.

Specified by:
setReference in class IdStoringStrategy
Parameters:
context - current context, not null
bean - current instance, not null
id - the ID to store
See Also:
IdStoringStrategy.setReference(org.apache.commons.betwixt.expression.Context, java.lang.Object, java.lang.String)

getReferenced

public java.lang.Object getReferenced(Context context,
                                      java.lang.String id)
Gets an object matching the given reference.

Specified by:
getReferenced in class IdStoringStrategy
Parameters:
context - Context, not null
id - the reference id
Returns:
an bean matching the given reference, or null if there is no bean matching the given reference

reset

public void reset()
Clears all beans.

Specified by:
reset in class IdStoringStrategy