KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > dsmlv2 > GrammarTransition


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.dsmlv2;
22
23
24 /**
25  * Define a transition between two states of a grammar. It stores the next
26  * state, and the action to execute while transiting.
27  *
28  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
29  * @version $Rev$, $Date$
30  */

31 public class GrammarTransition
32 {
33     /** The next state in the grammar */
34     private int nextState;
35
36     /** The action associated to the transition */
37     private GrammarAction action;
38
39     /** The current state */
40     private int currentState;
41
42     
43     /**
44      * Creates a new GrammarTransition object.
45      *
46      * @param currentState
47      * The current transition
48      * @param nextState
49      * The target state
50      * @param action
51      * The action to execute. It could be null.
52      */

53     public GrammarTransition( int currentState, int nextState, GrammarAction action )
54     {
55         this.currentState = currentState;
56         this.nextState = nextState;
57         this.action = action;
58     }
59
60     /**
61      * Gets the target state
62      *
63      * @return
64      * the target state.
65      */

66     public int getNextState()
67     {
68         return nextState;
69     }
70
71
72     /**
73      * Tells if the transition has an associated action.
74      *
75      * @return
76      * <code>true</code> if an action has been asociated to the
77      * transition
78      */

79     public boolean hasAction()
80     {
81         return action != null;
82     }
83
84
85     /**
86      * Gets the action associated with the transition
87      *
88      * @return
89      * the action associated with the transition
90      */

91     public GrammarAction getAction()
92     {
93         return action;
94     }
95
96
97     /**
98      * Returns a representation of the transition as a string
99      *
100      * @param grammar
101      * the grammar which state we want a String from
102      * @param statesEnum
103      * the states enum that contains the states' names
104      * @return
105      * a representation of the transition as a string.
106      */

107     public String JavaDoc toString( int grammar, IStates statesEnum )
108     {
109
110         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
111
112         sb.append( "Transition from <" ).append( statesEnum.getState( currentState ) ).append( "> to <" ).append(
113             statesEnum.getState( nextState ) ).append( ">, action : " ).append(
114             ( ( action == null ) ? "no action" : action.toString() ) ).append( ">" );
115
116         return sb.toString();
117     }
118 }
Popular Tags