home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 2009-05-06 | 61.6 KB | 1,839 lines
package mx.rpc.xml { import flash.utils.ByteArray; import flash.utils.getQualifiedClassName; import mx.collections.ArrayCollection; import mx.logging.ILogger; import mx.logging.Log; import mx.utils.DescribeTypeCache; import mx.utils.ObjectProxy; import mx.utils.URLUtil; import mx.utils.XMLUtil; import mx.utils.object_proxy; public class XMLDecoder extends SchemaProcessor implements IXMLDecoder { public static var listClass:Class = ArrayCollection; private var _recordXSIType:Boolean; protected var document:XML; private var log:ILogger; private var _makeObjectsBindable:Boolean; private var _typeRegistry:SchemaTypeRegistry; public function XMLDecoder() { super(); log = Log.getLogger("mx.rpc.xml.XMLDecoder"); typeRegistry = SchemaTypeRegistry.getInstance(); } public function createIterableValue(param1:Object = null) : * { var value:* = undefined; var c:Class = null; var type:Object = param1; try { if(type != null) { c = typeRegistry.getCollectionClass(type); if(c != null) { value = new c(); } } } catch(e1:Error) { log.debug("Error while resolving custom collection type for \'{0}\'.\nError: \'{1}\'.",type,e1); } try { if(value == null) { if(makeObjectsBindable) { value = new listClass(); } else { value = []; } } } catch(e2:Error) { log.warn("Unable to create instance of \'{0}\'.",listClass); } return value; } public function get makeObjectsBindable() : Boolean { return _makeObjectsBindable; } public function decodeAnyElement(param1:XML, param2:*, param3:QName, param4:XMLList, param5:DecodingContext = null, param6:Boolean = true) : Boolean { var _loc7_:Array = null; var _loc9_:String = null; var _loc13_:XML = null; var _loc14_:String = null; var _loc15_:String = null; var _loc16_:QName = null; var _loc17_:* = undefined; var _loc18_:* = undefined; if(param5 == null) { param5 = new DecodingContext(); } var _loc8_:Boolean = true; var _loc10_:uint = getMaxOccurs(param1); var _loc11_:uint = getMinOccurs(param1); if(param1 != null) { _loc14_ = param1["processContents"]; _loc15_ = param1["namespace"]; if(_loc15_ != "" && _loc15_ != "##any") { if(schemaManager.currentSchema != null && schemaManager.currentSchema.targetNamespace != null) { _loc9_ = schemaManager.currentSchema.targetNamespace.uri; } if(_loc15_ == "##other") { _loc8_ = false; } else { if(_loc15_.indexOf("##targetNamespace") >= 0) { _loc15_ = _loc15_.replace("##targetNamespace",_loc9_); } _loc7_ = _loc15_.split(" "); } } } var _loc12_:XMLList = getApplicableValues(param2,param4,null,param5,_loc10_); for each(_loc13_ in _loc12_) { _loc16_ = _loc13_.name() as QName; if(!_loc8_ && URLUtil.urisEqual(_loc16_.uri,_loc9_)) { break; } if(includeNamespace(_loc16_.uri,_loc7_)) { if(_loc14_ == "skip") { _loc18_ = _loc13_.toXMLString(); } else { _loc18_ = _loc13_; } decodeAnyType(param2,_loc16_,new XMLList(_loc18_)); if(param5.anyIndex < 0) { param5.anyIndex = param5.index + 0; } ++param5.index; } } return true; } public function decodeComplexRestriction(param1:XML, param2:*, param3:QName, param4:*) : void { var _loc9_:XML = null; var _loc5_:String = getAttributeFromNode("base",param1); if(_loc5_ == null) { throw new Error("A complexContent restriction must declare a base type."); } var _loc6_:QName = schemaManager.getQNameForPrefixedName(_loc5_,param1); var _loc7_:XMLList = param1.elements(); var _loc8_:XMLList = new XMLList(); if(param4 is XML) { _loc8_ = (param4 as XML).elements(); } else if(param4 is XMLList) { _loc8_ = param4; } for each(_loc9_ in _loc7_) { if(_loc9_.name() == constants.sequenceQName) { decodeSequence(_loc9_,param2,param3,_loc8_); } else if(_loc9_.name() == constants.groupQName) { decodeGroupReference(_loc9_,param2,param3,_loc8_); } else if(_loc9_.name() == constants.allQName) { decodeAll(_loc9_,param2,param3,_loc8_); } else if(_loc9_.name() == constants.choiceQName) { decodeChoice(_loc9_,param2,param3,_loc8_); } else if(_loc9_.name() == constants.attributeQName) { decodeAttribute(_loc9_,param2,param4); } else if(_loc9_.name() == constants.attributeGroupQName) { decodeAttributeGroup(_loc9_,param2,param4); } else if(_loc9_.name() == constants.anyAttributeQName) { decodeAnyAttribute(_loc9_,param2,param4); } } } public function decodeGroupElement(param1:XML, param2:*, param3:XMLList, param4:DecodingContext = null, param5:Boolean = true, param6:Boolean = true) : Boolean { var _loc9_:QName = null; var _loc13_:* = undefined; var _loc14_:String = null; var _loc15_:QName = null; var _loc16_:* = undefined; var _loc17_:uint = 0; var _loc18_:XML = null; if(param4 == null) { param4 = new DecodingContext(); } var _loc7_:uint = getMaxOccurs(param1); var _loc8_:uint = getMinOccurs(param1); if(_loc7_ == 0) { return true; } if(param1.attribute("ref").length() == 1) { _loc9_ = schemaManager.getQNameForPrefixedName(param1.@ref,param1,true); param1 = schemaManager.getNamedDefinition(_loc9_,constants.elementTypeQName); if(param1 == null) { throw new Error("Cannot resolve element definition for ref \'" + _loc9_ + "\'"); } } var _loc10_:String = param1.@name.toString(); var _loc11_:QName = schemaManager.getQNameForElement(_loc10_,getAttributeFromNode("form",param1)); var _loc12_:XMLList = getApplicableValues(param2,param3,_loc11_,param4,_loc7_); if(_loc12_.length() == 1 && isXSINil(_loc12_[0])) { setValue(param2,_loc11_,null); ++param4.index; if(_loc9_ != null) { schemaManager.releaseScope(); } return true; } if(_loc7_ > 1) { _loc14_ = getAttributeFromNode("type",param1); if(_loc14_ != null) { _loc15_ = schemaManager.getQNameForPrefixedName(_loc14_,param1); } _loc16_ = createIterableValue(_loc15_); if(param6) { setValue(param2,_loc11_,_loc16_,_loc15_); } else if(!(param2 is ContentProxy && param2.object_proxy::content != undefined)) { setValue(param2,null,_loc16_,_loc15_); } } if(_loc12_.length() == 0) { if(_loc9_ != null) { schemaManager.releaseScope(); } if(_loc8_ == 0) { return true; } return false; } if(_loc7_ == 1) { _loc13_ = decodeElementTopLevel(param1,_loc11_,parseValue(_loc11_,_loc12_)); setValue(param2,_loc11_,_loc13_); ++param4.index; } else if(_loc7_ > 1) { if(_loc12_.length() < _loc8_) { if(_loc9_ != null) { schemaManager.releaseScope(); } if(strictOccurenceBounds) { throw new Error("Value supplied for element \'" + _loc11_ + "\' occurs " + _loc12_.length() + " times which falls short of minOccurs " + _loc8_ + "."); } return false; } if(_loc12_.length() > _loc7_) { if(_loc9_ != null) { schemaManager.releaseScope(); } if(strictOccurenceBounds) { throw new Error("Value supplied for element of type \'" + _loc11_ + "\' occurs " + _loc12_.length() + " times which exceeds maxOccurs " + _loc7_ + "."); } return false; } _loc17_ = 0; while(_loc17_ < _loc7_ && _loc17_ < _loc12_.length()) { _loc18_ = _loc12_[_loc17_]; _loc13_ = decodeElementTopLevel(param1,_loc11_,_loc18_); setValue(param2,_loc11_,_loc13_); ++param4.index; _loc17_++; } } if(_loc9_ != null) { schemaManager.releaseScope(); } return true; } public function decodeElementTopLevel(param1:XML, param2:QName, param3:*) : * { var _loc4_:* = undefined; var _loc8_:* = undefined; var _loc10_:QName = null; var _loc11_:XML = null; var _loc12_:QName = null; var _loc5_:Boolean = param1.@nillable.toString() == "true" ? true : false; if((_loc5_) && param3 == null) { return param3; } var _loc6_:String = getAttributeFromNode("fixed",param1); if(_loc6_ != null) { param3 = _loc6_; } var _loc7_:String = getAttributeFromNode("default",param1); if(!_loc5_ && param3 == null) { param3 = _loc7_; } if(param3 == null) { return param3; } var _loc9_:String = getAttributeFromNode("type",param1); if(_loc9_ != null) { _loc10_ = schemaManager.getQNameForPrefixedName(_loc9_,param1); _loc4_ = createContent(_loc10_); decodeType(_loc10_,_loc4_,param2,param3); return _loc4_; } if(param1.hasComplexContent()) { _loc11_ = getSingleElementFromNode(param1,constants.complexTypeQName,constants.simpleTypeQName); _loc4_ = createContent(); if(_loc11_.name() == constants.complexTypeQName) { decodeComplexType(_loc11_,_loc4_,param2,param3); } else if(_loc11_.name() == constants.simpleTypeQName) { decodeSimpleType(_loc11_,_loc4_,param2,param3); } return _loc4_; } if(_loc6_ != null || _loc7_ != null) { _loc12_ = schemaManager.schemaDatatypes.stringQName; } else { _loc12_ = constants.anyTypeQName; } _loc4_ = createContent(_loc12_); decodeType(_loc12_,_loc4_,param2,param3); return _loc4_; } protected function parseValue(param1:*, param2:XMLList) : * { var _loc3_:* = param2; if(param2.hasSimpleContent()) { if(isXSINil(param2)) { _loc3_ = null; } else { _loc3_ = param2.toString(); } } else if(param2.length() == 1) { _loc3_ = param2[0]; } return _loc3_; } protected function includeNamespace(param1:String, param2:Array = null) : Boolean { var _loc3_:Boolean = false; var _loc4_:String = null; if(param2 != null) { _loc3_ = false; for each(_loc4_ in param2) { if(_loc4_ == "##local" && param1 == null) { return true; } if(URLUtil.urisEqual(param1,_loc4_)) { return true; } } return false; } return true; } public function get typeRegistry() : SchemaTypeRegistry { return _typeRegistry; } public function decodeSimpleContent(param1:XML, param2:*, param3:QName, param4:*, param5:XML = null) : void { var _loc7_:String = null; var _loc8_:QName = null; var _loc9_:* = undefined; var _loc10_:XML = null; var _loc11_:XMLList = null; var _loc12_:XML = null; var _loc13_:* = undefined; var _loc6_:XML = getSingleElementFromNode(param1,constants.extensionQName,constants.restrictionQName); if(param2 is ContentProxy) { ContentProxy(param2).object_proxy::isSimple = true; } if(_loc6_ != null) { _loc7_ = getAttributeFromNode("base",_loc6_); if(_loc7_ == null) { throw new Error("A simpleContent extension or restriction must declare a base type."); } _loc8_ = schemaManager.getQNameForPrefixedName(_loc7_,_loc6_); if(!isBuiltInType(_loc8_)) { _loc10_ = schemaManager.getNamedDefinition(_loc8_,constants.complexTypeQName,constants.simpleTypeQName); if(_loc10_ == null) { throw new Error("Cannot find base type definition \'" + _loc8_ + "\'"); } schemaManager.releaseScope(); } if(_loc6_.name() == constants.extensionQName) { if(isBuiltInType(_loc8_)) { _loc9_ = getSimpleValue(param4,param3); _loc13_ = marshallBuiltInType(_loc8_,param2,param3,_loc9_,param5); setSimpleValue(param2,param3,_loc13_,_loc8_); } else { decodeType(_loc8_,param2,param3,param4,param5); } _loc11_ = _loc6_.elements(); for each(_loc12_ in _loc11_) { if(_loc12_.name() == constants.attributeQName) { decodeAttribute(_loc12_,param2,param4,param5); } else if(_loc12_.name() == constants.attributeGroupQName) { decodeAttributeGroup(_loc12_,param2,param4,param5); } else if(_loc12_.name() == constants.anyAttributeQName) { decodeAnyAttribute(_loc12_,param2,param4,param5); } } } else if(_loc6_.name() == constants.restrictionQName) { _loc9_ = getSimpleValue(param4,param3); decodeSimpleRestriction(_loc6_,param2,param3,_loc9_); } } } public function decodeGroupReference(param1:XML, param2:*, param3:QName, param4:XMLList, param5:DecodingContext = null, param6:Boolean = true) : Boolean { var _loc7_:QName = null; var _loc10_:XML = null; if(param1.attribute("ref").length() == 1) { _loc7_ = schemaManager.getQNameForPrefixedName(param1.@ref,param1,true); param1 = schemaManager.getNamedDefinition(_loc7_,constants.groupQName); if(param1 == null) { throw new Error("Cannot resolve group definition for \'" + _loc7_ + "\'"); } var _loc8_:XMLList = param1.elements(); var _loc9_:Boolean = false; for each(_loc10_ in _loc8_) { if(_loc10_.name() == constants.allQName) { _loc9_ = decodeAll(_loc10_,param2,param3,param4,param5,param6); } else if(_loc10_.name() == constants.choiceQName) { _loc9_ = decodeChoice(_loc10_,param2,param3,param4,param5,param6); } else if(_loc10_.name() == constants.sequenceQName) { _loc9_ = decodeSequence(_loc10_,param2,param3,param4,param5,param6); } } schemaManager.releaseScope(); return _loc9_; } throw new Error("A group reference element must have the ref attribute."); } public function setSimpleValue(param1:*, param2:*, param3:*, param4:Object = null) : void { var _loc5_:ContentProxy = null; if(param1 is ContentProxy) { _loc5_ = param1 as ContentProxy; if(_loc5_.object_proxy::isSimple) { _loc5_.object_proxy::content = param3; return; } } setValue(param1,param2,param3,param4); } public function decodeAnyAttribute(param1:XML, param2:*, param3:* = undefined, param4:XML = null) : void { var _loc5_:XML = null; var _loc6_:Array = null; var _loc7_:Boolean = false; var _loc8_:String = null; var _loc9_:String = null; var _loc10_:XMLList = null; var _loc11_:XML = null; var _loc12_:QName = null; var _loc13_:* = undefined; if(param3 !== undefined && param3 is XML) { _loc5_ = param3 as XML; _loc7_ = true; _loc9_ = param1["namespace"]; if(_loc9_ != "" && _loc9_ != "##any") { if(schemaManager.currentSchema != null && schemaManager.currentSchema.targetNamespace != null) { _loc8_ = schemaManager.currentSchema.targetNamespace.uri; } if(_loc9_ == "##other") { _loc7_ = false; } else { if(_loc9_.indexOf("##targetNamespace") >= 0) { _loc9_ = _loc9_.replace("##targetNamespace",_loc8_); } _loc6_ = _loc9_.split(" "); } } _loc10_ = _loc5_.attributes(); for each(_loc11_ in _loc10_) { _loc12_ = _loc11_.name() as QName; if(!(!_loc7_ && URLUtil.urisEqual(_loc12_.uri,_loc8_))) { if(includeNamespace(_loc12_.uri,_loc6_)) { _loc13_ = getAttribute(param3,_loc12_); if(_loc13_ != null) { setAttribute(param2,_loc12_,_loc13_); } } } } } } public function decodeSimpleType(param1:XML, param2:*, param3:QName, param4:*, param5:XML = null) : void { var _loc6_:XML = getSingleElementFromNode(param1,constants.restrictionQName,constants.listQName,constants.unionQName); if(_loc6_.name() == constants.restrictionQName) { decodeSimpleRestriction(_loc6_,param2,param3,param4); } else if(_loc6_.name() == constants.listQName) { decodeSimpleList(_loc6_,param2,param3,param4,param5); } else if(_loc6_.name() == constants.listQName) { decodeSimpleUnion(_loc6_,param2,param3,param4,param5); } } public function hasAttribute(param1:*, param2:*) : Boolean { return getAttribute(param1,param2) !== undefined; } public function getProperties(param1:*) : Array { var _loc3_:XMLList = null; var _loc4_:XML = null; var _loc2_:Array = []; if(param1 is XML) { _loc3_ = XML(param1).elements(); } else if(param1 is XMLList) { _loc3_ = XMLList(param1).elements(); } if(_loc3_ != null) { for each(_loc4_ in _loc3_) { _loc2_.push(_loc4_.name()); } } return _loc2_; } protected function preProcessXML(param1:XML) : void { } protected function isXSINil(param1:*) : Boolean { var _loc2_:String = null; if(param1 != null) { _loc2_ = "false"; if(param1 is XML) { _loc2_ = XML(param1).attribute(constants.nilQName).toString(); } else if(param1 is XMLList) { _loc2_ = XMLList(param1).attribute(constants.nilQName).toString(); } if(_loc2_ == "true") { return true; } } return false; } public function set typeRegistry(param1:SchemaTypeRegistry) : void { _typeRegistry = param1; } public function marshallBuiltInType(param1:QName, param2:*, param3:QName, param4:*, param5:XML = null) : * { var _loc6_:* = undefined; var _loc7_:XMLList = null; if(param1 == constants.anyTypeQName && !isSimpleValue(param4)) { _loc6_ = createContent(); if(_loc6_ is ContentProxy) { ContentProxy(_loc6_).object_proxy::isSimple = false; } if(param4 is XML) { _loc7_ = param4.elements(); } else { _loc7_ = new XMLList(param4); } decodeAnyType(_loc6_,param3,_loc7_); return _loc6_; } return schemaManager.unmarshall(param4,param1,param5); } public function getSimpleValue(param1:*, param2:*) : * { var _loc3_:XML = null; var _loc4_:XMLList = null; if(param1 is XML) { _loc3_ = param1 as XML; if(_loc3_.hasSimpleContent()) { return _loc3_.toString(); } } else if(param1 is XMLList) { _loc4_ = param1 as XMLList; if(_loc4_.hasSimpleContent()) { return _loc4_.toString(); } } return getValue(param1,param2); } public function setValue(param1:*, param2:*, param3:*, param4:Object = null) : void { var existingValue:* = undefined; var propertyName:String = null; var proxyParent:ContentProxy = null; var parent:* = param1; var name:* = param2; var value:* = param3; var type:Object = param4; if(parent != null) { if(value is ContentProxy) { value = ContentProxy(value).object_proxy::content; } if(TypeIterator.isIterable(parent)) { TypeIterator.push(parent,value); } else if(name != null) { if(name is ContentProxy) { name = ContentProxy(name).object_proxy::content; } if(name is QName) { propertyName = QName(name).localName; } else { propertyName = Object(name).toString(); } if(parent is ContentProxy && Boolean(ContentProxy(parent).object_proxy::isSimple)) { existingValue = ContentProxy(parent).object_proxy::content; } else if(Object(parent).hasOwnProperty(propertyName)) { existingValue = getExistingValue(parent,propertyName); } else if(Object(parent).hasOwnProperty("_" + propertyName)) { existingValue = getExistingValue(parent,"_" + propertyName); } if(existingValue != null) { existingValue = promoteValueToArray(existingValue,type); TypeIterator.push(existingValue,value); value = existingValue; } try { if(parent is ContentProxy && Boolean(ContentProxy(parent).object_proxy::isSimple)) { ContentProxy(parent).object_proxy::content = value; } else { try { parent[propertyName] = value; } catch(e:Error) { parent["_" + propertyName] = value; } } } catch(e:Error) { log.warn("Unable to set property \'{0}\' on parent.",propertyName); } } else if(parent is ContentProxy) { proxyParent = parent as ContentProxy; existingValue = proxyParent.object_proxy::content; if(existingValue !== undefined) { existingValue = promoteValueToArray(existingValue,type); proxyParent.object_proxy::content = existingValue; TypeIterator.push(existingValue,value); value = existingValue; } proxyParent.object_proxy::content = value; } } } public function decodeComplexContent(param1:XML, param2:*, param3:QName, param4:*, param5:DecodingContext) : void { var _loc6_:XML = getSingleElementFromNode(param1,constants.extensionQName,constants.restrictionQName); if(_loc6_.name() == constants.extensionQName) { decodeComplexExtension(_loc6_,param2,param3,param4,param5); } else if(_loc6_.name() == constants.restrictionQName) { decodeComplexRestriction(_loc6_,param2,param3,param4); } } public function getValue(param1:*, param2:*, param3:Number = -1) : * { var _loc4_:* = undefined; var _loc5_:QName = null; var _loc6_:XMLList = null; if(param2 is QName) { _loc5_ = param2 as QName; if(_loc5_.uri == null || _loc5_.uri == "") { param2 = _loc5_.localName; } } if(param1 is XML) { _loc6_ = XML(param1).elements(param2); if(_loc6_.length() > 0) { _loc4_ = parseValue(param2,_loc6_); } } else if(param1 is XMLList) { _loc6_ = XMLList(param1).elements(param2); if(_loc6_.length() > 0) { _loc4_ = parseValue(param2,_loc6_); } } else if(param1 is ContentProxy) { if(_loc5_ != null) { param2 = _loc5_.localName; } _loc4_ = !!(param1 as ContentProxy).hasOwnProperty(param2) ? param1[param2] : undefined; } else if(!isSimpleValue(param1)) { _loc4_ = param1[param2]; } return _loc4_; } public function decodeComplexType(param1:XML, param2:*, param3:QName, param4:*, param5:XML = null, param6:DecodingContext = null) : void { var _loc9_:XML = null; if(param2 is ContentProxy) { ContentProxy(param2).object_proxy::isSimple = false; } var _loc7_:XMLList = param1.elements(); var _loc8_:XMLList = new XMLList(); if(param4 is XML) { _loc8_ = (param4 as XML).elements(); } else if(param4 is XMLList) { _loc8_ = param4; } for each(_loc9_ in _loc7_) { if(_loc9_.name() == constants.simpleContentQName) { decodeSimpleContent(_loc9_,param2,param3,param4,param5); } else if(_loc9_.name() == constants.complexContentQName) { decodeComplexContent(_loc9_,param2,param3,param4,param6); } else if(_loc9_.name() == constants.sequenceQName) { decodeSequence(_loc9_,param2,param3,_loc8_,param6); } else if(_loc9_.name() == constants.groupQName) { decodeGroupReference(_loc9_,param2,param3,_loc8_,param6); } else if(_loc9_.name() == constants.allQName) { decodeAll(_loc9_,param2,param3,_loc8_,param6); } else if(_loc9_.name() == constants.choiceQName) { decodeChoice(_loc9_,param2,param3,_loc8_,param6); } else if(_loc9_.name() == constants.attributeQName) { decodeAttribute(_loc9_,param2,param4,param5); } else if(_loc9_.name() == constants.attributeGroupQName) { decodeAttributeGroup(_loc9_,param2,param4,param5); } else if(_loc9_.name() == constants.anyAttributeQName) { decodeAnyAttribute(_loc9_,param2,param4,param5); } } } public function decodeChoice(param1:XML, param2:*, param3:QName, param4:XMLList, param5:DecodingContext = null, param6:Boolean = true) : Boolean { var _loc10_:Boolean = false; var _loc11_:uint = 0; var _loc12_:uint = 0; var _loc13_:XML = null; if(param5 == null) { param5 = new DecodingContext(); } var _loc7_:uint = getMaxOccurs(param1); var _loc8_:uint = getMinOccurs(param1); if(_loc7_ == 0) { return false; } if(param4 == null && _loc8_ == 0) { return true; } var _loc9_:XMLList = param1.elements(); if(_loc9_.length() == 0) { return true; } _loc12_ = 0; while(_loc12_ < _loc7_) { _loc11_ = uint(param5.index + 0); _loc10_ = false; for each(_loc13_ in _loc9_) { if(_loc13_.name() == constants.elementTypeQName) { _loc10_ ||= decodeGroupElement(_loc13_,param2,param4,param5,false); if(param5.index > _loc11_) { break; } } else if(_loc13_.name() == constants.sequenceQName) { _loc10_ ||= decodeSequence(_loc13_,param2,param3,param4,param5,false); if(param5.index > _loc11_) { break; } } else if(_loc13_.name() == constants.groupQName) { _loc10_ ||= decodeGroupReference(_loc13_,param2,param3,param4,param5,false); if(param5.index > _loc11_) { break; } } else if(_loc13_.name() == constants.choiceQName) { _loc10_ ||= decodeChoice(_loc13_,param2,param3,param4,param5,false); if(param5.index > _loc11_) { break; } } else if(_loc13_.name() == constants.anyQName) { _loc10_ ||= decodeAnyElement(_loc13_,param2,param3,param4,param5,false); if(param5.index > _loc11_) { break; } } } if(!_loc10_) { break; } _loc12_++; } if(_loc12_ < _loc8_) { if(param6 && strictOccurenceBounds) { throw new Error("Value supplied for choice " + param3.toString() + " occurs " + _loc12_ + " times which falls short of minOccurs " + _loc8_ + "."); } return false; } return true; } public function get recordXSIType() : Boolean { return _recordXSIType; } public function set recordXSIType(param1:Boolean) : void { _recordXSIType = param1; } public function decodeType(param1:QName, param2:*, param3:QName, param4:*, param5:XML = null) : void { var _loc6_:* = undefined; var _loc7_:XML = null; var _loc8_:QName = null; if(isBuiltInType(param1)) { _loc6_ = marshallBuiltInType(param1,param2,param3,param4,param5); setValue(param2,param3,_loc6_,param1); } else { _loc7_ = schemaManager.getNamedDefinition(param1,constants.complexTypeQName,constants.simpleTypeQName); if(_loc7_ == null) { throw new Error("Cannot find definition for type \'" + param1 + "\'"); } if(isXSINil(param4)) { setValue(param2,param3,null,param1); return; } _loc8_ = _loc7_.name() as QName; if(_loc8_ == constants.complexTypeQName) { decodeComplexType(_loc7_,param2,param3,param4,param5); } else { if(_loc8_ != constants.simpleTypeQName) { throw new Error("Invalid type definition " + _loc8_); } decodeSimpleType(_loc7_,param2,param3,param4,param5); } schemaManager.releaseScope(); } setXSIType(param2,param1); } protected function promoteValueToArray(param1:*, param2:Object = null) : * { var _loc3_:* = undefined; if(!TypeIterator.isIterable(param1)) { _loc3_ = createIterableValue(param2); TypeIterator.push(_loc3_,param1); param1 = _loc3_; } return param1; } public function decodeAttribute(param1:XML, param2:*, param3:* = undefined, param4:XML = null) : void { var _loc5_:QName = null; var _loc8_:QName = null; var _loc9_:String = null; var _loc10_:* = undefined; var _loc11_:String = null; var _loc12_:XML = null; var _loc13_:String = null; var _loc14_:QName = null; var _loc15_:* = undefined; if(param1.attribute("ref").length() == 1) { _loc5_ = schemaManager.getQNameForPrefixedName(param1.@ref,param1,true); param1 = schemaManager.getNamedDefinition(_loc5_,constants.attributeQName); if(param1 == null) { throw new Error("Cannot resolve attribute definition for \'" + _loc5_ + "\'"); } } var _loc6_:String = param1.@name.toString(); var _loc7_:String = param1.attribute("use").toString(); if(_loc7_ != "prohibited") { _loc8_ = schemaManager.getQNameForAttribute(_loc6_,getAttributeFromNode("form",param1)); _loc9_ = getAttributeFromNode("fixed",param1); if(_loc9_ != null) { param3 = _loc9_; } else { param3 = getAttribute(param3,_loc8_); if(param3 === undefined) { _loc11_ = getAttributeFromNode("default",param1); if(_loc11_ != null) { param3 = _loc11_; } } } if(param3 !== undefined) { _loc10_ = createContent(); _loc13_ = getAttributeFromNode("type",param1); if(_loc13_ != null) { _loc14_ = schemaManager.getQNameForPrefixedName(param1.@type,param1); } else { _loc14_ = schemaManager.schemaDatatypes.anySimpleTypeQName; } if(_loc14_ != null) { if(isBuiltInType(_loc14_)) { _loc15_ = marshallBuiltInType(_loc14_,_loc10_,_loc8_,param3,param4); setValue(_loc10_,_loc8_,_loc15_); } else { _loc12_ = schemaManager.getNamedDefinition(_loc14_,constants.simpleTypeQName); if(_loc12_ == null) { throw new Error("Cannot find simpleType " + _loc14_ + " for attribute " + _loc8_); } decodeSimpleType(_loc12_,_loc10_,_loc8_,param3,param4); schemaManager.releaseScope(); } } else { _loc12_ = getSingleElementFromNode(param1,constants.simpleTypeQName); if(_loc12_ != null) { decodeSimpleType(_loc12_,_loc10_,_loc8_,param3,param4); } else if(param3 != null) { _loc10_ = param3; } } } if(_loc10_ != null) { setAttribute(param2,_loc8_,_loc10_); } } if(_loc5_ != null) { schemaManager.releaseScope(); } } protected function getApplicableValues(param1:*, param2:XMLList, param3:QName, param4:DecodingContext, param5:uint) : XMLList { var _loc6_:XMLList = new XMLList(); var _loc7_:uint = uint(param4.index); var _loc8_:Boolean = false; if(param4.anyIndex > -1 && param3 != null) { _loc7_ = uint(param4.anyIndex); _loc8_ = true; } var _loc9_:uint = _loc7_; while(_loc9_ < param2.length()) { if(_loc6_.length() == param5) { break; } if(param3 == null || param2[_loc9_].name() == param3 || (param3.uri == "" || param3.uri == null) && param3.localName == param2[_loc9_].name().localName) { _loc6_ += param2[_loc9_]; if(_loc9_ < param4.index) { param1[param3.localName] = null; } _loc8_ = false; } else if(_loc8_ == false) { break; } _loc9_++; } return _loc6_; } public function decodeAttributeGroup(param1:XML, param2:*, param3:* = undefined, param4:XML = null) : void { var _loc5_:QName = null; var _loc7_:XML = null; var _loc8_:XMLList = null; var _loc9_:XML = null; var _loc10_:XML = null; if(param1.attribute("ref").length() == 1) { _loc5_ = schemaManager.getQNameForPrefixedName(param1.@ref,param1,true); param1 = schemaManager.getNamedDefinition(_loc5_,constants.attributeGroupQName); if(param1 == null) { throw new Error("Cannot resolve attributeGroup definition for \'" + _loc5_ + "\'"); } } var _loc6_:XMLList = param1.elements(constants.attributeQName); for each(_loc7_ in _loc6_) { decodeAttribute(_loc7_,param2,param3,param4); } _loc8_ = param1.elements(constants.attributeGroupQName); for each(_loc9_ in _loc8_) { decodeAttributeGroup(_loc9_,param2,param3,param4); } _loc10_ = getSingleElementFromNode(param1,constants.anyAttributeQName); if(_loc10_ != null) { decodeAnyAttribute(_loc10_,param2,param3,param4); } if(_loc5_ != null) { schemaManager.releaseScope(); } } public function decodeAll(param1:XML, param2:*, param3:QName, param4:XMLList, param5:DecodingContext = null, param6:Boolean = true) : Boolean { var _loc12_:XML = null; if(param5 == null) { param5 = new DecodingContext(); } var _loc7_:uint = getMinOccurs(param1); var _loc8_:XMLList = param1.elements(); var _loc9_:Boolean = _loc8_.length() > 1 || param5.hasContextSiblings; var _loc10_:Boolean = param6 && _loc7_ > 0; var _loc11_:* = !_loc10_; for each(_loc12_ in _loc8_) { param5.index = 0; param5.anyIndex = 0; if(_loc12_.name() == constants.annotationQName) { _loc11_ = true; } else if(_loc12_.name() == constants.elementTypeQName) { if(!decodeGroupElement(_loc12_,param2,param4,param5,_loc10_,_loc9_)) { break; } } else if(_loc12_.name() == constants.anyQName) { if(!decodeAnyElement(_loc12_,param2,param3,param4,param5,_loc10_)) { break; } } _loc11_ = true; } return _loc11_; } public function isSimpleValue(param1:*) : Boolean { if(param1 is XML) { return XML(param1).hasSimpleContent(); } if(param1 is String || param1 is Number || param1 is Boolean || param1 is Date || param1 is int || param1 is uint || param1 is ByteArray) { return true; } return false; } public function decodeSequence(param1:XML, param2:*, param3:QName, param4:XMLList, param5:DecodingContext = null, param6:Boolean = true) : Boolean { var _loc10_:uint = 0; var _loc12_:Boolean = false; var _loc13_:Boolean = false; var _loc14_:uint = 0; var _loc15_:XML = null; if(param5 == null) { param5 = new DecodingContext(); } var _loc7_:uint = getMaxOccurs(param1); var _loc8_:uint = getMinOccurs(param1); if(_loc7_ == 0) { return false; } if((param4 == null || param4.length() == 0) && _loc8_ == 0) { return true; } var _loc9_:XMLList = param1.elements(); var _loc11_:Boolean = _loc9_.length() > 1 || param5.hasContextSiblings; if(_loc9_.length() == 0) { return true; } _loc10_ = 0; while(true) { if(_loc10_ < _loc7_) { _loc12_ = param6 && _loc10_ < _loc8_; _loc13_ = true; _loc14_ = uint(param5.index + 0); for each(_loc15_ in _loc9_) { _loc13_ = false; if(_loc15_.name() == constants.annotationQName) { _loc13_ = true; } if(_loc15_.name() == constants.elementTypeQName) { if(!decodeGroupElement(_loc15_,param2,param4,param5,_loc12_,_loc11_)) { break; } } else if(_loc15_.name() == constants.groupQName) { if(!decodeGroupReference(_loc15_,param2,param3,param4,param5,_loc12_)) { break; } } else if(_loc15_.name() == constants.choiceQName) { if(!decodeChoice(_loc15_,param2,param3,param4,param5,_loc12_)) { break; } } else if(_loc15_.name() == constants.sequenceQName) { if(!decodeSequence(_loc15_,param2,param3,param4,param5,_loc12_)) { break; } } else if(_loc15_.name() == constants.anyQName) { if(!decodeAnyElement(_loc15_,param2,param3,param4,param5,_loc12_)) { break; } } _loc13_ = true; } if(!_loc13_ && _loc12_) { break; } if(_loc14_ != param5.index) { continue; } if(_loc13_) { _loc10_ = ++_loc10_ > _loc8_ ? _loc10_ : _loc8_; } } if(_loc10_ < _loc8_) { if(param6 && strictOccurenceBounds) { throw new Error("Value supplied for sequence " + param3.toString() + " occurs " + _loc10_ + " times which falls short of minOccurs " + _loc8_ + "."); } return false; } return true; _loc10_++; } if(strictOccurenceBounds) { throw new Error("Cannot find value for definition " + _loc15_.toXMLString() + " in sequence."); } return false; } public function setAttribute(param1:*, param2:*, param3:*) : void { var _loc4_:ContentProxy = null; var _loc5_:* = undefined; var _loc6_:SimpleContent = null; if(param1 is ContentProxy) { _loc4_ = param1 as ContentProxy; if(_loc4_.object_proxy::isSimple) { _loc5_ = _loc4_.object_proxy::content; if(!(_loc5_ is SimpleContent)) { _loc6_ = new SimpleContent(_loc5_); _loc4_.object_proxy::content = _loc6_; } _loc4_.object_proxy::isSimple = false; } } setValue(param1,param2,param3); } public function createContent(param1:QName = null) : * { var c:Class = null; var className:String = null; var type:QName = param1; var content:* = undefined; if(type != null && typeRegistry != null) { c = typeRegistry.getClass(type); if(c == null) { c = typeRegistry.getCollectionClass(type); } if(c != null) { try { content = new c(); } catch(e:Error) { className = getQualifiedClassName(c); log.debug("Unable to create new instance of Class \'{0}\' for type \'{1}\'.",className,type); } } } return new ContentProxy(content,makeObjectsBindable); } override public function reset() : void { super.reset(); document = null; } public function getAttribute(param1:*, param2:*) : * { var _loc3_:* = undefined; var _loc4_:XMLList = null; if(param1 is XML) { _loc4_ = XML(param1).attribute(param2); _loc3_ = parseValue(param2,_loc4_); } else if(param1 is XMLList) { _loc4_ = XMLList(param1).attribute(param2); _loc3_ = parseValue(param2,_loc4_); } return _loc3_; } public function decodeSimpleRestriction(param1:XML, param2:*, param3:QName, param4:*) : void { var _loc6_:String = null; var _loc7_:QName = null; var _loc5_:XML = getSingleElementFromNode(param1,constants.simpleTypeQName); if(_loc5_ != null) { decodeSimpleType(_loc5_,param2,param3,param4,param1); } else { _loc6_ = getAttributeFromNode("base",param1); _loc7_ = schemaManager.getQNameForPrefixedName(_loc6_,param1); decodeType(_loc7_,param2,param3,param4,param1); } } protected function setXSIType(param1:*, param2:QName) : void { if(param1 != null && recordXSIType) { if(param1 is ContentProxy) { param1 = param1.object_proxy::content; } if(param1 != null) { if(param1 is ObjectProxy) { ObjectProxy(param1).object_proxy::type = param2; } else if(param1 is IXMLSchemaInstance) { IXMLSchemaInstance(param1).xsiType = param2; } } } } public function decodeSimpleUnion(param1:XML, param2:*, param3:QName, param4:*, param5:XML = null) : void { var _loc8_:QName = null; var _loc9_:* = undefined; var _loc12_:String = null; var _loc13_:QName = null; var _loc6_:String = getAttributeFromNode("memberTypes",param1); var _loc7_:Array = _loc6_.split(" "); var _loc10_:int = 0; while(_loc10_ < _loc7_.length) { _loc12_ = _loc7_[_loc10_]; _loc13_ = schemaManager.getQNameForPrefixedName(_loc12_,param1); if(!isBuiltInType(_loc13_)) { _loc9_ = getValue(param4,_loc13_); if(_loc9_ !== undefined) { _loc8_ = _loc13_; break; } } _loc10_++; } if(!_loc8_) { _loc8_ = schemaManager.schemaDatatypes.stringQName; } var _loc11_:* = marshallBuiltInType(_loc8_,param2,param3,param4,param5); setValue(param2,param3,_loc11_,_loc8_); } protected function getExistingValue(param1:*, param2:String) : * { var className:String; var existingValue:* = undefined; var classInfo:XML = null; var properties:XMLList = null; var property:XML = null; var propertyType:String = null; var tempValue:* = undefined; var parent:* = param1; var propertyName:String = param2; var object:Object = Object(parent); if(parent is ContentProxy) { object = ContentProxy(parent).object_proxy::content; } if(object is ObjectProxy) { object = ObjectProxy(object).object_proxy::object; } className = getQualifiedClassName(object); if(className == "Object") { existingValue = parent[propertyName]; } else { classInfo = DescribeTypeCache.describeType(object).typeDescription; properties = classInfo..accessor.(@access == "readwrite" && @name == propertyName) + classInfo..variable.(@name == propertyName); if(properties.length() > 0) { property = properties[0]; propertyType = property.@type; tempValue = parent[propertyName]; if(propertyType == "Object" || propertyType == "*" || TypeIterator.isIterable(tempValue)) { existingValue = tempValue; } } } return existingValue; } protected function getXSIType(param1:*) : QName { var _loc2_:QName = null; var _loc3_:XML = null; var _loc4_:String = null; if(param1 is XML) { _loc3_ = param1 as XML; } else if(param1 is XMLList && param1.length() == 1) { _loc3_ = param1[0]; } if(_loc3_ != null) { _loc4_ = XMLUtil.getAttributeByQName(_loc3_,constants.typeAttrQName).toString(); if(_loc4_ != null && _loc4_ != "") { _loc2_ = schemaManager.getQNameForPrefixedName(_loc4_,_loc3_); } } return _loc2_; } public function decode(param1:*, param2:QName = null, param3:QName = null, param4:XML = null) : * { var content:* = undefined; var elementDefinition:XML = null; var xml:* = param1; var name:QName = param2; var type:QName = param3; var definition:XML = param4; if(!(xml is XML) && !(xml is XMLList) && !(xml is String)) { throw new ArgumentError("The xml argument must be of type XML, XMLList or String."); } if(xml is XML) { document = xml; } else if(xml is XMLList) { if(XMLList(xml).length() != 1) { throw new ArgumentError("The xml argument must have a length of 1 when passed as an XMLList."); } document = XMLList(xml)[0]; } else if(xml is String) { try { document = new XML(xml); } catch(e:Error) { throw new ArgumentError("The xml argument does not contain valid xml. " + xml); } } preProcessXML(document); if(type != null) { content = createContent(type); decodeType(type,content,name,document); } else { elementDefinition = definition; if(elementDefinition == null) { elementDefinition = schemaManager.getNamedDefinition(name,constants.elementTypeQName); } if(elementDefinition == null) { content = createContent(type); decodeType(constants.anyTypeQName,content,name,document); } else { content = decodeElementTopLevel(elementDefinition,name,document); if(definition == null) { schemaManager.releaseScope(); } } } if(content is ContentProxy) { content = ContentProxy(content).object_proxy::content; } return content; } public function hasValue(param1:*, param2:*) : Boolean { return getValue(param1,param2) !== undefined; } public function decodeAnyType(param1:*, param2:QName, param3:XMLList) : void { var _loc4_:XML = null; var _loc5_:QName = null; var _loc6_:* = undefined; var _loc7_:QName = null; for each(_loc4_ in param3) { _loc5_ = _loc4_.name() as QName; _loc7_ = getXSIType(_loc4_); if(_loc7_ != null) { _loc6_ = createContent(); decodeType(schemaManager.schemaDatatypes.anyTypeQName,_loc6_,_loc5_,_loc4_); } else { _loc6_ = marshallBuiltInType(schemaManager.schemaDatatypes.anyTypeQName,param1,_loc5_,_loc4_); } setValue(param1,_loc5_,_loc6_,_loc7_); } } public function set makeObjectsBindable(param1:Boolean) : void { _makeObjectsBindable = param1; } public function decodeComplexExtension(param1:XML, param2:*, param3:QName, param4:*, param5:DecodingContext = null) : void { var _loc11_:XML = null; if(param5 == null) { param5 = new DecodingContext(); } param5.hasContextSiblings = true; var _loc6_:String = getAttributeFromNode("base",param1); if(_loc6_ == null) { throw new Error("A complexContent extension must declare a base type."); } var _loc7_:QName = schemaManager.getQNameForPrefixedName(_loc6_,param1); var _loc8_:XML = schemaManager.getNamedDefinition(_loc7_,constants.complexTypeQName); if(_loc8_ == null) { throw new Error("Cannot find base type definition \'" + _loc7_ + "\'"); } decodeComplexType(_loc8_,param2,param3,param4,null,param5); schemaManager.releaseScope(); var _loc9_:XMLList = param1.elements(); var _loc10_:XMLList = new XMLList(); if(param4 is XML) { _loc10_ = (param4 as XML).elements(); } else if(param4 is XMLList) { _loc10_ = param4; } for each(_loc11_ in _loc9_) { if(_loc11_.name() == constants.sequenceQName) { decodeSequence(_loc11_,param2,param3,_loc10_,param5); } else if(_loc11_.name() == constants.groupQName) { decodeGroupReference(_loc11_,param2,param3,_loc10_,param5); } else if(_loc11_.name() == constants.allQName) { decodeAll(_loc11_,param2,param3,_loc10_,param5); } else if(_loc11_.name() == constants.choiceQName) { decodeChoice(_loc11_,param2,param3,_loc10_,param5); } else if(_loc11_.name() == constants.attributeQName) { decodeAttribute(_loc11_,param2,param4); } else if(_loc11_.name() == constants.attributeGroupQName) { decodeAttributeGroup(_loc11_,param2,param4); } else if(_loc11_.name() == constants.anyAttributeQName) { decodeAnyAttribute(_loc11_,param2,param4); } } } public function decodeSimpleList(param1:XML, param2:*, param3:QName, param4:*, param5:XML = null) : void { var _loc7_:QName = null; var _loc8_:XML = null; var _loc11_:* = undefined; var _loc12_:* = undefined; var _loc13_:String = null; var _loc6_:String = param1.@itemType; if(_loc6_ != "") { _loc7_ = schemaManager.getQNameForPrefixedName(_loc6_,param1); } else { _loc8_ = getSingleElementFromNode(param1,constants.simpleTypeQName); } var _loc9_:String = ""; if(!TypeIterator.isIterable(param4)) { param4 = [param4]; } var _loc10_:TypeIterator = new TypeIterator(param4); while(_loc10_.hasNext()) { _loc11_ = _loc10_.next(); _loc12_ = createContent(); if(_loc7_ != null) { decodeType(_loc7_,_loc12_,param3,_loc11_,param5); } else { decodeSimpleType(_loc8_,_loc12_,param3,_loc11_,param5); } _loc13_ = _loc12_ != null ? _loc12_.toString() : ""; _loc9_ = _loc9_.concat(_loc13_); if(_loc10_.hasNext()) { _loc9_ = _loc9_.concat(" "); } } setValue(param2,param3,_loc9_,_loc7_); } } }