コード例 #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
ファイル: Marshal.cs プロジェクト: Noisyfox/fSoap
        public Object readInstance(XmlPullParser parser, String namespace_, String name, PropertyInfo expected)
        {
            Dictionary <object, object> instance = new Dictionary <object, object>();
            String elementName = parser.getName();

            while (parser.nextTag() != XmlPullParser.END_TAG)
            {
                SoapObject item = new ItemSoapObject(instance);
                parser.require(XmlPullParser.START_TAG, null, "item");
                parser.nextTag();
                Object key = envelope.read(parser, item, 0, null, null, PropertyInfo.OBJECT_TYPE);
                parser.nextTag();
                if (key != null)
                {
                    item.setProperty(0, key);
                }
                Object value = envelope.read(parser, item, 1, null, null, PropertyInfo.OBJECT_TYPE);
                parser.nextTag();
                if (value != null)
                {
                    item.setProperty(1, value);
                }
                parser.require(XmlPullParser.END_TAG, null, "item");
            }
            parser.require(XmlPullParser.END_TAG, null, elementName);
            return(instance);
        }
コード例 #4
0
ファイル: SoapEnvelope.cs プロジェクト: Noisyfox/fSoap
        public void parseHeader(XmlPullParser parser)
        {
            // consume start header
            parser.nextTag();
            // look at all header entries
            Node headers = new Node();

            headers.parse(parser);
            int count = 0;

            for (int i = 0; i < headers.getChildCount(); i++)
            {
                Element child = headers.getElement(i);
                if (child != null)
                {
                    count++;
                }
            }
            headerIn = new Element[count];
            count    = 0;
            for (int i = 0; i < headers.getChildCount(); i++)
            {
                Element child = headers.getElement(i);
                if (child != null)
                {
                    headerIn[count++] = child;
                }
            }
        }
コード例 #5
0
        /** Fills the fault details from the given XML stream */

        public override void parse(XmlPullParser parser)
        {
            parseSelf(parser);
            // done parsing, populate some of the legacy public members
            faultcode   = Code.getElement(SoapEnvelope.ENV2003, "Value").getText(0);
            faultstring = Reason.getElement(SoapEnvelope.ENV2003, "Text").getText(0);
            detail      = Detail;
            faultactor  = null;
        }
コード例 #6
0
        /**
         * Read a SoapObject. This extracts any attributes and then reads the object as a FvmSerializable.
         */

        protected void readSerializable(XmlPullParser parser, SoapObject obj)
        {
            for (int counter = 0; counter < parser.getAttributeCount(); counter++)
            {
                String attributeName = parser.getAttributeName(counter);
                String value         = parser.getAttributeValue(counter);
                ((SoapObject)obj).addAttribute(attributeName, value);
            }
            readSerializable(parser, (FvmSerializable)obj);
        }
コード例 #7
0
        private void parseRequestFocus(XmlPullParser parser, View view)
        {
            int type;

            view.requestFocus();
            int currentDepth = parser.getDepth();

            while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT)
            {
                // Empty
            }
        }
コード例 #8
0
        void rInflate(XmlPullParser parser, View parent, AttributeSet attrs, bool finishInflate, bool inheritContext)
        {
            int depth = parser.getDepth();
            int type;

            while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT)
            {
                if (type != XmlPullParser.START_TAG)
                {
                    continue;
                }

                string name = parser.getName();

                if (TAG_REQUEST_FOCUS.Equals(name))
                {
                    parseRequestFocus(parser, parent);
                }
                else if (TAG_TAG.Equals(name))
                {
                    parseViewTag(parser, parent, attrs);
                }

                if (TAG_INCLUDE.Equals(name))
                {
                    if (parser.getDepth() == 0)
                    {
                        throw new Exception("<include /> cannot be the root element");
                    }

                    parseInclude(parser, parent, attrs, inheritContext);
                }
                else if (TAG_MERGE.Equals(name))
                {
                    throw new Exception("<merge /> must be the root element");
                }

                else
                {
                    View      view                 = createViewFromTag(parent, name, attrs, inheritContext);
                    ViewGroup viewGroup            = (ViewGroup)parent;
                    ViewGroup.LayoutParams lparams = viewGroup.generateLayoutParams(attrs);
                    rInflate(parser, view, attrs, true, true);
                    viewGroup.addView(view, lparams);
                }
            }

            if (finishInflate)
            {
                parent.onFinishInflate();
            }
        }
コード例 #9
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);
        }
コード例 #10
0
        /**
         * Create from inside an XML document. Called on a parser positioned at a
         * tag in an XML document, tries to create a ColorStateList from that tag.
         *
         * @throws XmlPullParserException if the current tag is not &lt;selector>
         * @return A color state list for the current tag.
         */
        private static ColorStateList createFromXmlInner(Resources r, XmlPullParser parser, AttributeSet attrs)
        {
            ColorStateList colorStateList;
            string         name = parser.getName();

            if (name.Equals("selector"))
            {
                colorStateList = new ColorStateList();
            }
            else
            {
                throw new Exception(parser.getPositionDescription() + ": invalid drawable tag " + name);
            }

            //colorStateList.inflate(r, parser, attrs);
            return(colorStateList);
        }
コード例 #11
0
        /**
         * Creates or retrieves a ColorStateList that always returns a single color.
         */
        /*public static ColorStateList valueOf(int color)
         * {
         *  // TODO: should we collect these eventually?
         *  lock(sCache)
         *  {
         *      WeakReference<ColorStateList> ref1 = sCache.get(color);
         *
         *      ColorStateList csl1;
         *      ref1.TryGetTarget(out csl1);
         *
         *      ColorStateList csl = ref1 != null ? csl1 : null;
         *      if (csl != null)
         *      {
         *          return csl;
         *      }
         *
         *      csl = new ColorStateList(EMPTY, new int[] { color });
         *      sCache.put(color, new WeakReference<ColorStateList>(csl));
         *      return csl;
         *  }
         * }*/

        /**
         * Create a ColorStateList from an XML document, given a set of {@link Resources}.
         */
        public static ColorStateList createFromXml(Resources r, XmlPullParser parser)
        {
            AttributeSet attrs = Xml.asAttributeSet(parser);

            int type;

            while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT)
            {
            }

            if (type != XmlPullParser.START_TAG)
            {
                throw new Exception("No start tag found");
            }

            return(createFromXmlInner(r, parser, attrs));
        }
コード例 #12
0
        /*
         * Returns the parent element if available, null otherwise
         *
         * public Element getParentElement() {
         * return (parent instanceof Element)
         *  ? ((Element) parent)
         *  : null;
         * }
         */

        /**
         * Builds the child elements from the given Parser. By overwriting
         * parse, an element can take complete control over parsing its
         * subtree. */

        public override void parse(XmlPullParser parser)
        {
            for (int i = parser.getNamespaceCount(parser.getDepth() - 1);
                 i < parser.getNamespaceCount(parser.getDepth());
                 i++)
            {
                setPrefix(parser.getNamespacePrefix(i), parser.getNamespaceUri(i));
            }


            for (int i = 0; i < parser.getAttributeCount(); i++)
            {
                setAttribute(parser.getAttributeNamespace(i),
//	                      parser.getAttributePrefix (i),
                             parser.getAttributeName(i),
                             parser.getAttributeValue(i));
            }


            //        if (prefixMap == null) throw new RuntimeException ("!!");

            init();


            if (parser.isEmptyElementTag())
            {
                parser.nextToken();
            }
            else
            {
                parser.nextToken();
                base.parse(parser);

                if (getChildCount() == 0)
                {
                    addChild(IGNORABLE_WHITESPACE, "");
                }
            }

            parser.require(
                XmlPullParser.END_TAG,
                getNamespace(),
                getName());

            parser.nextToken();
        }
コード例 #13
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);
        }
コード例 #14
0
        private void parseViewTag(XmlPullParser parser, View view, AttributeSet attrs)
        {
            int type;

            //The below will be activated in the final version of Astoria.
            //TypedArray ta = mContext.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ViewTag);
            //int key = ta.getResourceId(com.android.internal.R.styleable.ViewTag_id, 0);
            //string value = ta.getText(com.android.internal.R.styleable.ViewTag_value);
            //view.setTag(key, value);
            //ta.recycle();

            int currentDepth = parser.getDepth();

            while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT)
            {
                // Empty
            }
        }
コード例 #15
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();
        }
コード例 #16
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");
        }
コード例 #17
0
ファイル: Marshal.cs プロジェクト: Noisyfox/fSoap
        public Object readInstance(XmlPullParser parser, String namespace_, String name, PropertyInfo excepted)
        {
            String text = parser.nextText();

            switch (name[0])
            {
            case 's':
                return(text);

            case 'i':
                return(int.Parse(text));

            case 'l':
                return(long.Parse(text));

            case 'b':
                return(SoapEnvelope.stringToBoolean(text));

            default:
                throw new Exception();
            }
        }
