1 17 18 package SOFA.SOFAnode.Util.DFSRChecker.backend; 19 20 import java.util.TreeSet ; 21 22 import SOFA.SOFAnode.Util.DFSRChecker.CheckingResult; 23 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.AcceptingStateException; 24 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.BadActivityException; 25 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.CheckingException; 26 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.DFSRConsent; 27 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.DFSRTraverser; 28 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.InfiniteActivityException; 29 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.ItemAlreadyPresentException; 30 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.ItemNotPresentException; 31 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.NoActivityException; 32 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.Options; 33 import SOFA.SOFAnode.Util.DFSRChecker.node.ActionRepository; 34 import SOFA.SOFAnode.Util.DFSRChecker.node.AlternativeNode; 35 import SOFA.SOFAnode.Util.DFSRChecker.node.ConsentNode; 36 import SOFA.SOFAnode.Util.DFSRChecker.node.DeterministicNode; 37 import SOFA.SOFAnode.Util.DFSRChecker.node.EventNode; 38 import SOFA.SOFAnode.Util.DFSRChecker.node.InvalidParameterException; 39 import SOFA.SOFAnode.Util.DFSRChecker.node.TreeNode; 40 import SOFA.SOFAnode.Util.DFSRChecker.optimizer.OptExplicit; 41 import SOFA.SOFAnode.Util.DFSRChecker.parser.Debug; 42 import SOFA.SOFAnode.Util.DFSRChecker.state.Signature; 43 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPair; 44 45 46 50 public class ConsentBackend implements IBackend { 51 52 56 public ConsentBackend(ActionRepository repository) { 57 this.repository = repository; 58 } 59 60 70 public CheckingResult perform(TreeNode[] nodes, String [] synchroops, String [] unboundops) { 71 72 if (nodes.length < 2) { 74 return new CheckingResult(CheckingResult.ERR_OTHERERROR, "Consent backend: wrong number of items within the first array parameter (at least two required).\n"); 75 } 76 77 if (synchroops.length != nodes.length - 1) { 78 return new CheckingResult(CheckingResult.ERR_OTHERERROR, "Consent backend: wrong number of items within the second array parameter (1 lower than the number of components required).\n"); 79 } 80 81 if (Options.action == Options.ACTIONTESTCOMPLIANCE) 84 nodes[0] = invertProtocol(nodes[0], repository); 85 86 TreeNode result = new DeterministicNode(nodes[nodes.length - 1]); 87 88 TreeSet unbound = new TreeSet (); 89 for (int y = 0; y < unboundops.length; ++y) { 90 unbound.add(new Integer (repository.getItemIndex(unboundops[y]))); 91 } 92 93 for (int j = nodes.length - 2; j > 0; --j) { 94 String [] sprov; 95 TreeSet prov = new TreeSet (); 96 sprov = synchroops[j].split(","); 97 98 for (int i = 0; i < sprov.length; ++i) { 99 int index = repository.getItemIndex(sprov[i]); 100 if (index == -1) { 101 return new CheckingResult(CheckingResult.ERR_OTHERERROR, "Invalid provisions - not occuring within the protocols."); 102 } else { 103 prov.add(new Integer (index)); 104 } 105 } 106 107 result = new ConsentNode(new DeterministicNode(nodes[j]), result, prov, new TreeSet (), repository, true); 109 } 110 111 String [] sprov; 113 TreeSet prov = new TreeSet (); 114 sprov = synchroops[0].split(","); 115 116 for (int i = 0; i < sprov.length; ++i) { 117 int index = repository.getItemIndex(sprov[i]); 118 if (index == -1) { 119 return new CheckingResult(CheckingResult.ERR_OTHERERROR, "Invalid provisions - not occuring within the protocols."); 120 } else { 121 prov.add(new Integer (index)); 122 } 123 } 124 125 ConsentNode top = new ConsentNode(new DeterministicNode(nodes[0]), result, prov, unbound, repository, true); 126 127 Debug.println("State space estimate: " + top.getWeight()); 128 129 Debug.print("Optimizing the parse tree for the composition test......"); 131 132 try { 133 if (Options.forwardcutting) 134 top = (ConsentNode) top.forwardCut(repository.getAllUsedEventIndices()); 135 136 if (top != null) 137 Signature.setSize(top.getLeafCount()); 138 139 if ((Options.explicit) && (top != null)) 140 top = (ConsentNode) new OptExplicit(top, Options.explicitsize).perform(); 141 } catch (InvalidParameterException e) { 142 return new CheckingResult(CheckingResult.ERR_OTHERERROR, "Error while performing optimization. Bailing out...."); 143 } 144 145 Debug.println("done."); 146 147 148 if (top != null) { 150 151 TransitionPair.repository = repository; 152 153 DFSRTraverser dfsr1 = new DFSRTraverser(top, repository); 154 155 try { 156 dfsr1.run(new DFSRConsent(top)); 157 } catch (AcceptingStateException e) { 158 return new CheckingResult(CheckingResult.ERR_OTHERERROR, "Internal Checker error " + e.getMessage()); 159 } catch (BadActivityException e) { 160 return new CheckingResult(CheckingResult.ERR_BADACTIVITY, "Composition error detected - " + e.getMessage()); 161 } catch (NoActivityException e) { 162 return new CheckingResult(CheckingResult.ERR_NOACTIVITY, "Composition error detected - " + e.getMessage()); 163 } catch (InfiniteActivityException e) { 164 return new CheckingResult(CheckingResult.ERR_INFINITEACTIVITY, "Composition error detected - " + e.getMessage()); 165 } catch (CheckingException e) { 166 return new CheckingResult(CheckingResult.ERR_OTHERERROR, "Unknown error while checking - " + e.getMessage()); 167 } catch (InvalidParameterException e) { 168 return new CheckingResult(CheckingResult.ERR_OTHERERROR, "Error while checking (Invalid parameter exception): " + e.getMessage()); 169 } catch (ItemAlreadyPresentException e) { 170 return new CheckingResult(CheckingResult.ERR_OTHERERROR, "Error while checking (ItemAlreadyPresentException): " + e.getMessage()); 171 } catch (ItemNotPresentException e) { 172 return new CheckingResult(CheckingResult.ERR_OTHERERROR, "Error while checking (ItemNotPresentException): " + e.getMessage()); 173 } 174 } else 175 Debug.println("Warning: Automaton for consent is empty!"); 176 177 Debug.println("Protocols are composition error free."); 178 179 return new CheckingResult(CheckingResult.ERR_OK, "OK"); 180 } 181 182 public static TreeNode invertProtocol(TreeNode protocol, ActionRepository repository) { 183 184 if (protocol instanceof EventNode) { 185 return new EventNode(repository.getInverseAction(((EventNode) protocol).getEventIndex()), repository); 186 } 187 else if ((protocol instanceof AlternativeNode) && (((AlternativeNode)protocol).getorparallel())) { 188 protocol.changeChild(2, invertProtocol(protocol.getChildren()[2], repository)); 189 190 if (protocol.getChildren()[0] instanceof EventNode) 191 protocol.changeChild(0, invertProtocol(protocol.getChildren()[0], repository)); 192 193 if (protocol.getChildren()[1] instanceof EventNode) 194 protocol.changeChild(1, invertProtocol(protocol.getChildren()[1], repository)); 195 196 return protocol; 197 198 } else { 199 TreeNode[] children = protocol.getChildren(); 200 for (int i = 0; i < children.length; ++i) { 201 protocol.changeChild(i, invertProtocol(children[i], repository)); 202 } 203 204 return protocol; 205 } 206 } 207 208 209 211 214 private ActionRepository repository; 215 216 } | Popular Tags |