home *** CD-ROM | disk | FTP | other *** search
Text File | 2009-05-06 | 44.1 KB | 1,298 lines |
- package mx.rpc.xml
- {
- import flash.utils.ByteArray;
- import flash.utils.Dictionary;
- import mx.collections.IList;
- import mx.utils.ObjectProxy;
- import mx.utils.ObjectUtil;
- import mx.utils.object_proxy;
-
- public class XMLEncoder extends SchemaProcessor implements IXMLEncoder
- {
- private var _xmlSpecialCharsFilter:Function;
-
- private var _strictNillability:Boolean = false;
-
- public function XMLEncoder()
- {
- _xmlSpecialCharsFilter = escapeXML;
- super();
- }
-
- protected function deriveXSIType(param1:XML, param2:QName, param3:*) : void
- {
- }
-
- public function appendValue(param1:XMLList, param2:*) : void
- {
- param1[param1.length()] = param2;
- }
-
- public function getAttribute(param1:*, param2:*) : *
- {
- return getValue(param1,param2);
- }
-
- public function set strictNillability(param1:Boolean) : void
- {
- _strictNillability = param1;
- }
-
- public function encodeComplexType(param1:XML, param2:XML, param3:QName, param4:*, param5:XML = null) : void
- {
- var _loc8_:XML = null;
- var _loc6_:XMLList = param1.elements();
- var _loc7_:XMLList = new XMLList();
- for each(_loc8_ in _loc6_)
- {
- if(_loc8_.name() == constants.sequenceQName)
- {
- encodeSequence(_loc8_,_loc7_,param3,param4);
- }
- else if(_loc8_.name() == constants.simpleContentQName)
- {
- encodeSimpleContent(_loc8_,param2,param3,param4,param5);
- }
- else if(_loc8_.name() == constants.complexContentQName)
- {
- encodeComplexContent(_loc8_,param2,param3,param4);
- }
- else if(_loc8_.name() == constants.groupQName)
- {
- encodeGroupReference(_loc8_,_loc7_,param3,param4);
- }
- else if(_loc8_.name() == constants.allQName)
- {
- encodeAll(_loc8_,_loc7_,param3,param4);
- }
- else if(_loc8_.name() == constants.choiceQName)
- {
- encodeChoice(_loc8_,_loc7_,param3,param4);
- }
- else if(_loc8_.name() == constants.attributeQName)
- {
- encodeAttribute(_loc8_,param2,param3,param4,param5);
- }
- else if(_loc8_.name() == constants.attributeGroupQName)
- {
- encodeAttributeGroup(_loc8_,param2,param3,param4,param5);
- }
- else if(_loc8_.name() == constants.anyAttributeQName)
- {
- encodeAnyAttribute(_loc8_,param2,param3,param4,param5);
- }
- }
- setValue(param2,_loc7_);
- }
-
- public function encode(param1:*, param2:QName = null, param3:QName = null, param4:XML = null) : XMLList
- {
- var _loc6_:XML = null;
- var _loc7_:XML = null;
- var _loc8_:Boolean = false;
- var _loc5_:XMLList = new XMLList();
- if(param2 == null)
- {
- param2 = new QName("","root");
- }
- if(param3 != null)
- {
- _loc6_ = encodeXSINil(null,param2,param1);
- if(_loc6_ == null)
- {
- _loc6_ = createElement(param2);
- if(param1 == null)
- {
- setValue(_loc6_,null);
- }
- else
- {
- encodeType(param3,_loc6_,param2,param1);
- }
- }
- }
- else
- {
- _loc7_ = param4;
- _loc8_ = false;
- if(_loc7_ == null)
- {
- _loc7_ = schemaManager.getNamedDefinition(param2,constants.elementTypeQName);
- if(_loc7_ != null)
- {
- _loc8_ = true;
- }
- }
- _loc6_ = encodeElementTopLevel(_loc7_,param2,param1);
- if(_loc8_)
- {
- schemaManager.releaseScope();
- }
- }
- if(_loc6_ != null)
- {
- _loc5_ += _loc6_;
- }
- return _loc5_;
- }
-
- public function encodeXSINil(param1:XML, param2:QName, param3:*, param4:Boolean = true) : XML
- {
- var _loc6_:XML = null;
- var _loc5_:Boolean = true;
- if(strictNillability)
- {
- if(param1 != null)
- {
- _loc5_ = param1.@nillable.toString() == "true" ? true : false;
- }
- else
- {
- _loc5_ = false;
- }
- }
- var _loc7_:String = getAttributeFromNode("fixed",param1);
- if(!(strictNillability && _loc5_) && _loc7_ != null)
- {
- _loc6_ = createElement(param2);
- setValue(_loc6_,schemaManager.marshall(_loc7_,schemaManager.schemaDatatypes.stringQName));
- return _loc6_;
- }
- if(param3 != null)
- {
- return null;
- }
- var _loc8_:String = getAttributeFromNode("default",param1);
- if(param3 == null && _loc8_ != null)
- {
- _loc6_ = createElement(param2);
- setValue(_loc6_,schemaManager.marshall(_loc8_,schemaManager.schemaDatatypes.stringQName));
- return _loc6_;
- }
- if(_loc5_ && param3 === null && param4 == true)
- {
- _loc6_ = createElement(param2);
- setValue(_loc6_,null);
- return _loc6_;
- }
- return null;
- }
-
- public function resolveNamedProperty(param1:*, param2:*) : *
- {
- var value:* = undefined;
- var parent:* = param1;
- var name:* = param2;
- var fallbackName:String = null;
- if(!isSimpleValue(parent))
- {
- try
- {
- value = parent[name];
- if(value === undefined)
- {
- fallbackName = "_" + name.toString();
- }
- }
- catch(e:Error)
- {
- fallbackName = "_" + name.toString();
- }
- if(fallbackName != null && Boolean(parent.hasOwnProperty(fallbackName)))
- {
- value = parent[fallbackName];
- }
- }
- return value;
- }
-
- public function containsNodeByName(param1:XMLList, param2:QName, param3:Boolean = false) : Boolean
- {
- var _loc5_:XML = null;
- var _loc4_:String = schemaManager.currentSchema.targetNamespace.uri;
- for each(_loc5_ in param1)
- {
- if(param3 || param2.uri != "" && param2.uri != null)
- {
- if(_loc5_.name().uri == "" && _loc4_ == param2.uri)
- {
- if(_loc5_.name().localName == param2.localName)
- {
- return true;
- }
- }
- else if(_loc5_.name() == param2)
- {
- return true;
- }
- }
- else if(_loc5_.name().localName == param2.localName)
- {
- return true;
- }
- }
- return false;
- }
-
- public function encodeComplexExtension(param1:XML, param2:XML, param3:QName, param4:*) : void
- {
- var _loc10_:XML = null;
- var _loc11_:XML = null;
- var _loc5_:String = getAttributeFromNode("base",param1);
- if(_loc5_ == null)
- {
- throw new Error("A complexContent extension must declare a base type.");
- }
- var _loc6_:QName = schemaManager.getQNameForPrefixedName(_loc5_,param1);
- var _loc7_:XML = schemaManager.getNamedDefinition(_loc6_,constants.complexTypeQName);
- if(_loc7_ == null)
- {
- throw new Error("Cannot find base type definition \'" + _loc6_ + "\'");
- }
- encodeComplexType(_loc7_,param2,param3,param4);
- schemaManager.releaseScope();
- var _loc8_:XMLList = param1.elements();
- var _loc9_:XMLList = new XMLList();
- for each(_loc10_ in _loc8_)
- {
- if(_loc10_.name() == constants.sequenceQName)
- {
- encodeSequence(_loc10_,_loc9_,param3,param4);
- }
- else if(_loc10_.name() == constants.groupQName)
- {
- encodeGroupReference(_loc10_,_loc9_,param3,param4);
- }
- else if(_loc10_.name() == constants.allQName)
- {
- encodeAll(_loc10_,_loc9_,param3,param4);
- }
- else if(_loc10_.name() == constants.choiceQName)
- {
- encodeChoice(_loc10_,_loc9_,param3,param4);
- }
- else if(_loc10_.name() == constants.attributeQName)
- {
- encodeAttribute(_loc10_,param2,param3,param4);
- }
- else if(_loc10_.name() == constants.attributeGroupQName)
- {
- encodeAttributeGroup(_loc10_,param2,param3,param4);
- }
- else if(_loc10_.name() == constants.anyAttributeQName)
- {
- encodeAnyAttribute(_loc10_,param2,param3,param4);
- }
- }
- for each(_loc11_ in _loc9_)
- {
- delete param2[_loc11_.name()];
- delete param2[new QName("",_loc11_.name().localName)];
- delete param2[new QName(null,_loc11_.name().localName)];
- }
- setValue(param2,_loc9_);
- }
-
- public function encodeSimpleList(param1:XML, param2:XML, param3:QName, param4:*, param5:XML = null) : void
- {
- var _loc7_:QName = null;
- var _loc8_:XML = null;
- var _loc11_:* = undefined;
- var _loc12_:* = undefined;
- 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_ = <temp/>;
- if(_loc11_ != null)
- {
- if(_loc7_ != null)
- {
- encodeType(_loc7_,_loc12_,param3,_loc11_,param5);
- }
- else
- {
- encodeSimpleType(_loc8_,_loc12_,param3,_loc11_,param5);
- }
- _loc9_ = _loc9_.concat(_loc12_.toString());
- if(_loc10_.hasNext())
- {
- _loc9_ = _loc9_.concat(" ");
- }
- }
- }
- setValue(param2,_loc9_);
- }
-
- public function hasAttribute(param1:*, param2:*) : Boolean
- {
- return getAttribute(param1,param2) !== undefined;
- }
-
- public function encodeAll(param1:XML, param2:XMLList, param3:QName, param4:*, param5:Boolean = true) : Boolean
- {
- return encodeSequence(param1,param2,param3,param4,param5);
- }
-
- public function encodeAttribute(param1:XML, param2:XML, param3:QName, param4:* = undefined, param5:XML = null) : void
- {
- var _loc6_:QName = null;
- var _loc9_:QName = null;
- var _loc10_:String = null;
- var _loc11_:* = undefined;
- var _loc12_:Boolean = false;
- var _loc13_:String = null;
- var _loc14_:XML = null;
- var _loc15_:String = null;
- var _loc16_:QName = null;
- if(param1.attribute("ref").length() == 1)
- {
- _loc6_ = schemaManager.getQNameForPrefixedName(param1.@ref,param1,true);
- param1 = schemaManager.getNamedDefinition(_loc6_,constants.attributeQName);
- if(param1 == null)
- {
- throw new Error("Cannot resolve attribute definition for \'" + _loc6_ + "\'");
- }
- }
- var _loc7_:String = param1.@name.toString();
- var _loc8_:String = param1.attribute("use").toString();
- if(_loc8_ != "prohibited")
- {
- _loc9_ = schemaManager.getQNameForAttribute(_loc7_,getAttributeFromNode("form",param1));
- _loc10_ = getAttributeFromNode("fixed",param1);
- if(_loc10_ != null)
- {
- param4 = _loc10_;
- }
- else
- {
- param4 = getValue(param4,_loc9_);
- if(param4 === undefined)
- {
- _loc13_ = getAttributeFromNode("default",param1);
- if(_loc13_ != null)
- {
- param4 = _loc13_;
- }
- }
- }
- if(param4 !== undefined)
- {
- _loc11_ = <temp/>;
- _loc15_ = getAttributeFromNode("type",param1);
- if(_loc15_ != null)
- {
- _loc16_ = schemaManager.getQNameForPrefixedName(param1.@type,param1);
- }
- else
- {
- _loc16_ = schemaManager.schemaDatatypes.anySimpleTypeQName;
- }
- if(_loc16_ != null)
- {
- if(isBuiltInType(_loc16_))
- {
- _loc11_.appendChild(schemaManager.marshall(param4,_loc16_,param5));
- }
- else
- {
- _loc14_ = schemaManager.getNamedDefinition(_loc16_,constants.simpleTypeQName);
- if(_loc14_ == null)
- {
- throw new Error("Cannot find simpleType " + _loc16_ + " for attribute " + _loc9_);
- }
- encodeSimpleType(_loc14_,_loc11_,_loc9_,param4,param5);
- schemaManager.releaseScope();
- }
- }
- else
- {
- _loc14_ = getSingleElementFromNode(param1,constants.simpleTypeQName);
- if(_loc14_ != null)
- {
- encodeSimpleType(_loc14_,_loc11_,_loc9_,param4,param5);
- }
- else if(param4 != null)
- {
- _loc11_.appendChild(param4.toString());
- }
- }
- }
- if(_loc11_ !== undefined)
- {
- setAttribute(param2,_loc9_,_loc11_);
- }
- }
- if(_loc6_ != null)
- {
- schemaManager.releaseScope();
- }
- }
-
- public function setValue(param1:*, param2:*) : void
- {
- var _loc3_:XML = null;
- if(param2 !== undefined)
- {
- if(param1 is XML)
- {
- _loc3_ = param1 as XML;
- }
- else if(param1 is XMLList && param1.length() > 0)
- {
- _loc3_ = param1[param1.length() - 1];
- }
- if(_loc3_ != null)
- {
- if(param2 === null)
- {
- _loc3_[schemaManager.schemaConstants.nilQName] = "true";
- _loc3_.addNamespace(constants.xsiNamespace);
- }
- else if(param2 is XML || param2 is XMLList)
- {
- _loc3_.appendChild(param2);
- }
- else if(param2 !== undefined)
- {
- _loc3_.appendChild(xmlSpecialCharsFilter(Object(param2)));
- }
- }
- }
- }
-
- public function getProperties(param1:*) : Array
- {
- var _loc2_:Object = ObjectUtil.getClassInfo(param1 as Object,null,{"includeReadOnly":false});
- return _loc2_.properties;
- }
-
- public function encodeComplexRestriction(param1:XML, param2:XML, 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 = param2.elements();
- for each(_loc9_ in _loc7_)
- {
- if(_loc9_.name() == constants.sequenceQName)
- {
- encodeSequence(_loc9_,_loc8_,param3,param4);
- }
- else if(_loc9_.name() == constants.groupQName)
- {
- encodeGroupReference(_loc9_,_loc8_,param3,param4);
- }
- else if(_loc9_.name() == constants.allQName)
- {
- encodeAll(_loc9_,_loc8_,param3,param4);
- }
- else if(_loc9_.name() == constants.choiceQName)
- {
- encodeChoice(_loc9_,_loc8_,param3,param4);
- }
- else if(_loc9_.name() == constants.attributeQName)
- {
- encodeAttribute(_loc9_,param2,param3,param4,param1);
- }
- else if(_loc9_.name() == constants.attributeGroupQName)
- {
- encodeAttributeGroup(_loc9_,param2,param3,param4,param1);
- }
- else if(_loc9_.name() == constants.anyAttributeQName)
- {
- encodeAnyAttribute(_loc9_,param2,param3,param4,param1);
- }
- }
- param2.setChildren(_loc8_);
- }
-
- public function get xmlSpecialCharsFilter() : Function
- {
- return _xmlSpecialCharsFilter;
- }
-
- public function encodeAnyElement(param1:XML, param2:XMLList, param3:QName, param4:*, param5:Boolean = true, param6:Dictionary = null) : Boolean
- {
- var _loc9_:XML = null;
- var _loc10_:* = undefined;
- var _loc11_:* = undefined;
- var _loc12_:XMLList = null;
- var _loc13_:Object = null;
- var _loc14_:* = undefined;
- var _loc15_:QName = null;
- var _loc16_:XML = null;
- var _loc17_:XMLList = null;
- var _loc7_:uint = getMaxOccurs(param1);
- var _loc8_:uint = getMinOccurs(param1);
- if(isSimpleValue(param4))
- {
- _loc9_ = createElement(param3);
- setValue(_loc9_,param4);
- appendValue(param2,_loc9_);
- }
- else if(param4 is XML || param4 is XMLList)
- {
- appendValue(param2,param4);
- }
- else
- {
- if(param6 == null)
- {
- param6 = new Dictionary(true);
- }
- if(!(param4 is QName))
- {
- if(param6[param4] != null)
- {
- throw new Error("Cannot encode complex structure. Cyclic references detected.");
- }
- param6[param4] = true;
- }
- if(param4 is Array || param4 is IList)
- {
- if(param4 is IList)
- {
- param4 = IList(param4).toArray();
- }
- for each(_loc10_ in param4 as Array)
- {
- _loc11_ = createElement(param3);
- if(_loc10_ == null)
- {
- setValue(_loc11_,null);
- }
- else if(_loc10_ != null)
- {
- _loc12_ = new XMLList();
- encodeAnyElement(param1,_loc12_,param3,_loc10_,param5,param6);
- if(isSimpleValue(_loc10_))
- {
- _loc11_ = _loc12_[0];
- }
- else
- {
- setValue(_loc11_,_loc12_);
- }
- }
- appendValue(param2,_loc11_);
- }
- }
- else
- {
- for each(_loc13_ in getProperties(param4))
- {
- _loc14_ = getValue(param4,_loc13_);
- _loc15_ = new QName(param3.uri,_loc13_);
- if(!containsNodeByName(param2,_loc15_))
- {
- _loc16_ = encodeXSINil(param1,_loc15_,_loc14_);
- if(_loc16_ != null)
- {
- appendValue(param2,_loc16_);
- }
- else if(_loc14_ != null)
- {
- _loc17_ = new XMLList();
- encodeAnyElement(param1,_loc17_,_loc15_,_loc14_,param5,param6);
- appendValue(param2,_loc17_);
- }
- }
- }
- }
- delete param6[param4];
- }
- return true;
- }
-
- public function getSimpleValue(param1:*, param2:*) : *
- {
- var _loc3_:* = getValue(param1,param2);
- if(_loc3_ === undefined)
- {
- _loc3_ = getValue(param1,"_value");
- }
- return _loc3_;
- }
-
- public function getValue(param1:*, param2:*) : *
- {
- var _loc3_:* = undefined;
- var _loc4_:XMLList = null;
- if(param1 is XML || param1 is XMLList)
- {
- _loc4_ = param1[param2];
- if(_loc4_.length() > 0)
- {
- _loc3_ = _loc4_;
- }
- }
- else if(TypeIterator.isIterable(param1))
- {
- if(Boolean(param1.hasOwnProperty(param2)) && param1[param2] !== undefined)
- {
- _loc3_ = resolveNamedProperty(param1,param2);
- }
- else
- {
- _loc3_ = param1;
- }
- }
- else if(!isSimpleValue(param1))
- {
- if(param2 is QName)
- {
- param2 = QName(param2).localName;
- }
- _loc3_ = resolveNamedProperty(param1,param2);
- }
- else
- {
- _loc3_ = param1;
- }
- return _loc3_;
- }
-
- public function encodeGroupReference(param1:XML, param2:XMLList, param3:QName, param4:*, param5:Boolean = true) : Boolean
- {
- var _loc6_:QName = null;
- var _loc9_:XML = null;
- if(param1.attribute("ref").length() == 1)
- {
- _loc6_ = schemaManager.getQNameForPrefixedName(param1.@ref,param1,true);
- param1 = schemaManager.getNamedDefinition(_loc6_,constants.groupQName);
- if(param1 == null)
- {
- throw new Error("Cannot resolve group definition for \'" + _loc6_ + "\'");
- }
- var _loc7_:XMLList = param1.elements();
- var _loc8_:Boolean = false;
- for each(_loc9_ in _loc7_)
- {
- if(_loc9_.name() == constants.sequenceQName)
- {
- _loc8_ = encodeSequence(_loc9_,param2,param3,param4,param5);
- }
- else if(_loc9_.name() == constants.allQName)
- {
- _loc8_ = encodeAll(_loc9_,param2,param3,param4,param5);
- }
- else if(_loc9_.name() == constants.choiceQName)
- {
- _loc8_ = encodeChoice(_loc9_,param2,param3,param4,param5);
- }
- }
- schemaManager.releaseScope();
- return _loc8_;
- }
- throw new Error("A group reference element must have the ref attribute");
- }
-
- public function encodeSimpleRestriction(param1:XML, param2:XML, param3:QName, param4:*) : void
- {
- var _loc6_:String = null;
- var _loc7_:QName = null;
- var _loc5_:XML = getSingleElementFromNode(param1,constants.simpleTypeQName);
- if(_loc5_ != null)
- {
- encodeSimpleType(_loc5_,param2,param3,param4,param1);
- }
- else
- {
- _loc6_ = getAttributeFromNode("base",param1);
- _loc7_ = schemaManager.getQNameForPrefixedName(_loc6_,param1);
- encodeType(_loc7_,param2,param3,param4,param1);
- }
- }
-
- public function encodeAnyAttribute(param1:XML, param2:XML, param3:QName, param4:* = undefined, param5:XML = null) : void
- {
- var _loc6_:Object = null;
- var _loc7_:* = undefined;
- if(param4 !== undefined)
- {
- if(!isSimpleValue(param4) && !(param4 is Array))
- {
- for(_loc6_ in getProperties(param4))
- {
- if(!hasAttribute(param4,_loc6_) && !hasValue(param4,_loc6_))
- {
- _loc7_ = getAttribute(param4,_loc6_);
- if(_loc7_ != null)
- {
- setAttribute(param2,_loc6_,_loc7_);
- }
- }
- }
- }
- }
- }
-
- public function encodeSimpleUnion(param1:XML, param2:XML, param3:QName, param4:*, param5:XML = null) : void
- {
- var _loc8_:QName = null;
- var _loc9_:* = undefined;
- var _loc11_:String = null;
- var _loc12_:QName = null;
- var _loc6_:String = getAttributeFromNode("memberTypes",param1);
- var _loc7_:Array = _loc6_.split(" ");
- var _loc10_:int = 0;
- while(_loc10_ < _loc7_.length)
- {
- _loc11_ = _loc7_[_loc10_];
- _loc12_ = schemaManager.getQNameForPrefixedName(_loc11_,param1);
- if(!isBuiltInType(_loc12_))
- {
- _loc9_ = getValue(param4,_loc12_);
- if(_loc9_ !== undefined)
- {
- _loc8_ = _loc12_;
- break;
- }
- }
- _loc10_++;
- }
- if(!_loc8_)
- {
- _loc8_ = schemaManager.schemaDatatypes.stringQName;
- }
- setValue(param2,schemaManager.marshall(param4,_loc8_,param5));
- }
-
- public function encodeSimpleType(param1:XML, param2:XML, param3:QName, param4:*, param5:XML = null) : void
- {
- var _loc6_:XML = getSingleElementFromNode(param1,constants.restrictionQName,constants.listQName,constants.unionQName);
- if(_loc6_.name() == constants.restrictionQName)
- {
- encodeSimpleRestriction(_loc6_,param2,param3,param4);
- }
- else if(_loc6_.name() == constants.listQName)
- {
- encodeSimpleList(_loc6_,param2,param3,param4,param5);
- }
- else if(_loc6_.name() == constants.listQName)
- {
- encodeSimpleUnion(_loc6_,param2,param3,param4,param5);
- }
- }
-
- public function get strictNillability() : Boolean
- {
- return _strictNillability;
- }
-
- public function encodeElementTopLevel(param1:XML, param2:QName, param3:*) : XML
- {
- var _loc6_:QName = null;
- var _loc7_:XML = null;
- var _loc4_:XML = encodeXSINil(param1,param2,param3);
- if(_loc4_ != null)
- {
- return _loc4_;
- }
- if(param3 == null)
- {
- return null;
- }
- _loc4_ = createElement(param2);
- var _loc5_:String = getAttributeFromNode("type",param1);
- if(_loc5_ != null)
- {
- _loc6_ = schemaManager.getQNameForPrefixedName(_loc5_,param1);
- encodeType(_loc6_,_loc4_,param2,param3);
- }
- else if(param1 != null && Boolean(param1.hasComplexContent()))
- {
- _loc7_ = getSingleElementFromNode(param1,constants.complexTypeQName,constants.simpleTypeQName);
- if(_loc7_.name() == constants.complexTypeQName)
- {
- encodeComplexType(_loc7_,_loc4_,param2,param3);
- }
- else if(_loc7_.name() == constants.simpleTypeQName)
- {
- encodeSimpleType(_loc7_,_loc4_,param2,param3);
- }
- }
- else
- {
- encodeType(constants.anyTypeQName,_loc4_,param2,param3);
- }
- return _loc4_;
- }
-
- private function escapeXML(param1:Object) : String
- {
- var _loc2_:String = param1.toString();
- return _loc2_.replace(/&/g,"&").replace(/</g,"<");
- }
-
- public function encodeChoice(param1:XML, param2:XMLList, param3:QName, param4:*, param5:Boolean = true) : Boolean
- {
- var _loc10_:uint = 0;
- var _loc11_:uint = 0;
- var _loc12_:XML = null;
- var _loc6_:uint = getMaxOccurs(param1);
- var _loc7_:uint = getMinOccurs(param1);
- if(_loc6_ == 0)
- {
- return false;
- }
- if(param4 == null && _loc7_ == 0)
- {
- return true;
- }
- var _loc8_:XMLList = param1.elements();
- var _loc9_:Boolean = true;
- if(_loc8_.length() > 0)
- {
- _loc9_ = false;
- }
- for each(_loc12_ in _loc8_)
- {
- if(_loc12_.name() == constants.elementTypeQName)
- {
- _loc9_ = encodeGroupElement(_loc12_,param2,param3,param4,false) || _loc9_;
- }
- else if(_loc12_.name() == constants.sequenceQName)
- {
- _loc9_ = encodeSequence(_loc12_,param2,param3,param4,false) || _loc9_;
- }
- else if(_loc12_.name() == constants.groupQName)
- {
- _loc9_ = encodeGroupReference(_loc12_,param2,param3,param4,false) || _loc9_;
- }
- else if(_loc12_.name() == constants.choiceQName)
- {
- _loc9_ = encodeChoice(_loc12_,param2,param3,param4,false) || _loc9_;
- }
- else if(_loc12_.name() == constants.anyQName)
- {
- _loc9_ = encodeAnyElement(_loc12_,param2,param3,param4,false) || _loc9_;
- }
- }
- return _loc9_;
- }
-
- public function setAttribute(param1:XML, param2:*, param3:*) : void
- {
- if(param3 != null)
- {
- param1[param2] = param3.toString();
- }
- }
-
- public function isSimpleValue(param1:*) : Boolean
- {
- 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 encodeComplexContent(param1:XML, param2:XML, param3:QName, param4:*) : void
- {
- var _loc5_:XML = getSingleElementFromNode(param1,constants.extensionQName,constants.restrictionQName);
- if(_loc5_.name() == constants.extensionQName)
- {
- encodeComplexExtension(_loc5_,param2,param3,param4);
- }
- else if(_loc5_.name() == constants.restrictionQName)
- {
- encodeComplexRestriction(_loc5_,param2,param3,param4);
- }
- }
-
- public function createElement(param1:*) : XML
- {
- var _loc2_:XML = null;
- var _loc3_:QName = null;
- var _loc4_:String = null;
- var _loc5_:Namespace = null;
- if(param1 is QName)
- {
- _loc3_ = param1 as QName;
- }
- else
- {
- _loc3_ = new QName("",param1.toString());
- }
- _loc2_ = new XML("<" + _loc3_.localName + "/>");
- if(_loc3_.uri != null && _loc3_.uri.length > 0)
- {
- _loc4_ = schemaManager.getOrCreatePrefix(_loc3_.uri);
- _loc5_ = new Namespace(_loc4_,_loc3_.uri);
- _loc2_.setNamespace(_loc5_);
- }
- return _loc2_;
- }
-
- protected function setXSIType(param1:XML, param2:QName) : void
- {
- var _loc3_:String = param2.uri;
- var _loc4_:String = schemaManager.getOrCreatePrefix(_loc3_);
- var _loc5_:Namespace = new Namespace(_loc4_,_loc3_);
- param1.addNamespace(_loc5_);
- param1[constants.getXSIToken(constants.typeAttrQName)] = _loc4_ + ":" + param2.localName;
- }
-
- public function encodeGroupElement(param1:XML, param2:XMLList, param3:QName, param4:*, param5:Boolean = true) : Boolean
- {
- var _loc8_:QName = null;
- var _loc12_:XML = null;
- var _loc13_:uint = 0;
- var _loc14_:TypeIterator = null;
- var _loc15_:uint = 0;
- var _loc16_:* = undefined;
- var _loc6_:uint = getMaxOccurs(param1);
- var _loc7_:uint = getMinOccurs(param1);
- if(_loc6_ == 0)
- {
- return true;
- }
- param5 &&= _loc7_ > 0;
- if(param1.attribute("ref").length() == 1)
- {
- _loc8_ = schemaManager.getQNameForPrefixedName(param1.@ref,param1,true);
- param1 = schemaManager.getNamedDefinition(_loc8_,constants.elementTypeQName);
- if(param1 == null)
- {
- throw new Error("Cannot resolve element definition for ref \'" + _loc8_ + "\'");
- }
- }
- var _loc9_:String = param1.@name.toString();
- var _loc10_:QName = schemaManager.getQNameForElement(_loc9_,getAttributeFromNode("form",param1));
- var _loc11_:* = getValue(param4,_loc10_);
- if(_loc11_ == null)
- {
- _loc12_ = encodeElementTopLevel(param1,_loc10_,_loc11_);
- if(_loc12_ != null)
- {
- appendValue(param2,_loc12_);
- }
- if(_loc8_ != null)
- {
- schemaManager.releaseScope();
- }
- if(param5 && _loc12_ == null)
- {
- return false;
- }
- return true;
- }
- if(_loc6_ == 1)
- {
- _loc12_ = encodeElementTopLevel(param1,_loc10_,_loc11_);
- if(_loc12_ != null)
- {
- appendValue(param2,_loc12_);
- }
- }
- else if(_loc6_ > 1)
- {
- _loc13_ = getValueOccurence(_loc11_);
- if(_loc13_ < _loc7_)
- {
- throw new Error("Value supplied for element \'" + _loc10_ + "\' occurs " + _loc13_ + " times which falls short of minOccurs " + _loc7_ + ".");
- }
- if(_loc13_ > _loc6_)
- {
- throw new Error("Value supplied for element of type \'" + _loc10_ + "\' occurs " + _loc13_ + " times which exceeds maxOccurs " + _loc6_ + ".");
- }
- if(!TypeIterator.isIterable(_loc11_))
- {
- _loc11_ = [_loc11_];
- }
- _loc14_ = new TypeIterator(_loc11_);
- _loc15_ = 0;
- while(_loc15_ < _loc6_ && _loc15_ < _loc13_)
- {
- if(_loc14_.hasNext())
- {
- _loc16_ = _loc14_.next();
- }
- else if(_loc15_ > _loc7_)
- {
- break;
- }
- _loc12_ = encodeElementTopLevel(param1,_loc10_,_loc16_);
- if(_loc12_ == null)
- {
- _loc12_ = createElement(_loc10_);
- setValue(_loc12_,null);
- }
- appendValue(param2,_loc12_);
- _loc15_++;
- }
- }
- if(_loc8_ != null)
- {
- schemaManager.releaseScope();
- }
- return true;
- }
-
- public function set xmlSpecialCharsFilter(param1:Function) : void
- {
- if(param1 != null)
- {
- _xmlSpecialCharsFilter = param1;
- }
- else
- {
- _xmlSpecialCharsFilter = escapeXML;
- }
- }
-
- public function encodeType(param1:QName, param2:XML, param3:QName, param4:*, param5:XML = null) : void
- {
- var _loc8_:XMLList = null;
- var _loc9_:QName = null;
- var _loc6_:QName = getXSIType(param4);
- if(_loc6_ != null)
- {
- param1 = _loc6_;
- }
- var _loc7_:XML = schemaManager.getNamedDefinition(param1,constants.complexTypeQName,constants.simpleTypeQName);
- if(isBuiltInType(param1))
- {
- if(param1 == constants.anyTypeQName && !isSimpleValue(param4))
- {
- _loc8_ = new XMLList();
- encodeAnyElement(_loc7_,_loc8_,param3,param4);
- setValue(param2,_loc8_);
- }
- else
- {
- setValue(param2,schemaManager.marshall(param4,param1,param5));
- }
- deriveXSIType(param2,param1,param4);
- }
- else
- {
- if(_loc7_ == null)
- {
- throw new Error("Cannot find definition for type \'" + param1 + "\'");
- }
- _loc9_ = _loc7_.name() as QName;
- if(_loc9_ == constants.complexTypeQName)
- {
- encodeComplexType(_loc7_,param2,param3,param4,param5);
- }
- else
- {
- if(_loc9_ != constants.simpleTypeQName)
- {
- throw new Error("Invalid type definition " + _loc9_);
- }
- encodeSimpleType(_loc7_,param2,param3,param4,param5);
- }
- }
- if(_loc7_ != null)
- {
- schemaManager.releaseScope();
- }
- }
-
- public function encodeSimpleContent(param1:XML, param2:XML, 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 _loc6_:XML = getSingleElementFromNode(param1,constants.extensionQName,constants.restrictionQName);
- 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);
- setValue(param2,schemaManager.marshall(_loc9_,_loc8_,param5));
- }
- else
- {
- encodeType(_loc8_,param2,param4,param5);
- }
- _loc11_ = _loc6_.elements();
- for each(_loc12_ in _loc11_)
- {
- if(_loc12_.name() == constants.attributeQName)
- {
- encodeAttribute(_loc12_,param2,param3,param4,param5);
- }
- else if(_loc12_.name() == constants.attributeGroupQName)
- {
- encodeAttributeGroup(_loc12_,param2,param3,param4,param5);
- }
- else if(_loc12_.name() == constants.anyAttributeQName)
- {
- encodeAnyAttribute(_loc12_,param2,param3,param4,param5);
- }
- }
- }
- else if(_loc6_.name() == constants.restrictionQName)
- {
- _loc9_ = getSimpleValue(param4,param3);
- encodeSimpleRestriction(_loc6_,param2,param3,_loc9_);
- }
- }
- }
-
- protected function getXSIType(param1:*) : QName
- {
- var _loc2_:QName = null;
- if(param1 != null)
- {
- if(param1 is ObjectProxy && param1.object_proxy::type != null)
- {
- _loc2_ = param1.object_proxy::type;
- }
- else if(param1 is IXMLSchemaInstance && IXMLSchemaInstance(param1).xsiType != null)
- {
- _loc2_ = IXMLSchemaInstance(param1).xsiType;
- }
- }
- return _loc2_;
- }
-
- public function hasValue(param1:*, param2:*) : Boolean
- {
- return getValue(param1,param2) !== undefined;
- }
-
- public function encodeAttributeGroup(param1:XML, param2:XML, param3:QName, param4:* = undefined, param5:XML = null) : void
- {
- var _loc6_:QName = null;
- var _loc8_:XML = null;
- var _loc9_:XMLList = null;
- var _loc10_:XML = null;
- var _loc11_:XML = null;
- if(param1.attribute("ref").length() == 1)
- {
- _loc6_ = schemaManager.getQNameForPrefixedName(param1.@ref,param1,true);
- param1 = schemaManager.getNamedDefinition(_loc6_,constants.attributeGroupQName);
- if(param1 == null)
- {
- throw new Error("Cannot resolve attributeGroup definition for \'" + _loc6_ + "\'");
- }
- }
- var _loc7_:XMLList = param1.elements(constants.attributeQName);
- for each(_loc8_ in _loc7_)
- {
- encodeAttribute(_loc8_,param2,param3,param4,param5);
- }
- _loc9_ = param1.elements(constants.attributeGroupQName);
- for each(_loc10_ in _loc9_)
- {
- encodeAttributeGroup(_loc10_,param2,param3,param4,param5);
- }
- _loc11_ = getSingleElementFromNode(param1,constants.anyAttributeQName);
- if(_loc11_ != null)
- {
- encodeAnyAttribute(_loc11_,param2,param3,param4,param5);
- }
- if(_loc6_ != null)
- {
- schemaManager.releaseScope();
- }
- }
-
- public function encodeSequence(param1:XML, param2:XMLList, param3:QName, param4:*, param5:Boolean = true) : Boolean
- {
- var _loc11_:XML = null;
- var _loc6_:uint = getMaxOccurs(param1);
- var _loc7_:uint = getMinOccurs(param1);
- if(_loc6_ == 0)
- {
- return true;
- }
- if(param4 == null && _loc7_ == 0)
- {
- return true;
- }
- var _loc8_:XMLList = param1.elements();
- var _loc9_:Boolean = param5 && _loc7_ > 0;
- var _loc10_:Boolean = true;
- for each(_loc11_ in _loc8_)
- {
- _loc10_ = false;
- if(_loc11_.name() == constants.elementTypeQName)
- {
- if(!encodeGroupElement(_loc11_,param2,param3,param4,param5))
- {
- break;
- }
- }
- else if(_loc11_.name() == constants.groupQName)
- {
- if(!encodeGroupReference(_loc11_,param2,param3,param4,param5))
- {
- break;
- }
- }
- else if(_loc11_.name() == constants.choiceQName)
- {
- if(!encodeChoice(_loc11_,param2,param3,param4,param5))
- {
- break;
- }
- }
- else if(_loc11_.name() == constants.sequenceQName)
- {
- if(!encodeSequence(_loc11_,param2,param3,param4,param5))
- {
- break;
- }
- }
- else if(_loc11_.name() == constants.anyQName)
- {
- if(!encodeAnyElement(_loc11_,param2,param3,param4,param5))
- {
- break;
- }
- }
- _loc10_ = true;
- }
- return _loc10_ || !param5;
- }
- }
- }
-
-