2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

Coverage Report - org.apache.shale.dialog.basic.config.AbstractState
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractState
0%
0/16
N/A
1
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to you under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.shale.dialog.basic.config;
 19  
 
 20  
 import java.util.HashMap;
 21  
 import java.util.Iterator;
 22  
 import java.util.Map;
 23  
 import org.apache.shale.dialog.basic.model.Dialog;
 24  
 import org.apache.shale.dialog.basic.model.State;
 25  
 import org.apache.shale.dialog.basic.model.Transition;
 26  
 
 27  
 /**
 28  
  * <p>Abstract base class for {@link State} definitions.  Each state is owned
 29  
  * by exactly one owning {@link Dialog}.  While an application
 30  
  * is running, {@link Dialog} (and the constituent {@link State}s and
 31  
  * other configuration information) is immutable, so that it may be
 32  
  * shared by multiple simultaneous paths of execution.</p>
 33  
  *
 34  
  * @since 1.0.4
 35  
  */
 36  
 
 37  0
 public abstract class AbstractState implements State {
 38  
 
 39  
 
 40  
     // ------------------------------------------------------ Instance Variables
 41  
 
 42  
 
 43  
     /**
 44  
      * <p>The {@link Dialog} that owns this {@link State} instance.</p>
 45  
      */
 46  0
     private Dialog dialog = null;
 47  
 
 48  
 
 49  
     /**
 50  
      * <p>The identifier of this {@link State}, which must be unique among
 51  
      * all {@link State}s within the owning {@link Dialog}.</p>
 52  
      */
 53  0
     private String name = null;
 54  
 
 55  
 
 56  
     /**
 57  
      * <p>The {@link Transition}s owned by this {@link State}, keyed by
 58  
      * outcome.  <strong>FIXME</strong> - a different strategy will be needed
 59  
      * if {@link Transition}s become more complex and manage their own
 60  
      * criteria.</p>
 61  
      */
 62  0
     private Map transitions = new HashMap();
 63  
 
 64  
 
 65  
     // -------------------------------------------------------------- Properties
 66  
 
 67  
 
 68  
     /**
 69  
      * {@inheritDoc}
 70  
      */
 71  
     public Dialog getDialog() {
 72  
 
 73  0
         return this.dialog;
 74  
 
 75  
     }
 76  
 
 77  
 
 78  
     /**
 79  
      * {@inheritDoc}
 80  
      */
 81  
     public String getName() {
 82  
 
 83  0
         return this.name;
 84  
 
 85  
     }
 86  
 
 87  
 
 88  
     /**
 89  
      * {@inheritDoc}
 90  
      */
 91  
     public Iterator getTransitionOutcomes() {
 92  
 
 93  0
         return this.transitions.keySet().iterator();
 94  
 
 95  
     }
 96  
 
 97  
 
 98  
     // ---------------------------------------------------------- Public Methods
 99  
 
 100  
 
 101  
     /**
 102  
      * <p>Return the {@link Transition} for the specified logical outcome,
 103  
      * if any; otherwise, return <code>null</code>.</p>
 104  
      *
 105  
      * @param outcome Logical outcome for which to return a {@link Transition}
 106  
      * @return The matching {@link Transition}
 107  
      */
 108  
     public Transition findTransition(String outcome) {
 109  
 
 110  0
         return (Transition) transitions.get(outcome);
 111  
 
 112  
     }
 113  
 
 114  
 
 115  
     // --------------------------------------------------- Configuration Methods
 116  
 
 117  
 
 118  
     /**
 119  
      * <p>Add the specified {@link Transition} to the {@link Transition}s owned
 120  
      * by this {@link State}.</p>
 121  
      *
 122  
      * @param transition {@link Transition} to be added
 123  
      *
 124  
      * @exception IllegalArgumentException if the specified {@link Transition}
 125  
      *  cannot be added to this {@link State}
 126  
      */
 127  
     public void addTransition(Transition transition) throws IllegalArgumentException {
 128  
 
 129  
         // FIXME - addTransition() - ignore duplicate outcomes for now
 130  0
         transitions.put(transition.getOutcome(), transition);
 131  
 
 132  0
     }
 133  
 
 134  
 
 135  
     /**
 136  
      * <p>Remove the specified {@link Transition} from the {@link Transition}s
 137  
      * owned by this {@link State}, if it is currently registered.  Otherwise,
 138  
      * do nothing.</p>
 139  
      *
 140  
      * @param transition {@link Transition} to be removed
 141  
      */
 142  
     public void removeTransition(Transition transition) {
 143  
 
 144  0
         transitions.remove(transition.getOutcome());
 145  
 
 146  0
     }
 147  
 
 148  
 
 149  
     /**
 150  
      * <p>Set the {@link Dialog} that owns this {@link State}.</p>
 151  
      *
 152  
      * @param dialog New owning {@link Dialog}
 153  
      */
 154  
     public void setDialog(Dialog dialog) {
 155  
 
 156  0
         this.dialog = dialog;
 157  
 
 158  0
     }
 159  
 
 160  
 
 161  
 
 162  
     /**
 163  
      * <p>Set the identifier of this {@link State}, which must be unique
 164  
      * among the {@link State}s owned by the same {@link Dialog}.</p>
 165  
      *
 166  
      * @param name New identifier
 167  
      */
 168  
     public void setName(String name) {
 169  
 
 170  0
         this.name = name;
 171  
 
 172  0
     }
 173  
 
 174  
 
 175  
 }