コード例 #18
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();
        }
コード例 #19
0
ファイル: Marshal.cs プロジェクト: Noisyfox/fSoap
        public Object readInstance(XmlPullParser parser, String namespace_, String name, PropertyInfo propertyInfo)
        {
            String stringValue = parser.nextText();
            Object result;

            if (name.Equals("float"))
            {
                result = float.Parse(stringValue);
            }
            else if (name.Equals("double"))
            {
                result = double.Parse(stringValue);
            }
            else if (name.Equals("decimal"))
            {
                result = Decimal.Parse(stringValue);
            }
            else
            {
                throw new Exception("float, double, or decimal expected");
            }
            return(result);
        }
コード例 #20
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);
        }
コード例 #21
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);
        }
コード例 #22
0
ファイル: Marshal.cs プロジェクト: Noisyfox/fSoap
 public Object readInstance(XmlPullParser parser, String namespace_, String name, PropertyInfo expected)
 {
     return(IsoDate.stringToDate(parser.nextText(), IsoDate.DATE_TIME));
 }
コード例 #23
0
 public static AttributeSet asAttributeSet(XmlPullParser parser)
 {
     //return (parser instanceof AttributeSet) ?? (AttributeSet)parser: new XmlPullAttributes(parser);
     //return new XmlPullAttributes(parser);
     return(new XmlPullAttributes(parser));
 }
コード例 #24
0
 //This is a hack for the layout inflater.
 public static AttributeSet asAttributeSet(XmlPullParser parser, Context c)
 {
     //return (parser instanceof AttributeSet) ?? (AttributeSet)parser: new XmlPullAttributes(parser);
     //return new XmlPullAttributes(parser);
     return(new XmlPullAttributesFromResString(parser, c));
 }
コード例 #25
0
 public XmlPullAttributes(XmlPullParser parser)
 {
     mParser = parser;
 }
コード例 #26
0
        /**
         * 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);
        }
コード例 #27
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);
        }
コード例 #28
0
        private void parseInclude(XmlPullParser parser, View parent, AttributeSet attrs, bool inheritContext)
        {
            int type;

            //if (parent.GetType().Equals(typeof(ViewGroup)))
            if (parent is ViewGroup)
            {
                int layout = attrs.getAttributeResourceValue(null, "layout", 0); //This should return resource value, not name
                if (layout == 0)
                {
                    string value = attrs.getAttributeValue(null, "layout");
                    if (value == null)
                    {
                        throw new Exception("You must specifiy a layout in the" + " include tag: <include layout=\"@layout/layoutID\" />");
                    }
                    else
                    {
                        throw new Exception("You must specifiy a valid layout " + "reference. The layout ID " + value + " is not valid.");
                    }
                }

                else
                {
                    XmlResourceParser childParser = getContext().getResources().getLayout(layout);

                    try
                    {
                        AttributeSet childAttrs = Xml.asAttributeSet(childParser, mContext);

                        while ((type = childParser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT)
                        {
                            // Empty.
                        }

                        if (type != XmlPullParser.START_TAG)
                        {
                            throw new Exception(childParser.getPositionDescription() + ": No start tag found!");
                        }

                        string childName = childParser.getName();

                        if (TAG_MERGE.Equals(childName))
                        {
                            // Inflate all children.
                            rInflate(childParser, parent, childAttrs, false, inheritContext);
                        }
                        else
                        {
                            View      view  = createViewFromTag(parent, childName, childAttrs, inheritContext);
                            ViewGroup group = (ViewGroup)parent;

                            // We try to load the layout params set in the <include /> tag. If
                            // they don't exist, we will rely on the layout params set in the
                            // included XML file.
                            // During a layoutparams generation, a runtime exception is thrown
                            // if either layout_width or layout_height is missing. We catch
                            // this exception and set localParams accordingly: true means we
                            // successfully loaded layout params from the <include /> tag,
                            // false means we need to rely on the included layout params.
                            ViewGroup.LayoutParams lparams = null;
                            try
                            {
                                lparams = group.generateLayoutParams(attrs);
                            }
                            catch
                            {
                                lparams = group.generateLayoutParams(childAttrs);
                            }
                            finally
                            {
                                if (lparams != null)
                                {
                                    view.setLayoutParams(lparams);
                                }
                            }

                            // Inflate all children.
                            rInflate(childParser, view, childAttrs, true, true);

                            /*
                             * // Attempt to override the included layout's android:id with the
                             * // one set on the <include /> tag itself.
                             * TypedArray a = mContext.obtainStyledAttributes(attrs, com.android.inner.R.styleable.View, 0, 0);
                             * int id = a.getResourceId(com.android.inner.R.styleable.View_id, View.NO_ID);
                             * // While we're at it, let's try to override android:visibility.
                             * int visibility = a.getInt(com.android.inner.R.styleable.View_visibility, -1);
                             * a.recycle();
                             *
                             * if (id != View.NO_ID)
                             * {
                             *  view.setId(id);
                             * }
                             *
                             * switch (visibility)
                             * {
                             *  case 0:
                             *      view.setVisibility(View.VISIBLE);
                             *      break;
                             *  case 1:
                             *      view.setVisibility(View.INVISIBLE);
                             *      break;
                             *  case 2:
                             *      view.setVisibility(View.GONE);
                             *      break;
                             * }
                             */

                            group.addView(view);
                        }
                    }

                    finally { }
                }
            }
            else
            {
                throw new Exception("<include /> can only be used inside of a ViewGroup");
            }

            int currentDepth = parser.getDepth();

            while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT)
            {
                // Empty
            }
        }
