Coverage Report - org.apache.commons.betwixt.strategy.IdStoringStrategy

Classes in this File Line Coverage Branch Coverage Complexity
IdStoringStrategy
100% 
N/A 
1

 1  
 /*
 2  
  * Copyright 2005 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.commons.betwixt.strategy;
 18  
 
 19  
 import org.apache.commons.betwixt.expression.Context;
 20  
 
 21  
 /**
 22  
  * Pluggable strategy for id storage management.
 23  
  * It is possible to use this strategy for innovative
 24  
  * active storage storage strategies as well as passive ones.
 25  
  * For example, it is possible to have some beans map to 
 26  
  * references without ever being fully mapped.
 27  
  * 
 28  
  * @author <a href="mailto:christian@wilde-welt.de">Christian Aust </a>
 29  
  * @since 0.7
 30  
  */
 31  5519
 public abstract class IdStoringStrategy {
 32  
 
 33  
     /**
 34  
      * Default storage strategy
 35  
      * 
 36  
      * @deprecated do not use this singleton since it 
 37  
      * creates a static Map of all objects ever written. 
 38  
      * Use {@link #createDefault} instead
 39  
      */
 40  922
     public static IdStoringStrategy DEFAULT = new DefaultIdStoringStrategy();
 41  
 
 42  
     /**
 43  
      * Factory method creates the default <code>Betwixt</code> implementation.
 44  
      * The implementation created may vary if the default implementation changes.
 45  
      * @return <code>IdStoringStrategy</code> used as default
 46  
      */
 47  
     public static IdStoringStrategy createDefault() {
 48  3597
         return new DefaultIdStoringStrategy();
 49  
     }
 50  
         
 51  
     
 52  
     /**
 53  
      * Retrieves a reference for the given instance.
 54  
      * If a not null value is returned from this method,
 55  
      * then the bean content will not be written.
 56  
      * Use {@link org.apache.commons.betwixt.io.IDGenerator} strategy to vary the values
 57  
      * written for a bean.
 58  
      * 
 59  
      * @param context
 60  
      *            current context, not null
 61  
      * @param bean
 62  
      *            the instance, not null
 63  
      * @return id as String when this bean has already been reference, 
 64  
      * or null to indicate that this bean is not yet reference
 65  
      */
 66  
     public abstract String getReferenceFor(Context context, Object bean);
 67  
 
 68  
     /**
 69  
      * Stores an instance reference for later retrieval.
 70  
      * This method is shared by writing and reading.
 71  
      *  
 72  
      * @param context
 73  
      *            current context, not null
 74  
      * @param bean
 75  
      *            the instance, not null
 76  
      * @param id
 77  
      *            the id to use
 78  
      */
 79  
     public abstract void setReference(Context context, Object bean, String id);
 80  
 
 81  
     /**
 82  
      * Gets an object matching the given reference.
 83  
      * @param context <code>Context</code>, not null
 84  
      * @param id the reference id
 85  
      * @return an bean matching the given reference, 
 86  
      * or null if there is no bean matching the given reference
 87  
      */
 88  
     public abstract Object getReferenced(Context context, String id);
 89  
     
 90  
     /**
 91  
      * Reset to the initial state.
 92  
      *
 93  
      */
 94  
     public abstract void reset();
 95  
     
 96  
 }