You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2002/02/14 17:34:29 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/dom ElementNSImpl.java CoreDocumentImpl.java AttrNSImpl.java
sandygao 02/02/14 08:34:29
Modified: java/src/org/apache/xerces/dom ElementNSImpl.java
CoreDocumentImpl.java AttrNSImpl.java
Log:
Add a new way to create element/attribute nodes: passing an extra "localName" parameter, so that we can reuse the String objects we already have, instead of creating a new one.
Revision Changes Path
1.19 +23 -11 xml-xerces/java/src/org/apache/xerces/dom/ElementNSImpl.java
Index: ElementNSImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ElementNSImpl.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ElementNSImpl.java 29 Jan 2002 01:15:07 -0000 1.18
+++ ElementNSImpl.java 14 Feb 2002 16:34:29 -0000 1.19
@@ -1,4 +1,4 @@
-/* $Id: ElementNSImpl.java,v 1.18 2002/01/29 01:15:07 lehors Exp $ */
+/* $Id: ElementNSImpl.java,v 1.19 2002/02/14 16:34:29 sandygao Exp $ */
/*
* The Apache Software License, Version 1.1
*
@@ -89,16 +89,16 @@
/** DOM2: localName. */
protected String localName;
-
+
/**
* DOM2: Constructor for Namespace implementation.
*/
protected ElementNSImpl(CoreDocumentImpl ownerDocument,
- String namespaceURI,
- String qualifiedName)
+ String namespaceURI,
+ String qualifiedName)
throws DOMException
{
- super(ownerDocument, qualifiedName);
+ super(ownerDocument, qualifiedName);
int index = qualifiedName.indexOf(':');
String prefix;
@@ -128,13 +128,25 @@
}
}
}
- this.namespaceURI = namespaceURI;
+ this.namespaceURI = 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);
+ String value) {
+ super(ownerDocument, value);
}
//
@@ -204,7 +216,7 @@
if (needsSyncData()) {
synchronizeData();
}
- if (ownerDocument().errorChecking) {
+ if (ownerDocument().errorChecking) {
if (isReadOnly()) {
throw new DOMException(
DOMException.NO_MODIFICATION_ALLOWED_ERR,
@@ -212,7 +224,7 @@
}
if (!CoreDocumentImpl.isXMLName(prefix)) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
- "DOM002 Illegal character");
+ "DOM002 Illegal character");
}
if (namespaceURI == null || prefix.indexOf(':') >=0) {
throw new DOMException(DOMException.NAMESPACE_ERR,
@@ -236,7 +248,7 @@
* Returns the local part of the qualified name of this node.
* @since WD-DOM-Level-2-19990923
*/
- public String getLocalName()
+ public String getLocalName()
{
if (needsSyncData()) {
synchronizeData();
1.12 +133 -92 xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java
Index: CoreDocumentImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- CoreDocumentImpl.java 29 Jan 2002 01:15:07 -0000 1.11
+++ CoreDocumentImpl.java 14 Feb 2002 16:34:29 -0000 1.12
@@ -108,7 +108,7 @@
* @author Joe Kesselman, IBM
* @author Andy Clark, IBM
* @author Ralf Pfeiffer, IBM
- * @version $Id: CoreDocumentImpl.java,v 1.11 2002/01/29 01:15:07 lehors Exp $
+ * @version $Id: CoreDocumentImpl.java,v 1.12 2002/02/14 16:34:29 sandygao Exp $
* @since PR-DOM-Level-1-19980818.
*/
public class CoreDocumentImpl
@@ -314,7 +314,7 @@
callUserDataHandlers(this, newdoc, UserDataHandler.NODE_CLONED);
cloneNode(newdoc, deep);
- return newdoc;
+ return newdoc;
} // cloneNode(boolean):Node
@@ -374,7 +374,7 @@
public Node insertBefore(Node newChild, Node refChild)
throws DOMException {
- // Only one such child permitted
+ // Only one such child permitted
int type = newChild.getNodeType();
if (errorChecking) {
if((type == Node.ELEMENT_NODE && docElement != null) ||
@@ -384,17 +384,17 @@
}
}
- super.insertBefore(newChild,refChild);
+ super.insertBefore(newChild,refChild);
- // If insert succeeded, cache the kid appropriately
+ // If insert succeeded, cache the kid appropriately
if (type == Node.ELEMENT_NODE) {
- docElement = (ElementImpl)newChild;
+ docElement = (ElementImpl)newChild;
}
else if (type == Node.DOCUMENT_TYPE_NODE) {
- docType=(DocumentTypeImpl)newChild;
+ docType=(DocumentTypeImpl)newChild;
}
- return newChild;
+ return newChild;
} // insertBefore(Node,Node):Node
@@ -409,16 +409,16 @@
throws DOMException {
super.removeChild(oldChild);
- // If remove succeeded, un-cache the kid appropriately
+ // If remove succeeded, un-cache the kid appropriately
int type = oldChild.getNodeType();
if(type == Node.ELEMENT_NODE) {
- docElement = null;
+ docElement = null;
}
else if (type == Node.DOCUMENT_TYPE_NODE) {
- docType=null;
+ docType=null;
}
- return oldChild;
+ return oldChild;
} // removeChild(Node):Node
@@ -436,10 +436,10 @@
int type = oldChild.getNodeType();
if(type == Node.ELEMENT_NODE) {
- docElement = (ElementImpl)newChild;
+ docElement = (ElementImpl)newChild;
}
else if (type == Node.DOCUMENT_TYPE_NODE) {
- docType = (DocumentTypeImpl)newChild;
+ docType = (DocumentTypeImpl)newChild;
}
return oldChild;
} // replaceChild(Node,Node):Node
@@ -480,11 +480,11 @@
public Attr createAttribute(String name)
throws DOMException {
- if (errorChecking && !isXMLName(name)) {
+ if (errorChecking && !isXMLName(name)) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
"DOM002 Illegal character");
}
- return new AttrImpl(this, name);
+ return new AttrImpl(this, name);
} // createAttribute(String):Attr
@@ -534,11 +534,11 @@
public Element createElement(String tagName)
throws DOMException {
- if (errorChecking && !isXMLName(tagName)) {
+ if (errorChecking && !isXMLName(tagName)) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
"DOM002 Illegal character");
}
- return new ElementImpl(this, tagName);
+ return new ElementImpl(this, tagName);
} // createElement(String):Element
@@ -555,11 +555,11 @@
public EntityReference createEntityReference(String name)
throws DOMException {
- if (errorChecking && !isXMLName(name)) {
+ if (errorChecking && !isXMLName(name)) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
"DOM002 Illegal character");
}
- return new EntityReferenceImpl(this, name);
+ return new EntityReferenceImpl(this, name);
} // createEntityReference(String):EntityReference
@@ -580,11 +580,11 @@
String data)
throws DOMException {
- if (errorChecking && !isXMLName(target)) {
+ if (errorChecking && !isXMLName(target)) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
"DOM002 Illegal character");
}
- return new ProcessingInstructionImpl(this, target, data);
+ return new ProcessingInstructionImpl(this, target, data);
} // createProcessingInstruction(String,String):ProcessingInstruction
@@ -743,7 +743,7 @@
* The encoding of this document (part of XML Declaration)
*/
public String getEncoding() {
- return encoding;
+ return encoding;
}
/**
@@ -760,7 +760,7 @@
* The version of this document (part of XML Declaration)
*/
public String getVersion() {
- return version;
+ return version;
}
/**
@@ -818,11 +818,11 @@
String systemID)
throws DOMException {
- if (errorChecking && !isXMLName(qualifiedName)) {
+ if (errorChecking && !isXMLName(qualifiedName)) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
"DOM002 Illegal character");
}
- return new DocumentTypeImpl(this, qualifiedName, publicID, systemID);
+ return new DocumentTypeImpl(this, qualifiedName, publicID, systemID);
} // createDocumentType(String):DocumentType
@@ -841,11 +841,11 @@
public Entity createEntity(String name)
throws DOMException {
- if (errorChecking && !isXMLName(name)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
- "DOM002 Illegal character");
+ if (errorChecking && !isXMLName(name)) {
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
+ "DOM002 Illegal character");
}
- return new EntityImpl(this, name);
+ return new EntityImpl(this, name);
} // createEntity(String):Entity
@@ -864,11 +864,11 @@
public Notation createNotation(String name)
throws DOMException {
- if (errorChecking && !isXMLName(name)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
- "DOM002 Illegal character");
+ if (errorChecking && !isXMLName(name)) {
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
+ "DOM002 Illegal character");
}
- return new NotationImpl(this, name);
+ return new NotationImpl(this, name);
} // createNotation(String):Notation
@@ -879,9 +879,9 @@
public ElementDefinitionImpl createElementDefinition(String name)
throws DOMException {
- if (errorChecking && !isXMLName(name)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
- "DOM002 Illegal character");
+ if (errorChecking && !isXMLName(name)) {
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
+ "DOM002 Illegal character");
}
return new ElementDefinitionImpl(this, name);
@@ -899,7 +899,7 @@
* and a NOT_SUPPORTED_ERR exception is thrown if attempted.
*/
public Node importNode(Node source, boolean deep)
- throws DOMException {
+ throws DOMException {
return importNode(source, deep, false, null);
} // importNode(Node,boolean):Node
@@ -917,7 +917,7 @@
*/
private Node importNode(Node source, boolean deep, boolean cloningDoc,
Hashtable reversedIdentifiers)
- throws DOMException {
+ throws DOMException {
Node newnode=null;
// Sigh. This doesn't work; too many nodes have private data that
@@ -988,11 +988,11 @@
if( source.getOwnerDocument().getImplementation().hasFeature("XML", "2.0") ){
if (source.getLocalName() == null) {
- newnode = createAttribute(source.getNodeName());
- } else {
- newnode = createAttributeNS(source.getNamespaceURI(),
+ newnode = createAttribute(source.getNodeName());
+ } else {
+ newnode = createAttributeNS(source.getNamespaceURI(),
source.getNodeName());
- }
+ }
}
else {
newnode = createAttribute(source.getNodeName());
@@ -1023,52 +1023,52 @@
deep = true;
}
}
- break;
+ break;
}
- case TEXT_NODE: {
- newnode = createTextNode(source.getNodeValue());
- break;
+ case TEXT_NODE: {
+ newnode = createTextNode(source.getNodeValue());
+ break;
}
- case CDATA_SECTION_NODE: {
- newnode = createCDATASection(source.getNodeValue());
- break;
+ case CDATA_SECTION_NODE: {
+ newnode = createCDATASection(source.getNodeValue());
+ break;
}
- case ENTITY_REFERENCE_NODE: {
- newnode = createEntityReference(source.getNodeName());
+ case ENTITY_REFERENCE_NODE: {
+ newnode = createEntityReference(source.getNodeName());
// the subtree is created according to this doc by the method
// above, so avoid carrying over original subtree
deep = false;
- break;
+ break;
}
- case ENTITY_NODE: {
- Entity srcentity = (Entity)source;
- EntityImpl newentity =
- (EntityImpl)createEntity(source.getNodeName());
- newentity.setPublicId(srcentity.getPublicId());
- newentity.setSystemId(srcentity.getSystemId());
- newentity.setNotationName(srcentity.getNotationName());
+ case ENTITY_NODE: {
+ Entity srcentity = (Entity)source;
+ EntityImpl newentity =
+ (EntityImpl)createEntity(source.getNodeName());
+ newentity.setPublicId(srcentity.getPublicId());
+ newentity.setSystemId(srcentity.getSystemId());
+ newentity.setNotationName(srcentity.getNotationName());
// Kids carry additional value,
// allow deep import temporarily
newentity.isReadOnly(false);
- newnode = newentity;
- break;
+ newnode = newentity;
+ break;
}
- case PROCESSING_INSTRUCTION_NODE: {
- newnode = createProcessingInstruction(source.getNodeName(),
- source.getNodeValue());
- break;
+ case PROCESSING_INSTRUCTION_NODE: {
+ newnode = createProcessingInstruction(source.getNodeName(),
+ source.getNodeValue());
+ break;
}
- case COMMENT_NODE: {
- newnode = createComment(source.getNodeValue());
- break;
+ case COMMENT_NODE: {
+ newnode = createComment(source.getNodeValue());
+ break;
}
-
+
case DOCUMENT_TYPE_NODE: {
// unless this is used as part of cloning a Document
// forbid it for the sake of being compliant to the DOM spec
@@ -1108,21 +1108,21 @@
}
case DOCUMENT_FRAGMENT_NODE: {
- newnode = createDocumentFragment();
- // No name, kids carry value
- break;
+ newnode = createDocumentFragment();
+ // No name, kids carry value
+ break;
}
- case NOTATION_NODE: {
- Notation srcnotation = (Notation)source;
- NotationImpl newnotation =
- (NotationImpl)createNotation(source.getNodeName());
- newnotation.setPublicId(srcnotation.getPublicId());
- newnotation.setSystemId(srcnotation.getSystemId());
- // Kids carry additional value
- newnode = newnotation;
- // No name, no value
- break;
+ case NOTATION_NODE: {
+ Notation srcnotation = (Notation)source;
+ NotationImpl newnotation =
+ (NotationImpl)createNotation(source.getNodeName());
+ newnotation.setPublicId(srcnotation.getPublicId());
+ newnotation.setSystemId(srcnotation.getSystemId());
+ // Kids carry additional value
+ newnode = newnotation;
+ // No name, no value
+ break;
}
case DOCUMENT_NODE : // Can't import document nodes
default: { // Unknown node type
@@ -1133,19 +1133,19 @@
callUserDataHandlers(source, newnode, UserDataHandler.NODE_IMPORTED);
- // If deep, replicate and attach the kids.
- if (deep) {
- for (Node srckid = source.getFirstChild();
+ // If deep, replicate and attach the kids.
+ if (deep) {
+ for (Node srckid = source.getFirstChild();
srckid != null;
srckid = srckid.getNextSibling()) {
- newnode.appendChild(importNode(srckid, true, false,
+ newnode.appendChild(importNode(srckid, true, false,
reversedIdentifiers));
- }
+ }
}
if (newnode.getNodeType() == Node.ENTITY_NODE) {
((NodeImpl)newnode).setReadOnly(true, true);
}
- return newnode;
+ return newnode;
} // importNode(Node,boolean,boolean,Hashtable):Node
@@ -1367,7 +1367,7 @@
public Element createElementNS(String namespaceURI, String qualifiedName)
throws DOMException
{
- if (errorChecking && !isXMLName(qualifiedName)) {
+ if (errorChecking && !isXMLName(qualifiedName)) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
"DOM002 Illegal character");
}
@@ -1375,6 +1375,26 @@
}
/**
+ * Xerces-specific constructor. "localName" is passed in, so we don't need
+ * to create a new String for it.
+ *
+ * @param namespaceURI The namespace URI of the element to
+ * create.
+ * @param qualifiedName The qualified name of the element type to
+ * instantiate.
+ * @param localName The local name of the element to instantiate.
+ * @return Element A new Element object with the following attributes:
+ * @throws DOMException INVALID_CHARACTER_ERR: Raised if the specified
+ * name contains an invalid character.
+ */
+ public Element createElementNS(String namespaceURI, String qualifiedName,
+ String localpart)
+ throws DOMException
+ {
+ return new ElementNSImpl(this, namespaceURI, qualifiedName, localpart);
+ }
+
+ /**
* Introduced in DOM Level 2. <p>
* Creates an attribute of the given qualified name and namespace URI.
* If the given namespaceURI is null or an empty string and the
@@ -1395,7 +1415,7 @@
public Attr createAttributeNS(String namespaceURI, String qualifiedName)
throws DOMException
{
- if (errorChecking && !isXMLName(qualifiedName)) {
+ if (errorChecking && !isXMLName(qualifiedName)) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
"DOM002 Illegal character");
}
@@ -1403,6 +1423,27 @@
}
/**
+ * Xerces-specific constructor. "localName" is passed in, so we don't need
+ * to create a new String for it.
+ *
+ * @param namespaceURI The namespace URI of the attribute to
+ * create. When it is null or an empty string,
+ * this method behaves like createAttribute.
+ * @param qualifiedName The qualified name of the attribute to
+ * instantiate.
+ * @param localName The local name of the attribute to instantiate.
+ * @return Attr A new Attr object.
+ * @throws DOMException INVALID_CHARACTER_ERR: Raised if the specified
+ name contains an invalid character.
+ */
+ public Attr createAttributeNS(String namespaceURI, String qualifiedName,
+ String localName)
+ throws DOMException
+ {
+ return new AttrNSImpl(this, namespaceURI, qualifiedName, localName);
+ }
+
+ /**
* Introduced in DOM Level 2. <p>
* Returns a NodeList of all the Elements with a given local name and
* namespace URI in the order in which they would be encountered in a
@@ -1467,7 +1508,7 @@
parent.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
return child.getNodeType() == Node.ELEMENT_NODE;
}
- return 0 != (kidOK[parent.getNodeType()] & 1 << child.getNodeType());
+ return 0 != (kidOK[parent.getNodeType()] & 1 << child.getNodeType());
}
/**
1.24 +24 -13 xml-xerces/java/src/org/apache/xerces/dom/AttrNSImpl.java
Index: AttrNSImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttrNSImpl.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- AttrNSImpl.java 29 Jan 2002 01:15:06 -0000 1.23
+++ AttrNSImpl.java 14 Feb 2002 16:34:29 -0000 1.24
@@ -1,4 +1,4 @@
-/* $Id: AttrNSImpl.java,v 1.23 2002/01/29 01:15:06 lehors Exp $ */
+/* $Id: AttrNSImpl.java,v 1.24 2002/02/14 16:34:29 sandygao Exp $ */
/*
* The Apache Software License, Version 1.1
*
@@ -95,10 +95,10 @@
* DOM2: Constructor for Namespace implementation.
*/
protected AttrNSImpl(CoreDocumentImpl ownerDocument,
- String namespaceURI,
- String qualifiedName) {
+ String namespaceURI,
+ String qualifiedName) {
- super(ownerDocument, qualifiedName);
+ super(ownerDocument, qualifiedName);
int index = qualifiedName.indexOf(':');
String prefix;
@@ -111,7 +111,7 @@
(namespaceURI == null || !namespaceURI.equals(xmlnsURI))) {
throw new DOMException(DOMException.NAMESPACE_ERR,
- "DOM003 Namespace error");
+ "DOM003 Namespace error");
}
}
else {
@@ -140,13 +140,24 @@
}
}
}
- this.namespaceURI = namespaceURI;
+ this.namespaceURI = namespaceURI;
}
+ // when local name is known
+ protected AttrNSImpl(CoreDocumentImpl ownerDocument,
+ String namespaceURI,
+ String qualifiedName,
+ String localName) {
+ super(ownerDocument, qualifiedName);
+
+ this.localName = localName;
+ this.namespaceURI = namespaceURI;
+ }
+
// for DeferredAttrImpl
protected AttrNSImpl(CoreDocumentImpl ownerDocument,
- String value) {
- super(ownerDocument, value);
+ String value) {
+ super(ownerDocument, value);
}
//
@@ -174,7 +185,7 @@
// 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;
+ return namespaceURI;
}
/**
@@ -214,7 +225,7 @@
if (needsSyncData()) {
synchronizeData();
}
- if (ownerDocument().errorChecking) {
+ if (ownerDocument().errorChecking) {
if (isReadOnly()) {
throw new DOMException(
DOMException.NO_MODIFICATION_ALLOWED_ERR,
@@ -222,11 +233,11 @@
}
if (!CoreDocumentImpl.isXMLName(prefix)) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
- "DOM002 Illegal character");
+ "DOM002 Illegal character");
}
if (namespaceURI == null || prefix.indexOf(':') >=0) {
throw new DOMException(DOMException.NAMESPACE_ERR,
- "DOM003 Namespace error");
+ "DOM003 Namespace error");
} else if (prefix != null) {
if (prefix.equals("xmlns")) {
if (!namespaceURI.equals(xmlnsURI)){
@@ -245,7 +256,7 @@
}
}
// update node name with new qualifiedName
- name = prefix + ":" + localName;
+ name = prefix + ":" + localName;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org