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

Classes in this File Line Coverage Branch Coverage Complexity
Transition
100% 
100% 
1.231

 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  
 package org.apache.commons.scxml.model;
 18  
 
 19  
 import java.util.Map;
 20  
 
 21  
 /**
 22  
  * The class in this SCXML object model that corresponds to the
 23  
  * <transition> SCXML element. Transition rules are triggered
 24  
  * by "events" and conditionalized via
 25  
  * "guard-conditions".
 26  
  *
 27  
  */
 28  
 public class Transition extends Executable
 29  
         implements NamespacePrefixesHolder {
 30  
 
 31  
     /**
 32  
      * Serial version UID.
 33  
      */
 34  
     private static final long serialVersionUID = 1L;
 35  
 
 36  
     /**
 37  
      * Property that specifies the trigger for this transition.
 38  
      */
 39  
     private String event;
 40  
 
 41  
     /**
 42  
      * Optional guard condition.
 43  
      */
 44  
     private String cond;
 45  
 
 46  
     /**
 47  
      * Optional property that specifies the new state or parallel
 48  
      * element to transition to. May be specified by reference or in-line.
 49  
      */
 50  
     private TransitionTarget target;
 51  
 
 52  
     /**
 53  
      * The transition target ID (used by XML Digester only).
 54  
      */
 55  
     private String next;
 56  
 
 57  
     /**
 58  
      * The path for this transition.
 59  
      * @see Path
 60  
      */
 61  
     private Path path;
 62  
 
 63  
     /**
 64  
      * The current XML namespaces in the SCXML document for this action node,
 65  
      * preserved for deferred XPath evaluation.
 66  
      */
 67  
     private Map namespaces;
 68  
 
 69  
     /**
 70  
      * Constructor.
 71  
      */
 72  
     public Transition() {
 73  258
         super();
 74  258
         this.target = null;
 75  258
         this.path = null;
 76  258
     }
 77  
 
 78  
     /**
 79  
      * Get the guard condition (may be null).
 80  
      *
 81  
      * @return Returns the cond.
 82  
      */
 83  
     public final String getCond() {
 84  242
         return cond;
 85  
     }
 86  
 
 87  
     /**
 88  
      * Set the guard condition.
 89  
      *
 90  
      * @param cond The cond to set.
 91  
      */
 92  
     public final void setCond(final String cond) {
 93  88
         this.cond = cond;
 94  88
     }
 95  
 
 96  
     /**
 97  
      * Get the event that will trigger this transition (pending
 98  
      * evaluation of the guard condition in favor).
 99  
      *
 100  
      * @return Returns the event.
 101  
      */
 102  
     public final String getEvent() {
 103  631
         return event;
 104  
     }
 105  
 
 106  
     /**
 107  
      * Set the event that will trigger this transition (pending
 108  
      * evaluation of the guard condition in favor).
 109  
      *
 110  
      * @param event The event to set.
 111  
      */
 112  
     public final void setEvent(final String event) {
 113  187
         this.event = event;
 114  187
     }
 115  
 
 116  
     /**
 117  
      * Get the XML namespaces at this action node in the SCXML document.
 118  
      *
 119  
      * @return Returns the map of namespaces.
 120  
      */
 121  
     public final Map getNamespaces() {
 122  78
         return namespaces;
 123  
     }
 124  
 
 125  
     /**
 126  
      * Set the XML namespaces at this action node in the SCXML document.
 127  
      *
 128  
      * @param namespaces The document namespaces.
 129  
      */
 130  
     public final void setNamespaces(final Map namespaces) {
 131  240
         this.namespaces = namespaces;
 132  240
     }
 133  
 
 134  
     /**
 135  
      * Get the transition target (may be null).
 136  
      *
 137  
      * @return Returns the target as specified in SCXML markup.
 138  
      * <p>Remarks: Is <code>null</code> for &quot;stay&quot; transitions.
 139  
      *  Returns parent (the source node) for &quot;self&quot; transitions.</p>
 140  
      */
 141  
     public final TransitionTarget getTarget() {
 142  648
         return target;
 143  
     }
 144  
 
 145  
     /**
 146  
      * Get the runtime transition target, which always resolves to
 147  
      * a TransitionTarget instance.
 148  
      *
 149  
      * @return Returns the actual target of a transition at runtime.
 150  
      * <p>Remarks: For both the &quot;stay&quot; and &quot;self&quot;
 151  
      * transitions it returns parent (the source node). This method should
 152  
      * never return <code>null</code>.</p>
 153  
      */
 154  
     public final TransitionTarget getRuntimeTarget() {
 155  360
         if (target != null) {
 156  355
             return target;
 157  
         }
 158  5
         return getParent();
 159  
     }
 160  
 
 161  
 
 162  
     /**
 163  
      * Set the transition target.
 164  
      *
 165  
      * @param target The target to set.
 166  
      */
 167  
     public final void setTarget(final TransitionTarget target) {
 168  246
         this.target = target;
 169  246
     }
 170  
 
 171  
     /**
 172  
      * Get the ID of the transition target (may be null, if, for example,
 173  
      * the target is specified inline).
 174  
      *
 175  
      * @return String Returns the transition target ID
 176  
      *                (used by SCXML Digester only).
 177  
      * @see #getTarget()
 178  
      */
 179  
     public final String getNext() {
 180  275
         return next;
 181  
     }
 182  
 
 183  
     /**
 184  
      * Set the transition target by specifying its ID.
 185  
      *
 186  
      * @param next The the transition target ID (used by SCXML Digester only).
 187  
      * @see #setTarget(TransitionTarget)
 188  
      */
 189  
     public final void setNext(final String next) {
 190  243
         this.next = next;
 191  243
     }
 192  
 
 193  
     /**
 194  
      * Get the path of this transiton.
 195  
      *
 196  
      * @see Path
 197  
      * @return Path returns the transition path
 198  
      */
 199  
     public final Path getPath() {
 200  346
         if (path == null) {
 201  92
             path = new Path(getParent(), getTarget());
 202  
         }
 203  346
         return path;
 204  
     }
 205  
 
 206  
 }
 207