org.apache.commons.betwixt.strategy
Class DefaultIdStoringStrategy

java.lang.Object
  extended by org.apache.commons.betwixt.strategy.IdStoringStrategy
      extended by org.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.

DefaultIdStoringStrategy(Map, Map) allows the implementations to be specified. For example, those who want to use identity (rather than equality) should pass a IdentityHashMap instance.

Since:
0.7
Author:
Christian Aust

Field Summary
 
Fields inherited from class org.apache.commons.betwixt.strategy.IdStoringStrategy
DEFAULT
 
Constructor Summary
DefaultIdStoringStrategy()
          Constructs a IdStoringStrategy using a HashMap for storage.
DefaultIdStoringStrategy(java.util.Map idByBeanMap, java.util.Map beanByIdMap)
          Constructs a IdStoringStrategyusing the Map implementations provided 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 org.apache.commons.betwixt.strategy.IdStoringStrategy
createDefault
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultIdStoringStrategy

public DefaultIdStoringStrategy()
Constructs a IdStoringStrategy using a HashMap for storage.


DefaultIdStoringStrategy

public DefaultIdStoringStrategy(java.util.Map idByBeanMap,
                                java.util.Map beanByIdMap)
Constructs a IdStoringStrategyusing the Map implementations provided for storage.

Parameters:
idByBeanMap - Map implementation stores the ID's by bean
beanByIdMap - Map implementation stores the bean's by ID
Since:
0.8
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


Copyright 2002-2008 The Apache Software Foundation. All Rights Reserved.