You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ru...@apache.org on 2006/06/29 16:57:27 UTC
svn commit: r418064 - in
/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom:
AttrImpl.java DocumentImpl.java ElementImpl.java
Author: ruchithf
Date: Thu Jun 29 07:57:26 2006
New Revision: 418064
URL: http://svn.apache.org/viewvc?rev=418064&view=rev
Log:
Implemented getElementById()
Modified:
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/AttrImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/DocumentImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/AttrImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/AttrImpl.java?rev=418064&r1=418063&r2=418064&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/AttrImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/AttrImpl.java Thu Jun 29 07:57:26 2006
@@ -160,7 +160,7 @@
public Element getOwnerElement() {
// Owned is set to an element instance when the attribute is added to an
// element
- return (Element) (isOwned() ? ownerNode : null);
+ return (Element) (isOwned() ? parent : null);
}
public boolean getSpecified() {
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=418064&r1=418063&r2=418064&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/DocumentImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/DocumentImpl.java Thu Jun 29 07:57:26 2006
@@ -46,17 +46,21 @@
import javax.xml.stream.XMLStreamWriter;
import java.io.OutputStream;
+import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Vector;
public class DocumentImpl extends ParentNode implements Document, OMDocument {
- protected Hashtable identifiers;
-
private String xmlVersion;
private String charEncoding;
+ private Vector idAttrs;
+
protected ElementImpl documentElement;
+
+ protected Hashtable identifiers;
/**
* @param ownerDocument
@@ -222,9 +226,23 @@
throw new UnsupportedOperationException("TODO");
}
- public Element getElementById(String arg0) {
- // TODO getElementById
- throw new UnsupportedOperationException("TODO: getElementById");
+ public Element getElementById(String elementId) {
+
+ //If there are no id attrs
+ if(this.idAttrs == null) {
+ return null;
+ }
+
+ Enumeration attrEnum = this.idAttrs.elements();
+ while(attrEnum.hasMoreElements()) {
+ Attr tempAttr = (Attr)attrEnum.nextElement();
+ if(tempAttr.getValue().equals(elementId)) {
+ return tempAttr.getOwnerElement();
+ }
+ }
+
+ //If we reach this point then, there's no such attr
+ return null;
}
public NodeList getElementsByTagName(String arg0) {
@@ -458,6 +476,20 @@
this.firstChild.build();
}
this.done = true;
+ }
+
+ protected void addIdAttr(Attr attr) {
+ if(this.idAttrs == null) {
+ this.idAttrs = new Vector();
+ }
+ this.idAttrs.add(attr);
+ }
+
+ protected void removeIdAttr(Attr attr) {
+ if(this.idAttrs != null) {
+ this.idAttrs.remove(attr);
+ }
+
}
/*
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=418064&r1=418063&r2=418064&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java Thu Jun 29 07:57:26 2006
@@ -1387,7 +1387,7 @@
msg);
}
- tempAttr.isId = isId;
+ this.updateIsId(isId, tempAttr);
}
public void setIdAttributeNS(String namespaceURI, String localName, boolean isId)
@@ -1409,7 +1409,7 @@
msg);
}
- tempAttr.isId = isId;
+ this.updateIsId(isId, tempAttr);
}
public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException {
@@ -1439,7 +1439,21 @@
msg);
}
+ this.updateIsId(isId, tempAttr);
+ }
+
+ /**
+ * Updates the id state of the attr and notifies the document
+ * @param isId
+ * @param tempAttr
+ */
+ private void updateIsId(boolean isId, AttrImpl tempAttr) {
tempAttr.isId = isId;
+ if(isId) {
+ this.ownerNode.addIdAttr(tempAttr);
+ } else {
+ this.ownerNode.removeIdAttr(tempAttr);
+ }
}
public TypeInfo getSchemaTypeInfo() {
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org