📄 serializationcontext.java
字号:
// 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; } public void writeXMLDeclaration() throws IOException { writer.write("<?xml version=\"1.0\" encoding=\""); writer.write(encoding); writer.write("\"?>"); startOfDocument = false; } /** * Writes (using the Writer) the start tag for element QName along with the * indicated attributes and namespace mappings. * @param qName is the name of the element * @param attributes are the attributes to write */ public void startElement(QName qName, Attributes attributes) throws IOException { java.util.ArrayList vecQNames = null; if (debugEnabled) { log.debug(Messages.getMessage("startElem00", "[" + qName.getNamespaceURI() + "]:" + qName.getLocalPart())); } if (startOfDocument && sendXMLDecl) { writeXMLDeclaration(); } if (writingStartTag) { writer.write('>'); if (pretty) writer.write('\n'); indent++; } if (pretty) for (int i=0; i<indent; i++) writer.write(' '); String elementQName = qName2String(qName, true); writer.write('<'); writer.write(elementQName); if (writeXMLType != null) { attributes = setTypeAttribute(attributes, writeXMLType); writeXMLType = null; } if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { String qname = attributes.getQName(i); writer.write(' '); String prefix = ""; String uri = attributes.getURI(i); if (uri != null && uri.length() > 0) { if (qname.length() == 0) { // If qname isn't set, generate one prefix = getPrefixForURI(uri); } else { // If it is, make sure the prefix looks reasonable. int idx = qname.indexOf(':'); if (idx > -1) { prefix = qname.substring(0, idx); prefix = getPrefixForURI(uri, prefix, true); } } if (prefix.length() > 0) { qname = prefix + ':' + attributes.getLocalName(i); } else { qname = attributes.getLocalName(i); } } else { qname = attributes.getQName(i); if(qname.length() == 0) qname = attributes.getLocalName(i); } if (qname.startsWith("xmlns")) { if (vecQNames == null) vecQNames = new ArrayList(); vecQNames.add(qname); } writer.write(qname); writer.write("=\""); getEncoder().writeEncoded(writer, attributes.getValue(i)); writer.write('"'); } } if (noNamespaceMappings) { nsStack.push(); } else { for (Mapping map=nsStack.topOfFrame(); map!=null; map=nsStack.next()) { if (!(map.getNamespaceURI().equals(Constants.NS_URI_XMLNS) && map.getPrefix().equals("xmlns")) && !(map.getNamespaceURI().equals(Constants.NS_URI_XML) && map.getPrefix().equals("xml"))) { StringBuffer sb = new StringBuffer("xmlns"); if (map.getPrefix().length() > 0) { sb.append(':'); sb.append(map.getPrefix()); } if ((vecQNames==null) || (vecQNames.indexOf(sb.toString())==-1)) { writer.write(' '); sb.append("=\""); sb.append(map.getNamespaceURI()); sb.append('"'); writer.write(sb.toString()); } } } noNamespaceMappings = true; } writingStartTag = true; elementStack.push(elementQName); onlyXML=true; } /** * Writes the end element tag for the open element. **/ public void endElement() throws IOException { String elementQName = (String)elementStack.pop(); if (debugEnabled) { log.debug(Messages.getMessage("endElem00", "" + elementQName)); } nsStack.pop(); if (writingStartTag) { writer.write("/>"); if (pretty) writer.write('\n'); writingStartTag = false; return; } if (onlyXML) { indent--; if (pretty) for (int i=0; i<indent; i++) writer.write(' '); } writer.write("</"); writer.write(elementQName); writer.write('>'); if (pretty) if (indent>0) writer.write('\n'); onlyXML=true; } /** * Convenience operation to write out (to Writer) the characters * in p1 starting at index p2 for length p3. * @param p1 character array to write * @param p2 starting index in array * @param p3 length to write */ public void writeChars(char [] p1, int p2, int p3) throws IOException { if (startOfDocument && sendXMLDecl) { writeXMLDeclaration(); } if (writingStartTag) { writer.write('>'); writingStartTag = false; } writeSafeString(String.valueOf(p1,p2,p3)); onlyXML=false; } /** * Convenience operation to write out (to Writer) the String * @param string is the String to write. */ public void writeString(String string) throws IOException { if (startOfDocument && sendXMLDecl) { writeXMLDeclaration(); } if (writingStartTag) { writer.write('>'); writingStartTag = false; } writer.write(string); onlyXML=false; } /** * Convenience operation to write out (to Writer) the String * properly encoded with xml entities (like &) * @param string is the String to write. */ public void writeSafeString(String string) throws IOException { if (startOfDocument && sendXMLDecl) { writeXMLDeclaration(); } if (writingStartTag) { writer.write('>'); writingStartTag = false; } getEncoder().writeEncoded(writer, string); onlyXML=false; } /** * Output a DOM representation to a SerializationContext * @param el is a DOM Element */ 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()); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -