Example usage for org.xml.sax.helpers AttributesImpl AttributesImpl

List of usage examples for org.xml.sax.helpers AttributesImpl AttributesImpl

Introduction

In this page you can find the example usage for org.xml.sax.helpers AttributesImpl AttributesImpl.

Prototype

public AttributesImpl() 

Source Link

Document

Construct a new, empty AttributesImpl object.

Usage

From source file:org.apache.axis.encoding.ser.MapSerializer.java

/** Serialize a Map
 *
 * Walk the collection of keys, serializing each key/value pair
 * inside an <item> element./*from w ww .  ja  v a 2 s .c  o  m*/
 *
 * @param name the desired QName for the element
 * @param attributes the desired attributes for the element
 * @param value the Object to serialize
 * @param context the SerializationContext in which to do all this
 * @exception IOException
 */
public void serialize(QName name, Attributes attributes, Object value, SerializationContext context)
        throws IOException {
    if (!(value instanceof Map))
        throw new IOException(Messages.getMessage("noMap00", "MapSerializer", value.getClass().getName()));

    Map map = (Map) value;

    context.startElement(name, attributes);

    AttributesImpl itemsAttributes = new AttributesImpl();
    String encodingURI = context.getMessageContext().getEncodingStyle();
    String encodingPrefix = context.getPrefixForURI(encodingURI);
    String soapPrefix = context.getPrefixForURI(Constants.SOAP_MAP.getNamespaceURI());
    itemsAttributes.addAttribute(encodingURI, "type", encodingPrefix + ":type", "CDATA",
            encodingPrefix + ":Array");
    itemsAttributes.addAttribute(encodingURI, "arrayType", encodingPrefix + ":arrayType", "CDATA",
            soapPrefix + ":item[" + map.size() + "]");

    for (Iterator i = map.entrySet().iterator(); i.hasNext();) {
        Map.Entry entry = (Map.Entry) i.next();
        Object key = entry.getKey();
        Object val = entry.getValue();

        context.startElement(QNAME_ITEM, null);

        // Since the Key and Value can be any type, send type info
        context.serialize(QNAME_KEY, null, key, null, null, Boolean.TRUE);
        context.serialize(QNAME_VALUE, null, val, null, null, Boolean.TRUE);

        context.endElement();
    }

    context.endElement();
}

From source file:org.apache.axis.encoding.SerializationContext.java

