KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > xjc > runtime > UnmarshallingContext


1 package com.sun.tools.xjc.runtime;
2
3 import javax.xml.bind.ValidationEvent;
4 import javax.xml.namespace.NamespaceContext JavaDoc;
5
6 import org.xml.sax.Attributes JavaDoc;
7 import org.xml.sax.Locator JavaDoc;
8 import org.xml.sax.SAXException JavaDoc;
9
10 import com.sun.xml.bind.unmarshaller.Tracer;
11
12 /**
13  * Methods exposed by the unmarshalling coordinator object
14  * to the generated code.
15  *
16  * This interface will be implemented by the coordinator, which
17  * converts whatever events (e.g., SAX) into unmarshalling events.
18  *
19  * <p>
20  * Errors detected by the AbstractUnmarshallingEventHandlerImpl-derived classes should
21  * be either thrown as {@link UnrepotedException} or reported through
22  * the handleEvent method of this interface.
23  *
24  * @author
25  * <a HREF="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
26  */

27 public interface UnmarshallingContext extends NamespaceContext JavaDoc
28 {
29     /** Obtains a reference to the current grammar info. */
30     GrammarInfo getGrammarInfo();
31     
32     
33     
34     /**
35      * Pushes the current content handler into the stack
36      * and registers the newly specified content handler so
37      * that it can receive SAX events.
38      *
39      * @param memento
40      * When this newly specified handler will be removed from the stack,
41      * the leaveChild event will be fired to the parent handler
42      * with this memento.
43      */

44     void pushContentHandler( UnmarshallingEventHandler handler, int memento );
45     
46     /**
47      * Pops a content handler from the stack and registers
48      * it as the current content handler.
49      *
50      * <p>
51      * This method will also fire the leaveChild event with the
52      * associated memento.
53      */

54     void popContentHandler() throws SAXException JavaDoc;
55     
56     /**
57      * Gets the current handler.
58      */

59     UnmarshallingEventHandler getCurrentHandler();
60
61     /**
62      * Returns a list of prefixes newly declared on this element.
63      *
64      * This method has to be called after the {@link #pushAttributes}
65      * method is called.
66      *
67      * @return
68      * A possible zero-length array of prefixes. The default prefix
69      * is represented by the empty string.
70      */

71     String JavaDoc[] getNewlyDeclaredPrefixes();
72     
73     /**
74      * Returns a list of all in-scope prefixes.
75      *
76      * @return
77      * A possible zero-length array of prefixes. The default prefix
78      * is represented by the empty string.
79      */

80     String JavaDoc[] getAllDeclaredPrefixes();
81     
82     
83     /**
84      * Stores a new attribute set.
85      * This method should be called by the generated code
86      * when it "eats" an enterElement event.
87      *
88      * @param collectText
89      * false if the context doesn't need to fire text events
90      * for texts inside this element. True otherwise.
91      */

92     void pushAttributes( Attributes JavaDoc atts, boolean collectText );
93     
94     /**
95      * Discards the previously stored attribute set.
96      * This method should be called by the generated code
97      * when it "eats" a leaveElement event.
98      */

99     void popAttributes();
100     
101     /**
102      * Gets the index of the attribute with the specified name.
103      * This is usually faster when you only need to test with
104      * a simple name.
105      *
106      * @return
107      * -1 if not found.
108      */

109     int getAttribute( String JavaDoc uri, String JavaDoc name );
110     
111     /**
112      * Gets all the unconsumed attributes.
113      * If you need to find attributes based on more complex filter,
114      * you need to use this method.
115      */

116     Attributes JavaDoc getUnconsumedAttributes();
117     
118     /**
119      * Fires an attribute event for the specified attribute,
120      * and marks the attribute as "used".
121      */

122     void consumeAttribute( int idx ) throws SAXException JavaDoc;
123     
124     /**
125      * Marks the attribute as "used" and return the value of the attribute.
126      */

127     String JavaDoc eatAttribute( int idx ) throws SAXException JavaDoc;
128     
129     /**
130      * Adds a job that will be executed at the last of the unmarshalling.
131      * This method is used to support ID/IDREF feature, but it can be used
132      * for other purposes as well.
133      *
134      * @param job
135      * The run method of this object is called.
136      */

137     void addPatcher( Runnable JavaDoc job );
138     // the patcher can throw JAXBException?
139

140     /**
141      * Adds the object which is currently being unmarshalled
142      * to the ID table.
143      *
144      * @return
145      * Returns the value passed as the parameter.
146      * This is a hack, but this makes it easier for ID
147      * transducer to do its job.
148      */

149     String JavaDoc addToIdTable( String JavaDoc id );
150     //
151
// throwing an exception is one way. Overwriting the previous one
152
// is another way. The latter allows us to process invalid documents,
153
// while the former makes it impossible to handle them.
154
//
155
// I prefer to be flexible in terms of invalid document handling,
156
// so chose not to throw an exception.
157
//
158
// I believe this is an implementation choice, not the spec issue.
159
// -kk
160

161     /**
162      * Looks up the ID table and gets associated object.
163      *
164      * @return
165      * If there is no object associated with the given id,
166      * this method returns null.
167      */

168     Object JavaDoc getObjectFromId( String JavaDoc id );
169     // if we don't find ID.
170

171     
172     /**
173      * Gets the current source location information.
174      */

175     Locator JavaDoc getLocator();
176     
177     /**
178      * Reports an error to the user, and asks if s/he wants
179      * to recover. If the canRecover flag is false, regardless
180      * of the client instruction, an exception will be thrown.
181      *
182      * Only if the flag is true and the user wants to recover from an error,
183      * the method returns normally.
184      *
185      * The thrown exception will be catched by the unmarshaller.
186      */

187     void handleEvent( ValidationEvent event, boolean canRecover ) throws SAXException JavaDoc;
188     
189     
190 //
191
//
192
// the copy of the org.relaxng.datatype.ValidationContext interface.
193
//
194
// this interface doesn't derive from that interface so that we don't have
195
// a direct dependency to it, but we provide the same functionality so that
196
// we can adopt this interface into the ValidationContext interface.
197
//
198
// see the ValidationContextAdaptor class.
199
String JavaDoc resolveNamespacePrefix( String JavaDoc prefix );
200     String JavaDoc getBaseUri();
201     boolean isUnparsedEntity( String JavaDoc entityName );
202     boolean isNotation( String JavaDoc notationName );
203     
204     
205     
206     
207 // DBG
208
/**
209      * Gets a tracer object.
210      *
211      * Tracer can be used to trace the unmarshalling behavior.
212      * Note that to debug the unmarshalling process,
213      * you have to configure XJC so that it will emit trace codes
214      * in the unmarshaller.
215      */

216     Tracer getTracer();
217 }
218
Popular Tags