FileDocCategorySizeDatePackage
AttrNSImpl.javaAPI DocJava SE 5 API12991Fri Aug 26 14:55:42 BST 2005com.sun.org.apache.xerces.internal.dom

AttrNSImpl

public class AttrNSImpl extends AttrImpl
AttrNSImpl inherits from AttrImpl and adds namespace support.

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.

author
Arnaud Le Hors, IBM
author
Andy Clark, IBM
author
Ralf Pfeiffer, IBM
version
$Id: AttrNSImpl.java,v 1.43 2004/02/16 05:34:38 mrglavas Exp $

Fields Summary
static final long
serialVersionUID
Serialization version.
static final String
xmlnsURI
static final String
xmlURI
protected String
namespaceURI
DOM2: Namespace URI.
protected String
localName
DOM2: localName.
Constructors Summary
public AttrNSImpl()


    /*
     * Default constructor
     */
     
protected AttrNSImpl(CoreDocumentImpl ownerDocument, String namespaceURI, String qualifiedName)
DOM2: Constructor for Namespace implementation.


        super(ownerDocument, qualifiedName);
        setName(namespaceURI, qualifiedName);
    
public AttrNSImpl(CoreDocumentImpl ownerDocument, String namespaceURI, String qualifiedName, String localName)

        super(ownerDocument, qualifiedName);
        
        this.localName = localName;
        this.namespaceURI = namespaceURI;
    
protected AttrNSImpl(CoreDocumentImpl ownerDocument, String value)

        super(ownerDocument, value);
    
Methods Summary
public java.lang.StringgetLocalName()
Introduced in DOM Level 2.

Returns the local part of the qualified name of this node.

since
WD-DOM-Level-2-19990923

        if (needsSyncData()) {
            synchronizeData();
        }
        return localName;
    
public java.lang.StringgetNamespaceURI()
Introduced in DOM Level 2.

The namespace URI of this node, or null if it is unspecified.

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.

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

        if (needsSyncData()) {
            synchronizeData();
        }
        // REVIST: This code could/should be done at a lower-level, such that
        // the namespaceURI is set properly upon creation. However, there still
        // seems to be some DOM spec interpretation grey-area.
        return namespaceURI;
    
public java.lang.StringgetPrefix()
Introduced in DOM Level 2.

The namespace prefix of this node, or null if it is unspecified.

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

        if (needsSyncData()) {
            synchronizeData();
        }
        int index = name.indexOf(':");
        return index < 0 ? null : name.substring(0, index); 
    
public java.lang.StringgetTypeNamespace()

see
org.w3c.dom.TypeInfo#getTypeNamespace()

        if (type !=null) {
            if (type instanceof XSSimpleTypeDecl){
                return ((XSSimpleTypeDecl)type).getNamespace();
            }
            return DTD_URI;
        }
        return null;
    
public booleanisDerivedFrom(java.lang.String typeNamespaceArg, java.lang.String typeNameArg, int derivationMethod)
DOM Level 3 Experimental

see
org.w3c.dom.TypeInfo#isDerivedFrom()

        
        //REVISIT: XSSimpleTypeDecl.derivedFrom and 
        //derivationMethod constants in DOM vs Xerces
        if (type !=null){
            if (type instanceof XSSimpleTypeDecl){
                return ((XSSimpleTypeDecl)type).derivedFrom(typeNamespaceArg,typeNameArg,(short)derivationMethod);
            }
        }                                	
        return false;
    
voidrename(java.lang.String namespaceURI, java.lang.String qualifiedName)

        if (needsSyncData()) {
            synchronizeData();
        }
	this.name = qualifiedName;
        setName(namespaceURI, qualifiedName);
    
private voidsetName(java.lang.String namespaceURI, java.lang.String qname)

        
        String prefix;
		// DOM Level 3: namespace URI is never empty string.
        this.namespaceURI = namespaceURI;
        if (namespaceURI !=null) {
  	        this.namespaceURI = (namespaceURI.length() == 0)? null
                                 : namespaceURI;

		}
		int colon1 = qname.indexOf(':");
		int colon2 = qname.lastIndexOf(':");
		ownerDocument().checkNamespaceWF(qname, colon1, colon2);
		if (colon1 < 0) {
			// there is no prefix
			localName = qname;
			ownerDocument().checkQName(null, localName);
			if (ownerDocument().errorChecking) {
				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);
				}
			}
		}
		else {
			prefix = qname.substring(0, colon1);
			localName = qname.substring(colon2+1);
			ownerDocument().checkQName(prefix, localName);
            ownerDocument().checkDOMNSErr(prefix, namespaceURI);
        }
    
public voidsetPrefix(java.lang.String prefix)
Introduced in DOM Level 2.

Note that setting this attribute changes the nodeName attribute, which holds the qualified name, as well as the tagName and name attributes of the Element and Attr interfaces, when applicable.

param
prefix The namespace prefix of this node, or null(empty string) if it is unspecified.
exception
INVALID_CHARACTER_ERR Raised if the specified prefix contains an invalid character.
exception
DOMException
since
WD-DOM-Level-2-19990923

        if (needsSyncData()) {
            synchronizeData();
        }
        if (ownerDocument().errorChecking) {
            if (isReadOnly()) {
                String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
                throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
            }
            if (prefix != null && prefix.length() != 0) {

                if (!CoreDocumentImpl.isXMLName(prefix,ownerDocument().isXML11Version())) {
                    String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
                    throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
                }
                if (namespaceURI == null || prefix.indexOf(':") >=0) {
                    String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
                    throw new DOMException(DOMException.NAMESPACE_ERR, msg);
               
                }
               if (prefix.equals("xmlns")) {
                    if (!namespaceURI.equals(xmlnsURI)){
                        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
                        throw new DOMException(DOMException.NAMESPACE_ERR, msg);
                    }
                } else if (prefix.equals("xml")) {
                    if (!namespaceURI.equals(xmlURI)) {
                        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
                        throw new DOMException(DOMException.NAMESPACE_ERR, msg);
                    }
                }else if (name.equals("xmlns")) {
                    String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
                    throw new DOMException(DOMException.NAMESPACE_ERR, msg);
                }
            } 
        }

        // update node name with new qualifiedName
        if (prefix !=null && prefix.length() != 0) {
            name = prefix + ":" + localName;
        }
        else {
            name = localName;
        }
    
public voidsetValues(com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl ownerDocument, java.lang.String namespaceURI, java.lang.String qualifiedName, java.lang.String localName)
NON-DOM: resets this node and sets specified values for the node

param
ownerDocument
param
namespaceURI
param
qualifiedName
param
localName


        super.textNode = null;
        super.flags = 0;
        isSpecified(true);
        hasStringValue(true);
        super.setOwnerDocument(ownerDocument);
        this.localName = localName;
        this.namespaceURI = namespaceURI;
        super.name = qualifiedName;
        super.value = null;