/**
 * Serialize the indicated value as an element with the name
 * indicated by elemQName./*from  w  ww . java  2 s.c  o m*/
 * The attributes are additional attribute to be serialized on the element.
 * The value is the object being serialized.  (It may be serialized
 * directly or serialized as an mult-ref'd item)
 * The value is an Object, which may be a wrapped primitive.
 * The xmlType (if specified) is the QName of the type that is used to set
 * xsi:type.
 * The sendNull flag indicates whether to end an element with an xsi:nil="true" attribute for null
 * variables (if Boolean.TRUE), or nothing (if Boolean.FALSE).
 * The sendType flag indicates whether the xsi:type flag should be sent
 * (default is true).
 * @param elemQName is the QName of the element
 * @param attributes are additional attributes
 * @param value is the object to serialize
 * @param xmlType is the qname of the type or null.
 * @param javaType is the java type of the value
 * @param sendNull determines whether to send null values.
 * @param sendType determines whether to set xsi:type attribute.
 */
public void serialize(QName elemQName, Attributes attributes, Object value, QName xmlType, Class javaClass,
        Boolean sendNull, Boolean sendType) throws IOException {
    boolean sendXSITypeCache = sendXSIType;
    if (sendType != null) {
        sendXSIType = sendType.booleanValue();
    }
    boolean shouldSendType = shouldSendXSIType();

    try {
        Boolean sendNullCache = this.sendNull;
        if (sendNull != null) {
            this.sendNull = sendNull;
        } else {
            sendNull = this.sendNull;
        }

        if (value == null) {
            // If the value is null, the element is
            // passed with xsi:nil="true" to indicate that no object is present.
            if (this.sendNull.booleanValue()) {
                AttributesImpl attrs = new AttributesImpl();
                if (attributes != null && 0 < attributes.getLength())
                    attrs.setAttributes(attributes);
                if (shouldSendType)
                    attrs = (AttributesImpl) setTypeAttribute(attrs, xmlType);
                String nil = schemaVersion.getNilQName().getLocalPart();
                attrs.addAttribute(schemaVersion.getXsiURI(), nil, "xsi:" + nil, "CDATA", "true");
                startElement(elemQName, attrs);
                endElement();
            }
            this.sendNull = sendNullCache;
            return;
        }

        Message msg = getCurrentMessage();
        if (null != msg) {
            //Get attachments. returns null if no attachment support.
            Attachments attachments = getCurrentMessage().getAttachmentsImpl();

            if (null != attachments && attachments.isAttachment(value)) {
                //Attachment support and this is an object that should be treated as an attachment.

                //Allow an the attachment to do its own serialization.
                serializeActual(elemQName, attributes, value, xmlType, javaClass, sendType);

                //No need to add to mulitRefs. Attachment data stream handled by
                // the message;
                this.sendNull = sendNullCache;
                return;
            }
        }

        // If multi-reference is enabled and this object value is not a primitive
        // and we are not forcing serialization of the object, then generate
        // an element href (and store the object for subsequent outputMultiRef
        // processing).

        // NOTE : you'll notice that everywhere we register objects in the
        // multiRefValues and secondLevelObjects collections, we key them
        // using getIdentityKey(value) instead of the Object reference itself.
        // THIS IS IMPORTANT, and please make sure you understand what's
        // going on if you change any of this code.  It's this way to make
        // sure that individual Objects are serialized separately even if the
        // hashCode() and equals() methods have been overloaded to make two
        // Objects appear equal.

        if (doMultiRefs && isEncoded() && (value != forceSer) && !isPrimitive(value)) {
            if (multiRefIndex == -1)
                multiRefValues = new HashMap();

            String id;

            // Look for a multi-ref descriptor for this Object.
            MultiRefItem mri = (MultiRefItem) multiRefValues.get(getIdentityKey(value));
            if (mri == null) {
                // Didn't find one, so create one, give it a new ID, and store
                // it for next time.
                multiRefIndex++;
                id = "id" + multiRefIndex;
                mri = new MultiRefItem(id, xmlType, sendType, value);
                multiRefValues.put(getIdentityKey(value), mri);

                /**
                 * If we're SOAP 1.2, we can "inline" the serializations,
                 * so put it out now, with it's ID.
                 */
                if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
                    AttributesImpl attrs = new AttributesImpl();
                    if (attributes != null && 0 < attributes.getLength())
                        attrs.setAttributes(attributes);
                    attrs.addAttribute("", Constants.ATTR_ID, "id", "CDATA", id);
                    serializeActual(elemQName, attrs, value, xmlType, javaClass, sendType);
                    this.sendNull = sendNullCache;
                    return;
                }

                /** If we're in the middle of writing out
                 * the multi-refs, we've already cloned the list of objects
                 * and so even though we add a new one to multiRefValues,
                 * it won't get serialized this time around.
                 *
                 * To deal with this, we maintain a list of "second level"
                 * Objects - ones that need serializing as a result of
                 * serializing the first level.  When outputMultiRefs() is
                 * nearly finished, it checks to see if secondLevelObjects
                 * is empty, and if not, it goes back and loops over those
                 * Objects.  This can happen N times depending on how deep
                 * the Object graph goes.
                 */
                if (outputMultiRefsFlag) {
                    if (secondLevelObjects == null)
                        secondLevelObjects = new HashSet();
                    secondLevelObjects.add(getIdentityKey(value));
                }
            } else {
                // Found one, remember it's ID
                id = mri.id;
            }

            // Serialize an HREF to our object
            AttributesImpl attrs = new AttributesImpl();
            if (attributes != null && 0 < attributes.getLength())
                attrs.setAttributes(attributes);
            attrs.addAttribute("", soapConstants.getAttrHref(), soapConstants.getAttrHref(), "CDATA", '#' + id);

            startElement(elemQName, attrs);
            endElement();
            this.sendNull = sendNullCache;
            return;
        }

        // The forceSer variable is set by outputMultiRefs to force
        // serialization of this object via the serialize(...) call
        // below.  However, if the forced object contains a self-reference, we
        // get into an infinite loop..which is why it is set back to null
        // before the actual serialization.
        if (value == forceSer)
            forceSer = null;

        // Actually serialize the value.  (i.e. not an href like above)
        serializeActual(elemQName, attributes, value, xmlType, javaClass, sendType);
    } finally {
        sendXSIType = sendXSITypeCache;
    }
}

