Coverage Report - org.apache.commons.workflow.base.BaseRegistry
 
Classes in this File Line Coverage Branch Coverage Complexity
BaseRegistry
0%
0/15
0%
0/2
1.167
 
 1  
 /*
 2  
  * Copyright 1999-2001,2004 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.workflow.base;
 18  
 
 19  
 
 20  
 import java.util.HashMap;
 21  
 import org.apache.commons.workflow.Activity;
 22  
 import org.apache.commons.workflow.Registry;
 23  
 
 24  
 
 25  
 /**
 26  
  * <p><strong>BaseRegistry</strong> is a convenient base class for more
 27  
  * sophisticated <code>Registry</code> implementations.</p>
 28  
  *
 29  
  * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $
 30  
  * @author Craig R. McClanahan
 31  
  */
 32  
 
 33  0
 public class BaseRegistry implements Registry {
 34  
 
 35  
 
 36  
     // ----------------------------------------------------- Instance Variables
 37  
 
 38  
 
 39  
     /**
 40  
      * The set of Activity instances registered with this Registry, keyed
 41  
      * by identifier.
 42  
      */
 43  0
     protected HashMap activities = new HashMap();
 44  
 
 45  
 
 46  
     // ------------------------------------------------------------- Properties
 47  
 
 48  
 
 49  
     // --------------------------------------------------------- Public Methods
 50  
 
 51  
 
 52  
     /**
 53  
      * Add a new Activity to the set of Activity instances known to this
 54  
      * Registry.
 55  
      *
 56  
      * @param activity The new activity to be added
 57  
      */
 58  
     public void addActivity(Activity activity) {
 59  
 
 60  0
         activities.put(activity.getId(), activity);
 61  
 
 62  0
     }
 63  
 
 64  
 
 65  
     /**
 66  
      * Clear any existing Activity instances registered with this Registry.
 67  
      */
 68  
     public void clear() {
 69  
 
 70  0
         activities.clear();
 71  
 
 72  0
     }
 73  
 
 74  
 
 75  
     /**
 76  
      * Return the complete set of Activity instances associated with
 77  
      * this Activity.  If there are no such registered Activity instances,
 78  
      * a zero-length array is returned.
 79  
      */
 80  
     public Activity[] findActivities() {
 81  
 
 82  0
         Activity results[] = new Activity[activities.size()];
 83  0
         return ((Activity[]) activities.values().toArray(results));
 84  
 
 85  
     }
 86  
 
 87  
 
 88  
     /**
 89  
      * Return the registered Activity with the specified identifier, if any;
 90  
      * otherwise return <code>null</code>.
 91  
      *
 92  
      * @param id Identifier of the desired Activity
 93  
      */
 94  
     public Activity findActivity(String id) {
 95  
 
 96  0
         return ((Activity) activities.get(id));
 97  
 
 98  
     }
 99  
 
 100  
 
 101  
     /**
 102  
      * Remove the specified Activity from this Registry.
 103  
      *
 104  
      * @param activity The Activity to be removed
 105  
      */
 106  
     public void removeActivity(Activity activity) {
 107  
 
 108  0
         activities.remove(activity.getId());
 109  
 
 110  0
     }
 111  
 
 112  
 
 113  
     // ------------------------------------------------------- Static Variables
 114  
 
 115  
 
 116  
     /**
 117  
      * The singleton registry instance.
 118  
      */
 119  0
     protected static Registry registry = null;
 120  
 
 121  
 
 122  
     // --------------------------------------------------------- Static Methods
 123  
 
 124  
 
 125  
     /**
 126  
      * Factory method to return a Singleton (per class loader)
 127  
      * <code>Registry</code> instance.
 128  
      */
 129  
     public static Registry getRegistry() {
 130  
 
 131  0
         if (registry == null)
 132  0
             registry = new BaseRegistry();
 133  0
         return (registry);
 134  
 
 135  
     }
 136  
 
 137  
 
 138  
 }