Red Hat Application Migration Toolkit
package org.exolab.castor.xml; import java.io.PrintWriter; import java.io.Serializable; import java.io.StringWriter; import java.lang.reflect.Array; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Stack; import java.util.StringTokenizer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.castor.core.util.Base64Decoder; import org.castor.core.util.HexDecoder; import org.castor.xml.InternalContext; import org.castor.xml.UnmarshalListener; import org.castor.xml.UnmarshalListenerAdapter; import org.exolab.castor.mapping.ClassDescriptor; import org.exolab.castor.mapping.ExtendedFieldHandler; import org.exolab.castor.mapping.FieldHandler; import org.exolab.castor.mapping.MapItem; import org.exolab.castor.mapping.loader.FieldHandlerImpl; import org.exolab.castor.types.AnyNode; import org.exolab.castor.util.DefaultObjectFactory; import org.exolab.castor.util.ObjectFactory; import org.exolab.castor.xml.AttributeSet; import org.exolab.castor.xml.IDResolver; import org.exolab.castor.xml.IDResolverImpl; import org.exolab.castor.xml.Introspector; import org.exolab.castor.xml.MarshalException; import org.exolab.castor.xml.MarshalFramework; import org.exolab.castor.xml.Namespaces; import org.exolab.castor.xml.NodeType; import org.exolab.castor.xml.ReferenceInfo; import org.exolab.castor.xml.ResolverException; import org.exolab.castor.xml.UnmarshalState; import org.exolab.castor.xml.ValidationContext; import org.exolab.castor.xml.ValidationException; import org.exolab.castor.xml.Validator; import org.exolab.castor.xml.XMLClassDescriptor; import org.exolab.castor.xml.XMLFieldDescriptor; import org.exolab.castor.xml.MarshalFramework.InheritanceMatch; import org.exolab.castor.xml.MarshalFramework.InternalXMLClassDescriptor; import org.exolab.castor.xml.descriptors.PrimitivesClassDescriptor; import org.exolab.castor.xml.descriptors.StringClassDescriptor; import org.exolab.castor.xml.util.AttributeSetImpl; import org.exolab.castor.xml.util.ContainerElement; import org.exolab.castor.xml.util.SAX2ANY; import org.exolab.castor.xml.util.XMLClassDescriptorImpl; import org.exolab.castor.xml.util.XMLFieldDescriptorImpl; import org.xml.sax.AttributeList; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.DocumentHandler; import org.xml.sax.ErrorHandler; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; public final class UnmarshalHandler extends MarshalFramework implements ContentHandler, DocumentHandler, ErrorHandler { private static final Log LOG = LogFactory.getLog(UnmarshalHandler.class); private static final String ERROR_DID_NOT_FIND_CLASSDESCRIPTOR = "unable to find or create a ClassDescriptor for class: "; private static final String XML_PREFIX = "xml"; private static final String XMLNS = "xmlns"; private static final String XMLNS_PREFIX = "xmlns:"; private static final int XMLNS_PREFIX_LENGTH = "xmlns:".length(); private static final String XSI_TYPE = "type"; private static final String XML_SPACE = "space"; private static final String XML_SPACE_WITH_PREFIX = "xml:space"; private static final String PRESERVE = "preserve"; private Stack _stateInfo; private UnmarshalState _topState; private Class _topClass; private Object _topObject; private boolean _clearCollections; private Locator _locator; private IDResolver _idResolver; private UnmarshalListener _unmarshalListener; private boolean _validate; private Hashtable _resolveTable; private Map _javaPackages; private ClassLoader _loader; private static final StringClassDescriptor STRING_DESCRIPTOR = new StringClassDescriptor(); private SAX2ANY _anyUnmarshaller; private int _depth; private AnyNode _node; private Namespaces _namespaces; private HashMap _namespaceToPackage; private ObjectFactory _objectFactory; private boolean _reuseObjects; private boolean _strictAttributes; private boolean _strictElements; private int _ignoreElementDepth; private boolean _createNamespaceScope; private UnmarshalHandler.ElementInfo _elemInfo; private AttributeSetImpl _reusableAtts; private boolean _wsPreserve; protected UnmarshalHandler() { this((Class)null); } protected UnmarshalHandler(Class topClass) { this((InternalContext)null, topClass); } protected UnmarshalHandler(InternalContext internalContext, Class topClass) { super(internalContext); this._stateInfo = null; this._topState = null; this._topClass = null; this._topObject = null; this._clearCollections = false; this._locator = null; this._idResolver = null; this._unmarshalListener = null; this._validate = true; this._resolveTable = new Hashtable(); this._javaPackages = null; this._loader = null; this._anyUnmarshaller = null; this._depth = 0; this._node = null; this._namespaces = null; this._namespaceToPackage = null; this._objectFactory = new DefaultObjectFactory(); this._reuseObjects = false; this._strictAttributes = false; this._strictElements = true; this._ignoreElementDepth = 0; this._createNamespaceScope = true; this._elemInfo = null; this._reusableAtts = null; this._wsPreserve = false; this._stateInfo = new Stack(); this._idResolver = new IDResolverImpl(); this._javaPackages = new HashMap(); this._topClass = topClass; this._namespaces = new Namespaces(); this._namespaceToPackage = new HashMap(); } public void addNamespaceToPackageMapping(String nsURI, String packageName) { if(nsURI == null) { nsURI = ""; } if(packageName == null) { packageName = ""; } this._namespaceToPackage.put(nsURI, packageName); } public Object getCurrentObject() { if(!this._stateInfo.isEmpty()) { UnmarshalState state = (UnmarshalState)this._stateInfo.peek(); if(state != null) { return state._object; } } return null; } public Object getObject() { return this._topState != null?this._topState._object:null; } public void setClassLoader(ClassLoader loader) { this._loader = loader; } public void setClearCollections(boolean clear) { this._clearCollections = clear; } /** @deprecated */ public void setDebug(boolean debug) { } public void setIDResolver(IDResolver idResolver) { ((IDResolverImpl)this._idResolver).setResolver(idResolver); } public void setIgnoreExtraAttributes(boolean ignoreExtraAtts) { this._strictAttributes = !ignoreExtraAtts; } public void setIgnoreExtraElements(boolean ignoreExtraElems) { this._strictElements = !ignoreExtraElems; } /** @deprecated */ public void setLogWriter(PrintWriter printWriter) { } public void setReuseObjects(boolean reuse) { this._reuseObjects = reuse; } public void setRootObject(Object root) { this._topObject = root; } /** @deprecated */ public void setUnmarshalListener(org.exolab.castor.xml.UnmarshalListener listener) { if(listener == null) { listener = null; } else { UnmarshalListenerAdapter adapter = new UnmarshalListenerAdapter(); adapter.setOldListener(listener); this._unmarshalListener = adapter; } } public void setUnmarshalListener(UnmarshalListener listener) { this._unmarshalListener = listener; } public void setValidation(boolean validate) { this._validate = validate; } public void setWhitespacePreserve(boolean preserve) { this._wsPreserve = preserve; } public void characters(char[] ch, int start, int length) throws SAXException { if(LOG.isTraceEnabled()) { StringBuffer state = new StringBuffer(21 + length); state.append("#characters: "); state.append(ch, start, length); LOG.trace(state.toString()); } if(this._ignoreElementDepth <= 0) { if(!this._stateInfo.empty()) { if(this._anyUnmarshaller != null) { this._anyUnmarshaller.characters(ch, start, length); } else { UnmarshalState var8 = (UnmarshalState)this._stateInfo.peek(); boolean removedTrailingWhitespace = false; boolean removedLeadingWhitespace = false; if(!var8._wsPreserve) { boolean whitespace; while(length > 0) { whitespace = false; switch(ch[start]) { case '\t': case '\n': case '\r': case ' ': whitespace = true; } if(!whitespace) { break; } removedLeadingWhitespace = true; ++start; --length; } if(length == 0) { removedTrailingWhitespace = removedLeadingWhitespace; } else { while(length > 0) { whitespace = false; switch(ch[start + length - 1]) { case '\t': case '\n': case '\r': case ' ': whitespace = true; } if(!whitespace) { break; } removedTrailingWhitespace = true; --length; } } } if(var8._buffer == null) { var8._buffer = new StringBuffer(); } else if(!var8._wsPreserve && length > 0 && (var8._trailingWhitespaceRemoved || removedLeadingWhitespace)) { var8._buffer.append(' '); } var8._trailingWhitespaceRemoved = removedTrailingWhitespace; var8._buffer.append(ch, start, length); } } } } public void endDocument() throws SAXException { } public void endElement(String name) throws SAXException { if(LOG.isTraceEnabled()) { LOG.trace("#endElement: " + name); } if(this._ignoreElementDepth > 0) { --this._ignoreElementDepth; } else { if(this._anyUnmarshaller != null) { this._anyUnmarshaller.endElement(name); --this._depth; if(this._depth != 0) { return; } this._node = this._anyUnmarshaller.getStartingNode(); this._anyUnmarshaller = null; } if(this._stateInfo.empty()) { throw new SAXException("missing start element: " + name); } else { int idx = name.indexOf(58); if(idx >= 0) { name = name.substring(idx + 1); } UnmarshalState state = (UnmarshalState)this._stateInfo.pop(); XMLFieldDescriptor descriptor = state._fieldDesc; if(!state._elementName.equals(name)) { if(descriptor.isContainer()) { this._stateInfo.push(state); StringBuffer var20 = null; if(state._buffer != null && !isWhitespace(state._buffer) && state._classDesc.getContentDescriptor() == null) { var20 = state._buffer; state._buffer = null; } this.endElement(state._elementName); if(var20 != null) { state = (UnmarshalState)this._stateInfo.peek(); if(state._buffer == null) { state._buffer = var20; } else { state._buffer.append(var20.toString()); } } this.endElement(name); } else { String var19 = "error in xml, expecting </" + state._elementName; var19 = var19 + ">, but received </" + name + "> instead."; throw new SAXException(var19); } } else { Class type = state._type; String var31; if(type == null) { if(!state._wrapper) { LOG.info("Ignoring " + state._elementName + " no descriptor was found"); } StringBuffer var21 = null; if(state._buffer != null && !isWhitespace(state._buffer)) { var21 = state._buffer; state._buffer = null; } if(var21 != null) { UnmarshalState var44 = state; var31 = state._elementName; label292: while(true) { while(true) { if((var44 = var44._parent) == null) { break label292; } if(!var44._wrapper && var44._classDesc != null) { XMLFieldDescriptor var35 = var44._classDesc.getContentDescriptor(); if(var35 != null && var31.equals(var35.getLocationPath())) { if(var44._buffer == null) { var44._buffer = var21; } else { var44._buffer.append(var21.toString()); } } } else { var31 = var44._elementName + "/" + var31; } } } } this._namespaces = this._namespaces.getParent(); } else { boolean byteArray = false; if(type.isArray()) { byteArray = type.getComponentType() == Byte.TYPE; } if(state._object == null && !state._primitiveOrImmutable) { this._namespaces = this._namespaces.getParent(); } else { String ex; if(state._primitiveOrImmutable) { String val = null; if(state._buffer != null) { val = state._buffer.toString(); state._buffer.setLength(0); } if(type == String.class && !((XMLFieldDescriptorImpl)descriptor).isDerivedFromXSList()) { if(val != null) { state._object = val; } else if(state._nil) { state._object = null; } else { state._object = ""; } } else if(byteArray && !descriptor.isDerivedFromXSList()) { if(val == null) { state._object = new byte[0]; } else { state._object = this.decodeBinaryData(descriptor, val); } } else if(state._args != null) { state._object = this.createInstance(state._type, state._args); } else if(descriptor.isMultivalued() && descriptor.getSchemaType() != null && descriptor.getSchemaType().equals("list") && ((XMLFieldDescriptorImpl)descriptor).isDerivedFromXSList()) { StringTokenizer fieldState = new StringTokenizer(val); ArrayList firstOccurance = new ArrayList(); while(fieldState.hasMoreTokens()) { ex = fieldState.nextToken(); if(isPrimitive(descriptor.getFieldType())) { firstOccurance.add(this.toPrimitiveObject(type, ex, state._fieldDesc)); } else { Class sw = descriptor.getFieldType(); if(sw.isArray() && sw.getComponentType() == Byte.TYPE) { firstOccurance.add(this.decodeBinaryData(descriptor, ex)); } } } state._object = firstOccurance; } else if(state._nil) { state._object = null; } else { state._object = this.toPrimitiveObject(type, val, state._fieldDesc); } } else if(UnmarshalHandler.ArrayHandler.class.isAssignableFrom(state._type)) { state._object = ((UnmarshalHandler.ArrayHandler)state._object).getObject(); state._type = state._object.getClass(); } UnmarshalState var27; if(state._buffer != null && state._buffer.length() > 0 && state._classDesc != null) { XMLFieldDescriptor var23 = state._classDesc.getContentDescriptor(); if(var23 != null) { Object var22 = state._buffer.toString(); if(isPrimitive(var23.getFieldType())) { var22 = this.toPrimitiveObject(var23.getFieldType(), (String)var22, state._fieldDesc); } else { Class var24 = var23.getFieldType(); if(var24.isArray() && var24.getComponentType() == Byte.TYPE) { var22 = this.decodeBinaryData(descriptor, (String)var22); } } try { FieldHandler var26 = var23.getHandler(); boolean var32 = true; if(this._reuseObjects) { Object var33 = var26.getValue(state._object); if(var33 != null) { var32 = !var33.equals(var22); } } if(var32) { var26.setValue(state._object, var22); } } catch (IllegalStateException var16) { ex = "unable to add text content to "; ex = ex + descriptor.getXMLName(); ex = ex + " due to the following error: " + var16; throw new SAXException(ex, var16); } } else { if(descriptor.isReference()) { var27 = (UnmarshalState)this._stateInfo.peek(); this.processIDREF(state._buffer.toString(), descriptor, var27._object); this._namespaces = this._namespaces.getParent(); return; } if(!isWhitespace(state._buffer)) { var31 = "Illegal Text data found as child of: " + name; var31 = var31 + "\n value: \"" + state._buffer + "\""; throw new SAXException(var31); } } } if(this._unmarshalListener != null && state._object != null) { this._unmarshalListener.unmarshalled(state._object, state._parent == null?null:state._parent._object); } String var36; if(this._stateInfo.empty()) { if(this.isValidating()) { ValidationException var39 = null; ValidationException var29 = null; if(this._resolveTable != null && !this.getInternalContext().getLenientIdValidation()) { Enumeration var30 = this._resolveTable.keys(); while(var30.hasMoreElements()) { Object var43 = var30.nextElement(); var36 = "unable to resolve reference: " + var43; if(var39 == null) { var39 = new ValidationException(var36); var29 = var39; } else { var29.setNext(new ValidationException(var36)); var29 = var29.getNext(); } } } try { Validator var34 = new Validator(); ValidationContext var45 = new ValidationContext(); var45.setInternalContext(this.getInternalContext()); var34.validate(state._object, var45); if(!this.getInternalContext().getLenientIdValidation()) { var34.checkUnresolvedIdrefs(var45); } var45.cleanup(); } catch (ValidationException var17) { if(var39 == null) { var39 = var17; } else { var29.setNext(var17); } } if(var39 != null) { throw new SAXException(var39); } } } else if(descriptor.isIncremental()) { this._namespaces = this._namespaces.getParent(); } else { Object var25 = state._object; if(this._node != null) { var25 = this._node; this._node = null; } var27 = state; boolean var28 = false; state = (UnmarshalState)this._stateInfo.peek(); if(state._wrapper) { state = var27._targetState; } if(!descriptor.isMultivalued()) { if(state.isUsed(descriptor)) { ex = "element \"" + name; ex = ex + "\" occurs more than once. (parent class: " + state._type.getName() + ")"; var36 = name; while(true) { UnmarshalState pw; do { if(this._stateInfo.isEmpty()) { ex = ex + "\n location: /" + var36; ValidationException var38 = new ValidationException(ex); throw new SAXException(var38); } pw = (UnmarshalState)this._stateInfo.pop(); } while(!pw._wrapper && pw._fieldDesc.isContainer()); var36 = state._elementName + "/" + var36; } } state.markAsUsed(descriptor); if(state._classDesc.getIdentity() == descriptor) { state._key = var25; } } else { if(!state.isUsed(descriptor)) { var28 = true; } state.markAsUsed(descriptor); } try { FieldHandler var42 = descriptor.getHandler(); var36 = descriptor.getSchemaType(); if(var36 != null && var36.equals("QName")) { var25 = this.resolveNamespace(var25); } boolean var41 = true; if(this._reuseObjects && var27._primitiveOrImmutable) { Object var46 = var42.getValue(state._object); if(var46 != null) { var41 = !var46.equals(var25); } } if(descriptor.isMapped()) { MapItem var47; if(!(var25 instanceof MapItem)) { var47 = new MapItem(var27._key, var25); var25 = var47; } else { var47 = (MapItem)var25; if(var47.getValue() == null) { var41 = false; this.addReference(var47.toString(), state._object, descriptor); } } } if(var41) { if(var28 && this._clearCollections) { var42.resetValue(state._object); } if(descriptor.isMultivalued() && descriptor.getSchemaType() != null && descriptor.getSchemaType().equals("list") && ((XMLFieldDescriptorImpl)descriptor).isDerivedFromXSList()) { List var48 = (List)var25; Iterator iterator = var48.iterator(); while(iterator.hasNext()) { Object value = iterator.next(); var42.setValue(state._object, value); if(this._unmarshalListener != null) { this._unmarshalListener.fieldAdded(descriptor.getFieldName(), state._object, var27._object); } } } else { var42.setValue(state._object, var25); if(this._unmarshalListener != null) { this._unmarshalListener.fieldAdded(descriptor.getFieldName(), state._object, var27._object); } } } } catch (Exception var18) { StringWriter var37 = new StringWriter(); PrintWriter var40 = new PrintWriter(var37); var18.printStackTrace(var40); var40.flush(); String err = "unable to add \'" + name + "\' to <"; err = err + state._fieldDesc.getXMLName(); err = err + "> due to the following exception: \n"; err = err + ">>>--- Begin Exception ---<<< \n"; err = err + var37.toString(); err = err + ">>>---- End Exception ----<<< \n"; throw new SAXException(err, var18); } this._namespaces = this._namespaces.getParent(); if(state._fieldDesc.isContainer() && state._classDesc.isChoice() && !state._fieldDesc.isMultivalued()) { this.endElement(state._elementName); } } } } } } } } private byte[] decodeBinaryData(XMLFieldDescriptor descriptor, String binaryData) { byte[] decodedValue; if((!descriptor.isMultivalued() || !"hexBinary".equals(descriptor.getComponentType())) && !"hexBinary".equals(descriptor.getSchemaType())) { decodedValue = Base64Decoder.decode(binaryData); } else { decodedValue = HexDecoder.decode(binaryData); } return decodedValue; } public void endElement(String namespaceURI, String localName, String qName) throws SAXException { if(qName == null || qName.length() == 0) { String prefix; if(localName == null || localName.length() == 0) { prefix = "Missing either \'qName\' or \'localName\', both cannot be null or emtpy."; throw new SAXException(prefix); } qName = localName; if(namespaceURI != null && namespaceURI.length() > 0) { prefix = this._namespaces.getNamespacePrefix(namespaceURI); if(prefix != null && prefix.length() > 0) { qName = prefix + ":" + localName; } } } this.endElement(qName); } public void endPrefixMapping(String prefix) throws SAXException { if(this._anyUnmarshaller != null) { this._anyUnmarshaller.endPrefixMapping(prefix); } } public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { if(this._ignoreElementDepth <= 0) { if(!this._stateInfo.empty()) { if(this._anyUnmarshaller != null) { this._anyUnmarshaller.ignorableWhitespace(ch, start, length); } else { UnmarshalState state = (UnmarshalState)this._stateInfo.peek(); if(state._wsPreserve) { if(state._buffer == null) { state._buffer = new StringBuffer(); } state._buffer.append(ch, start, length); } } } } } public void processingInstruction(String target, String data) throws SAXException { } public void setDocumentLocator(Locator locator) { this._locator = locator; } public Locator getDocumentLocator() { return this._locator; } public void skippedEntity(String name) throws SAXException { } public void startDocument() throws SAXException { } public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if(LOG.isTraceEnabled()) { if(qName != null && qName.length() > 0) { LOG.trace("#startElement: " + qName); } else { LOG.trace("#startElement: " + localName); } } if(!this._strictElements && this._ignoreElementDepth > 0) { ++this._ignoreElementDepth; } else if(this._anyUnmarshaller != null) { ++this._depth; this._anyUnmarshaller.startElement(namespaceURI, localName, qName, atts); } else { if(this._createNamespaceScope) { this._namespaces = this._namespaces.createNamespaces(); } else { this._createNamespaceScope = true; } if(this._reusableAtts == null) { if(atts != null) { this._reusableAtts = new AttributeSetImpl(atts.getLength()); } else { this._reusableAtts = new AttributeSetImpl(); } } else { this._reusableAtts.clear(); } boolean hasQNameAtts = false; int idx; String defaultNamespace; if(atts != null && atts.getLength() > 0) { for(idx = 0; idx < atts.getLength(); ++idx) { defaultNamespace = atts.getQName(idx); if(defaultNamespace != null && defaultNamespace.length() > 0) { if(defaultNamespace.equals("xmlns")) { this._namespaces.addNamespace("", atts.getValue(idx)); } else if(defaultNamespace.startsWith("xmlns:")) { String idx1 = defaultNamespace.substring("xmlns:".length()); this._namespaces.addNamespace(idx1, atts.getValue(idx)); } else if(defaultNamespace.indexOf(58) < 0) { this._reusableAtts.setAttribute(defaultNamespace, atts.getValue(idx), atts.getURI(idx)); } else { hasQNameAtts = true; } } else { defaultNamespace = atts.getLocalName(idx); if("xmlns".equals(defaultNamespace)) { this._namespaces.addNamespace("", atts.getValue(idx)); } else { this._reusableAtts.setAttribute(defaultNamespace, atts.getValue(idx), atts.getURI(idx)); } } } } if(hasQNameAtts) { for(idx = 0; idx < atts.getLength(); ++idx) { defaultNamespace = atts.getQName(idx); if(defaultNamespace != null && defaultNamespace.length() > 0 && !defaultNamespace.equals("xmlns") && !defaultNamespace.startsWith("xmlns:")) { int var12 = defaultNamespace.indexOf(58); if(var12 >= 0) { String prefix = defaultNamespace.substring(0, var12); defaultNamespace = defaultNamespace.substring(var12 + 1); String nsURI = atts.getURI(idx); if(nsURI == null || nsURI.length() == 0) { nsURI = this._namespaces.getNamespaceURI(prefix); } this._reusableAtts.setAttribute(defaultNamespace, atts.getValue(idx), nsURI); } } } } if(this._elemInfo == null) { this._elemInfo = new UnmarshalHandler.ElementInfo((String)null, atts); } else { this._elemInfo.clear(); this._elemInfo._attributes = atts; } String var11; if(localName != null && localName.length() != 0) { if(qName != null && qName.length() != 0) { this._elemInfo._qName = qName; } else if(namespaceURI != null && namespaceURI.length() != 0) { var11 = this._namespaces.getNamespacePrefix(namespaceURI); if(var11 != null && var11.length() > 0) { this._elemInfo._qName = var11 + ":" + localName; } } else { this._elemInfo._qName = localName; } } else { if(qName == null || qName.length() == 0) { var11 = "Missing either \'localName\' or \'qName\', both cannot be emtpy or null."; throw new SAXException(var11); } localName = qName; this._elemInfo._qName = qName; } idx = localName.indexOf(58); if(idx >= 0) { defaultNamespace = localName.substring(0, idx); localName = localName.substring(idx + 1); if(namespaceURI == null || namespaceURI.length() == 0) { namespaceURI = this._namespaces.getNamespaceURI(defaultNamespace); } } else { defaultNamespace = this._namespaces.getNamespaceURI(""); if(defaultNamespace != null && !defaultNamespace.equals("http://castor.exolab.org")) { namespaceURI = defaultNamespace; } if(namespaceURI != null && namespaceURI.length() == 0) { namespaceURI = null; } } this.startElement(localName, namespaceURI, this._reusableAtts); } } public void startElement(String name, AttributeList attList) throws SAXException { if(LOG.isTraceEnabled()) { LOG.trace("#startElement: " + name); } if(!this._strictElements && this._ignoreElementDepth > 0) { ++this._ignoreElementDepth; } else if(this._anyUnmarshaller != null) { ++this._depth; this._anyUnmarshaller.startElement(name, attList); } else { if(this._elemInfo == null) { this._elemInfo = new UnmarshalHandler.ElementInfo(name, attList); } else { this._elemInfo.clear(); this._elemInfo._qName = name; this._elemInfo._attributeList = attList; } String namespace = null; this._namespaces = this._namespaces.createNamespaces(); AttributeSet atts = this.processAttributeList(attList); String prefix = ""; int idx = name.indexOf(58); if(idx >= 0) { prefix = name.substring(0, idx); name = name.substring(idx + 1); } namespace = this._namespaces.getNamespaceURI(prefix); this.startElement(name, namespace, atts); } } private void startElement(String name, String namespace, AttributeSet atts) throws SAXException { UnmarshalState state = null; String xmlSpace = null; if(atts != null) { xmlSpace = atts.getValue("space", "http://www.w3.org/XML/1998/namespace"); if(xmlSpace == null) { xmlSpace = atts.getValue("xml:space", ""); } } String classDesc; XMLClassDescriptor cdInherited; String path; if(this._stateInfo.empty()) { if(this._topClass == null && this._topObject != null) { this._topClass = this._topObject.getClass(); } if(this.getInternalContext().getXMLClassDescriptorResolver() == null) { String var44 = "XMLClassDescriptorResolver is not set!"; LOG.warn(var44); throw new IllegalStateException(var44); } else { this._topState = new UnmarshalState(); this._topState._elementName = name; this._topState._wsPreserve = xmlSpace != null?"preserve".equals(xmlSpace):this._wsPreserve; Object var39 = null; String var40 = null; if(this._topClass == null) { var40 = this.getInstanceType(atts, (String)null); if(var40 != null) { try { this._topClass = this.loadClass(var40, (ClassLoader)null); } catch (ClassNotFoundException var29) { ; } if(this._topClass == null) { var39 = this.getClassDescriptor(var40); if(var39 != null) { this._topClass = ((XMLClassDescriptor)var39).getJavaClass(); } if(this._topClass == null) { throw new SAXException("Class not found: " + var40); } } } else { var39 = this.resolveByXMLName(name, namespace, (ClassLoader)null); if(var39 == null) { var39 = this.getClassDescriptor(name, this._loader); if(var39 == null) { var39 = this.getClassDescriptor(this.getJavaNaming().toJavaClassName(name)); } } if(var39 != null) { this._topClass = ((XMLClassDescriptor)var39).getJavaClass(); } } if(this._topClass == null) { String var51 = "The class for the root element \'" + name + "\' could not be found."; throw new SAXException(var51); } } XMLFieldDescriptorImpl var50 = new XMLFieldDescriptorImpl(this._topClass, name, name, NodeType.Element); this._topState._fieldDesc = var50; if(var39 == null) { var39 = this.getClassDescriptor(this._topClass); } if(var39 == null && isPrimitive(this._topClass)) { var39 = new PrimitivesClassDescriptor(this._topClass); var50.setIncremental(false); this._topState._primitiveOrImmutable = true; } var50.setClassDescriptor((ClassDescriptor)var39); if(var39 == null) { if(!isPrimitive(this._topClass) && !Serializable.class.isAssignableFrom(this._topClass)) { throw new SAXException("The marshaller cannot unmarshal non primitive types that do not implement java.io.Serializable"); } else { classDesc = "unable to create XMLClassDescriptor for class: " + this._topClass.getName(); throw new SAXException(classDesc); } } else { this._topState._classDesc = (XMLClassDescriptor)var39; this._topState._type = this._topClass; if(this._topObject == null && !this._topState._primitiveOrImmutable) { classDesc = this.getJavaPackage(this._topClass); if(var40 == null) { var40 = this.getInstanceType(atts, classDesc); } else { var40 = null; } if(var40 != null) { Class var49 = null; try { cdInherited = this.getClassDescriptor(var40); boolean var47 = true; if(cdInherited != null) { var49 = cdInherited.getJavaClass(); if(var49 != null) { var47 = !var40.equals(var49.getName()); } } if(var47) { try { var49 = this.loadClass(var40, (ClassLoader)null); } catch (ClassNotFoundException var36) { if(cdInherited != null) { var49 = cdInherited.getJavaClass(); } } } if(var49 == null) { throw new SAXException("Class not found: " + var40); } if(!this._topClass.isAssignableFrom(var49)) { path = var49 + " is not a subclass of " + this._topClass; throw new SAXException(path); } } catch (Exception var37) { String var46 = "unable to instantiate " + var40 + "; "; throw new SAXException(var46 + var37, var37); } UnmarshalHandler.Arguments var45 = this.processConstructorArgs(atts, (XMLClassDescriptor)var39); this._topState._object = this.createInstance(var49, var45); } else { UnmarshalHandler.Arguments var48 = this.processConstructorArgs(atts, (XMLClassDescriptor)var39); this._topState._object = this.createInstance(this._topClass, var48); } } else { this._topState._object = this._topObject; } this._stateInfo.push(this._topState); if(!this._topState._primitiveOrImmutable) { if(this._unmarshalListener != null) { this._unmarshalListener.initialized(this._topState._object, this._topState._parent == null?null:this._topState._parent._object); } this.processAttributes(atts, (XMLClassDescriptor)var39); if(this._unmarshalListener != null) { this._unmarshalListener.attributesProcessed(this._topState._object, this._topState._parent == null?null:this._topState._parent._object); } this.processNamespaces((XMLClassDescriptor)var39); } classDesc = this.getJavaPackage(this._topClass); if(this.getMappedPackage(namespace) == null) { this.addNamespaceToPackageMapping(namespace, classDesc); } } } } else { UnmarshalState parentState = (UnmarshalState)this._stateInfo.peek(); XMLClassDescriptor cls; for(boolean canAccept = false; parentState._fieldDesc != null && parentState._fieldDesc.isContainer() && !canAccept; cls = null) { cls = parentState._classDesc; if(cls == null) { cls = (XMLClassDescriptor)parentState._fieldDesc.getClassDescriptor(); if(cls == null) { cls = this.getClassDescriptor(parentState._object.getClass()); } } canAccept = cls.canAccept(name, namespace, parentState._object); if(!canAccept) { if(cls.getFieldDescriptor(name, namespace, NodeType.Element) != null && !parentState._fieldDesc.isMultivalued()) { classDesc = "The container object (" + cls.getJavaClass().getName(); classDesc = classDesc + ") cannot accept the child object associated with the element \'" + name + "\'"; classDesc = classDesc + " because the container is already full!"; ValidationException descriptor = new ValidationException(classDesc); throw new SAXException(descriptor); } this.endElement(parentState._elementName); parentState = (UnmarshalState)this._stateInfo.peek(); } } state = new UnmarshalState(); state._elementName = name; state._parent = parentState; if(xmlSpace != null) { state._wsPreserve = "preserve".equals(xmlSpace); } else { state._wsPreserve = parentState._wsPreserve; } this._stateInfo.push(state); if(parentState._object != null || parentState._wrapper) { cls = null; XMLClassDescriptor var41 = parentState._classDesc; if(var41 == null) { var41 = (XMLClassDescriptor)parentState._fieldDesc.getClassDescriptor(); if(var41 == null) { var41 = this.getClassDescriptor(parentState._object.getClass()); } } XMLFieldDescriptor var43 = null; cdInherited = null; UnmarshalState targetState = parentState; path = ""; StringBuffer pathBuf = null; int count = 0; boolean isWrapper; String object; String handler; for(isWrapper = false; var43 == null; ++count) { if(path.length() > 0) { object = path + "/" + name; var43 = var41.getFieldDescriptor(object, namespace, NodeType.Element); } if(var43 == null) { var43 = var41.getFieldDescriptor(name, namespace, NodeType.Element); } if(var43 != null && !var43.isContainer() && namespace != null && namespace.length() > 0 && !namespaceEquals(namespace, var43.getNameSpaceURI()) && (var43.getNameSpaceURI() != null || !var43.matches("*"))) { var43 = null; } if(var43 == null && !targetState._wrapper) { InheritanceMatch[] var52 = null; try { var52 = this.searchInheritance(name, namespace, var41); } catch (MarshalException var35) { ; } if(var52.length != 0) { InheritanceMatch var53 = null; for(int useHandler = 0; useHandler < var52.length; ++useHandler) { if(parentState._elementName.equals(var52[useHandler].parentFieldDesc.getLocationPath())) { var53 = var52[useHandler]; break; } } if(var53 == null) { var53 = var52[0]; } var43 = var53.parentFieldDesc; cdInherited = var53.inheritedClassDesc; break; } handler = name; if(count > 0) { handler = path + "/" + name; } isWrapper = isWrapper || hasFieldsAtLocation(handler, var41); } else if(var43 != null) { object = var43.getLocationPath(); if(object == null) { object = ""; } if(path.equals(object)) { break; } var43 = null; } else { if(pathBuf == null) { pathBuf = new StringBuffer(); } else { pathBuf.setLength(0); } pathBuf.append(path); pathBuf.append('/'); pathBuf.append(name); isWrapper = isWrapper || hasFieldsAtLocation(pathBuf.toString(), var41); } if(targetState == this._topState) { break; } if(count == 0) { path = targetState._elementName; } else { if(pathBuf == null) { pathBuf = new StringBuffer(); } else { pathBuf.setLength(0); } pathBuf.append(targetState._elementName); pathBuf.append('/'); pathBuf.append(path); path = pathBuf.toString(); } targetState = targetState._parent; var41 = targetState._classDesc; } if(var43 != null && this.isValidating() && !this.getInternalContext().getLenientSequenceOrder()) { try { var41.checkDescriptorForCorrectOrderWithinSequence(var43, parentState, name); } catch (ValidationException var34) { throw new SAXException(var34); } } if(var43 == null) { var41 = var41; if(isWrapper) { state._classDesc = new XMLClassDescriptorImpl(ContainerElement.class, name); state._wrapper = true; if(LOG.isDebugEnabled()) { LOG.debug("wrapper-element: " + name); } this.processWrapperAttributes(atts); } else { object = "unable to find FieldDescriptor for \'" + name; object = object + "\' in ClassDescriptor of " + var41.getXMLName(); if(var41 instanceof InternalXMLClassDescriptor) { var41 = ((InternalXMLClassDescriptor)var41).getClassDescriptor(); } boolean var61 = this.getInternalContext().getBooleanProperty("org.exolab.castor.xml.lenient.introspected.element.strictness").booleanValue(); if(!this._strictElements) { ++this._ignoreElementDepth; this._stateInfo.pop(); this._namespaces = this._namespaces.getParent(); if(LOG.isDebugEnabled()) { LOG.debug(object + " - ignoring extra element."); } } else if(var61 && Introspector.introspected(var41)) { LOG.warn(object); } else { throw new SAXException(object); } } } else { if(targetState != parentState) { state._targetState = targetState; parentState = targetState; } Object var54 = parentState._object; if(var43.isContainer()) { if(LOG.isDebugEnabled()) { LOG.debug("#container: " + var43.getFieldName()); } state.clear(); state._wsPreserve = parentState._wsPreserve; state._parent = parentState; state._elementName = var43.getFieldName(); state._fieldDesc = var43; state._classDesc = (XMLClassDescriptor)var43.getClassDescriptor(); handler = null; Object var60; if(!var43.isMultivalued()) { FieldHandler var58 = var43.getHandler(); var60 = var58.getValue(var54); if(var60 != null) { if(state._classDesc != null) { if(state._classDesc.canAccept(name, namespace, var60)) { parentState.markAsNotUsed(var43); } } else { parentState.markAsNotUsed(var43); } } else { var60 = var58.newInstance(var54); } } else { Class var59 = var43.getFieldType(); try { var60 = var59.newInstance(); } catch (Exception var30) { throw new SAXException(var30); } } state._object = var60; state._type = var60.getClass(); this._namespaces = this._namespaces.createNamespaces(); this.startElement(name, namespace, atts); } else { state._fieldDesc = var43; var41 = null; if(cdInherited != null) { var41 = cdInherited; } else if(!name.equals(var43.getXMLName())) { var41 = this.resolveByXMLName(name, namespace, (ClassLoader)null); } if(var41 == null) { var41 = (XMLClassDescriptor)var43.getClassDescriptor(); } FieldHandler var56 = var43.getHandler(); boolean var55 = true; String nil; String err; Class var42; try { if(var41 != null) { var42 = var41.getJavaClass(); if(var43.getFieldType() != var42) { state._derived = true; } } else { var42 = var43.getFieldType(); } if(var42 == null) { var42 = Object.class; } nil = this.getJavaPackage(parentState._type); err = this.getInstanceType(atts, nil); Class byteArray; String err1; if(err != null) { byteArray = null; try { XMLClassDescriptor ex = this.getClassDescriptor(err, this._loader); boolean var66 = true; if(ex != null) { byteArray = ex.getJavaClass(); var41 = ex; if(byteArray != null) { var66 = !byteArray.getName().equals(err); } } if(var66) { byteArray = this.loadClass(err, (ClassLoader)null); FieldHandler sx = var43.getHandler(); boolean idx = false; if(sx instanceof FieldHandlerImpl) { idx = ((FieldHandlerImpl)sx).isCollection(); } else { idx = Introspector.isCollection(byteArray); } if(!idx && !var42.isAssignableFrom(byteArray) && !isPrimitive(var42)) { String err2 = byteArray.getName() + " is not a subclass of " + var42.getName(); throw new SAXException(err2); } } var42 = byteArray; var55 = false; } catch (Exception var33) { err1 = "unable to instantiate " + err; throw new SAXException(err1 + "; " + var33, var33); } } if(var42 == Object.class && parentState._object instanceof UnmarshalHandler.ArrayHandler) { var42 = ((UnmarshalHandler.ArrayHandler)parentState._object).componentType(); } String var67; if(var42 == Object.class) { byteArray = parentState._type; ClassLoader var62 = byteArray.getClassLoader(); var41 = this.resolveByXMLName(name, namespace, var62); err1 = null; if(var41 == null) { err1 = this.getJavaNaming().toJavaClassName(name); var41 = this.getClassDescriptor(err1, var62); } if(var41 == null) { var67 = byteArray.getName(); int var71 = var67.lastIndexOf(46); if(var71 > 0) { var67 = var67.substring(0, var71 + 1); err1 = var67 + err1; var41 = this.getClassDescriptor(err1, var62); } } if(var41 == null) { this._anyUnmarshaller = new SAX2ANY(this._namespaces, state._wsPreserve); if(this._elemInfo._attributeList != null) { this._anyUnmarshaller.startElement(this._elemInfo._qName, this._elemInfo._attributeList); } else { this._anyUnmarshaller.startElement(namespace, name, this._elemInfo._qName, this._elemInfo._attributes); } this._depth = 1; state._object = this._anyUnmarshaller.getStartingNode(); state._type = var42; return; } var42 = var41.getJavaClass(); var55 = false; } boolean var63 = false; if(var42.isArray()) { var63 = var42.getComponentType() == Byte.TYPE; } UnmarshalHandler.Arguments var64; if(!isPrimitive(var42) && !var43.isImmutable() && !var63) { if(var41 == null) { var41 = this.getClassDescriptor(var42); } if(!state._derived && var55) { boolean var65 = true; if(this._reuseObjects) { state._object = var56.getValue(parentState._object); var65 = state._object == null; } if(var65) { UnmarshalHandler.Arguments var70 = this.processConstructorArgs(atts, var41); if(var70._values != null && var70._values.length > 0) { if(!(var56 instanceof ExtendedFieldHandler)) { var67 = "constructor arguments can only be used with an ExtendedFieldHandler."; throw new SAXException(var67); } ExtendedFieldHandler var68 = (ExtendedFieldHandler)var56; state._object = var68.newInstance(parentState._object, var70._values); } else { state._object = var56.newInstance(parentState._object); } } } if(state._object != null) { var42 = state._object.getClass(); if(var41 != null && var41.getJavaClass() != var42) { var41 = null; } } else { try { if(var42.isArray()) { state._object = new UnmarshalHandler.ArrayHandler(var42.getComponentType()); var42 = UnmarshalHandler.ArrayHandler.class; } else { var64 = this.processConstructorArgs(atts, var41); state._object = this.createInstance(var42, var64); } } catch (Exception var32) { err1 = "unable to instantiate a new type of: "; err1 = err1 + this.className(var42); err1 = err1 + "; " + var32.getMessage(); SAXException var69 = new SAXException(err1, var32); throw var69; } } } else { state._object = null; state._primitiveOrImmutable = true; if(var43.isImmutable()) { if(var41 == null) { var41 = this.getClassDescriptor(var42); } state._classDesc = var41; var64 = this.processConstructorArgs(atts, var41); if(var64 != null && var64.size() > 0) { state._args = var64; } } } state._type = var42; } catch (IllegalStateException var38) { LOG.error(var38.toString()); throw new SAXException(var38); } if(var41 == null) { var41 = this.getClassDescriptor(var42); } state._classDesc = var41; if(state._object == null && !state._primitiveOrImmutable) { nil = "unable to unmarshal: " + name + "\n"; nil = nil + " - unable to instantiate: " + this.className(var42); throw new SAXException(nil); } else { if(var43.isIncremental()) { if(LOG.isDebugEnabled()) { LOG.debug("debug: Processing incrementally for element: " + name); } try { var56.setValue(parentState._object, state._object); } catch (IllegalStateException var31) { err = "unable to add \"" + name + "\" to "; err = err + parentState._fieldDesc.getXMLName(); err = err + " due to the following error: " + var31; throw new SAXException(err, var31); } } if(state._object != null) { if(this._unmarshalListener != null) { this._unmarshalListener.initialized(state._object, state._parent == null?null:state._parent._object); } this.processAttributes(atts, var41); if(this._unmarshalListener != null) { this._unmarshalListener.attributesProcessed(state._object, state._parent == null?null:state._parent._object); } this.processNamespaces(var41); } else if(state._type != null && !state._primitiveOrImmutable) { if(atts != null) { this.processWrapperAttributes(atts); StringBuffer var57 = new StringBuffer(); var57.append("The current object for element \'"); var57.append(name); var57.append("\' is null. Processing attributes as location"); var57.append("/wrapper only and ignoring all other attribtes."); LOG.warn(var57.toString()); } } else if(atts != null) { nil = atts.getValue("nil", "http://www.w3.org/2001/XMLSchema-instance"); state._nil = "true".equals(nil); this.processWrapperAttributes(atts); } } } } } } } private boolean isValidating() { return this._validate; } public void startPrefixMapping(String prefix, String uri) throws SAXException { if(!"xml".equals(prefix) || !"http://www.w3.org/XML/1998/namespace".equals(uri)) { if(!"xmlns".equals(prefix)) { if(this._anyUnmarshaller != null) { this._anyUnmarshaller.startPrefixMapping(prefix, uri); } else if(this._createNamespaceScope) { this._namespaces = this._namespaces.createNamespaces(); this._createNamespaceScope = false; } this._namespaces.addNamespace(prefix, uri); } } } public void error(SAXParseException exception) throws SAXException { String err = "Parsing Error : " + exception.getMessage() + '\n' + "Line : " + exception.getLineNumber() + '\n' + "Column : " + exception.getColumnNumber() + '\n'; throw new SAXException(err, exception); } public void fatalError(SAXParseException exception) throws SAXException { String err = "Parsing Error : " + exception.getMessage() + '\n' + "Line : " + exception.getLineNumber() + '\n' + "Column : " + exception.getColumnNumber() + '\n'; throw new SAXException(err, exception); } public void warning(SAXParseException exception) throws SAXException { String err = "Parsing Error : " + exception.getMessage() + '\n' + "Line : " + exception.getLineNumber() + '\n' + "Column : " + exception.getColumnNumber() + '\n'; throw new SAXException(err, exception); } private void addReference(String idRef, Object parent, XMLFieldDescriptor descriptor) { ReferenceInfo refInfo = new ReferenceInfo(idRef, parent, descriptor); refInfo.setNext((ReferenceInfo)this._resolveTable.get(idRef)); this._resolveTable.put(idRef, refInfo); } private Object createInstance(Class type, UnmarshalHandler.Arguments args) throws SAXException { Object instance = null; try { if(args == null) { instance = this._objectFactory.createInstance(type); } else { instance = this._objectFactory.createInstance(type, args._types, args._values); } return instance; } catch (Exception var6) { String msg = "Unable to instantiate " + type.getName() + "; "; throw new SAXException(msg, var6); } } private String getInstanceType(AttributeSet atts, String currentPackage) throws SAXException { if(atts == null) { return null; } else { String type = atts.getValue("type", "http://www.w3.org/2001/XMLSchema-instance"); if(type != null) { if(type.startsWith("java:")) { return type.substring("java:".length()); } int idx = type.indexOf(58); String typeNamespaceURI = null; String classDesc; if(idx >= 0) { classDesc = type.substring(0, idx); type = type.substring(idx + 1); typeNamespaceURI = this._namespaces.getNamespaceURI(classDesc); } classDesc = null; try { XMLClassDescriptor classDesc1 = this.getInternalContext().getXMLClassDescriptorResolver().resolveByXMLName(type, typeNamespaceURI, this._loader); if(classDesc1 != null) { return classDesc1.getJavaClass().getName(); } String rx = this.getJavaNaming().toJavaClassName(type); String adjClassName = rx; String mappedPackage = this.getMappedPackage(typeNamespaceURI); if(mappedPackage != null && mappedPackage.length() > 0) { adjClassName = mappedPackage + "." + rx; } classDesc1 = this.getInternalContext().getXMLClassDescriptorResolver().resolve(adjClassName, this._loader); if(classDesc1 != null) { return classDesc1.getJavaClass().getName(); } if(currentPackage != null && currentPackage.length() > 0) { adjClassName = currentPackage + '.' + rx; } classDesc1 = this.getInternalContext().getXMLClassDescriptorResolver().resolve(adjClassName, this._loader); if(classDesc1 != null) { return classDesc1.getJavaClass().getName(); } classDesc1 = this.getInternalContext().getXMLClassDescriptorResolver().resolve(type, this._loader); if(classDesc1 != null) { return classDesc1.getJavaClass().getName(); } } catch (ResolverException var10) { throw new SAXException(var10); } } return null; } } private String getMappedPackage(String namespace) { String lookUpKey = namespace != null?namespace:""; return (String)this._namespaceToPackage.get(lookUpKey); } private void processAttributes(AttributeSet atts, XMLClassDescriptor classDesc) throws SAXException { if(atts != null && atts.getSize() != 0) { UnmarshalState var21 = (UnmarshalState)this._stateInfo.peek(); Object var22 = var21._object; if(classDesc == null) { classDesc = var21._classDesc; if(classDesc == null) { this.processWrapperAttributes(atts); return; } } boolean[] var23 = new boolean[atts.getSize()]; XMLFieldDescriptor[] var24 = classDesc.getAttributeDescriptors(); XMLFieldDescriptor[] i = var24; int namespace = var24.length; XMLFieldDescriptor descriptor; String ise; String err; for(int name = 0; name < namespace; ++name) { descriptor = i[name]; ise = descriptor.getXMLName(); err = descriptor.getNameSpaceURI(); String pathBuf = descriptor.getLocationPath(); String targetState = ""; if(pathBuf != null && pathBuf.length() > 0) { targetState = targetState + pathBuf + "/"; } targetState = targetState + ise; int tmpPath; if(targetState != null && !ise.equals(targetState)) { tmpPath = atts.getIndex(ise, err); if(tmpPath >= 0) { var23[tmpPath] = true; } } else { tmpPath = atts.getIndex(ise, err); String attValue = null; if(tmpPath >= 0) { attValue = atts.getValue(tmpPath); var23[tmpPath] = true; } try { this.processAttribute(ise, err, attValue, descriptor, classDesc, var22); } catch (IllegalStateException var20) { String err1 = "unable to add attribute \"" + ise + "\" to \'"; err1 = err1 + var21._classDesc.getJavaClass().getName(); err1 = err1 + "\' due to the following error: " + var20; throw new SAXException(err1, var20); } } } for(int var25 = 0; var25 < var23.length; ++var25) { if(!var23[var25]) { String var26 = atts.getNamespace(var25); String var27 = atts.getName(var25); String var29; if("http://www.w3.org/2001/XMLSchema-instance".equals(var26)) { if("nil".equals(var27)) { var29 = atts.getValue(var25); var21._nil = "true".equals(var29); } } else if(var27.startsWith("xml:")) { if(LOG.isDebugEnabled()) { var29 = "ignoring attribute \'" + var27 + "\' for class: " + var21._classDesc.getJavaClass().getName(); LOG.debug(var29); } } else { descriptor = classDesc.getFieldDescriptor(var27, var26, NodeType.Attribute); if(descriptor == null) { int var28 = this._stateInfo.size() - 2; err = var21._elementName; StringBuffer var30 = null; while(var28 >= 0) { UnmarshalState var31 = (UnmarshalState)this._stateInfo.elementAt(var28); --var28; if(var31._wrapper) { if(var30 == null) { var30 = new StringBuffer(); } else { var30.setLength(0); } var30.append(var31._elementName); var30.append('/'); var30.append(err); err = var30.toString(); } else { classDesc = var31._classDesc; descriptor = classDesc.getFieldDescriptor(var27, var26, NodeType.Attribute); if(descriptor != null) { String var32 = descriptor.getLocationPath(); if(var32 == null) { var32 = ""; } if(err.equals(var32)) { break; } } if(var30 == null) { var30 = new StringBuffer(); } else { var30.setLength(0); } var30.append(var31._elementName); var30.append('/'); var30.append(err); err = var30.toString(); descriptor = null; } } } if(descriptor == null) { if(this._strictAttributes) { ise = "The attribute \'" + var27 + "\' appears illegally on element \'" + var21._elementName + "\'."; throw new SAXException(ise); } } else { try { this.processAttribute(var27, var26, atts.getValue(var25), descriptor, classDesc, var22); } catch (IllegalStateException var19) { err = "unable to add attribute \"" + var27 + "\" to \'"; err = err + var21._classDesc.getJavaClass().getName(); err = err + "\' due to the following error: " + var19; throw new SAXException(err, var19); } } } } } } else { if(classDesc != null) { XMLFieldDescriptor[] state = classDesc.getAttributeDescriptors(); for(int object = 0; object < state.length; ++object) { XMLFieldDescriptor processedAtts = state[object]; if(processedAtts != null && processedAtts.isRequired() && (this.isValidating() || LOG.isDebugEnabled())) { String descriptors = classDesc.getXMLName() + " is missing " + "required attribute: " + processedAtts.getXMLName(); if(this._locator != null) { descriptors = descriptors + "\n - line: " + this._locator.getLineNumber() + " column: " + this._locator.getColumnNumber(); } if(this.isValidating()) { throw new SAXException(descriptors); } LOG.debug(descriptors); } } } } } private void processWrapperAttributes(AttributeSet atts) throws SAXException { UnmarshalState state = (UnmarshalState)this._stateInfo.peek(); for(int i = 0; i < atts.getSize(); ++i) { String name = atts.getName(i); String namespace = atts.getNamespace(i); if(!"http://www.w3.org/2001/XMLSchema-instance".equals(namespace)) { XMLFieldDescriptor descriptor = null; XMLClassDescriptor classDesc = null; int pIdx = this._stateInfo.size() - 2; String path = state._elementName; StringBuffer pathBuf = null; UnmarshalState targetState = null; while(pIdx >= 0) { targetState = (UnmarshalState)this._stateInfo.elementAt(pIdx); --pIdx; if(targetState._wrapper) { if(pathBuf == null) { pathBuf = new StringBuffer(); } else { pathBuf.setLength(0); } pathBuf.append(targetState._elementName); pathBuf.append('/'); pathBuf.append(path); path = pathBuf.toString(); } else { classDesc = targetState._classDesc; XMLFieldDescriptor[] ise = classDesc.getAttributeDescriptors(); boolean err = false; for(int a = 0; a < ise.length; ++a) { descriptor = ise[a]; if(descriptor != null && descriptor.matches(name)) { String tmpPath = descriptor.getLocationPath(); if(tmpPath == null) { tmpPath = ""; } if(path.equals(tmpPath)) { err = true; break; } } } if(err) { break; } if(pathBuf == null) { pathBuf = new StringBuffer(); } else { pathBuf.setLength(0); } pathBuf.append(targetState._elementName); pathBuf.append('/'); pathBuf.append(path); path = pathBuf.toString(); descriptor = null; } } if(descriptor != null) { try { this.processAttribute(name, namespace, atts.getValue(i), descriptor, classDesc, targetState._object); } catch (IllegalStateException var16) { String var17 = "unable to add attribute \"" + name + "\" to \'"; var17 = var17 + state._classDesc.getJavaClass().getName(); var17 = var17 + "\' due to the following error: " + var16; throw new SAXException(var17, var16); } } } } } private void processAttribute(String attName, String attNamespace, String attValue, XMLFieldDescriptor descriptor, XMLClassDescriptor classDesc, Object parent) throws SAXException { FieldHandler handler; while(descriptor.isContainer()) { handler = descriptor.getHandler(); Object type = handler.getValue(parent); if(type == null) { type = handler.newInstance(parent); handler.setValue(parent, type); } ClassDescriptor valueType = ((XMLFieldDescriptorImpl)descriptor).getClassDescriptor(); descriptor = ((XMLClassDescriptor)valueType).getFieldDescriptor(attName, attNamespace, NodeType.Attribute); parent = type; } if(attValue == null) { if(descriptor.isRequired() && this.isValidating()) { String handler3 = classDesc.getXMLName() + " is missing " + "required attribute: " + attName; if(this._locator != null) { handler3 = handler3 + "\n - line: " + this._locator.getLineNumber() + " column: " + this._locator.getColumnNumber(); } throw new SAXException(handler3); } } else { if(classDesc.getIdentity() == descriptor) { try { ((IDResolverImpl)this._idResolver).bind(attValue, parent, this.isValidating() && !this.getInternalContext().getLenientIdValidation()); } catch (ValidationException var14) { throw new SAXException("Duplicate ID " + attValue + " encountered.", var14); } UnmarshalState handler1 = (UnmarshalState)this._stateInfo.peek(); handler1._key = attValue; this.resolveReferences(attValue, parent); } else if(descriptor.isReference()) { if(descriptor.isMultivalued()) { StringTokenizer handler2 = new StringTokenizer(attValue); while(handler2.hasMoreTokens()) { this.processIDREF(handler2.nextToken(), descriptor, parent); } } else { this.processIDREF(attValue, descriptor, parent); } return; } if(!descriptor.isConstructorArgument()) { handler = descriptor.getHandler(); if(handler != null) { Class type1 = descriptor.getFieldType(); String valueType1 = descriptor.getSchemaType(); boolean isPrimative = isPrimitive(type1); boolean isQName = valueType1 != null && valueType1.equals("QName"); boolean isByteArray = false; if(type1.isArray()) { isByteArray = type1.getComponentType() == Byte.TYPE; } if(descriptor.isMultivalued()) { StringTokenizer attrValueTokenizer = new StringTokenizer(attValue); while(attrValueTokenizer.hasMoreTokens()) { attValue = attrValueTokenizer.nextToken(); this.setAttributeValueOnObject(attValue, descriptor, parent, handler, type1, isPrimative, isQName, isByteArray); } } else { this.setAttributeValueOnObject(attValue, descriptor, parent, handler, type1, isPrimative, isQName, isByteArray); } } } } } private void setAttributeValueOnObject(String attValue, XMLFieldDescriptor descriptor, Object parent, FieldHandler handler, Class type, boolean isPrimitive, boolean isQName, boolean isByteArray) throws SAXException { Object value = attValue; if(isPrimitive) { value = this.toPrimitiveObject(type, attValue, descriptor); } if(isByteArray) { if(attValue == null) { value = new byte[0]; } else if("hexBinary".equals(descriptor.getComponentType())) { value = HexDecoder.decode(attValue); } else { value = Base64Decoder.decode(attValue); } } if(isQName) { value = this.resolveNamespace(value); } handler.setValue(parent, value); } private UnmarshalHandler.Arguments processConstructorArgs(AttributeSet atts, XMLClassDescriptor classDesc) throws SAXException { if(classDesc == null) { return new UnmarshalHandler.Arguments(); } else { int count = 0; XMLFieldDescriptor[] descriptors = classDesc.getAttributeDescriptors(); XMLFieldDescriptor[] args = descriptors; int arr$ = descriptors.length; int len$; for(len$ = 0; len$ < arr$; ++len$) { XMLFieldDescriptor i$ = args[len$]; if(i$ != null && i$.isConstructorArgument()) { ++count; } } UnmarshalHandler.Arguments var16 = new UnmarshalHandler.Arguments(); if(count == 0) { return var16; } else { var16._values = new Object[count]; var16._types = new Class[count]; XMLFieldDescriptor[] var17 = descriptors; len$ = descriptors.length; for(int var18 = 0; var18 < len$; ++var18) { XMLFieldDescriptor descriptor = var17[var18]; if(descriptor != null && descriptor.isConstructorArgument()) { int argIndex = descriptor.getConstructorArgumentIndex(); String name; if(argIndex >= count) { name = "argument index out of bounds: " + argIndex; throw new SAXException(name); } var16._types[argIndex] = descriptor.getFieldType(); name = descriptor.getXMLName(); String namespace = descriptor.getNameSpaceURI(); int index = atts.getIndex(name, namespace); if(index >= 0) { String value = atts.getValue(index); Object var19; if(isPrimitive(var16._types[argIndex])) { var19 = this.toPrimitiveObject(var16._types[argIndex], (String)value, descriptor); } else { var19 = this.convertToEnumObject(descriptor, value); } String valueType = descriptor.getSchemaType(); if(valueType != null && valueType.equals("QName")) { var19 = this.resolveNamespace(var19); } var16._values[argIndex] = var19; } else if(isPrimitive(var16._types[argIndex])) { var16._values[argIndex] = this.toPrimitiveObject(var16._types[argIndex], (String)null, descriptor); } else { var16._values[argIndex] = null; } } } return var16; } } } private Object convertToEnumObject(XMLFieldDescriptor descriptor, Object value) { Class fieldType = descriptor.getFieldType(); try { Method valueOfMethod = fieldType.getMethod("valueOf", new Class[]{String.class}); if(valueOfMethod != null && Modifier.isStatic(valueOfMethod.getModifiers())) { Class e = valueOfMethod.getReturnType(); if(e.isAssignableFrom(fieldType)) { Object enumObject = valueOfMethod.invoke((Object)null, new Object[]{value}); value = enumObject; } } } catch (SecurityException var7) { ; } catch (NoSuchMethodException var8) { ; } catch (IllegalArgumentException var9) { ; } catch (IllegalAccessException var10) { ; } catch (InvocationTargetException var11) { ; } return value; } private boolean processIDREF(String idRef, XMLFieldDescriptor descriptor, Object parent) { Object value = this._idResolver.resolve(idRef); if(value == null) { this.addReference(idRef, parent, descriptor); } else { FieldHandler handler = descriptor.getHandler(); if(handler != null) { handler.setValue(parent, value); } } return value != null; } private AttributeSet processAttributeList(AttributeList atts) throws SAXException { if(atts == null) { return new AttributeSetImpl(0); } else { int attCount = 0; boolean[] validAtts = new boolean[atts.getLength()]; String namespace; for(int attSet = 0; attSet < validAtts.length; ++attSet) { String i = atts.getName(attSet); if(i.equals("xmlns")) { this._namespaces.addNamespace("", atts.getValue(attSet)); } else if(i.startsWith("xmlns:")) { namespace = i.substring(XMLNS_PREFIX_LENGTH); this._namespaces.addNamespace(namespace, atts.getValue(attSet)); } else { validAtts[attSet] = true; ++attCount; } } AttributeSetImpl var11 = null; if(attCount > 0) { var11 = new AttributeSetImpl(attCount); for(int var12 = 0; var12 < validAtts.length; ++var12) { if(validAtts[var12]) { namespace = null; String attName = atts.getName(var12); int idx = attName.indexOf(58); if(idx > 0) { String prefix = attName.substring(0, idx); if(!prefix.equals("xml")) { attName = attName.substring(idx + 1); namespace = this._namespaces.getNamespaceURI(prefix); if(namespace == null) { String error = "The namespace associated with the prefix \'" + prefix + "\' could not be resolved."; throw new SAXException(error); } } } var11.setAttribute(attName, atts.getValue(var12), namespace); } } } else { var11 = new AttributeSetImpl(0); } return var11; } } private void processNamespaces(XMLClassDescriptor classDesc) { if(classDesc != null) { XMLFieldDescriptor nsDescriptor = classDesc.getFieldDescriptor((String)null, (String)null, NodeType.Namespace); if(nsDescriptor != null) { UnmarshalState state = (UnmarshalState)this._stateInfo.peek(); FieldHandler handler = nsDescriptor.getHandler(); if(handler != null) { Enumeration enumeration = this._namespaces.getLocalNamespacePrefixes(); while(enumeration.hasMoreElements()) { String nsPrefix = (String)enumeration.nextElement(); if(nsPrefix == null) { nsPrefix = ""; } String nsURI = this._namespaces.getNamespaceURI(nsPrefix); if(nsURI == null) { nsURI = ""; } MapItem mapItem = new MapItem(nsPrefix, nsURI); handler.setValue(state._object, mapItem); } } } } } private Object resolveNamespace(Object value) throws SAXException { if(value != null && value instanceof String) { String result = (String)value; int idx = result.indexOf(58); String prefix = null; if(idx > 0) { prefix = result.substring(0, idx); if("xml".equals(prefix)) { return value; } result = result.substring(idx + 1); } String namespace = this._namespaces.getNamespaceURI(prefix); if(namespace != null && namespace.length() > 0) { result = '{' + namespace + '}' + result; return result; } else if(namespace == null && prefix != null) { throw new SAXException("The namespace associated with the prefix: \'" + prefix + "\' is null."); } else { return result; } } else { return value; } } private XMLClassDescriptor getClassDescriptor(String className) throws SAXException { Class type = null; try { if(this._loader != null) { type = this._loader.loadClass(className); } else { type = Class.forName(className); } } catch (ClassNotFoundException var4) { return null; } return this.getClassDescriptor(type); } private XMLClassDescriptor getClassDescriptor(Class cls) throws SAXException { if(cls == null) { return null; } else if(cls == String.class) { return STRING_DESCRIPTOR; } else if(cls.isArray()) { return null; } else if(isPrimitive(cls)) { return null; } else { XMLClassDescriptor classDesc = null; try { InternalContext rx = this.getInternalContext(); classDesc = (XMLClassDescriptor)rx.getXMLClassDescriptorResolver().resolve(cls); } catch (ResolverException var4) { ; } if(classDesc != null) { return new InternalXMLClassDescriptor(this, classDesc); } else { if(LOG.isDebugEnabled()) { LOG.debug("unable to find or create a ClassDescriptor for class: " + cls.getName()); } return classDesc; } } } private XMLClassDescriptor getClassDescriptor(String className, ClassLoader loader) throws SAXException { XMLClassDescriptor classDesc = null; try { classDesc = this.getInternalContext().getXMLClassDescriptorResolver().resolve(className, loader); } catch (ResolverException var5) { throw new SAXException(var5); } if(classDesc != null) { return new InternalXMLClassDescriptor(this, classDesc); } else { if(LOG.isDebugEnabled()) { LOG.debug("unable to find or create a ClassDescriptor for class: " + className); } return classDesc; } } private XMLClassDescriptor resolveByXMLName(String name, String namespace, ClassLoader loader) throws SAXException { try { return this.getInternalContext().getXMLClassDescriptorResolver().resolveByXMLName(name, namespace, loader); } catch (ResolverException var5) { throw new SAXException(var5); } } private String getJavaPackage(Class type) { if(type == null) { return null; } else { String pkg = (String)this._javaPackages.get(type); if(pkg == null) { pkg = type.getName(); int idx = pkg.lastIndexOf(46); if(idx > 0) { pkg = pkg.substring(0, idx); } else { pkg = ""; } this._javaPackages.put(type, pkg); } return pkg; } } private String className(Class type) { return type.isArray()?this.className(type.getComponentType()) + "[]":type.getName(); } private static boolean isWhitespace(StringBuffer sb) { int i = 0; while(i < sb.length()) { char ch = sb.charAt(i); switch(ch) { case '\t': case '\n': case '\r': case ' ': ++i; break; default: return false; } } return true; } private Class loadClass(String className, ClassLoader loader) throws ClassNotFoundException { return loader != null?loader.loadClass(className):(this._loader != null?this._loader.loadClass(className):Class.forName(className)); } private void resolveReferences(String id, Object value) throws SAXException { if(id != null && value != null) { if(this._resolveTable != null) { for(ReferenceInfo refInfo = (ReferenceInfo)this._resolveTable.remove(id); refInfo != null; refInfo = refInfo.getNext()) { try { FieldHandler ise = refInfo.getDescriptor().getHandler(); if(ise != null) { ise.setValue(refInfo.getTarget(), value); } if(refInfo.getTarget() instanceof MapItem) { this.resolveReferences(refInfo.getTarget().toString(), refInfo.getTarget()); } } catch (IllegalStateException var6) { String err = "Attempting to resolve an IDREF: " + id + "resulted in the following error: " + var6.toString(); throw new SAXException(err, var6); } } } } } private Object toPrimitiveObject(Class type, String value, XMLFieldDescriptor fieldDesc) throws SAXException { try { return toPrimitiveObject(type, value); } catch (Exception var8) { String err = "The following error occured while trying to "; err = err + "unmarshal field " + fieldDesc.getFieldName(); UnmarshalState state = (UnmarshalState)this._stateInfo.peek(); if(state != null && state._object != null) { err = err + " of class " + state._object.getClass().getName(); } err = err + "."; SAXException saxException = new SAXException(err); saxException.initCause(var8); throw saxException; } } public static Object toPrimitiveObject(Class type, String value) { Object primitive = value; if(value != null && type != Character.TYPE && type != Character.class) { value = value.trim(); } boolean isNull = value == null || value.length() == 0; if(type != Integer.TYPE && type != Integer.class) { if(type != Boolean.TYPE && type != Boolean.class) { if(type != Double.TYPE && type != Double.class) { if(type != Long.TYPE && type != Long.class) { if(type != Character.TYPE && type != Character.class) { if(type != Short.TYPE && type != Short.class) { if(type != Float.TYPE && type != Float.class) { if(type != Byte.TYPE && type != Byte.class) { if(type == BigDecimal.class) { if(isNull) { primitive = new BigDecimal(0); } else { primitive = new BigDecimal(value); } } else if(type == BigInteger.class) { if(isNull) { primitive = BigInteger.valueOf(0L); } else { primitive = new BigInteger(value); } } else if(type.getSuperclass().getName().equals("java.lang.Enum")) { if(isNull) { primitive = null; } else { Method e; try { e = type.getMethod("fromValue", new Class[]{String.class}); primitive = e.invoke((Object)null, new Object[]{value}); return primitive; } catch (NoSuchMethodException var9) { ; } catch (IllegalArgumentException var10) { throw new IllegalStateException(var10.toString()); } catch (IllegalAccessException var11) { throw new IllegalStateException(var11.toString()); } catch (InvocationTargetException var12) { if(var12.getTargetException() instanceof RuntimeException) { throw (RuntimeException)var12.getTargetException(); } } try { e = type.getMethod("valueOf", new Class[]{String.class}); primitive = e.invoke((Object)null, new Object[]{value}); } catch (IllegalAccessException var6) { throw new IllegalStateException(var6.toString()); } catch (InvocationTargetException var7) { if(var7.getTargetException() instanceof RuntimeException) { throw (RuntimeException)var7.getTargetException(); } } catch (NoSuchMethodException var8) { String err = type.getName() + " does not contain the required method: public static " + type.getName() + " valueOf(String);"; throw new IllegalArgumentException(err); } } } } else if(isNull) { primitive = new Byte(0); } else { primitive = new Byte(value); } } else if(isNull) { primitive = new Float(0.0F); } else { primitive = new Float(value); } } else if(isNull) { primitive = new Short(0); } else { primitive = new Short(value); } } else if(!isNull) { primitive = new Character(value.charAt(0)); } else { primitive = new Character('\u0000'); } } else if(isNull) { primitive = new Long(0L); } else { primitive = new Long(value); } } else if(isNull) { primitive = new Double(0.0D); } else { primitive = new Double(value); } } else if(isNull) { primitive = Boolean.FALSE; } else if(!value.equals("1") && !value.toLowerCase().equals("true")) { if(!value.equals("0") && !value.toLowerCase().equals("false")) { throw new IllegalArgumentException(" A value of >" + value + "< cannot be converted to a boolean value."); } primitive = Boolean.FALSE; } else { primitive = Boolean.TRUE; } } else if(isNull) { primitive = new Integer(0); } else { primitive = new Integer(value); } return primitive; } public ObjectFactory getObjectFactory() { return this._objectFactory; } public void setObjectFactory(ObjectFactory objectFactory) { this._objectFactory = objectFactory; } public static class ArrayHandler { Class _componentType = null; ArrayList _items = null; ArrayHandler(Class componentType) { if(componentType == null) { String err = "The argument \'componentType\' may not be null."; throw new IllegalArgumentException(err); } else { this._componentType = componentType; this._items = new ArrayList(); } } public void addObject(Object obj) { if(obj != null) { this._items.add(obj); } } public Object getObject() { int size = this._items.size(); Object array = Array.newInstance(this._componentType, size); for(int i = 0; i < size; ++i) { Array.set(array, i, this._items.get(i)); } return array; } public Class componentType() { return this._componentType; } } class Arguments { private Object[] _values = null; private Class[] _types = null; public int size() { return this._values == null?0:this._values.length; } } class ElementInfo { private String _qName = null; private Attributes _attributes = null; private AttributeList _attributeList = null; ElementInfo() { } ElementInfo(String qName, Attributes atts) { this._qName = qName; this._attributes = atts; } ElementInfo(String qName, AttributeList atts) { this._qName = qName; this._attributeList = atts; } void clear() { this._qName = null; this._attributes = null; this._attributeList = null; } } }