コード例 #1
0
        public override void parseBody(XmlPullParser parser)
        {
            bodyIn = null;
            parser.nextTag();
            if (parser.getEventType() == XmlPullParser.START_TAG && parser.getNamespace().Equals(env) &&
                parser.getName().Equals("Fault"))
            {
                SoapFault fault;
                if (this.version < SoapEnvelope.VER12)
                {
                    fault = new SoapFault(this.version);
                }
                else
                {
                    fault = new SoapFault12(this.version);
                }
                fault.parse(parser);
                bodyIn = fault;
            }
            else
            {
                while (parser.getEventType() == XmlPullParser.START_TAG)
                {
                    String rootAttr = parser.getAttributeValue(enc, ROOT_LABEL);

                    Object o = read(parser, null, -1, parser.getNamespace(), parser.getName(),
                                    PropertyInfo.OBJECT_TYPE);
                    if ("1".Equals(rootAttr) || bodyIn == null)
                    {
                        bodyIn = o;
                    }
                    parser.nextTag();
                }
            }
        }
コード例 #2
0
ファイル: SoapEnvelope.cs プロジェクト: Noisyfox/fSoap
 public virtual void parseBody(XmlPullParser parser)
 {
     parser.nextTag();
     // insert fault generation code here
     if (parser.getEventType() == XmlPullParser.START_TAG &&
         parser.getNamespace().Equals(env) &&
         parser.getName().Equals("Fault"))
     {
         SoapFault fault;
         if (this.version < SoapEnvelope.VER12)
         {
             fault = new SoapFault(this.version);
         }
         else
         {
             fault = new SoapFault12(this.version);
         }
         fault.parse(parser);
         bodyIn = fault;
     }
     else
     {
         Node node = (bodyIn
                      is Node)
             ? (Node)bodyIn
             : new Node();
         node.parse(parser);
         bodyIn = node;
     }
 }
コード例 #3
0
ファイル: Node.cs プロジェクト: Noisyfox/fSoap
        /** Recursively builds the child elements from the given parser
         * until an end tag or end document is found.
         * The end tag is not consumed. */

        public virtual void parse(XmlPullParser parser)
        {
            bool leave = false;

            do
            {
                int type = parser.getEventType();

                //         System.out.println(parser.getPositionDescription());

                switch (type)
                {
                case XmlPullParser.START_TAG:
                {
                    Element child =
                        createElement(
                            parser.getNamespace(),
                            parser.getName());
                    //    child.setAttributes (event.getAttributes ());
                    addChild(ELEMENT, child);

                    // order is important here since
                    // setparent may perform some init code!

                    child.parse(parser);
                    break;
                }

                case XmlPullParser.END_DOCUMENT:
                case XmlPullParser.END_TAG:
                    leave = true;
                    break;

                default:
                    if (parser.getText() != null)
                    {
                        addChild(
                            type == XmlPullParser.ENTITY_REF ? TEXT : type,
                            parser.getText());
                    }
                    else if (
                        type == XmlPullParser.ENTITY_REF &&
                        parser.getName() != null)
                    {
                        addChild(ENTITY_REF, parser.getName());
                    }
                    parser.nextToken();
                    break;
                }
            } while (!leave);
        }
コード例 #4
0
        protected void readVector(XmlPullParser parser, List <object> v, PropertyInfo elementType)
        {
            String namespace_ = null;
            String name       = null;
            int    size       = v.Count;
            bool   dynamic    = true;
            String type       = parser.getAttributeValue(enc, ARRAY_TYPE_LABEL);

            if (type != null)
            {
                int cut0 = type.IndexOf(':');
                int cut1 = type.IndexOf("[", cut0);
                name = type.Substring(cut0 + 1, cut1 - cut0 - 1);
                String prefix = cut0 == -1 ? "" : type.Substring(0, cut0);
                namespace_ = parser.getNamespace(prefix);
                size       = getIndex(type, cut1, -1);
                if (size != -1)
                {
                    setSize(v, size);
                    dynamic = false;
                }
            }
            if (elementType == null)
            {
                elementType = PropertyInfo.OBJECT_TYPE;
            }
            parser.nextTag();
            int position = getIndex(parser.getAttributeValue(enc, "offset"), 0, 0);

            while (parser.getEventType() != XmlPullParser.END_TAG)
            {
                // handle position
                position = getIndex(parser.getAttributeValue(enc, "position"), 0, position);
                if (dynamic && position >= size)
                {
                    size = position + 1;
                    setSize(v, size);
                }
                // implicit handling of position exceeding specified size
                v[position] = read(parser, v, position, namespace_, name, elementType);
                position++;
                parser.nextTag();
            }
            parser.require(XmlPullParser.END_TAG, null, null);
        }