コード例 #29
0
 public XmlPullAttributesFromResString(XmlPullParser parser, Context c)
 {
     mParser  = parser;
     mContext = c;
 }
コード例 #30
0
        public virtual View inflate(XmlPullParser parser, ViewGroup root, bool attachToRoot)
        {
            //Trace.traceBegin(Trace.TRACE_TAG_VIEW, "inflate");

            AttributeSet attrs       = Xml.asAttributeSet(parser, mContext);
            Context      lastContext = (Context)mConstructorArgs[0];

            mConstructorArgs[0] = mContext;
            View result = root;

            try
            {
                // Look for the root node.
                int type;
                while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT)
                {
                    // Empty
                    //"WHAT A MISTAKE!" - DJT; but this is how Android does it so we'll do it here :(
                }

                if (type != XmlPullParser.START_TAG)
                {
                    throw new Exception(parser.getPositionDescription() + ": No start tag found!");
                }

                string name = parser.getName();

                if (DEBUG)
                {
                    Debug.WriteLine("**************************");
                    Debug.WriteLine("Creating root view: " + name);
                    Debug.WriteLine("**************************");
                }

                if (TAG_MERGE.Equals(name))
                {
                    if (root == null || !attachToRoot)
                    {
                        throw new Exception("<merge /> can be used only with a valid " + "ViewGroup root and attachToRoot=true");
                    }

                    rInflate(parser, root, attrs, false, false);
                }

                else
                {
                    // Temp is the root view that was found in the xml
                    View temp = createViewFromTag(root, name, attrs, false);

                    ViewGroup.LayoutParams lparams = null;

                    if (root != null)
                    {
                        if (DEBUG)
                        {
                            Debug.WriteLine("Creating params from root: " + root);
                        }

                        // Create layout params that match root, if supplied
                        lparams = root.generateLayoutParams(attrs);

                        if (!attachToRoot)
                        {
                            // Set the layout params for temp if we are not
                            // attaching. (If we are, we use addView, below)
                            temp.setLayoutParams(lparams);
                        }
                    }

                    if (DEBUG)
                    {
                        Debug.WriteLine("-----> start inflating children");
                    }

                    // Inflate all children under temp
                    rInflate(parser, temp, attrs, true, true);

                    if (DEBUG)
                    {
                        Debug.WriteLine("-----> done inflating children");
                    }

                    // We are supposed to attach all the views we found (int temp)
                    // to root. Do that now.
                    if (root != null && attachToRoot)
                    {
                        root.addView(temp, lparams);
                    }

                    // Decide whether to return the root that was passed in or the
                    // top view found in xml.
                    if (root == null || !attachToRoot)
                    {
                        result = temp;
                    }
                }
            }
            catch
            {
                throw;
            }

            finally
            {
                // Don't retain static reference on context.
                mConstructorArgs[0] = lastContext;
                mConstructorArgs[1] = null;
            }

            //Trace.traceEnd(Trace.TRACE_TAG_VIEW);

            return(result);
        }