KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: AtomicNode.java,v 1.1 2005/07/13 07:27:49 kofron Exp $
3  *
4  * Copyright 2004
5  * Distributed Systems Research Group
6  * Department of Software Engineering
7  * Faculty of Mathematics and Physics
8  * Charles University, Prague
9  *
10  * Copyright 2005
11  * Formal Methods In Software Engineering Group
12  * Institute of Computer Science
13  * Academy of Sciences of the Czech Republic
14  *
15  * This code was developed by Jan Kofron <kofron@nenya.ms.mff.cuni.cz>
16  */

17
18 package SOFA.SOFAnode.Util.DFSRChecker.node;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.TreeSet JavaDoc;
23
24
25 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.CheckingException;
26 import SOFA.SOFAnode.Util.DFSRChecker.state.SimpleState;
27 import SOFA.SOFAnode.Util.DFSRChecker.state.State;
28 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPair;
29 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPairs;
30 import SOFA.SOFAnode.Util.DFSRChecker.utils.AnotatedProtocol;
31
32
33 /**
34  * This class represents an atomic action inside of a parse tree.
35  */

36 public class AtomicNode extends TreeNode {
37
38     /**
39      * Creates a new instance of AtomicNode.
40      *
41      * @param events the events forming this atomic action
42      * @param repository the action repository
43      */

44     public AtomicNode(int eventindex, TreeSet JavaDoc events, ActionRepository repository) {
45         super(getProtocol(events, repository));
46
47         this.eventIndex = eventindex;
48         this.events = events;
49         this.initState = null;
50         this.initTransitions = new TransitionPairs(new TransitionPair[1]);
51         this.initTransitions.transitions[0] = null;
52         this.secondTransitions = new TransitionPairs(new TransitionPair[0]);
53         this.nodes = new TreeNode[0];
54         this.weight = 2;
55         this.repository = repository;
56     }
57
58     /**
59      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getWeight()
60      */

61     public long getWeight() {
62         return 2;
63     }
64
65     /**
66      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getInitial()
67      */

68     public State getInitial() {
69         if (initState == null) {
70             initState = new SimpleState(0);
71             this.initTransitions.transitions[0] = new TransitionPair(eventIndex, new SimpleState(1));
72         }
73         
74         return initState;
75     }
76
77     /**
78      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#isAccepting(SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.state.State)
79      */

80     public boolean isAccepting(State state) {
81         return (((SimpleState) state).state == 1);
82     }
83
84     /**
85      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getTransitions(SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.state.State)
86      */

87     public TransitionPairs getTransitions(State state) throws InvalidParameterException, CheckingException {
88         if (((SimpleState) state).state == 0)
89             return initTransitions;
90         else if (((SimpleState) state).state == 1)
91             return secondTransitions;
92         else
93             throw new InvalidParameterException();
94     }
95
96     /**
97      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getTypeName()
98      */

99     public String JavaDoc[] getTypeName() {
100         String JavaDoc[] result = { "AtomicAction", "atomic action" };
101         return result;
102     }
103     
104     
105     public TreeNode forwardCut(TreeSet JavaDoc livingevents) {
106         return this;
107     }
108
109     /**
110      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getAnotatedProtocol(SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.state.State)
111      */

112     public AnotatedProtocol getAnotatedProtocol(State state) {
113         SimpleState sstate = (SimpleState) state;
114         String JavaDoc result = new String JavaDoc();
115         ArrayList JavaDoc indicesresult = new ArrayList JavaDoc();
116         
117         result = protocol;
118         if (state != null)
119             if (((SimpleState)state).state == 0)
120                 indicesresult.add(new Integer JavaDoc(0));
121             else
122                 indicesresult.add(new Integer JavaDoc(result.length()));
123         
124         return new AnotatedProtocol(result, indicesresult);
125     }
126     
127     /**
128      * Creates the protocol (i.e. [_actionlist]) string
129      * @param events the events creating this atomic action
130      * @param repository the action repository
131      * @return the protocol describing this aotmic action
132      */

133     private static String JavaDoc getProtocol(TreeSet JavaDoc events, ActionRepository repository) {
134         String JavaDoc p = new String JavaDoc();
135          
136         Iterator JavaDoc it = events.iterator();
137         
138         p = repository.getItemString(((Integer JavaDoc)it.next()).intValue());
139         
140         while (it.hasNext())
141             p = p + ", " + repository.getItemString(((Integer JavaDoc)it.next()).intValue());
142             
143         p = "[" + p + "]";
144         
145         return p;
146     }
147     
148     
149     /**
150      * The index of thic atomic action
151      */

152     private int eventIndex;
153     
154     /**
155      * the events forming this atomic action
156      */

157     private TreeSet JavaDoc events;
158     
159     /**
160      * Simple state for initial state representation
161      */

162     private SimpleState initState;
163     
164     /**
165      * The action repository
166      */

167     private ActionRepository repository;
168
169     /**
170      * Transitions for initial state
171      */

172     final private TransitionPairs initTransitions;
173
174     /**
175      * Transitions for the second state
176      */

177     final private TransitionPairs secondTransitions;
178
179     
180 }
181
Popular Tags