1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.asn1new.ber.grammar;
18
19 /***
20 * Define a transition between two states of a grammar. It stores the
21 * next state, and the action to execute while transiting.
22 *
23 *
24 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
25 */
26 public class GrammarTransition
27 {
28
29
30 /*** The next state in the grammar */
31 private int nextState;
32
33 /*** The action associated to the transition */
34 private GrammarAction action;
35
36 /*** The current state */
37 private int currentState;
38
39
40
41 /***
42 * Creates a new GrammarTransition object.
43 *
44 * @param currentState The current transition
45 * @param nextState The target state
46 * @param action The action to execute. It could be null.
47 */
48 public GrammarTransition( int currentState, int nextState, GrammarAction action )
49 {
50 this.currentState = currentState;
51 this.nextState = nextState;
52 this.action = action;
53 }
54
55
56
57 /***
58 * @return Returns the target state.
59 */
60 public int getNextState()
61 {
62 return nextState;
63 }
64
65 /***
66 * Tells if the transition has an associated action.
67 *
68 * @return <code>true</code> if an action has been asociated to the transition
69 */
70 public boolean hasAction()
71 {
72 return action != null;
73 }
74
75 /***
76 * @return Returns the action associated with the transition
77 */
78 public GrammarAction getAction()
79 {
80 return action;
81 }
82
83 /***
84 * @param grammar The grammar which state we want a String from
85 * @return A representation of the transition as a string.
86 */
87 public String toString(int grammar, IStates statesEnum)
88 {
89
90 StringBuffer sb = new StringBuffer();
91
92 sb.append( "Transition from <" ).append( statesEnum.getState( grammar, currentState ) ).append( "> to <" )
93 .append( statesEnum.getState( grammar, nextState ) ).append( ">, action : " )
94 .append( ( ( action == null ) ? "no action" : action.toString() ) ).append( ">" );
95
96 return sb.toString();
97 }
98 }