⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messageelement.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.axis.message;import org.apache.axis.AxisFault;import org.apache.axis.Constants;import org.apache.axis.MessageContext;import org.apache.axis.components.logger.LogFactory;import org.apache.axis.encoding.DeserializationContext;import org.apache.axis.encoding.Deserializer;import org.apache.axis.encoding.SerializationContext;import org.apache.axis.encoding.TextSerializationContext;import org.apache.axis.constants.Style;import org.apache.axis.soap.SOAPConstants;import org.apache.axis.utils.Mapping;import org.apache.axis.utils.Messages;import org.apache.axis.utils.XMLUtils;import org.apache.commons.logging.Log;import org.w3c.dom.Attr;import org.w3c.dom.CDATASection;import org.w3c.dom.CharacterData;import org.w3c.dom.Comment;import org.w3c.dom.DOMException;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.w3c.dom.Text;import org.w3c.dom.NamedNodeMap;import org.xml.sax.Attributes;import org.xml.sax.ContentHandler;import org.xml.sax.InputSource;import org.xml.sax.SAXException;import org.xml.sax.helpers.AttributesImpl;import javax.xml.namespace.QName;import javax.xml.rpc.encoding.TypeMapping;import javax.xml.soap.Name;import javax.xml.soap.SOAPElement;import javax.xml.soap.SOAPException;import javax.xml.parsers.ParserConfigurationException;import java.io.Reader;import java.io.Serializable;import java.io.StringReader;import java.io.StringWriter;import java.util.ArrayList;import java.util.Enumeration;import java.util.Iterator;import java.util.List;import java.util.Vector;/** * MessageElement is the base type of nodes of the SOAP message parse tree. * * Note: it was made Serializable to help users of Apache SOAP who had * exploited the serializability of the DOM tree to migrate to Axis. * @todo implement the NodeList methods properly, with tests.  */public class MessageElement extends NodeImpl implements SOAPElement,        Serializable,        org.w3c.dom.NodeList,  // ADD Nodelist Interfaces for SAAJ 1.2        Cloneable{    protected static Log log =        LogFactory.getLog(MessageElement.class.getName());    private static final Mapping enc11Mapping =            new Mapping(Constants.URI_SOAP11_ENC,                        "SOAP-ENC");    private static final Mapping enc12Mapping =            new Mapping(Constants.URI_SOAP12_ENC,                        "SOAP-ENC");    protected String    id;    protected String    href;    protected boolean   _isRoot = true;    protected SOAPEnvelope message = null;    protected transient DeserializationContext context;    protected transient QName typeQName = null;    protected Vector qNameAttrs = null;    // Some message representations - as recorded SAX events...    protected transient SAX2EventRecorder recorder = null;    protected int startEventIndex = 0;    protected int startContentsIndex = 0;    protected int endEventIndex = -1;    public ArrayList namespaces = null;    /** Our encoding style, if any */    protected String encodingStyle = null;    /** Object value, possibly supplied by subclass */    private Object objectValue = null;    /** No-arg constructor for building messages?     */    public MessageElement()    {    }    /**     * constructor     * @param namespace namespace of element     * @param localPart local name     */    public MessageElement(String namespace, String localPart)    {        namespaceURI = namespace;        name = localPart;    }    /**     * constructor. Automatically adds a namespace-prefix mapping to the mapping table     * @param localPart local name     * @param prefix prefix     * @param namespace namespace     */    public MessageElement(String localPart, String prefix, String namespace)    {        this.namespaceURI = namespace;        this.name = localPart;        this.prefix = prefix;        addMapping(new Mapping(namespace, prefix));    }    /**     * construct using a {@link javax.xml.soap.Name} implementation,     * @see #MessageElement(String, String, String)     * @param eltName     */    public MessageElement(Name eltName)    {        this(eltName.getLocalName(),eltName.getPrefix(), eltName.getURI());    }    /**     * constructor binding the internal object value field to the     * value parameter     * @param namespace namespace of the element     * @param localPart local name     * @param value value of the node     */    public MessageElement(String namespace, String localPart, Object value)    {        this(namespace, localPart);        objectValue = value;    }    /**     * constructor declaring the qualified name of the node     * @param name naming information     */    public MessageElement(QName name)    {        this(name.getNamespaceURI(), name.getLocalPart());    }    /**     * constructor declaring the qualified name of the node     * and its value     * @param name naming information     * @param value value of the node     */    public MessageElement(QName name, Object value)    {        this(name.getNamespaceURI(), name.getLocalPart());        objectValue = value;    }    /**     * create a node through a deep copy of the passed in element.     * @param elem name to copy from     */    public MessageElement(Element elem)    {        namespaceURI = elem.getNamespaceURI();        name = elem.getLocalName();        copyNode(elem);    }    /**     * construct a text element.     * @param text text data. This is <i>not</i> copied; it is referred to in the MessageElement.     */    public MessageElement(CharacterData text)    {        textRep = text;        namespaceURI = text.getNamespaceURI();        name = text.getLocalName();    }    /**     * Advanced constructor used for deserialization.     * <ol>     * <li>The context provides the mappings and Sax event recorder     * <li>The soap messaging style is determined from the current message context, defaulting     * to SOAP1.1 if there is no current context.     * <li>if there is an id attribute (any namespace), then the ID is registered     * with {@link DeserializationContext#registerElementByID(String, MessageElement)} ;a  new recorder is     * created if needed.     * <li>If there is an attribute "root" in the default SOAP namespace, then it is examined     * to see if it marks the element as root (value=="1" or not)     * <li>If there is an arrayType attribute then we assume we are an array and set our     * {@link #typeQName} field appropriately.     * <li>The {@link #href} field is set if there is a relevant href value     * </ol>     *     * @param namespace namespace namespace of element     * @param localPart local name local name of element     * @param prefix prefix prefix of element     * @param attributes attributes to save as our attributes     * @param context deserialization context for this message element     * @throws AxisFault if the encoding style is not recognized/supported     */    public MessageElement(String namespace, String localPart, String prefix,                   Attributes attributes, DeserializationContext context)        throws AxisFault    {        if (log.isDebugEnabled()) {            log.debug(Messages.getMessage("newElem00", super.toString(),                                            "{" + prefix + "}" + localPart));            for (int i = 0; attributes != null && i < attributes.getLength(); i++) {                log.debug("  " + attributes.getQName(i) + " = '" + attributes.getValue(i) + "'");            }        }        this.namespaceURI = namespace;        this.name = localPart;        this.prefix = prefix;        this.context = context;        this.startEventIndex = context.getStartOfMappingsPos();        setNSMappings(context.getCurrentNSMappings());        this.recorder = context.getRecorder();        if (attributes != null && attributes.getLength() > 0) {            this.attributes = attributes;            this.typeQName = context.getTypeFromAttributes(namespace,                                                      localPart,                                                      attributes);            String rootVal = attributes.getValue(Constants.URI_DEFAULT_SOAP_ENC, Constants.ATTR_ROOT);            if (rootVal != null) {                _isRoot = "1".equals(rootVal);            }            id = attributes.getValue(Constants.ATTR_ID);            // Register this ID with the context.....            if (id != null) {                context.registerElementByID(id, this);                if (recorder == null) {                    recorder = new SAX2EventRecorder();                    context.setRecorder(recorder);                }            }            // Set the encoding style to the attribute value.  If null,            // we just automatically use our parent's (see getEncodingStyle)            MessageContext mc = context.getMessageContext();            SOAPConstants sc = (mc != null) ?                                            mc.getSOAPConstants() :                                            SOAPConstants.SOAP11_CONSTANTS;            href = attributes.getValue(sc.getAttrHref());            // If there's an arrayType attribute, we can pretty well guess that we're an Array???            if (attributes.getValue(Constants.URI_DEFAULT_SOAP_ENC, Constants.ATTR_ARRAY_TYPE) != null) {                typeQName = Constants.SOAP_ARRAY;            }            encodingStyle =                    attributes.getValue(sc.getEncodingURI(),                                        Constants.ATTR_ENCODING_STYLE);            // if no-encoding style was defined, we don't define as well            if (Constants.URI_SOAP12_NOENC.equals(encodingStyle))                encodingStyle = null;            // If we have an encoding style, and are not a MESSAGE style            // operation (in other words - we're going to do some data            // binding), AND we're SOAP 1.2, check the encoding style against            // the ones we've got type mappings registered for.  If it isn't            // registered, throw a DataEncodingUnknown fault as per the            // SOAP 1.2 spec.            if (encodingStyle != null &&                    sc.equals(SOAPConstants.SOAP12_CONSTANTS) &&                    (mc.getOperationStyle() != Style.MESSAGE)) {                TypeMapping tm = mc.getTypeMappingRegistry().                        getTypeMapping(encodingStyle);                if (tm == null ||                        (tm.equals(mc.getTypeMappingRegistry().                                                getDefaultTypeMapping()))) {                    AxisFault badEncodingFault = new AxisFault(                            Constants.FAULT_SOAP12_DATAENCODINGUNKNOWN,                            "bad encoding style", null, null);                    throw badEncodingFault;                }            }        }    }    /**     * Retrieve the DeserializationContext associated with this MessageElement     *     * @return The DeserializationContext associated with this MessageElement     */    public DeserializationContext getDeserializationContext()    {        return context;    }    /** !!! TODO : Make sure this handles multiple targets     */    protected Deserializer fixupDeserializer;    public void setFixupDeserializer(Deserializer dser)    {        // !!! Merge targets here if already set?        fixupDeserializer = dser;    }    public Deserializer getFixupDeserializer()    {        return fixupDeserializer;    }    /**     * record the end index of the SAX recording.     * @param endIndex end value     */    public void setEndIndex(int endIndex)    {        endEventIndex = endIndex;        //context.setRecorder(null);    }    /**     * get the is-root flag     * @return true if the element is considered a document root.     */    public boolean isRoot() { return _isRoot; }    /**     * get a saved ID     * @return ID or null for no ID     */    public String getID() { return id; }    /**     * get a saved href     * @return href or null     */    public String getHref() { return href; }    /**     * get the attributes     * @return attributes. If this equals {@link NullAttributes.singleton} it is null     *     */    public Attributes getAttributesEx() { return attributes; }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -