elementnsimpl.java

来自「JAVA 所有包」· Java 代码 · 共 486 行 · 第 1/2 页

JAVA
486
字号
/* * Copyright 1999-2002,2004,2005 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 com.sun.org.apache.xerces.internal.dom;import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition;import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;import com.sun.org.apache.xerces.internal.impl.dv.xs.XSSimpleTypeDecl;import com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl;import com.sun.org.apache.xerces.internal.util.URI;import com.sun.org.apache.xerces.internal.xni.NamespaceContext;import org.w3c.dom.Attr;import org.w3c.dom.DOMException;/** * ElementNSImpl inherits from ElementImpl and adds namespace support. * <P> * The qualified name is the node name, and we store localName which is also * used in all queries. On the other hand we recompute the prefix when * necessary. *  * @xerces.internal *  * @author Elena litani, IBM * @author Neeraj Bajaj, Sun Microsystems * @version $Id: ElementNSImpl.java,v 1.2.6.1 2005/08/31 12:17:52 sunithareddy Exp $ */public class ElementNSImpl    extends ElementImpl {    //    // Constants    //    /** Serialization version. */    static final long serialVersionUID = -9142310625494392642L;    static final String xmlURI = "http://www.w3.org/XML/1998/namespace";    //    // Data    //    /** DOM2: Namespace URI. */    protected String namespaceURI;    /** DOM2: localName. */    protected String localName;    /** DOM3: type information */    // REVISIT: we are losing the type information in DOM during serialization    transient XSTypeDefinition type;    protected ElementNSImpl() {        super();    }    /**     * DOM2: Constructor for Namespace implementation.     */    protected ElementNSImpl(CoreDocumentImpl ownerDocument,                            String namespaceURI,                            String qualifiedName)        throws DOMException    {        super(ownerDocument, qualifiedName);        setName(namespaceURI, qualifiedName);    }	private void setName(String namespaceURI, String qname) {		String prefix;		// DOM Level 3: namespace URI is never empty string.		this.namespaceURI = namespaceURI;		if (namespaceURI != null) {            //convert the empty string to 'null'			this.namespaceURI =	(namespaceURI.length() == 0) ? null : namespaceURI;		}        int colon1, colon2 ;        //NAMESPACE_ERR:        //1. if the qualified name is 'null' it is malformed.        //2. or if the qualifiedName is null and the namespaceURI is different from null,        // We dont need to check for namespaceURI != null, if qualified name is null throw DOMException.        if(qname == null){				String msg =					DOMMessageFormatter.formatMessage(						DOMMessageFormatter.DOM_DOMAIN,						"NAMESPACE_ERR",						null);				throw new DOMException(DOMException.NAMESPACE_ERR, msg);        }        else{		    colon1 = qname.indexOf(':');		    colon2 = qname.lastIndexOf(':');        }		ownerDocument.checkNamespaceWF(qname, colon1, colon2);		if (colon1 < 0) {			// there is no prefix			localName = qname;			if (ownerDocument.errorChecking) {			    ownerDocument.checkQName(null, localName);			    if (qname.equals("xmlns")			        && (namespaceURI == null			        || !namespaceURI.equals(NamespaceContext.XMLNS_URI))			        || (namespaceURI!=null && namespaceURI.equals(NamespaceContext.XMLNS_URI)			        && !qname.equals("xmlns"))) {			        String msg =			            DOMMessageFormatter.formatMessage(			                    DOMMessageFormatter.DOM_DOMAIN,			                    "NAMESPACE_ERR",			                    null);			        throw new DOMException(DOMException.NAMESPACE_ERR, msg);			    }			}		}//there is a prefix		else {		    prefix = qname.substring(0, colon1);		    localName = qname.substring(colon2 + 1);		    		    //NAMESPACE_ERR:		    //1. if the qualifiedName has a prefix and the namespaceURI is null,		    		    //2. or if the qualifiedName has a prefix that is "xml" and the namespaceURI		    //is different from " http://www.w3.org/XML/1998/namespace"		    		    if (ownerDocument.errorChecking) {		        if( namespaceURI == null || ( prefix.equals("xml") && !namespaceURI.equals(NamespaceContext.XML_URI) )){		            String msg =		                DOMMessageFormatter.formatMessage(		                        DOMMessageFormatter.DOM_DOMAIN,		                        "NAMESPACE_ERR",		                        null);		            throw new DOMException(DOMException.NAMESPACE_ERR, msg);		        }		        		        ownerDocument.checkQName(prefix, localName);		        ownerDocument.checkDOMNSErr(prefix, namespaceURI);		    }		}	}    // when local name is known    protected ElementNSImpl(CoreDocumentImpl ownerDocument,                            String namespaceURI, String qualifiedName,                            String localName)        throws DOMException    {        super(ownerDocument, qualifiedName);        this.localName = localName;        this.namespaceURI = namespaceURI;    }    // for DeferredElementImpl    protected ElementNSImpl(CoreDocumentImpl ownerDocument,                            String value) {        super(ownerDocument, value);    }    // Support for DOM Level 3 renameNode method.    // Note: This only deals with part of the pb. CoreDocumentImpl    // does all the work.    void rename(String namespaceURI, String qualifiedName)    {        if (needsSyncData()) {            synchronizeData();        }		this.name = qualifiedName;        setName(namespaceURI, qualifiedName);        reconcileDefaultAttributes();    }    /**     * NON-DOM: resets this node and sets specified values for the node     *     * @param ownerDocument     * @param namespaceURI     * @param qualifiedName     * @param localName     */    protected void setValues (CoreDocumentImpl ownerDocument,                            String namespaceURI, String qualifiedName,                            String localName){        // remove children first        firstChild = null;        previousSibling = null;        nextSibling = null;        fNodeListCache = null;        // set owner document        attributes = null;        super.flags = 0;        setOwnerDocument(ownerDocument);        // synchronizeData will initialize attributes        needsSyncData(true);        super.name = qualifiedName;        this.localName = localName;        this.namespaceURI = namespaceURI;    }    //    // Node methods    //    //    //DOM2: Namespace methods.    //    /**     * Introduced in DOM Level 2. <p>     *     * The namespace URI of this node, or null if it is unspecified.<p>     *     * This is not a computed value that is the result of a namespace lookup based on     * an examination of the namespace declarations in scope. It is merely the     * namespace URI given at creation time.<p>     *     * For nodes created with a DOM Level 1 method, such as createElement     * from the Document interface, this is null.     * @since WD-DOM-Level-2-19990923     */    public String getNamespaceURI()

⌨️ 快捷键说明

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