| Method from com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext Detail: |
public void addPatcher(Patcher job) {
// re-allocate buffer if necessary
if( patchers==null )
patchers = new Patcher[32];
if( patchers.length == patchersLen ) {
Patcher[] buf = new Patcher[patchersLen*2];
System.arraycopy(patchers,0,buf,0,patchersLen);
patchers = buf;
}
patchers[patchersLen++] = job;
}
Adds a job that will be executed at the last of the unmarshalling.
This method is used to support ID/IDREF feature, but it can be used
for other purposes as well. |
public String addToIdTable(String id) throws SAXException {
// Hmm...
// in cases such as when ID is used as an attribute, or as @XmlValue
// the target wilil be current.target.
// but in some other cases, such as when ID is used as a child element
// or a value of JAXBElement, it's current.prev.target.
// I don't know if this detection logic is complete
Object o = current.target;
if(o==null)
o = current.prev.target;
idResolver.bind(id,o);
return id;
}
Adds the object which is currently being unmarshalled
to the ID table. |
public Object createInstance(Class clazz) throws SAXException {
if(!factories.isEmpty()) {
Factory factory = factories.get(clazz);
if(factory!=null)
return factory.createInstance();
}
return ClassFactory.create(clazz);
}
Creates a new instance of the specified class.
In the unmarshaller, we need to check the user-specified factory class. |
public Object createInstance(JaxBeanInfo beanInfo) throws SAXException {
if(!factories.isEmpty()) {
Factory factory = factories.get(beanInfo.jaxbType);
if(factory!=null)
return factory.createInstance();
}
try {
return beanInfo.createInstance(this);
} catch (IllegalAccessException e) {
Loader.reportError("Unable to create an instance of "+beanInfo.jaxbType.getName(),e,false);
} catch (InvocationTargetException e) {
Loader.reportError("Unable to create an instance of "+beanInfo.jaxbType.getName(),e,false);
} catch (InstantiationException e) {
Loader.reportError("Unable to create an instance of "+beanInfo.jaxbType.getName(),e,false);
}
return null; // can never be here
}
Creates a new instance of the specified class.
In the unmarshaller, we need to check the user-specified factory class. |
public void endDocument() throws SAXException {
runPatchers();
idResolver.endDocument();
isUnmarshalInProgress = false;
currentElement = null;
locator = DUMMY_INSTANCE;
environmentNamespaceContext = null;
// at the successful completion, scope must be all closed
assert root==current;
resetThreadAffinity();
}
|
public final void endElement(TagName tagName) throws SAXException {
pushCoordinator();
try {
State child = current;
// tell the child that your time is up
child.loader.leaveElement(child,tagName);
// child.pop will erase them so store them now
Object target = child.target;
Receiver recv = child.receiver;
Intercepter intercepter = child.intercepter;
child.pop();
// then let the parent know
if(intercepter!=null)
target = intercepter.intercept(current,target);
if(recv!=null)
recv.receive(current,target);
} finally {
popCoordinator();
}
}
|
public void endPrefixMapping(String prefix) {
nsLen-=2;
}
|
public void endScope(int frameSize) throws SAXException {
try {
for( ; frameSize >0; frameSize-- )
scopes[scopeTop--].finish();
} catch (AccessorException e) {
handleError(e);
}
}
|
public void errorUnresolvedIDREF(Object bean,
String idref) throws SAXException {
handleEvent( new ValidationEventImpl(
ValidationEvent.ERROR,
Messages.UNRESOLVED_IDREF.format(idref),
new ValidationEventLocatorImpl(bean)), true );
}
Called when there's no corresponding ID value. |
public boolean expectText() {
return current.loader.expectText;
}
|
public String[] getAllDeclaredPrefixes() {
return getPrefixList( 2 ); // skip the default ""- >"" mapping
}
Returns a list of all in-scope prefixes. |
public UnmarshallingContext getContext() {
return this;
}
|
public UnmarshallingContext.State getCurrentState() {
return current;
}
|
public Object getInnerPeer() {
if(assoc!=null && isInplaceMode)
return assoc.getInnerPeer(currentElement);
else
return null;
}
Gets the inner peer JAXB object associated with the current element. |
public static UnmarshallingContext getInstance() {
return (UnmarshallingContext) Coordinator._getInstance();
}
When called from within the realm of the unmarshaller, this method
returns the current UnmarshallingContext in charge. |
public JAXBContextImpl getJAXBContext() {
return parent.context;
}
|
protected ValidationEventLocator getLocation() {
return locator.getLocation();
}
|
public LocatorEx getLocator() {
return locator;
}
Gets the current source location information in SAX Locator .
Sometimes the unmarshaller works against a different kind of XML source,
making this information meaningless. |
public String getNamespaceURI(String prefix) {
if (prefix == null)
throw new IllegalArgumentException();
if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE))
return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
return resolveNamespacePrefix(prefix);
}
|
public String[] getNewlyDeclaredPrefixes() {
return getPrefixList( current.prev.numNsDecl );
}
Returns a list of prefixes newly declared on the current element. |
public Callable getObjectFromId(String id,
Class targetType) throws SAXException {
return idResolver.resolve(id,targetType);
}
|
public Object getOuterPeer() {
if(assoc!=null && isInplaceMode)
return assoc.getOuterPeer(currentElement);
else
return null;
}
Gets the outer peer JAXB object associated with the current element. |
public TextPredictor getPredictor() {
return this;
}
|
public String getPrefix(String uri) {
if( uri==null )
throw new IllegalArgumentException();
if( uri.equals(XMLConstants.XML_NS_URI) )
return XMLConstants.XML_NS_PREFIX;
if( uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI) )
return XMLConstants.XMLNS_ATTRIBUTE;
for( int i=nsLen-2; i >=0; i-=2 )
if(uri.equals(nsBind[i+1]))
if( getNamespaceURI(nsBind[i]).equals(nsBind[i+1]) )
// make sure that this prefix is still effective.
return nsBind[i];
if(environmentNamespaceContext!=null)
return environmentNamespaceContext.getPrefix(uri);
return null;
}
|
public Iterator getPrefixes(String uri) {
// TODO: could be implemented much faster
// wrap it into unmodifiable list so that the remove method
// will throw UnsupportedOperationException.
return Collections.unmodifiableList(
getAllPrefixesInList(uri)).iterator();
}
|
public Object getResult() throws UnmarshalException {
if(isUnmarshalInProgress)
throw new IllegalStateException();
if(!aborted) return result;
// there was an error.
throw new UnmarshalException((String)null);
}
Gets the result of the unmarshalling |
public Scope getScope(int offset) {
return scopes[scopeTop-offset];
}
Gets the currently active Scope . |
public String getXMIMEContentType() {
/*
this won't work when the class is like
class Foo {
@XmlValue Image img;
}
because the target will return Foo, not the class enclosing Foo
which will have xmime:contentType
*/
Object t = current.target;
if(t==null) return null;
return getJAXBContext().getXMIMEContentType(t);
}
Gets the xmime:contentType value for the current object. |
public void handleError(Exception e) throws SAXException {
handleError(e,true);
}
|
public void handleError(String msg) {
handleEvent(new ValidationEventImpl(ValidationEvent.ERROR,msg,locator.getLocation()));
}
|
public void handleError(Exception e,
boolean canRecover) throws SAXException {
handleEvent(new ValidationEventImpl(ValidationEvent.ERROR,e.getMessage(),locator.getLocation(),e),canRecover);
}
|
public boolean handleEvent(ValidationEvent event) {
try {
// if the handler says "abort", we will not return the object.
boolean recover = parent.getEventHandler().handleEvent(event);
if(!recover) aborted = true;
return recover;
} catch( RuntimeException re ) {
// if client event handler causes a runtime exception, then we
// have to return false.
return false;
}
}
|
public void handleEvent(ValidationEvent event,
boolean canRecover) throws SAXException {
ValidationEventHandler eventHandler = parent.getEventHandler();
boolean recover = eventHandler.handleEvent(event);
// if the handler says "abort", we will not return the object
// from the unmarshaller.getResult()
if(!recover) aborted = true;
if( !canRecover || !recover )
throw new SAXParseException2( event.getMessage(), locator,
new UnmarshalException(
event.getMessage(),
event.getLinkedException() ) );
}
Reports an error to the user, and asks if s/he wants
to recover. If the canRecover flag is false, regardless
of the client instruction, an exception will be thrown.
Only if the flag is true and the user wants to recover from an error,
the method returns normally.
The thrown exception will be catched by the unmarshaller. |
public void recordInnerPeer(Object innerPeer) {
if(assoc!=null)
assoc.addInner(currentElement,innerPeer);
}
Notifies the context about the inner peer of the current element.
If the unmarshalling is building the association, the context
will use this information. Otherwise it will be just ignored. |
public void recordOuterPeer(Object outerPeer) {
if(assoc!=null)
assoc.addOuter(currentElement,outerPeer);
}
Notifies the context about the outer peer of the current element.
If the unmarshalling is building the association, the context
will use this information. Otherwise it will be just ignored. |
public void reset(InfosetScanner scanner,
boolean isInplaceMode,
JaxBeanInfo expectedType,
IDResolver idResolver) {
this.scanner = scanner;
this.isInplaceMode = isInplaceMode;
this.expectedType = expectedType;
this.idResolver = idResolver;
}
|
public void setFactories(Object factoryInstances) {
factories.clear();
if(factoryInstances==null) {
return;
}
if(factoryInstances instanceof Object[]) {
for( Object factory : (Object[])factoryInstances ) {
// look for all the public methods inlcuding derived ones
addFactory(factory);
}
} else {
addFactory(factoryInstances);
}
}
|
public void startDocument(LocatorEx locator,
NamespaceContext nsContext) throws SAXException {
this.locator = locator;
this.environmentNamespaceContext = nsContext;
// reset the object
result = null;
current = root;
patchersLen=0;
aborted = false;
isUnmarshalInProgress = true;
nsLen=0;
startPrefixMapping("",""); // by default, the default ns is bound to "".
setThreadAffinity();
if(expectedType!=null)
root.loader = EXPECTED_TYPE_ROOT_LOADER;
else
root.loader = DEFAULT_ROOT_LOADER;
idResolver.startDocument(this);
}
|
public void startElement(TagName tagName) throws SAXException {
pushCoordinator();
try {
_startElement(tagName);
} finally {
popCoordinator();
}
}
|
public void startPrefixMapping(String prefix,
String uri) {
if(nsBind.length==nsLen) {
// expand the buffer
String[] n = new String[nsLen*2];
System.arraycopy(nsBind,0,n,0,nsLen);
nsBind=n;
}
nsBind[nsLen++] = prefix;
nsBind[nsLen++] = uri;
}
|
public void startScope(int frameSize) {
for( int i=0; i< scopes.length; i++ )
scopes[i] = new Scope(this);
scopeTop += frameSize;
// reallocation
if(scopeTop >=scopes.length) {
Scope[] s = new Scope[Math.max(scopeTop+1,scopes.length*2)];
System.arraycopy(scopes,0,s,0,scopes.length);
for( int i=scopes.length; i< s.length; i++ )
s[i] = new Scope(this);
scopes = s;
}
}
Starts a new packing scope.
This method allocates a specified number of fresh Scope objects.
They can be accessed by the #getScope method until the corresponding
#endScope method is invoked.
A new scope will mask the currently active scope. Only one frame of Scope s
can be accessed at any given time. |
public void text(CharSequence pcdata) throws SAXException {
State cur = current;
pushCoordinator();
try {
if(cur.elementDefaultValue!=null) {
if(pcdata.length()==0) {
// send the default value into the unmarshaller instead
pcdata = cur.elementDefaultValue;
}
}
cur.loader.text(cur,pcdata);
} finally {
popCoordinator();
}
}
|