Coverage Report - org.apache.commons.scxml.model.TransitionTarget

Classes in this File Line Coverage Branch Coverage Complexity
TransitionTarget
100% 
100% 
1.333

 1  
 /*
 2  
  *
 3  
  *   Copyright 2005-2006 The Apache Software Foundation.
 4  
  *
 5  
  *  Licensed under the Apache License, Version 2.0 (the "License");
 6  
  *  you may not use this file except in compliance with the License.
 7  
  *  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.commons.scxml.model;
 19  
 
 20  
 /**
 21  
  * An abstract base class for elements in SCXML that can serve as a
 22  
  * <target> for a <transition>, such as State or Parallel.
 23  
  *
 24  
  */
 25  
 public abstract class TransitionTarget {
 26  
 
 27  
     /**
 28  
      * Identifier for this transition target. Other parts of the SCXML
 29  
      * document may refer to this <state> using this ID.
 30  
      */
 31  
     private String id;
 32  
 
 33  
     /**
 34  
      * Optional property holding executable content to be run upon
 35  
      * entering this transition target.
 36  
      */
 37  
     private OnEntry onEntry;
 38  
 
 39  
     /**
 40  
      * Optional property holding executable content to be run upon
 41  
      * exiting this transition target.
 42  
      */
 43  
     private OnExit onExit;
 44  
 
 45  
     /**
 46  
      * Optional property holding the data model for this transition target.
 47  
      */
 48  
     private Datamodel datamodel;
 49  
 
 50  
     /**
 51  
      * The parent of this transition target (may be null, if the parent
 52  
      * is the SCXML document root).
 53  
      */
 54  
     private TransitionTarget parent;
 55  
 
 56  
     /**
 57  
      * Constructor.
 58  
      */
 59  
     public TransitionTarget() {
 60  399
         super();
 61  399
         onEntry = new OnEntry(); //empty defaults
 62  399
         onEntry.setParent(this);
 63  399
         onExit = new OnExit();   //empty defaults
 64  399
         onExit.setParent(this);
 65  399
         parent = null;
 66  399
     }
 67  
 
 68  
     /**
 69  
      * Get the identifier for this transition target (may be null).
 70  
      *
 71  
      * @return Returns the id.
 72  
      */
 73  
     public final String getId() {
 74  970
         return id;
 75  
     }
 76  
 
 77  
     /**
 78  
      * Set the identifier for this transition target.
 79  
      *
 80  
      * @param id The id to set.
 81  
      */
 82  
     public final void setId(final String id) {
 83  285
         this.id = id;
 84  285
     }
 85  
 
 86  
     /**
 87  
      * Get the onentry property.
 88  
      *
 89  
      * @return Returns the onEntry.
 90  
      */
 91  
     public final OnEntry getOnEntry() {
 92  414
         return onEntry;
 93  
     }
 94  
 
 95  
     /**
 96  
      * Set the onentry property.
 97  
      *
 98  
      * @param onEntry The onEntry to set.
 99  
      */
 100  
     public final void setOnEntry(final OnEntry onEntry) {
 101  53
         this.onEntry = onEntry;
 102  53
     }
 103  
 
 104  
     /**
 105  
      * Get the onexit property.
 106  
      *
 107  
      * @return Returns the onExit.
 108  
      */
 109  
     public final OnExit getOnExit() {
 110  332
         return onExit;
 111  
     }
 112  
 
 113  
     /**
 114  
      * Set the onexit property.
 115  
      *
 116  
      * @param onExit The onExit to set.
 117  
      */
 118  
     public final void setOnExit(final OnExit onExit) {
 119  30
         this.onExit = onExit;
 120  30
     }
 121  
 
 122  
     /**
 123  
      * Get the data model for this transition target.
 124  
      *
 125  
      * @return Returns the data model.
 126  
      */
 127  
     public final Datamodel getDatamodel() {
 128  189
         return datamodel;
 129  
     }
 130  
 
 131  
     /**
 132  
      * Set the data model for this transition target.
 133  
      *
 134  
      * @param datamodel The Datamodel to set.
 135  
      */
 136  
     public final void setDatamodel(final Datamodel datamodel) {
 137  6
         this.datamodel = datamodel;
 138  6
     }
 139  
 
 140  
     /**
 141  
      * Get the parent TransitionTarget.
 142  
      *
 143  
      * @return Returns the parent state
 144  
      * (null if parent is <scxml> element)
 145  
      */
 146  
     public final TransitionTarget getParent() {
 147  3540
         return parent;
 148  
     }
 149  
 
 150  
     /**
 151  
      * Set the parent TransitionTarget.
 152  
      *
 153  
      * @param parent The parent state to set
 154  
      */
 155  
     public final void setParent(final TransitionTarget parent) {
 156  291
         this.parent = parent;
 157  291
     }
 158  
 
 159  
     /**
 160  
      * Get the parent State.
 161  
      *
 162  
      * @return The parent State
 163  
      */
 164  
     public final State getParentState() {
 165  404
         TransitionTarget tt = this.getParent();
 166  404
         if (tt == null) {
 167  207
             return null;
 168  
         } else {
 169  197
             if (tt instanceof State) {
 170  178
                 return (State) tt;
 171  
             } else { //tt is Parallel
 172  19
                 return tt.getParentState();
 173  
             }
 174  
         }
 175  
     }
 176  
 
 177  
 }
 178