KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: EventNode.java,v 1.4 2005/07/08 12:04:12 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.TreeSet JavaDoc;
22
23
24 import SOFA.SOFAnode.Util.DFSRChecker.state.SimpleState;
25 import SOFA.SOFAnode.Util.DFSRChecker.state.State;
26 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPair;
27 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPairs;
28 import SOFA.SOFAnode.Util.DFSRChecker.utils.AnotatedProtocol;
29
30
31 /**
32  * This is a class extending TreeNode representing an event node within the
33  * tree.
34  */

35 public class EventNode extends TreeNode {
36
37     /** Creates a new instance of EventNode */
38     public EventNode(int eventindex, ActionRepository repository) {
39         super(repository.getItemString(eventindex));
40         this.eventIndex = eventindex;
41
42         this.initState = new SimpleState(0);
43
44         this.initTransitions = new TransitionPairs(new TransitionPair[1]);
45         this.initTransitions.transitions[0] = new TransitionPair(eventindex, new SimpleState(1));
46
47         this.secondTransitions = new TransitionPairs(new TransitionPair[0]);
48
49         this.nodes = new TreeNode[0];
50
51         this.weight = 2;
52         
53     }
54
55     /**
56      *
57      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getInitial()
58      */

59     public State getInitial() {
60         return initState;
61     }
62
63     /**
64      *
65      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#isAccepting(SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.state.State)
66      */

67     public boolean isAccepting(State state) {
68         return (((SimpleState) state).state == 1);
69     }
70
71     /**
72      *
73      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getTransitions(SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.state.State)
74      */

75     public TransitionPairs getTransitions(State state) throws InvalidParameterException {
76         if (((SimpleState) state).state == 0)
77             return initTransitions;
78         else if (((SimpleState) state).state == 1)
79             return secondTransitions;
80         else
81             throw new InvalidParameterException();
82     }
83
84     /**
85      *
86      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getWeight()
87      */

88     public long getWeight() {
89         return 2;
90     }
91
92     /**
93      *
94      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#forwardCut(java.util.TreeSet)
95      */

96     public TreeNode forwardCut(TreeSet JavaDoc livingevents) {
97         if (livingevents.contains(new Integer JavaDoc(eventIndex)))
98             return this;
99         else
100             return null;
101     }
102
103     /**
104      * @return the symbolic name of the treenode denoting its type
105      */

106     public String JavaDoc[] getTypeName() {
107         String JavaDoc[] result = { "Event", "" };
108         return result;
109     }
110
111     /**
112      * @return the eventindex
113      */

114     public int getEventIndex() {
115         return eventIndex;
116     }
117     
118     public int getLeafCount() {
119         return 1;
120     }
121
122     /**
123      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getAnotatedProtocol(SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.state.State)
124      */

125     public AnotatedProtocol getAnotatedProtocol(State state) {
126         SimpleState sstate = (SimpleState) state;
127         String JavaDoc result = new String JavaDoc();
128         ArrayList JavaDoc indicesresult = new ArrayList JavaDoc();
129         
130         result = protocol;
131         if (state != null)
132             if (((SimpleState)state).state == 0)
133                 indicesresult.add(new Integer JavaDoc(0));
134             else
135                 indicesresult.add(new Integer JavaDoc(result.length()));
136         
137         return new AnotatedProtocol(result, indicesresult);
138     }
139     
140     
141     //--------------------------------------------------------------------------
142
/**
143      * event index
144      */

145     final private int eventIndex;
146
147     /**
148      * Simple state for initial state representation
149      */

150     private SimpleState initState;
151     
152     /**
153      * Transitions for initial state
154      */

155     final private TransitionPairs initTransitions;
156
157     /**
158      * Transitions for the second state
159      */

160     final private TransitionPairs secondTransitions;
161
162 }
Popular Tags