コード例 #5
0
        private void parseSelf(XmlPullParser parser)
        {
            parser.require(XmlPullParser.START_TAG, SoapEnvelope.ENV2003, "Fault");

            while (parser.nextTag() == XmlPullParser.START_TAG)
            {
                string name       = parser.getName();
                string namespace_ = parser.getNamespace();
                parser.nextTag();
                if (name.ToLower().Equals("Code".ToLower()))
                {
                    Code = new Node();
                    Code.parse(parser);
                }
                else if (name.ToLower().Equals("Reason".ToLower()))
                {
                    Reason = new Node();
                    Reason.parse(parser);
                }
                else if (name.ToLower().Equals("Node".ToLower()))
                {
                    Node = new Node();
                    Node.parse(parser);
                }
                else if (name.ToLower().Equals("Role".ToLower()))
                {
                    Role = new Node();
                    Role.parse(parser);
                }
                else if (name.ToLower().Equals("Detail".ToLower()))
                {
                    Detail = new Node();
                    Detail.parse(parser);
                }
                else
                {
                    throw new Exception("unexpected tag:" + name);
                }

                parser.require(XmlPullParser.END_TAG, namespace_, name);
            }
            parser.require(XmlPullParser.END_TAG, SoapEnvelope.ENV2003, "Fault");
            parser.nextTag();
        }
コード例 #6
0
ファイル: SoapEnvelope.cs プロジェクト: Noisyfox/fSoap
        /** Parses the SOAP envelope from the given parser */

        public void parse(XmlPullParser parser)
        {
            parser.nextTag();
            parser.require(XmlPullParser.START_TAG, env, "Envelope");
            encodingStyle = parser.getAttributeValue(env, "encodingStyle");
            parser.nextTag();
            if (parser.getEventType() == XmlPullParser.START_TAG &&
                parser.getNamespace().Equals(env) &&
                parser.getName().Equals("Header"))
            {
                parseHeader(parser);
                parser.require(XmlPullParser.END_TAG, env, "Header");
                parser.nextTag();
            }
            parser.require(XmlPullParser.START_TAG, env, "Body");
            encodingStyle = parser.getAttributeValue(env, "encodingStyle");
            parseBody(parser);
            parser.require(XmlPullParser.END_TAG, env, "Body");
            parser.nextTag();
            parser.require(XmlPullParser.END_TAG, env, "Envelope");
        }
コード例 #7
0
        /** Fills the fault details from the given XML stream */

        public virtual void parse(XmlPullParser parser)
        {
            parser.require(XmlPullParser.START_TAG, SoapEnvelope.ENV, "Fault");
            while (parser.nextTag() == XmlPullParser.START_TAG)
            {
                string name = parser.getName();
                if (name.Equals("detail"))
                {
                    detail = new Node();
                    detail.parse(parser);
                    // Handle case '...<detail/></soap:Fault>'
                    if (parser.getNamespace().Equals(SoapEnvelope.ENV) && parser.getName().Equals("Fault"))
                    {
                        break;
                    }
                    continue;
                }
                if (name.Equals("faultcode"))
                {
                    faultcode = parser.nextText();
                }
                else if (name.Equals("faultstring"))
                {
                    faultstring = parser.nextText();
                }
                else if (name.Equals("faultactor"))
                {
                    faultactor = parser.nextText();
                }
                else
                {
                    throw new Exception("unexpected tag:" + name);
                }
                parser.require(XmlPullParser.END_TAG, null, name);
            }
            parser.require(XmlPullParser.END_TAG, SoapEnvelope.ENV, "Fault");
            parser.nextTag();
        }
