Ejemplo n.º 1
0
        /**
         * Creates a new SoapObject based on this, allows usage of SoapObjects as
         * templates. One application is to set the expected return type of a soap
         * call if the server does not send explicit type information.
         *
         * @return a copy of this.
         */

        public SoapObject newInstance()
        {
            SoapObject o = new SoapObject(namespace_, name);

            for (int propIndex = 0; propIndex < properties.Count; propIndex++)
            {
                Object prop = properties[propIndex];
                if (prop is PropertyInfo)
                {
                    PropertyInfo propertyInfo        = (PropertyInfo)properties[propIndex];
                    PropertyInfo propertyInfoClonned = (PropertyInfo)propertyInfo.clone();
                    o.addProperty(propertyInfoClonned);
                }
                else if (prop is SoapObject)
                {
                    o.addSoapObject(((SoapObject)prop).newInstance());
                }
            }
            for (int attribIndex = 0; attribIndex < getAttributeCount(); attribIndex++)
            {
                AttributeInfo newAI = new AttributeInfo();
                getAttributeInfo(attribIndex, newAI);
                AttributeInfo attributeInfo = newAI; // (AttributeInfo)
                // attributes.elementAt(attribIndex);
                o.addAttribute(attributeInfo);
            }
            return(o);
        }
Ejemplo n.º 2
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);
        }