1 2 3 11 12 package SOFA.SOFAnode.Util.DFSRChecker; 13 14 import java.util.TreeSet ; 15 16 import SOFA.SOFAnode.Util.BehaviorProtocolChecker; 17 import SOFA.SOFAnode.Util.SyntaxErrorException; 18 import SOFA.SOFAnode.Util.DFSRChecker.backend.*; 19 import SOFA.SOFAnode.Util.DFSRChecker.node.*; 20 import SOFA.SOFAnode.Util.DFSRChecker.parser.*; 21 22 29 public class DFSRChecker implements BehaviorProtocolChecker { 30 31 32 public DFSRChecker() { 33 } 34 35 38 public int StatisticsMaxStates() { 39 return -1; 40 } 41 42 47 public String frame2arch(String frameProt, String [] providesOperations, String archProt, String [] ifaceOperations) { 48 ActionRepository repository = new ActionRepository(); 49 50 61 Builder parser = new Builder(repository); 63 64 try { 65 TreeNode frame = parser.build(new StringTokenizer(frameProt)); 66 TreeNode arch = parser.build(new StringTokenizer(archProt)); 67 68 TreeSet ifaceops = new TreeSet (); 69 70 for (int i = 0; i < ifaceOperations.length; ++i) 71 ifaceops.add(new Integer (ActionRepository.getPure(repository.getItemIndex(ifaceOperations[i])))); 72 73 arch = new RestrictionNode(arch, ifaceops, repository); 74 75 ConsentBackend ce = new ConsentBackend(repository); 77 78 TreeNode[] nodes = new TreeNode[2]; 79 nodes[1] = frame; 80 nodes[0] = arch; 81 82 String [] provarray = new String [1]; 83 84 provarray[0] = ""; 85 for (int i = 0; i < providesOperations.length; ++i) { 86 provarray[0] += providesOperations[i].substring(1) + ","; 88 } 89 provarray[0] = provarray[0].substring(0, provarray[0].length() - 1); 90 91 CheckingResult result = ce.perform(nodes, provarray, new String [0]); 93 if (result.type == CheckingResult.ERR_OK) 94 return null; 95 else 96 return result.description; 97 98 } catch (SyntaxErrorException e) { 99 return "Error: SyntaxErrorException: " + e.getMessage(); 100 } 101 } 102 103 108 public String int2frame(String ifaceProt, boolean provide, String [] ifaceOperations, String frameProt) { 109 ActionRepository repository = new ActionRepository(); 110 111 119 121 Builder parser = new Builder(repository); 122 123 try { 124 TreeNode frame = parser.build(new StringTokenizer(frameProt)); 125 TreeNode iface = parser.build(new StringTokenizer(ifaceProt)); 126 127 TreeSet ifaceops = new TreeSet (); 128 129 for (int i = 0; i < ifaceOperations.length; ++i) 130 ifaceops.add(new Integer (ActionRepository.getPure(repository.getItemIndex(ifaceOperations[i])))); 131 132 frame = new RestrictionNode(frame, ifaceops, repository); 133 134 ConsentBackend ce = new ConsentBackend(repository); 136 137 TreeNode[] nodes = new TreeNode[2]; 138 if (provide) { 141 nodes[0] = frame; 142 nodes[1] = iface; 143 } else { 144 nodes[0] = iface; 145 nodes[1] = frame; 146 } 147 148 String [] provarray = new String [1]; 149 150 provarray[0] = ""; 151 for (int i = 0; i < ifaceOperations.length; ++i) { 152 provarray[0] += ifaceOperations[i].substring(1) + ","; 154 } 155 provarray[0] = provarray[0].substring(0, provarray[0].length() - 1); 156 157 CheckingResult result = ce.perform(nodes, provarray, new String [0]); 159 if (result.type == CheckingResult.ERR_OK) 160 return null; 161 else 162 return result.description; 163 } catch (SyntaxErrorException e) { 164 return "Error: SyntaxErrorException: " + e.getMessage(); 165 } 166 } 167 168 169 170 171 172 173 } | Popular Tags |