コード例 #8
0
        /**
         * Builds an object from the XML stream. This method is public for usage in conjuction with Marshal
         * subclasses. Precondition: On the start tag of the object or property, so href can be read.
         */

        public Object read(XmlPullParser parser, Object owner, int index, String namespace_, String name,
                           PropertyInfo expected)
        {
            String elementName = parser.getName();
            String href        = parser.getAttributeValue(null, HREF_LABEL);
            Object obj;

            if (href != null)
            {
                if (owner == null)
                {
                    throw new Exception("href at root level?!?");
                }
                href = getIdFromHref(href);
                obj  = idMap[href];
                if (obj == null || obj is FwdRef)
                {
                    FwdRef f = new FwdRef();
                    f.next      = (FwdRef)obj;
                    f.obj       = owner;
                    f.index     = index;
                    idMap[href] = f;
                    obj         = null;
                }
                parser.nextTag(); // start tag
                parser.require(XmlPullParser.END_TAG, null, elementName);
            }
            else
            {
                String nullAttr = parser.getAttributeValue(xsi, NIL_LABEL);
                String id       = parser.getAttributeValue(null, ID_LABEL);
                if (nullAttr == null)
                {
                    nullAttr = parser.getAttributeValue(xsi, NULL_LABEL);
                }
                if (nullAttr != null && SoapEnvelope.stringToBoolean(nullAttr))
                {
                    obj = null;
                    parser.nextTag();
                    parser.require(XmlPullParser.END_TAG, null, elementName);
                }
                else
                {
                    String type = parser.getAttributeValue(xsi, TYPE_LABEL);
                    if (type != null)
                    {
                        int cut = type.IndexOf(':');
                        name = type.Substring(cut + 1);
                        String prefix = cut == -1 ? "" : type.Substring(0, cut);
                        namespace_ = parser.getNamespace(prefix);
                    }
                    else if (name == null && namespace_ == null)
                    {
                        if (parser.getAttributeValue(enc, ARRAY_TYPE_LABEL) != null)
                        {
                            namespace_ = enc;
                            name       = ARRAY_MAPPING_NAME;
                        }
                        else
                        {
                            Object[] names = getInfo(expected.type, null);
                            namespace_ = (String)names[0];
                            name       = (String)names[1];
                        }
                    }
                    // be sure to set this flag if we don't know the types.
                    if (type == null)
                    {
                        implicitTypes = true;
                    }
                    obj = readInstance(parser, namespace_, name, expected);
                    if (obj == null)
                    {
                        obj = readUnknown(parser, namespace_, name);
                    }
                }
                // finally, care about the id....
                if (id != null)
                {
                    resolveReference(id, obj);
                }
            }

            parser.require(XmlPullParser.END_TAG, null, elementName);
            return(obj);
        }
コード例 #9
0
        /**
         * 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);
        }
コード例 #10
0
        /**
         * Read a FvmSerializable.
         */

        protected void readSerializable(XmlPullParser parser, FvmSerializable obj)
        {
            int tag = 0;

            try
            {
                tag = parser.nextTag();
            }
            catch (XmlPullParserException e)
            {
                if (obj is HasInnerText)
                {
                    ((HasInnerText)obj).setInnerText((parser.getText() != null) ? parser.getText() : "");
                }
                tag = parser.nextTag();
            }
            while (tag != XmlPullParser.END_TAG)
            {
                String name = parser.getName();
                if (!implicitTypes || !(obj is SoapObject))
                {
                    PropertyInfo info          = new PropertyInfo();
                    int          propertyCount = obj.getPropertyCount();
                    bool         propertyFound = false;

                    for (int i = 0; i < propertyCount && !propertyFound; i++)
                    {
                        info.clear();
                        obj.getPropertyInfo(i, properties, info);

                        if ((name.Equals(info.name) && info.namespace_ == null) ||
                            (name.Equals(info.name) && parser.getNamespace().Equals(info.namespace_)))
                        {
                            propertyFound = true;
                            obj.setProperty(i, read(parser, obj, i, null, null, info));
                        }
                    }

                    if (!propertyFound)
                    {
                        if (avoidExceptionForUnknownProperty)
                        {
                            // Dummy loop to read until corresponding END tag
                            while (parser.next() != XmlPullParser.END_TAG || !name.Equals(parser.getName()))
                            {
                            }
                            ;
                        }
                        else
                        {
                            throw new Exception("Unknown Property: " + name);
                        }
                    }
                    else
                    {
                        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);
                            }
                        }
                    }
                }
                else
                {
                    // I can only make this work for SoapObjects - hence the check above
                    // I don't understand namespaces well enough to know whether it is correct in the next line...
                    ((SoapObject)obj).addProperty(parser.getName(), read(parser, obj, obj.getPropertyCount(),
                                                                         ((SoapObject)obj).getNamespace(), name, PropertyInfo.OBJECT_TYPE));
                }
                try
                {
                    tag = parser.nextTag();
                }
                catch (XmlPullParserException e)
                {
                    if (obj is HasInnerText)
                    {
                        ((HasInnerText)obj).setInnerText((parser.getText() != null) ? parser.getText() : "");
                    }
                    tag = parser.nextTag();
                }
            }
            parser.require(XmlPullParser.END_TAG, null, null);
        }