2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu
.java
.beans
.encoder
;
41 import java
.util
.HashMap
;
43 /** <p>Provides the infrastructure for the state machine and the transition
46 * <p>Each states knows a set of successor. There can be one successor for
47 * every transition variant. Furthermore a state knows about a default
48 * successor which is taken when there is no special setup for a
51 * @author Robert Schuster (robertschuster@fsfe.org)
54 public abstract class ScannerState
57 static final int TRANSITION_METHOD_INVOCATION
= 0;
59 static final int TRANSITION_STATIC_METHOD_INVOCATION
= 1;
61 static final int TRANSITION_STATIC_FIELD_ACCESS
= 2;
63 static final int TRANSITION_CLASS_RESOLUTION
= 3;
65 static final int TRANSITION_OBJECT_INSTANTIATION
= 4;
67 static final int TRANSITION_PRIMITIVE_INSTANTIATION
= 5;
69 static final int TRANSITION_OBJECT_ARRAY_INSTANTIATION
= 6;
71 static final int TRANSITION_PRIMITIVE_ARRAY_INSTANTIATION
= 7;
73 static final int TRANSITION_ARRAY_SET
= 8;
75 static final int TRANSITION_ARRAY_GET
= 9;
77 static final int TRANSITION_LIST_SET
= 10;
79 static final int TRANSITION_LIST_GET
= 11;
81 static final int TRANSITION_NULL_OBJECT
= 12;
83 static final int TRANSITION_STRING_REFERENCE
= 13;
85 static final int TRANSITION_OBJECT_REFERENCE
= 14;
87 static final int TRANSITION_FIRST
= 0;
89 static final int TRANSITION_LAST
= 14;
91 static final String DEFAULT_STATE_NAME
= "default";
93 String defaultSuccessor
= DEFAULT_STATE_NAME
;
95 static String
[] transitionNames
= { "METHOD_INVOCATION", "STATIC_METHOD_INVOCATION",
96 "STATIC_FIELD_ACCESS", "CLASS_RESOLUTION",
97 "OBJECT_INSTANTIATION",
98 "PRIMITIVE_INSTANTIATION", "OBJECT_ARRAY_INSTANTIATION",
99 "PRIMITIVE_ARRAY_INSTANTIATION",
100 "ARRAY_SET", "ARRAY_GET", "LIST_SET", "LIST_GET",
101 "NULL_OBJECT", "STRING_REFERENCE", "OBJECT_REFERENCE" };
104 * Stores the transition setup as the relation
105 * transition->successor's state name.
107 HashMap transitions
= new HashMap();
115 final void init(String newName
)
117 assert (name
== null);
122 final String
getName()
127 final void enter(Context ctx
)
135 protected void enterImpl(Context ctx
)
139 final Context
context()
150 * <p>Stores a successor's state name for a certain transition.</p>
152 * <p>This method is only used at the configuration time of the state
155 * @param transition One of the transition constants.
156 * @param stateName The state name of the successor.
158 final void putSuccessor(int transition
, String stateName
)
160 assert (transition
>= TRANSITION_FIRST
&& transition
<= TRANSITION_LAST
) :
161 "Transition identifier '" + transition
+ "' is unknown.";
163 transitions
.put(new Integer(transition
), stateName
);
166 /** <p>Retrieves a the state name of a successor for the given transition
169 * <p>Returns the default successor's state name if no special setup was
172 * @param transition One of the transition constants.
173 * @return The state name of the successor.
175 final String
getSuccessor(int transition
)
177 String state
= (String
) transitions
.get(new Integer(transition
));
179 return (state
== null) ? defaultSuccessor
: state
;
183 * Sets the name for the default successor state.
185 * @param newDefaultSuccessor The default successor's state name.
187 final void setDefaultSuccessor(String newDefaultSuccessor
)
189 defaultSuccessor
= newDefaultSuccessor
;
192 abstract void methodInvocation(String methodName
);
194 abstract void staticMethodInvocation(String className
, String methodName
);
196 abstract void staticFieldAccess(String className
, String fieldName
);
198 abstract void classResolution(String className
);
200 abstract void objectInstantiation(String className
, ObjectId objectId
);
202 abstract void primitiveInstantiation(String primitiveName
,
203 String valueAsString
);
205 abstract void objectArrayInstantiation(String arrayClassName
, String lengthAsString
, ObjectId objectId
);
207 abstract void primitiveArrayInstantiation(String arrayClassName
, String lengthAsString
, ObjectId objectId
);
209 abstract void arraySet(String indexAsString
);
211 abstract void arrayGet(String indexAsString
);
213 abstract void listGet();
215 abstract void listSet();
217 abstract void nullObject();
219 abstract void stringReference(String string
);
221 abstract void objectReference(ObjectId id
);
224 * <p>A special event that does not provoke a direct transition.</p>
226 * <p>Instead the transition is done by the <code>ScanEngine</code>: It goes
227 * back to the previous state and just uses this method to inform the state
228 * about this happening.</p>