KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Util > ActionToken


1 /* $Id: ActionToken.java,v 1.2 2004/05/20 14:23:52 bures Exp $ */
2
3 package SOFA.SOFAnode.Util;
4
5
6 /**
7  * A String wrapper implementing action tokens with support for behavior protocol-specific
8  * renaming operations.
9  *
10  * @author Stanislav Visnovsky
11  * @version 1.0.0
12 */

13 class ActionToken implements Printer {
14
15 /**
16  * public event name for easy handling of the wrapped string
17 */

18     public String JavaDoc name;
19
20 /**
21  * Constructor for creating a new event name from string.
22  *
23  * @author Stanislav Visnovsky
24  * @version 1.0.0
25 */

26     public ActionToken( String JavaDoc s ) {
27         name = s;
28     }
29
30 /**
31  * Creates an instance of an action token by transforming the action token to
32  * the corresponding tau action token. ? or ! at the beginning of the action token
33  * will be replaced by #.
34  *
35  * @author Stanislav Visnovsky
36  * @version 1.0.0
37  * @return new tau action token
38 */

39     public ActionToken toTauActionToken() {
40         if( name.startsWith("?") || name.startsWith( "!" ) )
41             return new ActionToken((new String JavaDoc("#")).concat(name.substring(1)));
42         else return new ActionToken("#" + name );
43     }
44
45 /**
46  * Creates an instance of an action token by transforming the action token to
47  * the corresponding inverse action token.
48  * Thus, ?a will create !a and vice versa. Other starting characters are let unchanged.
49  *
50  * @author Stanislav Visnovsky
51  * @version 1.0.0
52  * @return new action token
53 */

54     public ActionToken toInverseActionToken() {
55         String JavaDoc e;
56         if( name.startsWith( "!" ) )
57             e = (new String JavaDoc( "?" )).concat(name.substring(1));
58         else if( name.startsWith( "?" ) )
59             e = (new String JavaDoc( "!" )).concat(name.substring(1));
60         else e = name;
61         return new ActionToken(e);
62     }
63
64 /**
65  * Creates an event from the action token by removing leading ?, ! or #.
66  *
67  * @author Stanislav Visnovsky
68  * @version 1.0.0
69  * @return action token as event
70 */

71     public ActionToken toEvent() {
72         String JavaDoc e = name;
73         if( name.startsWith( "!" ) || name.startsWith( "?" ) || name.startsWith( "#" ) )
74           e = name.substring(1);
75         return new ActionToken(e);
76     }
77
78 /**
79  * Tests, whether the action token is a request, i.e., ends with ^
80  *
81  * @author Stanislav Visnovsky
82  * @version 1.0.0
83  * @return result of the test
84 */

85     public boolean isRequest() {
86         return name.endsWith( "^" );
87     }
88
89 /**
90  * Tests, whether the action token is a response, i.e., ends with $
91  *
92  * @author Stanislav Visnovsky
93  * @version 1.0.0
94  * @return result of the test
95 */

96     public boolean isResponse() {
97         return name.endsWith( "$" );
98     }
99
100 /**
101  * Tests, whether the action token is a general event, i.e., ends with ~
102  *
103  * @author Stanislav Visnovsky
104  * @version 1.0.0
105  * @return result of the test
106 */

107     public boolean isGeneralEvent() {
108         return name.endsWith( "~" );
109     }
110
111     public boolean isEvent() {
112     return ! ( name.startsWith("?") || name.startsWith("!") || name.startsWith( "#" ));
113     }
114
115 /**
116  * Tests, whether the action token is a special event, ie. []
117  *
118  * @author Stanislav Visnovsky
119  * @version 1.0.0
120  * @return result of the test
121 */

122     public boolean isSpecial() {
123         return name.startsWith( "[" );
124     }
125
126 /**
127  * Tests, whether the action token is a simple call abbreviation, i.e.,
128  * it does not ends by $,^ or ~
129  *
130  * @author Stanislav Visnovsky
131  * @version 1.0.0
132  * @return result of the test
133 */

134     public boolean isSimpleCall() {
135         return ! ( this.isResponse() || this.isRequest() || this.isGeneralEvent() || this.isSpecial() );
136     }
137
138     public String JavaDoc getHashKey() {
139     return name.intern();
140     }
141     
142     public void Print( int level ) {
143     Debug.println( level, name );
144     }
145     
146     public void Print( ) {
147     this.Print( 1 );
148     }
149 }
Popular Tags