From source file:org.apache.axis.encoding.SerializationContext.java

/**
 * The serialize method uses hrefs to reference all non-primitive
 * values.  These values are stored and serialized by calling
 * outputMultiRefs after the serialize method completes.
 *///from w ww . j  av  a  2 s . c  o m
public void outputMultiRefs() throws IOException {
    if (!doMultiRefs || (multiRefValues == null) || soapConstants == SOAPConstants.SOAP12_CONSTANTS)
        return;
    outputMultiRefsFlag = true;
    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute("", "", "", "", "");

    String encodingURI = soapConstants.getEncodingURI();
    // explicitly state that this attribute is not a root
    String prefix = getPrefixForURI(encodingURI);
    String root = prefix + ":root";
    attrs.addAttribute(encodingURI, Constants.ATTR_ROOT, root, "CDATA", "0");

    // Make sure we put the encodingStyle on each multiref element we
    // output.
    String encodingStyle;
    if (msgContext != null) {
        encodingStyle = msgContext.getEncodingStyle();
    } else {
        encodingStyle = soapConstants.getEncodingURI();
    }
    String encStyle = getPrefixForURI(soapConstants.getEnvelopeURI()) + ':' + Constants.ATTR_ENCODING_STYLE;
    attrs.addAttribute(soapConstants.getEnvelopeURI(), Constants.ATTR_ENCODING_STYLE, encStyle, "CDATA",
            encodingStyle);

    // Make a copy of the keySet because it could be updated
    // during processing
    HashSet keys = new HashSet();
    keys.addAll(multiRefValues.keySet());
    Iterator i = keys.iterator();
    while (i.hasNext()) {
        while (i.hasNext()) {
            AttributesImpl attrs2 = new AttributesImpl(attrs);
            Object val = i.next();
            MultiRefItem mri = (MultiRefItem) multiRefValues.get(val);
            attrs2.setAttribute(0, "", Constants.ATTR_ID, "id", "CDATA", mri.id);

            forceSer = mri.value;

            // Now serialize the value.
            // The sendType parameter is defaulted for interop purposes.
            // Some of the remote services do not know how to
            // ascertain the type in these circumstances (though Axis does).
            serialize(multirefQName, attrs2, mri.value, mri.xmlType, null, this.sendNull, Boolean.TRUE); // mri.sendType
        }

        // Done processing the iterated values.  During the serialization
        // of the values, we may have run into new nested values.  These
        // were placed in the secondLevelObjects map, which we will now
        // process by changing the iterator to locate these values.
        if (secondLevelObjects != null) {
            i = secondLevelObjects.iterator();
            secondLevelObjects = null;
        }
    }

    // Reset maps and flags
    forceSer = null;
    outputMultiRefsFlag = false;
    multiRefValues = null;
    multiRefIndex = -1;
    secondLevelObjects = null;
}

From source file:org.apache.axis.encoding.SerializationContext.java

