1 2 package SOFA.SOFAnode.Made.CDL; 3 import java.rmi.RemoteException ; 4 5 import SOFA.SOFAnode.Made.TIR.ProtocolDef; 6 import SOFA.SOFAnode.Made.TIR.ProtocolMode; 7 import SOFA.SOFAnode.Made.TIR.ProtocolOperDef; 8 import SOFA.SOFAnode.Made.TIR.ProtocolOperKind; 9 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate; 10 11 abstract class CompProtOper { 12 public int type; 13 public CompProtOper(int t) { type = t; } 14 abstract public String toText(); 15 16 public static ProtocolOperDef toNormalIface(CompProtOper p, ProtocolDef newprot) throws CDLExceptRemote, CDLExceptToNormal { 17 try { 18 String [] s = new String [1]; 19 ProtocolOperDef ret = null; 20 switch (p.type) { 21 case CompProtKind.p_operand: 22 s[0]=((CompProtOperand) p).operand; 23 ret = newprot.create_operand(ProtocolMode.pm_none, s); 24 break; 25 case CompProtKind.p_nulloperand: 26 ret = newprot.create_nulloperand(); 27 break; 28 case CompProtKind.p_metaoperand: 29 ret = newprot.create_metaoperand(((CompProtMetaOperand) p).name); 30 break; 31 case CompProtKind.p_repetition: 32 ret = newprot.create_unoperation(ProtocolOperKind.pok_repetition, toNormalIface(((CompProtUnOper) p).operand, newprot)); 33 break; 34 case CompProtKind.p_andparallel: 35 ret = newprot.create_binoperation(ProtocolOperKind.pok_andparallel, toNormalIface(((CompProtBinOper) p).operand1, newprot), toNormalIface(((CompProtBinOper) p).operand2, newprot)); 36 break; 37 case CompProtKind.p_orparallel: 38 ret = newprot.create_binoperation(ProtocolOperKind.pok_orparallel, toNormalIface(((CompProtBinOper) p).operand1, newprot), toNormalIface(((CompProtBinOper) p).operand2, newprot)); 39 break; 40 case CompProtKind.p_alternative: 41 ret = newprot.create_binoperation(ProtocolOperKind.pok_alternative, toNormalIface(((CompProtBinOper) p).operand1, newprot), toNormalIface(((CompProtBinOper) p).operand2, newprot)); 42 break; 43 case CompProtKind.p_sequence: 44 ret = newprot.create_binoperation(ProtocolOperKind.pok_sequence, toNormalIface(((CompProtBinOper) p).operand1, newprot), toNormalIface(((CompProtBinOper) p).operand2, newprot)); 45 break; 46 case CompProtKind.p_restriction: 47 ret = newprot.create_binoperation(ProtocolOperKind.pok_restriction, toNormalIface(((CompProtBinOper) p).operand1, newprot), toNormalIface(((CompProtBinOper) p).operand2, newprot)); 48 break; 49 default: break; 50 } 51 if (ret==null) 52 throw new CDLExceptToNormal("Can't create protocol"); 53 return ret; 54 } catch (RemoteException e) { 55 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 56 } catch (TIRExceptCreate e) { 57 throw new CDLExceptToNormal("Can't create protocol: "+e.getMessage()); 58 } 59 } 60 61 public static ProtocolOperDef toNormalFrame(CompProtOper p, ProtocolDef newprot) throws CDLExceptRemote, CDLExceptToNormal { 62 try { 63 String [] s = new String [2]; 64 ProtocolOperDef ret = null; 65 switch (p.type) { 66 case CompProtKind.p_operand: 67 s[0]=((CompProtOperand) p).ifacename; 68 s[1]=((CompProtOperand) p).operand; 69 ret = newprot.create_operand(((CompProtOperand) p).mode, s); 70 break; 71 case CompProtKind.p_nulloperand: 72 ret = newprot.create_nulloperand(); 73 break; 74 case CompProtKind.p_metaoperand: 75 ret = newprot.create_metaoperand(((CompProtMetaOperand) p).name); 76 break; 77 case CompProtKind.p_nestedoperand: 78 s[0]=((CompProtNestedOperand) p).ifacename; 79 s[1]=((CompProtNestedOperand) p).operand; 80 ret = newprot.create_nestedoperand(((CompProtNestedOperand) p).mode, s, toNormalFrame(((CompProtNestedOperand) p).nestOperand, newprot)); 81 break; 82 case CompProtKind.p_repetition: 83 ret = newprot.create_unoperation(ProtocolOperKind.pok_repetition, toNormalFrame(((CompProtUnOper) p).operand, newprot)); 84 break; 85 case CompProtKind.p_andparallel: 86 ret = newprot.create_binoperation(ProtocolOperKind.pok_andparallel, toNormalFrame(((CompProtBinOper) p).operand1, newprot), toNormalFrame(((CompProtBinOper) p).operand2, newprot)); 87 break; 88 case CompProtKind.p_orparallel: 89 ret = newprot.create_binoperation(ProtocolOperKind.pok_orparallel, toNormalFrame(((CompProtBinOper) p).operand1, newprot), toNormalFrame(((CompProtBinOper) p).operand2, newprot)); 90 break; 91 case CompProtKind.p_alternative: 92 ret = newprot.create_binoperation(ProtocolOperKind.pok_alternative, toNormalFrame(((CompProtBinOper) p).operand1, newprot), toNormalFrame(((CompProtBinOper) p).operand2, newprot)); 93 break; 94 case CompProtKind.p_sequence: 95 ret = newprot.create_binoperation(ProtocolOperKind.pok_sequence, toNormalFrame(((CompProtBinOper) p).operand1, newprot), toNormalFrame(((CompProtBinOper) p).operand2, newprot)); 96 break; 97 case CompProtKind.p_restriction: 98 ret = newprot.create_binoperation(ProtocolOperKind.pok_restriction, toNormalFrame(((CompProtBinOper) p).operand1, newprot), toNormalFrame(((CompProtBinOper) p).operand2, newprot)); 99 break; 100 default: break; 101 } 102 if (ret==null) 103 throw new CDLExceptToNormal("Can't create protocol"); 104 return ret; 105 } catch (RemoteException e) { 106 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 107 } catch (TIRExceptCreate e) { 108 throw new CDLExceptToNormal("Can't create protocol: "+e.getMessage()); 109 } 110 } 111 } 112 | Popular Tags |