/** * Returns a string array containing the namespace, name, id and Marshal object for the given java object. * This method is used by the SoapWriter in order to map Java objects to the corresponding SOAP section * five XML code. */ public Object[] getInfo(Object type, Object instance) { if (type == null) { if (instance is SoapObject || instance is SoapPrimitive) { type = instance; } else { type = instance.GetType(); } } if (type is SoapObject) { SoapObject so = (SoapObject)type; return(new Object[] { so.getNamespace(), so.getName(), null, null }); } if (type is SoapPrimitive) { SoapPrimitive sp = (SoapPrimitive)type; return(new Object[] { sp.getNamespace(), sp.getName(), null, DEFAULT_MARSHAL }); } if ((type is Type) && type != PropertyInfo.OBJECT_CLASS) { Object[] tmp = (Object[])classToQName[((Type)type).Name]; if (tmp != null) { return(tmp); } } return(new Object[] { xsd, ANY_TYPE_LABEL, null, null }); }
public override bool Equals(object o) { if (!(o is SoapPrimitive)) { return(false); } SoapPrimitive p = (SoapPrimitive)o; bool varsEqual = name.Equals(p.name) && (namespace_ == null ? p.namespace_ == null : namespace_.Equals(p.namespace_)) && (value == null ? (p.value == null) : value.Equals(p.value)); return(varsEqual && attributesAreEqual(p)); }
/** * Returns a new object read from the given parser. If no mapping is found, null is returned. This method * is used by the SoapParser in order to convert the XML code to Java objects. */ public Object readInstance(XmlPullParser parser, String namespace_, String name, PropertyInfo expected) { SoapPrimitive key = new SoapPrimitive(namespace_, name, null); if (!qNameToClass.ContainsKey(key)) { return(null); } Object obj = qNameToClass[key]; if (obj is Marshal) { return(((Marshal)obj).readInstance(parser, namespace_, name, expected)); } else if (obj is SoapObject) { obj = ((SoapObject)obj).newInstance(); } else if (obj == typeof(SoapObject)) { obj = new SoapObject(namespace_, name); } else { try { obj = Activator.CreateInstance((Type)obj); } catch (Exception e) { throw new Exception(e.ToString()); } } if (obj is HasAttributes) { HasAttributes soapObject = (HasAttributes)obj; int cnt = parser.getAttributeCount(); for (int counter = 0; counter < cnt; counter++) { AttributeInfo attributeInfo = new AttributeInfo(); attributeInfo.setName(parser.getAttributeName(counter)); attributeInfo.setValue(parser.getAttributeValue(counter)); attributeInfo.setNamespace(parser.getAttributeNamespace(counter)); attributeInfo.setType(parser.getAttributeType(counter)); soapObject.setAttribute(attributeInfo); } } // ok, obj is now the instance, fill it.... if (obj is SoapObject) { readSerializable(parser, (SoapObject)obj); } else if (obj is FvmSerializable) { if (obj is HasInnerText) { ((HasInnerText)obj).setInnerText((parser.getText() != null) ? parser.getText() : ""); } readSerializable(parser, (FvmSerializable)obj); } else if (obj is List <object> ) { readVector(parser, (List <object>)obj, expected.elementType); } else { throw new Exception("no deserializer for " + obj.GetType()); } return(obj); }
/** * If the type of the object cannot be determined, and thus no Marshal class can handle the object, this * method is called. It will build either a SoapPrimitive or a SoapObject * * @param parser * @param typeNamespace * @param typeName * @return unknownObject wrapped as a SoapPrimitive or SoapObject * @throws IOException * @throws XmlPullParserException */ protected Object readUnknown(XmlPullParser parser, String typeNamespace, String typeName) { String name = parser.getName(); String namespace_ = parser.getNamespace(); // cache the attribute info list from the current element before we move on List <object> attributeInfoVector = new List <object>(); for (int attributeCount = 0; attributeCount < parser.getAttributeCount(); attributeCount++) { AttributeInfo attributeInfo = new AttributeInfo(); attributeInfo.setName(parser.getAttributeName(attributeCount)); attributeInfo.setValue(parser.getAttributeValue(attributeCount)); attributeInfo.setNamespace(parser.getAttributeNamespace(attributeCount)); attributeInfo.setType(parser.getAttributeType(attributeCount)); attributeInfoVector.Add(attributeInfo); } parser.next(); // move to text, inner start tag or end tag Object result = null; String text = null; if (parser.getEventType() == XmlPullParser.TEXT) { text = parser.getText(); SoapPrimitive sp = new SoapPrimitive(typeNamespace, typeName, text); result = sp; // apply all the cached attribute info list before we add the property and descend further for parsing for (int i = 0; i < attributeInfoVector.Count; i++) { sp.addAttribute((AttributeInfo)attributeInfoVector[i]); } parser.next(); } else if (parser.getEventType() == XmlPullParser.END_TAG) { SoapObject so = new SoapObject(typeNamespace, typeName); // apply all the cached attribute info list before we add the property and descend further for parsing for (int i = 0; i < attributeInfoVector.Count; i++) { so.addAttribute((AttributeInfo)attributeInfoVector[i]); } result = so; } if (parser.getEventType() == XmlPullParser.START_TAG) { if (text != null && text.Trim().Length != 0) { throw new Exception("Malformed input: Mixed content"); } SoapObject so = new SoapObject(typeNamespace, typeName); // apply all the cached attribute info list before we add the property and descend further for parsing for (int i = 0; i < attributeInfoVector.Count; i++) { so.addAttribute((AttributeInfo)attributeInfoVector[i]); } while (parser.getEventType() != XmlPullParser.END_TAG) { so.addProperty(parser.getNamespace(), parser.getName(), read(parser, so, so.getPropertyCount(), null, null, PropertyInfo.OBJECT_TYPE)); parser.nextTag(); } result = so; } parser.require(XmlPullParser.END_TAG, namespace_, name); return(result); }