/**
 * Output a DOM representation to a SerializationContext
 * @param el is a DOM Element/*  www .j ava2s  .  c o m*/
 */
public void writeDOMElement(Element el) throws IOException {
    if (startOfDocument && sendXMLDecl) {
        writeXMLDeclaration();
    }

    // If el is a Text element, write the text and exit
    if (el instanceof org.apache.axis.message.Text) {
        writeSafeString(((Text) el).getData());
        return;
    }

    AttributesImpl attributes = null;
    NamedNodeMap attrMap = el.getAttributes();

    if (attrMap.getLength() > 0) {
        attributes = new AttributesImpl();
        for (int i = 0; i < attrMap.getLength(); i++) {
            Attr attr = (Attr) attrMap.item(i);
            String tmp = attr.getNamespaceURI();
            if (tmp != null && tmp.equals(Constants.NS_URI_XMLNS)) {
                String prefix = attr.getLocalName();
                if (prefix != null) {
                    if (prefix.equals("xmlns"))
                        prefix = "";
                    String nsURI = attr.getValue();
                    registerPrefixForURI(prefix, nsURI);
                }
                continue;
            }

            attributes.addAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getName(), "CDATA",
                    attr.getValue());
        }
    }

    String namespaceURI = el.getNamespaceURI();
    String localPart = el.getLocalName();
    if (namespaceURI == null || namespaceURI.length() == 0)
        localPart = el.getNodeName();
    QName qName = new QName(namespaceURI, localPart);

    startElement(qName, attributes);

    NodeList children = el.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            writeDOMElement((Element) child);
        } else if (child instanceof CDATASection) {
            writeString("<![CDATA[");
            writeString(((Text) child).getData());
            writeString("]]>");
        } else if (child instanceof Comment) {
            writeString("<!--");
            writeString(((CharacterData) child).getData());
            writeString("-->");
        } else if (child instanceof Text) {
            writeSafeString(((Text) child).getData());
        }
    }

    endElement();
}

From source file:org.apache.axis.encoding.SerializationContext.java

/**
 * Obtains the type attribute that should be serialized and returns the new list of Attributes
 * @param attributes of the qname//from   w  w  w  .j a  v  a  2  s. c  o m
 * @param type is the qname of the type
 * @return new list of Attributes
 */
public Attributes setTypeAttribute(Attributes attributes, QName type) {
    SchemaVersion schema = SchemaVersion.SCHEMA_2001;
    if (msgContext != null) {
        schema = msgContext.getSchemaVersion();
    }

    if (type == null || type.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) >= 0
            || ((attributes != null) && (attributes.getIndex(schema.getXsiURI(), "type") != -1)))
        return attributes;

    AttributesImpl attrs = new AttributesImpl();
    if (attributes != null && 0 < attributes.getLength())
        attrs.setAttributes(attributes);

    String prefix = getPrefixForURI(schema.getXsiURI(), "xsi");

    attrs.addAttribute(schema.getXsiURI(), "type", prefix + ":type", "CDATA", attributeQName2String(type));
    return attrs;
}

From source file:org.apache.axis.encoding.SerializationContextImpl.java

