KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: ActionTokenArray.java,v 1.2 2004/05/20 14:23:53 bures Exp $ */
2
3 package SOFA.SOFAnode.Util;
4
5 import java.util.Hashtable JavaDoc;
6 import java.util.Iterator JavaDoc;
7
8 /**
9  * The class for collection of action tokens with support for
10  * lookup by action token with the same event name.
11  *
12  * @author Stanislav Visnovsky
13  * @version 1.0.0
14  *
15  * @see ActionToken
16 */

17
18 public class ActionTokenArray {
19
20     public boolean tokens[];
21
22     public int size;
23
24 /**
25  * Simple constructor of an empty array. Its size is determined from number
26  * of all action tokens in EdgeFactory table.
27  *
28  * @author Stanislav Visnovsky
29  * @version 2.0.0
30  * @see EdgeFactory#ActionTokens
31  */

32     public ActionTokenArray() {
33         tokens = new boolean[ EdgeFactory.getActionTokensNum() ];
34     size = EdgeFactory.getActionTokensNum();
35     }
36
37 /**
38  * Simple copy constructor of a collection from hashtable. This requires that
39  * EdgeFactory.ActionTokens contains all action tokens in hashtable.
40  *
41  * @author Stanislav Visnovsky
42  * @version 2.0.0
43  * @see EdgeFactory.ActionTokens
44  */

45     public ActionTokenArray( Hashtable JavaDoc h ) {
46     this();
47     Debug.println(3, "ActionTokenArray: This is hashtable copy constructor");
48     for( Iterator JavaDoc i = h.values().iterator(); i.hasNext(); ) {
49         ActionToken t = (ActionToken)i.next() ;
50         if( t.isEvent() ) {
51         int j = EdgeFactory.getActionTokenIdx( new ActionToken( "?"+t.name) );
52         this.tokens[j] = true;
53 // this.tokens[ EdgeFactory.inverseActionTokens[j]] = true;
54
} else tokens[ EdgeFactory.getActionTokenIdx( t )] = true;
55     }
56     Debug.println(3, "ActionTokenArray: Finished hashtable copy constructor");
57     }
58   
59 /**
60  * Simple copy constructor of a collection from other array
61  *
62  * @author Stanislav Visnovsky
63  * @version 2.0.0
64  */

65     public ActionTokenArray( ActionTokenArray h ) {
66     this();
67     for( int i = 0 ; i < h.size ; i ++ )
68         tokens[i] = h.tokens[i];
69     }
70   
71 /**
72  * Constructor of an collection from an array of strings representing action tokens or events.
73  * If an element does not have an action suffix, it creates two action tokens correponding to
74  * the request and the response.
75  *
76  * @author Stanislav Visnovsky
77  * @version 2.0.0
78  */

79     public ActionTokenArray( String JavaDoc[] tokens ) {
80
81     this.tokens = new boolean[ EdgeFactory.getActionTokensNum()];
82     size = EdgeFactory.getActionTokensNum();
83
84     // fill the collection
85
for( int i=0; i<tokens.length ; i++ ) {
86             ActionToken a = new ActionToken(tokens[i]);
87             if( a.isSimpleCall() ) {
88         int j = EdgeFactory.getActionTokenIdx( new ActionToken(tokens[i]+"^") );
89         this.tokens[j] = true;
90         j = EdgeFactory.getActionTokenIdx( new ActionToken(tokens[i]+"$").toInverseActionToken() );
91         this.tokens[ j ] = true;
92         } else this.tokens[EdgeFactory.getActionTokenIdx( new ActionToken( tokens[i]))] = true;
93     }
94     }
95
96 /**
97  * Method for membership test for the action token with the same
98  * event as t has.
99  *
100  * @author Stanislav Visnovsky
101  * @version 2.0.0
102  *
103  * @return true if collection contains corresponding action token
104  * @param t t with event to lookup
105  *
106  * @see ActionToken#toInverseActionToken
107  * @see ActionToken#toTauActionToken
108  */

109     public boolean containsWithEventName( int tran ) {
110     if( tran == -1 ) return false;
111         int inverse = EdgeFactory.inverseActionTokens[tran];
112     if( inverse == -1 ) inverse = tran;
113         int tau = EdgeFactory.tauActionTokens[tran];
114     if( tau == -1 ) tau = tran;
115
116     return ( tokens[ tran ] || tokens[ inverse ] || tokens[tau] );
117     }
118
119 /**
120  * Transforms the collection into a comma-separated list of action tokens.
121  *
122  * @author Stanislav Visnovsky
123  * @version 1.0.0
124  *
125  * @return generated list
126  *
127  */

128     public String JavaDoc toList() {
129         String JavaDoc l = "";
130     for( int i = 0 ; i<size ; i ++ )
131         if( tokens[i] )
132         l = l + "," + EdgeFactory.ActionTokens[i].name;
133
134         if( l != "" ) l = l.substring(1); // eliminate leading ,
135
Debug.println( 3, "List of tokens: "+l );
136         return l;
137     }
138 }
Popular Tags