ElementNSImplpublic class ElementNSImpl extends ElementImpl ElementNSImpl inherits from ElementImpl 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. |
Fields Summary |
---|
static final long | serialVersionUIDSerialization version. | static final String | xmlURI | protected String | namespaceURIDOM2: Namespace URI. | protected String | localNameDOM2: localName. | transient XSTypeDefinition | typeDOM3: type information |
Constructors Summary |
---|
protected ElementNSImpl()
super();
| protected ElementNSImpl(CoreDocumentImpl ownerDocument, String namespaceURI, String qualifiedName)DOM2: Constructor for Namespace implementation.
super(ownerDocument, qualifiedName);
setName(namespaceURI, qualifiedName);
| protected ElementNSImpl(CoreDocumentImpl ownerDocument, String namespaceURI, String qualifiedName, String localName)
super(ownerDocument, qualifiedName);
this.localName = localName;
this.namespaceURI = namespaceURI;
| protected ElementNSImpl(CoreDocumentImpl ownerDocument, String value)
super(ownerDocument, value);
|
Methods Summary |
---|
public java.lang.String | getBaseURI()DOM Level 3 WD - Experimental.
Retrieve baseURI
if (needsSyncData()) {
synchronizeData();
}
// Absolute base URI is computed according to XML Base (http://www.w3.org/TR/xmlbase/#granularity)
// 1. the base URI specified by an xml:base attribute on the element, if one exists
if (attributes != null) {
Attr attrNode = (Attr)attributes.getNamedItemNS("http://www.w3.org/XML/1998/namespace", "base");
if (attrNode != null) {
String uri = attrNode.getNodeValue();
if (uri.length() != 0 ) {// attribute value is always empty string
try {
uri = new URI(uri).toString();
}
catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException e) {
// This may be a relative URI.
// Start from the base URI of the parent, or if this node has no parent, the owner node.
NodeImpl parentOrOwner = (parentNode() != null) ? parentNode() : ownerNode;
// Make any parentURI into a URI object to use with the URI(URI, String) constructor.
String parentBaseURI = (parentOrOwner != null) ? parentOrOwner.getBaseURI() : null;
if (parentBaseURI != null) {
try {
uri = new URI(new URI(parentBaseURI), uri).toString();
}
catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException ex){
// This should never happen: parent should have checked the URI and returned null if invalid.
return null;
}
return uri;
}
// REVISIT: what should happen in this case?
return null;
}
return uri;
}
}
}
//2.the base URI of the element's parent element within the document or external entity,
//if one exists
String parentElementBaseURI = (this.parentNode() != null) ? this.parentNode().getBaseURI() : null ;
//base URI of parent element is not null
if(parentElementBaseURI != null){
try {
//return valid absolute base URI
return new URI(parentElementBaseURI).toString();
}
catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException e){
// REVISIT: what should happen in this case?
return null;
}
}
//3. the base URI of the document entity or external entity containing the element
String baseURI = (this.ownerNode != null) ? this.ownerNode.getBaseURI() : null ;
if(baseURI != null){
try {
//return valid absolute base URI
return new URI(baseURI).toString();
}
catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException e){
// REVISIT: what should happen in this case?
return null;
}
}
return null;
| public java.lang.String | getLocalName()Introduced in DOM Level 2.
Returns the local part of the qualified name of this node.
if (needsSyncData()) {
synchronizeData();
}
return localName;
| public java.lang.String | getNamespaceURI()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.
if (needsSyncData()) {
synchronizeData();
}
return namespaceURI;
| public java.lang.String | getPrefix()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.
if (needsSyncData()) {
synchronizeData();
}
int index = name.indexOf(':");
return index < 0 ? null : name.substring(0, index);
| public java.lang.String | getTypeName()
if (type !=null){
if (type instanceof XSSimpleTypeDefinition) {
return ((XSSimpleTypeDecl) type).getTypeName();
} else {
return ((XSComplexTypeDecl) type).getTypeName();
}
}
return null;
| public java.lang.String | getTypeNamespace()
if (type !=null){
return type.getNamespace();
}
return null;
| public boolean | isDerivedFrom(java.lang.String typeNamespaceArg, java.lang.String typeNameArg, int derivationMethod)Introduced in DOM Level 2.
Checks if a type is derived from another by restriction. See:
http://www.w3.org/TR/DOM-Level-3-Core/core.html#TypeInfo-isDerivedFrom
if(needsSyncData()) {
synchronizeData();
}
if (type != null) {
if (type instanceof XSSimpleTypeDefinition) {
return ((XSSimpleTypeDecl) type).isDOMDerivedFrom(
typeNamespaceArg, typeNameArg, derivationMethod);
} else {
return ((XSComplexTypeDecl) type).isDOMDerivedFrom(
typeNamespaceArg, typeNameArg, derivationMethod);
}
}
return false;
| void | rename(java.lang.String namespaceURI, java.lang.String qualifiedName)
if (needsSyncData()) {
synchronizeData();
}
this.name = qualifiedName;
setName(namespaceURI, qualifiedName);
reconcileDefaultAttributes();
| private void | setName(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) {
//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);
}
}
| public void | setPrefix(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.
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);
} 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);
}
}
}
}
// update node name with new qualifiedName
if (prefix !=null && prefix.length() != 0) {
name = prefix + ":" + localName;
}
else {
name = localName;
}
| public void | setType(com.sun.org.apache.xerces.internal.xs.XSTypeDefinition type)NON-DOM: setting type used by the DOM parser
this.type = type;
| protected void | setValues(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
// 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;
|
|