/**
 * Serialize the indicated value as an element with the name
 * indicated by elemQName./*from www.jav a2s.c  om*/
 * The attributes are additional attribute to be serialized on the element.
 * The value is the object being serialized.  (It may be serialized
 * directly or serialized as an mult-ref'd item)
 * The value is an Object, which may be a wrapped primitive.
 * The xmlType (if specified) is the QName of the type that is used to set
 * xsi:type.
 * The sendNull flag indicates whether null values should be sent over the
 * wire (default is to send such values with xsi:nil="true").
 * The sendType flag indicates whether the xsi:type flag should be sent
 * (default is true).
 * @param elemQName is the QName of the element
 * @param attributes are additional attributes
 * @param value is the object to serialize
 * @param xmlType is the qname of the type or null.
 * @param sendNull determines whether to send null values.
 * @param sendType determines whether to set xsi:type attribute.
 */
public void serialize(QName elemQName,
                      Attributes attributes,
                      Object value,
                      QName xmlType,
                      boolean sendNull,
                      Boolean sendType)
    throws IOException
{
    boolean shouldSendType = (sendType == null) ? shouldSendXSIType() :
        sendType.booleanValue();

    if (value == null) {
        // If the value is null, the element is
        // passed with xsi:nil="true" to indicate that no object is present.
        if (sendNull) {
            AttributesImpl attrs = new AttributesImpl();
            if (attributes != null && 0 < attributes.getLength())
                attrs.setAttributes(attributes);
            if (shouldSendType)
                attrs = (AttributesImpl) setTypeAttribute(attrs, xmlType);
            String nil = schemaVersion.getNilQName().getLocalPart();
            attrs.addAttribute(schemaVersion.getXsiURI(), nil, "xsi:" + nil,
                               "CDATA", "true");
            startElement(elemQName, attrs);
            endElement();
        }
        return;
    }

    Message msg= getCurrentMessage();
    if(null != msg){
        //Get attachments. returns null if no attachment support.
        Attachments attachments= getCurrentMessage().getAttachmentsImpl();

        if( null != attachments && attachments.isAttachment(value)){
            //Attachment support and this is an object that should be treated as an attachment.

            //Allow an the attachment to do its own serialization.
            serializeActual(elemQName, attributes, value,
                            xmlType, sendType);

            //No need to add to mulitRefs. Attachment data stream handled by
            // the message;
            return;
        }
    }

    // If multi-reference is enabled and this object value is not a primitive
    // and we are not forcing serialization of the object, then generate
    // an element href (and store the object for subsequent outputMultiRef
    // processing).

    // NOTE : you'll notice that everywhere we register objects in the
    // multiRefValues and secondLevelObjects collections, we key them
    // using getIdentityKey(value) instead of the Object reference itself.
    // THIS IS IMPORTANT, and please make sure you understand what's
    // going on if you change any of this code.  It's this way to make
    // sure that individual Objects are serialized separately even if the
    // hashCode() and equals() methods have been overloaded to make two
    // Objects appear equal.

    if (doMultiRefs && (msgContext == null || msgContext.isEncoded()) &&
            (value != forceSer) && !isPrimitive(value)) {
        if (multiRefIndex == -1)
            multiRefValues = new HashMap();

        String id;

        // Look for a multi-ref descriptor for this Object.
        MultiRefItem mri = (MultiRefItem)multiRefValues.get(
                                                    getIdentityKey(value));
        if (mri == null) {
            // Didn't find one, so create one, give it a new ID, and store
            // it for next time.
            multiRefIndex++;
            id = "id" + multiRefIndex;
            mri = new MultiRefItem (id, xmlType, sendType, value);
            multiRefValues.put(getIdentityKey(value), mri);

            /**
             * If we're SOAP 1.2, we can "inline" the serializations,
             * so put it out now, with it's ID.
             */
            if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
                AttributesImpl attrs = new AttributesImpl();
                if (attributes != null && 0 < attributes.getLength())
                    attrs.setAttributes(attributes);
                attrs.addAttribute("", Constants.ATTR_ID, "id", "CDATA",
                                   id);
                serializeActual(elemQName, attrs, value, xmlType, sendType);
                return;
            }


            /** If we're in the middle of writing out
             * the multi-refs, we've already cloned the list of objects
             * and so even though we add a new one to multiRefValues,
             * it won't get serialized this time around.
             *
             * To deal with this, we maintain a list of "second level"
             * Objects - ones that need serializing as a result of
             * serializing the first level.  When outputMultiRefs() is
             * nearly finished, it checks to see if secondLevelObjects
             * is empty, and if not, it goes back and loops over those
             * Objects.  This can happen N times depending on how deep
             * the Object graph goes.
             */
            if (outputMultiRefsFlag) {
                if (secondLevelObjects == null)
                    secondLevelObjects = new HashSet();
                secondLevelObjects.add(getIdentityKey(value));
            }
        } else {
            // Found one, remember it's ID
            id = mri.id;
        }

        // Serialize an HREF to our object
        AttributesImpl attrs = new AttributesImpl();
        if (attributes != null && 0 < attributes.getLength())
            attrs.setAttributes(attributes);
        attrs.addAttribute("", soapConstants.getAttrHref(), soapConstants.getAttrHref(),
                           "CDATA", '#' + id);

        startElement(elemQName, attrs);
        endElement();
        return;
    }

    // The forceSer variable is set by outputMultiRefs to force
    // serialization of this object via the serialize(...) call
    // below.  However, if the forced object contains a self-reference, we
    // get into an infinite loop..which is why it is set back to null
    // before the actual serialization.
    if (value == forceSer)
        forceSer = null;

    // Actually serialize the value.  (i.e. not an href like above)
    serializeActual(elemQName, attributes, value, xmlType, sendType);
}

