KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: DFSRChecker.java,v 1.4 2005/07/08 12:04:11 kofron Exp $ */
2
3 /*
4  * DFSRChecker.java
5  *
6  * Created on 1. b°ezen 2004, 14:23
7  *
8  * @author Jan Kofron
9  * @version 1.0.0
10  */

11
12 package SOFA.SOFAnode.Util.DFSRChecker;
13
14 import java.util.TreeSet JavaDoc;
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 /**
23  * This is implementation of BehaviorProtocolChecker for SOFAnode. Frame and
24  * Architecture and Interface and Frame protocols can be checked.
25  *
26  * @author Jan Kofron
27  * @version 1.0.0
28  */

29 public class DFSRChecker implements BehaviorProtocolChecker {
30
31     /** Creates a new instance of DFSRChecker */
32     public DFSRChecker() {
33     }
34
35     /**
36      * Not implemented...
37      */

38     public int StatisticsMaxStates() {
39         return -1;
40     }
41
42     /**
43      *
44      * @see SOFA.SOFAnode.Util.BehaviorProtocolChecker#frame2arch(java.lang.String,
45      * java.lang.String[], java.lang.String, java.lang.String[])
46      */

47     public String JavaDoc frame2arch(String JavaDoc frameProt, String JavaDoc[] providesOperations, String JavaDoc archProt, String JavaDoc[] ifaceOperations) {
48         ActionRepository repository = new ActionRepository();
49
50         //debug
51
/*
52          * System.out.println("Arch prot: " + archProt);
53          * System.out.println("Frame prot: " + frameProt);
54          * System.out.println("ifaceops: "); for (int i = 0; i <
55          * ifaceOperations.length; ++i) System.out.println(ifaceOperations[i]);
56          * System.out.println("providesops: "); for (int i = 0; i <
57          * providesOperations.length; ++i)
58          * System.out.println(providesOperations[i]);
59          *
60          */

61         //debug
62
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 JavaDoc ifaceops = new TreeSet JavaDoc();
69
70             for (int i = 0; i < ifaceOperations.length; ++i)
71                 ifaceops.add(new Integer JavaDoc(ActionRepository.getPure(repository.getItemIndex(ifaceOperations[i]))));
72
73             arch = new RestrictionNode(arch, ifaceops, repository);
74
75             //ComplianceBackend ce = new ComplianceBackend(repository);
76
ConsentBackend ce = new ConsentBackend(repository);
77
78             TreeNode[] nodes = new TreeNode[2];
79             nodes[1] = frame;
80             nodes[0] = arch;
81
82             String JavaDoc[] provarray = new String JavaDoc[1];
83
84             provarray[0] = "";
85             for (int i = 0; i < providesOperations.length; ++i) {
86                 // cut off the first ? and !
87
provarray[0] += providesOperations[i].substring(1) + ",";
88             }
89             provarray[0] = provarray[0].substring(0, provarray[0].length() - 1);
90
91             // that't ok, in SOFA we have no incomplete bindings so far
92
CheckingResult result = ce.perform(nodes, provarray, new String JavaDoc[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     /**
104      *
105      * @see SOFA.SOFAnode.Util.BehaviorProtocolChecker#int2frame(java.lang.String,
106      * boolean, java.lang.String[], java.lang.String)
107      */

108     public String JavaDoc int2frame(String JavaDoc ifaceProt, boolean provide, String JavaDoc[] ifaceOperations, String JavaDoc frameProt) {
109         ActionRepository repository = new ActionRepository();
110
111         //debug
112
/*
113          * System.out.println("Iface prot: " + ifaceProt);
114          * System.out.println("Frame prot: " + frameProt);
115          * System.out.println("ifaceops: "); for (int i = 0; i <
116          * ifaceOperations.length; ++i) System.out.println(ifaceOperations[i]);
117          *
118          */

119         //debug
120

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 JavaDoc ifaceops = new TreeSet JavaDoc();
128
129             for (int i = 0; i < ifaceOperations.length; ++i)
130                 ifaceops.add(new Integer JavaDoc(ActionRepository.getPure(repository.getItemIndex(ifaceOperations[i]))));
131
132             frame = new RestrictionNode(frame, ifaceops, repository);
133
134             //ComplianceBackend ce = new ComplianceBackend(repository);
135
ConsentBackend ce = new ConsentBackend(repository);
136
137             TreeNode[] nodes = new TreeNode[2];
138             // compliance is checked in the way according to the value of
139
// provide param
140
if (provide) {
141                 nodes[0] = frame;
142                 nodes[1] = iface;
143             } else {
144                 nodes[0] = iface;
145                 nodes[1] = frame;
146             }
147
148             String JavaDoc[] provarray = new String JavaDoc[1];
149
150             provarray[0] = "";
151             for (int i = 0; i < ifaceOperations.length; ++i) {
152                 // cut off the first ? and !
153
provarray[0] += ifaceOperations[i].substring(1) + ",";
154             }
155             provarray[0] = provarray[0].substring(0, provarray[0].length() - 1);
156
157             // that't ok, in SOFA we have no incomplete bindings so far
158
CheckingResult result = ce.perform(nodes, provarray, new String JavaDoc[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     /** @link dependency */
169     /* # Builder lnkBuilder; */
170
171     /** @link dependency */
172     /* # ComplianceBackend lnkComplianceBackend; */
173 }
Popular Tags