1 2 3 package SOFA.SOFAnode.Util; 4 5 class ProtocolToken extends Protocol { 6 7 private int token; 8 9 public ProtocolToken( ActionToken elem ) { 10 super( elem ); 11 token = EdgeFactory.getActionTokenIdx( elem ); 12 } 13 14 public ProtocolToken( int elem ) { 15 super( EdgeFactory.ActionTokens[elem] ); 16 token = elem; 17 } 18 19 public Protocol Copy() { 20 return new ProtocolToken( new ActionToken( ((ActionToken)element).name )); 21 } 22 23 public boolean Restrict( ActionTokenArray a ) { 24 if( token == 0 ) return true; if( !a.tokens[token] ) { 26 Debug.println(3, "Token "+EdgeFactory.ActionTokens[token].name+" is restricted out"); 27 element = new ActionToken( "NULL" ); 28 token = 0; 29 return true; 30 } else return token == 0; 31 } 32 33 public Machine createMachine() { 34 35 Machine result = new machineImpl(); 36 int start = result.addState(); 37 38 result.SetStart( start ); 39 40 switch( token ) { 41 case 0: result.AddStop( start ); break; 42 case 1: result.AddStop( start ); result.addUpdateEdge( start ); break; 43 default: 44 int stop = result.addState(); 45 result.AddStop( stop ); 46 result.addEdge( start, token, stop ); 47 } 48 return result; 49 } 50 51 public void Print( int level ) { 52 if( token == 0 ) Debug.println( level, "NULL" ); 53 else ((Printer)EdgeFactory.ActionTokens[token]).Print( level ); 54 } 55 56 public Protocol getSameType( Object p1, Object p2 ) { 57 return new ProtocolToken( (ActionToken)((ProtocolToken)p1).getElement() ); 58 } 59 60 public Protocol Left() { 61 return this.Copy(); 62 } 63 } | Popular Tags |