1
2
3
4
5
6
7
8 package de.nierbeck.timeTrack.model.impl.runtime;
9
10 import javax.xml.bind.ValidationEvent;
11 import javax.xml.namespace.NamespaceContext;
12
13 import org.xml.sax.Attributes;
14 import org.xml.sax.Locator;
15 import org.xml.sax.SAXException;
16
17 import com.sun.xml.bind.unmarshaller.Tracer;
18
19 /***
20 * Methods exposed by the unmarshalling coordinator object to the generated
21 * code.
22 *
23 * This interface will be implemented by the coordinator, which converts
24 * whatever events (e.g., SAX) into unmarshalling events.
25 *
26 * <p>
27 * Errors detected by the AbstractUnmarshallingEventHandlerImpl-derived classes
28 * should be either thrown as {@link UnrepotedException} or reported through the
29 * handleEvent method of this interface.
30 *
31 * @author <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
32 */
33 public interface UnmarshallingContext extends NamespaceContext {
34 /*** Obtains a reference to the current grammar info. */
35 GrammarInfo getGrammarInfo();
36
37 /***
38 * Pushes the current content handler into the stack and registers the newly
39 * specified content handler so that it can receive SAX events.
40 *
41 * @param memento
42 * When this newly specified handler will be removed from the
43 * stack, the leaveChild event will be fired to the parent
44 * handler with this memento.
45 */
46 void pushContentHandler(UnmarshallingEventHandler handler, int memento);
47
48 /***
49 * Pops a content handler from the stack and registers it as the current
50 * content handler.
51 *
52 * <p>
53 * This method will also fire the leaveChild event with the associated
54 * memento.
55 */
56 void popContentHandler() throws SAXException;
57
58 /***
59 * Gets the current handler.
60 */
61 UnmarshallingEventHandler getCurrentHandler();
62
63 /***
64 * Returns a list of prefixes newly declared on this element.
65 *
66 * This method has to be called after the {@link #pushAttributes} method is
67 * called.
68 *
69 * @return A possible zero-length array of prefixes. The default prefix is
70 * represented by the empty string.
71 */
72 String[] getNewlyDeclaredPrefixes();
73
74 /***
75 * Returns a list of all in-scope prefixes.
76 *
77 * @return A possible zero-length array of prefixes. The default prefix is
78 * represented by the empty string.
79 */
80 String[] getAllDeclaredPrefixes();
81
82 /***
83 * Stores a new attribute set. This method should be called by the generated
84 * code when it "eats" an enterElement event.
85 *
86 * @param collectText
87 * false if the context doesn't need to fire text events for
88 * texts inside this element. True otherwise.
89 */
90 void pushAttributes(Attributes atts, boolean collectText);
91
92 /***
93 * Discards the previously stored attribute set. This method should be
94 * called by the generated code when it "eats" a leaveElement event.
95 */
96 void popAttributes();
97
98 /***
99 * Gets the index of the attribute with the specified name. This is usually
100 * faster when you only need to test with a simple name.
101 *
102 * @return -1 if not found.
103 */
104 int getAttribute(String uri, String name);
105
106 /***
107 * Gets all the unconsumed attributes. If you need to find attributes based
108 * on more complex filter, you need to use this method.
109 */
110 Attributes getUnconsumedAttributes();
111
112 /***
113 * Fires an attribute event for the specified attribute, and marks the
114 * attribute as "used".
115 */
116 void consumeAttribute(int idx) throws SAXException;
117
118 /***
119 * Marks the attribute as "used" and return the value of the attribute.
120 */
121 String eatAttribute(int idx) throws SAXException;
122
123 /***
124 * Adds a job that will be executed at the last of the unmarshalling. This
125 * method is used to support ID/IDREF feature, but it can be used for other
126 * purposes as well.
127 *
128 * @param job
129 * The run method of this object is called.
130 */
131 void addPatcher(Runnable job);
132
133
134
135 /***
136 * Adds the object which is currently being unmarshalled to the ID table.
137 *
138 * @return Returns the value passed as the parameter. This is a hack, but
139 * this makes it easier for ID transducer to do its job.
140 */
141 String addToIdTable(String id);
142
143
144
145
146
147
148
149
150
151
152
153
154 /***
155 * Looks up the ID table and gets associated object.
156 *
157 * @return If there is no object associated with the given id, this method
158 * returns null.
159 */
160 Object getObjectFromId(String id);
161
162
163
164 /***
165 * Gets the current source location information.
166 */
167 Locator getLocator();
168
169 /***
170 * Reports an error to the user, and asks if s/he wants to recover. If the
171 * canRecover flag is false, regardless of the client instruction, an
172 * exception will be thrown.
173 *
174 * Only if the flag is true and the user wants to recover from an error, the
175 * method returns normally.
176 *
177 * The thrown exception will be catched by the unmarshaller.
178 */
179 void handleEvent(ValidationEvent event, boolean canRecover)
180 throws SAXException;
181
182
183
184
185
186
187
188
189
190
191 String resolveNamespacePrefix(String prefix);
192
193 String getBaseUri();
194
195 boolean isUnparsedEntity(String entityName);
196
197 boolean isNotation(String notationName);
198
199
200 /***
201 * Gets a tracer object.
202 *
203 * Tracer can be used to trace the unmarshalling behavior. Note that to
204 * debug the unmarshalling process, you have to configure XJC so that it
205 * will emit trace codes in the unmarshaller.
206 */
207 Tracer getTracer();
208 }