Пример #1
0
        /**
         * Write the instance out. In case it is an AttributeContainer write those our first though.
         * If it HasAttributes then write the attributes and values.
         *
         * @param writer   the xml serializer.
         * @param instance
         * @throws IOException
         */

        public void writeInstance(XmlSerializer writer, Object instance)
        {
            if (instance is AttributeContainer)
            {
                AttributeContainer attributeContainer = (AttributeContainer)instance;
                int cnt = attributeContainer.getAttributeCount();
                for (int counter = 0; counter < cnt; counter++)
                {
                    AttributeInfo attributeInfo = new AttributeInfo();
                    attributeContainer.getAttributeInfo(counter, attributeInfo);
                    try
                    {
                        attributeContainer.getAttribute(counter, attributeInfo);
                    }
                    catch (Exception e)
                    {
                        //e.printStackTrace();
                    }
                    if (attributeInfo.getValue() != null)
                    {
                        writer.attribute(attributeInfo.getNamespace(), attributeInfo.getName(),
                                         (attributeInfo.getValue() != null) ? attributeInfo.getValue().ToString() : "");
                    }
                }
            }
            else if (instance is HasAttributes)
            {
                HasAttributes soapObject = (HasAttributes)instance;
                int           cnt        = soapObject.getAttributeCount();
                for (int counter = 0; counter < cnt; counter++)
                {
                    AttributeInfo attributeInfo = new AttributeInfo();
                    soapObject.getAttributeInfo(counter, attributeInfo);
                    try
                    {
                        soapObject.getAttribute(counter, attributeInfo);
                    }
                    catch (Exception e)
                    {
                        //e.printStackTrace();
                    }
                    if (attributeInfo.getValue() != null)
                    {
                        writer.attribute(attributeInfo.getNamespace(), attributeInfo.getName(),
                                         attributeInfo.getValue() != null ? attributeInfo.getValue().ToString() : "");
                    }
                }
            }
            writer.text(instance.ToString());
        }
Пример #2
0
        /**
         * Checks that the two objects have identical sets of attributes.
         *
         * @param other
         * @return {@code true} of the attrubte sets are equal, {@code false} otherwise.
         */

        protected bool attributesAreEqual(AttributeContainer other)
        {
            int numAttributes = getAttributeCount();

            if (numAttributes != other.getAttributeCount())
            {
                return(false);
            }

            for (int attribIndex = 0; attribIndex < numAttributes; attribIndex++)
            {
                AttributeInfo thisAttrib      = (AttributeInfo)this.attributes[attribIndex];
                Object        thisAttribValue = thisAttrib.getValue();
                if (!other.hasAttribute(thisAttrib.getName()))
                {
                    return(false);
                }
                Object otherAttribValue = other.getAttributeSafely(thisAttrib.getName());
                if (!thisAttribValue.Equals(otherAttribValue))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
        private void writeAttributes(XmlSerializer writer, HasAttributes obj)
        {
            HasAttributes soapObject = (HasAttributes)obj;
            int           cnt        = soapObject.getAttributeCount();

            for (int counter = 0; counter < cnt; counter++)
            {
                AttributeInfo attributeInfo = new AttributeInfo();
                soapObject.getAttributeInfo(counter, attributeInfo);
                soapObject.getAttribute(counter, attributeInfo);
                if (attributeInfo.getValue() != null)
                {
                    writer.attribute(attributeInfo.getNamespace(), attributeInfo.getName(),
                                     attributeInfo.getValue().ToString());
                }
            }
        }
Пример #4
0
        public void getAttributeInfo(int index, AttributeInfo attributeInfo)
        {
            AttributeInfo p = (AttributeInfo)attributes[index];

            attributeInfo.name        = p.name;
            attributeInfo.namespace_  = p.namespace_;
            attributeInfo.flags       = p.flags;
            attributeInfo.type        = p.type;
            attributeInfo.elementType = p.elementType;
            attributeInfo.value       = p.getValue();
        }
Пример #5
0
        /**
         * Get the attribute's toString value.
         */

        public String getAttributeAsString(int index)
        {
            AttributeInfo attributeInfo = (AttributeInfo)attributes[index];

            return(attributeInfo.getValue().ToString());
        }