From source file:org.apache.axis.encoding.SerializationContextImpl.java

/**
 * The serialize method uses hrefs to reference all non-primitive
 * values.  These values are stored and serialized by calling
 * outputMultiRefs after the serialize method completes.
 *//*from w  w w .j  a  v a  2 s.c om*/
public void outputMultiRefs() throws IOException
{
    if (!doMultiRefs || (multiRefValues == null) ||
            soapConstants == SOAPConstants.SOAP12_CONSTANTS)
        return;
    outputMultiRefsFlag = true;
    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute("","","","","");

    String encodingURI = soapConstants.getEncodingURI();
    // explicitly state that this attribute is not a root
    String prefix = getPrefixForURI(encodingURI);
    String root = prefix + ":root";
    attrs.addAttribute(encodingURI, Constants.ATTR_ROOT, root,
                       "CDATA", "0");

    // Make sure we put the encodingStyle on each multiref element we
    // output.
    String encodingStyle;
    if (msgContext != null) {
        encodingStyle = msgContext.getEncodingStyle();
    } else {
        encodingStyle = soapConstants.getEncodingURI();
    }
    String encStyle = getPrefixForURI(soapConstants.getEnvelopeURI()) +
                                      ':' + Constants.ATTR_ENCODING_STYLE;
    attrs.addAttribute(soapConstants.getEnvelopeURI(),
                       Constants.ATTR_ENCODING_STYLE,
                       encStyle,
                       "CDATA",
                       encodingStyle);

    // Make a copy of the keySet because it could be updated
    // during processing
    HashSet keys = new HashSet();
    keys.addAll(multiRefValues.keySet());
    Iterator i = keys.iterator();
    while (i.hasNext()) {
        while (i.hasNext()) {
            Object val = i.next();
            MultiRefItem mri = (MultiRefItem) multiRefValues.get(val);
            attrs.setAttribute(0, "", Constants.ATTR_ID, "id", "CDATA",
                               mri.id);

            forceSer = mri.value;

            // Now serialize the value.
            // The sendType parameter is defaulted for interop purposes.
            // Some of the remote services do not know how to
            // ascertain the type in these circumstances (though Axis does).
            serialize(multirefQName, attrs, mri.value,
                      mri.xmlType,
                      true,
                      Boolean.TRUE);   // mri.sendType
        }

        // Done processing the iterated values.  During the serialization
        // of the values, we may have run into new nested values.  These
        // were placed in the secondLevelObjects map, which we will now
        // process by changing the iterator to locate these values.
        if (secondLevelObjects != null) {
            i = secondLevelObjects.iterator();
            secondLevelObjects = null;
        }
    }

    // Reset maps and flags
    forceSer = null;
    outputMultiRefsFlag = false;
    multiRefValues = null;
    multiRefIndex = -1;
    secondLevelObjects = null;
}

