325N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 325N/A * This code is free software; you can redistribute it and/or modify it 325N/A * under the terms of the GNU General Public License version 2 only, as 325N/A * published by the Free Software Foundation. Oracle designates this 325N/A * particular file as subject to the "Classpath" exception as provided 325N/A * by Oracle in the LICENSE file that accompanied this code. 325N/A * This code is distributed in the hope that it will be useful, but WITHOUT 325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 325N/A * version 2 for more details (a copy is included in the LICENSE file that 325N/A * accompanied this code). 325N/A * You should have received a copy of the GNU General Public License version 325N/A * 2 along with this work; if not, write to the Free Software Foundation, 325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 325N/A * or visit www.oracle.com if you need additional information or have any 325N/A * Center of the unmarshalling. 325N/A * This object is responsible for coordinating {@link Loader}s to 325N/A * perform the whole unmarshalling. 325N/A * @author Kohsuke Kawaguchi 325N/A * The currently active state. 325N/A /** Root object that is being unmarshalled. */ 325N/A * If non-null, this unmarshaller will unmarshal {@code JAXBElement<EXPECTEDTYPE>} 325N/A * regardless of the tag name, as opposed to deciding the root object by using 325N/A * The property has a package-level access, because we cannot copy this value 325N/A * to {@link UnmarshallingContext} when it is created. The property 325N/A * on {@link Unmarshaller} could be changed after the handler is created. 325N/A * This flag is set to true at the startDocument event 325N/A * and false at the endDocument event. 325N/A * Until the first document is unmarshalled, we don't 325N/A * want to return an object. So this variable is initialized 325N/A * If the unmarshaller is doing associative unmarshalling, 325N/A * this field is initialized to non-null. 325N/A * Indicates whether we are doing in-place unmarshalling 325N/A * This flag is unused when {@link #assoc}==null. 325N/A * If it's non-null, then <tt>true</tt> indicates 325N/A * that we are doing in-place associative unmarshalling. 325N/A * If <tt>false</tt>, then we are doing associative unmarshalling 325N/A * without object reuse. 325N/A * This object is consulted to get the element object for 325N/A * the current element event. 325N/A * This is used when we are building an association map. 325N/A * @see XmlVisitor#startDocument(LocatorEx, NamespaceContext) 325N/A * User-supplied {@link ClassLoader} for converting name to {@link Class}. 325N/A * For backward compatibility, when null, use thread context classloader. 325N/A * State information for each element. 325N/A * Loader that owns this element. 325N/A * Once {@link #loader} is completed, this receiver 325N/A * Object being unmarshalled by this {@link #loader}. 325N/A * Hack for making JAXBElement unmarshalling work. 325N/A * While the unmarshalling is in progress, the {@link #target} field stores the object being unmarshalled. 325N/A * This makes it convenient to keep track of the unmarshalling activity in context of XML infoset, but 325N/A * since there's only one {@link State} per element, this mechanism only works when there's one object 325N/A * per element, which breaks down when we have {@link JAXBElement}, since the presence of JAXBElement 325N/A * requires that we have two objects unmarshalled (a JAXBElement X and a value object Y bound to an XML type.) 325N/A * So to make room for storing both, this {@link #backup} field is used. When we create X instance 325N/A * in the above example, we set that to {@code state.prev.target} and displace its old value to 325N/A * {@code state.prev.backup} (where Y goes to {@code state.target}.) Upon the completion of the unmarshalling 325N/A * of Y, we revert this. 325N/A * While this attributes X incorrectly to its parent element, this preserves the parent/child 325N/A * relationship between unmarshalled objects and {@link State} parent/child relationship, and 325N/A * it thereby makes {@link Receiver} mechanism simpler. 325N/A * Yes, I know this is a hack, and no, I'm not proud of it. 325N/A * @see ElementBeanInfoImpl.IntercepterLoader#startElement(State, TagName) 325N/A * @see ElementBeanInfoImpl.IntercepterLoader#intercept(State, Object) 325N/A * Number of {@link UnmarshallingContext#nsBind}s declared thus far. 325N/A * (The value of {@link UnmarshallingContext#nsLen} when this state is pushed. 325N/A * If this element has an element default value. 325N/A * This should be set by either a parent {@link Loader} when 325N/A * {@link Loader#childElement(State, TagName)} is called 325N/A * or by a child {@link Loader} when 325N/A * {@link Loader#startElement(State, TagName)} is called. 325N/A * {@link State} for the parent element 325N/A * {@link State} objects form a doubly linked list. 325N/A * Stub to the user-specified factory method. 325N/A * Creates a new unmarshaller. 325N/A * Must be both non-null when the unmarshaller does the 325N/A * in-place unmarshalling. Otherwise must be both null. 325N/A * On top of {@link JAXBContextImpl#selectRootLoader(State, TagName)}, 325N/A * this method also consults {@link ClassResolver}. 325N/A * if {@link ValidationEventHandler} reported a failure. 325N/A * Allocates a few more {@link State}s. 325N/A * Allocating multiple {@link State}s at once allows those objects 325N/A * to be allocated near each other, which reduces the working set 325N/A * of CPU. It improves the chance the relevant data is in the cache. 325N/A // this method should be used only when we run out of a state. 325N/A for(
int i=
0; i<
8; i++ )
325N/A * User-specified factory methods. 325N/A // look for all the public methods inlcuding derived ones 325N/A // look for methods whose signature is T createXXX() 325N/A // remember the current element if we are interested in it. 325N/A // because the inner peer might not be found while we consume 325N/A // the enter element token, we need to keep this information 325N/A // longer than this callback. That's why we assign it to a field. 325N/A // tell the parent about the new child 325N/A // and tell the new child that you are activated 325N/A // send the default value into the unmarshaller instead 325N/A // tell the child that your time is up 325N/A // child.pop will erase them so store them now 325N/A // then let the parent know 325N/A // at the successful completion, scope must be all closed 325N/A * You should be always calling this through {@link TextPredictor}. 325N/A * You should be always getting {@link TextPredictor} from {@link XmlVisitor}. 325N/A * Gets the result of the unmarshalling 325N/A * Creates a new instance of the specified class. 325N/A * In the unmarshaller, we need to check the user-specified factory class. 325N/A * Creates a new instance of the specified class. 325N/A * In the unmarshaller, we need to check the user-specified factory class. 325N/A * Reports an error to the user, and asks if s/he wants 325N/A * to recover. If the canRecover flag is false, regardless 325N/A * of the client instruction, an exception will be thrown. 325N/A * Only if the flag is true and the user wants to recover from an error, 325N/A * the method returns normally. 325N/A * The thrown exception will be catched by the unmarshaller. 325N/A // if the handler says "abort", we will not return the object 325N/A // from the unmarshaller.getResult() 325N/A // if the handler says "abort", we will not return the object. 325N/A // if client event handler causes a runtime exception, then we 325N/A // have to return false. 325N/A * Reports an exception found during the unmarshalling to the user. 325N/A * This method is a convenience method that calls into 325N/A * {@link #handleEvent(ValidationEvent, boolean)} 325N/A * Gets the current source location information in SAX {@link Locator}. 325N/A * Sometimes the unmarshaller works against a different kind of XML source, 325N/A * making this information meaningless. 325N/A * Called when there's no corresponding ID value. 325N/A * Submitted patchers in the order they've submitted. 325N/A * initialize it with null. 325N/A * Adds a job that will be executed at the last of the unmarshalling. 325N/A * This method is used to support ID/IDREF feature, but it can be used 325N/A * for other purposes as well. 325N/A * The run method of this object is called. 325N/A // re-allocate buffer if necessary 325N/A /** Executes all the patchers. */ 325N/A * Adds the object which is currently being unmarshalled 325N/A * Returns the value passed as the parameter. 325N/A * This is a hack, but this makes it easier for ID 325N/A * transducer to do its job. 325N/A // TODO: what shall we do if the ID is already declared? 325N/A // throwing an exception is one way. Overwriting the previous one 325N/A // is another way. The latter allows us to process invalid documents, 325N/A // while the former makes it impossible to handle them. 325N/A // I prefer to be flexible in terms of invalid document handling, 325N/A // so chose not to throw an exception. 325N/A // I believe this is an implementation choice, not the spec issue. 325N/A // in cases such as when ID is used as an attribute, or as @XmlValue 325N/A // the target wilil be current.target. 325N/A // but in some other cases, such as when ID is used as a child element 325N/A // or a value of JAXBElement, it's current.prev.target. 325N/A // I don't know if this detection logic is complete 325N/A * Looks up the ID table and gets associated object. 325N/A * The exception thrown from {@link Callable#call()} means the unmarshaller should abort 325N/A * @see IDResolver#resolve(String, Class) 325N/A// namespace binding maintainance 325N/A // temporary workaround until Zephyr fixes 6337180 325N/A // by default, the default ns is bound to "". 325N/A // but allow environmentNamespaceContext to take precedence 325N/A * Returns a list of prefixes newly declared on the current element. 325N/A * A possible zero-length array of prefixes. The default prefix 325N/A * is represented by the empty string. 325N/A * Returns a list of all in-scope prefixes. 325N/A * A possible zero-length array of prefixes. The default prefix 325N/A * is represented by the empty string. 325N/A // NamespaceContext2 implementation 325N/A // TODO: could be implemented much faster 325N/A // wrap it into unmodifiable list so that the remove method 325N/A // will throw UnsupportedOperationException. 325N/A // make sure that this prefix is still effective. 325N/A // make sure that this prefix is still effective. 325N/A * Points to the top of the scope stack (=size-1). 325N/A * Starts a new packing scope. 325N/A * This method allocates a specified number of fresh {@link Scope} objects. 325N/A * They can be accessed by the {@link #getScope} method until the corresponding 325N/A * {@link #endScope} method is invoked. 325N/A * A new scope will mask the currently active scope. Only one frame of {@link Scope}s 325N/A * can be accessed at any given time. 325N/A * The # of slots to be allocated. 325N/A * Ends the current packing scope. 325N/A * If any packing in progress will be finalized by this method. 325N/A * The same size that gets passed to the {@link #startScope(int)} 325N/A // the error might have left scopes in inconsistent state, 325N/A // so replace them by fresh ones 325N/A * Gets the currently active {@link Scope}. 325N/A * a number between [0,frameSize) 325N/A * always a valid {@link Scope} object. 325N/A * Root loader that uses the tag name and possibly its @xsi:type 325N/A * to decide how to start unmarshalling. 325N/A * Receives the root element and determines how to start 325N/A // the registry doesn't know about this element. 325N/A // we don't even know its xsi:type 325N/A * Root loader that uses {@link UnmarshallingContext#expectedType} 325N/A * to decide how to start unmarshalling. 325N/A * Receives the root element and determines how to start 325N/A // unmarshals the specified type 325N/A // this is bit wasteful, as in theory we should have each expectedType keep 325N/A // nillable version --- but that increases the combination from two to four, 325N/A // which adds the resident memory footprint. Since XsiNilLoader is small, 325N/A // I intentionally allocate a new instance freshly. 325N/A// in-place unmarshalling related capabilities 325N/A * Notifies the context about the inner peer of the current element. 325N/A * If the unmarshalling is building the association, the context 325N/A * will use this information. Otherwise it will be just ignored. 325N/A * Gets the inner peer JAXB object associated with the current element. 325N/A * null if the current element doesn't have an inner peer, 325N/A * or if we are not doing the in-place unmarshalling. 325N/A * Notifies the context about the outer peer of the current element. 325N/A * If the unmarshalling is building the association, the context 325N/A * will use this information. Otherwise it will be just ignored. 325N/A * Gets the outer peer JAXB object associated with the current element. 325N/A * null if the current element doesn't have an inner peer, 325N/A * or if we are not doing the in-place unmarshalling. 325N/A * Gets the xmime:contentType value for the current object. 325N/A * @see JAXBContextImpl#getXMIMEContentType(Object) 325N/A this won't work when the class is like 325N/A because the target will return Foo, not the class enclosing Foo 325N/A which will have xmime:contentType 325N/A * When called from within the realm of the unmarshaller, this method 325N/A * returns the current {@link UnmarshallingContext} in charge. 325N/A * Allows to access elements which are expected in current state. 325N/A * Useful for getting elements for current parent. 325N/A * Allows to access attributes which are expected in current state. 325N/A * Useful for getting attributes for current parent. 325N/A * Gets StructureLoader if used as loader. 325N/A * Useful when determining if element is mixed or not.