From source file:org.apache.axis.encoding.SerializationContextImpl.java

/**
 * Output a DOM representation to a SerializationContext
 * @param el is a DOM Element//from  w  w  w  .  ja  v  a 2s  .  com
 */
public void writeDOMElement(Element el)
    throws IOException
{
    AttributesImpl attributes = null;
    NamedNodeMap attrMap = el.getAttributes();

    if (attrMap.getLength() > 0) {
        attributes = new AttributesImpl();
        for (int i = 0; i < attrMap.getLength(); i++) {
            Attr attr = (Attr)attrMap.item(i);
            String tmp = attr.getNamespaceURI();
            if ( tmp != null && tmp.equals(Constants.NS_URI_XMLNS) ) {
                String prefix = attr.getLocalName();
                if (prefix != null) {
                    if (prefix.equals("xmlns"))
                        prefix = "";
                    String nsURI = attr.getValue();
                    registerPrefixForURI(prefix, nsURI);
                }
                continue;
            }

            attributes.addAttribute(attr.getNamespaceURI(),
                                    attr.getLocalName(),
                                    attr.getName(),
                                    "CDATA", attr.getValue());
        }
    }

    String namespaceURI = el.getNamespaceURI();
    String localPart = el.getLocalName();
    if(namespaceURI == null || namespaceURI.length()==0)
        localPart = el.getNodeName();
    QName qName = new QName(namespaceURI, localPart);

    startElement(qName, attributes);

    NodeList children = el.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            writeDOMElement((Element)child);
        } else if (child instanceof CDATASection) {
            writeString("<![CDATA[");
            writeString(((Text)child).getData());
            writeString("]]>");
        } else if (child instanceof Comment) {
            writeString("<!--");
            writeString(((CharacterData)child).getData());
            writeString("-->");
        } else if (child instanceof Text) {
            writeSafeString(((Text)child).getData());
        }
    }

    endElement();
}

From source file:org.apache.axis.encoding.SerializationContextImpl.java

/**
 * Obtains the type attribute that should be serialized and returns the new list of Attributes
 * @param attributes of the qname//  w  w  w . j  ava  2  s . c om
 * @param type is the qname of the type
 * @return new list of Attributes
 */
public Attributes setTypeAttribute(Attributes attributes, QName type)
{
    if (type == null ||
         type.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) >= 0 ||
        ((attributes != null) &&
         (attributes.getIndex(Constants.URI_DEFAULT_SCHEMA_XSI,
                            "type") != -1)))
        return attributes;

    AttributesImpl attrs = new AttributesImpl();
    if (attributes != null && 0 < attributes.getLength() )
        attrs.setAttributes(attributes);

    String prefix = getPrefixForURI(Constants.URI_DEFAULT_SCHEMA_XSI,
                                       "xsi");

    attrs.addAttribute(Constants.URI_DEFAULT_SCHEMA_XSI,
                       "type",
                       prefix + ":type",
                       "CDATA", attributeQName2String(type));
    return attrs;
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * Obtain an Attributes collection consisting of all attributes
 * for this MessageElement, including namespace declarations.
 *
 * @return Attributes collection//  w ww. j a  v a  2 s. c o  m
 */
public Attributes getCompleteAttributes() {
    if (namespaces == null) {
        return attributes;
    }

    AttributesImpl attrs = null;
    if (attributes == NullAttributes.singleton) {
        attrs = new AttributesImpl();
    } else {
        attrs = new AttributesImpl(attributes);
    }

    for (Iterator iterator = namespaces.iterator(); iterator.hasNext();) {
        Mapping mapping = (Mapping) iterator.next();
        String prefix = mapping.getPrefix();
        String nsURI = mapping.getNamespaceURI();
        attrs.addAttribute(Constants.NS_URI_XMLNS, prefix, "xmlns:" + prefix, nsURI, "CDATA");
    }
    return attrs;
}