1999-08-06 00:28:53 +00:00
|
|
|
/*
|
1999-11-06 02:47:15 +00:00
|
|
|
The contents of this file are subject to the Mozilla Public
|
|
|
|
License Version 1.1 (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.mozilla.org/MPL/
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS
|
|
|
|
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
implied. See the License for the specific language governing
|
|
|
|
rights and limitations under the License.
|
|
|
|
|
|
|
|
The Original Code is mozilla.org code.
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is Sun Microsystems,
|
|
|
|
Inc. Portions created by Sun are
|
|
|
|
Copyright (C) 1999 Sun Microsystems, Inc. All
|
|
|
|
Rights Reserved.
|
|
|
|
|
|
|
|
Contributor(s):
|
1999-08-06 00:28:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.mozilla.dom;
|
|
|
|
|
|
|
|
import org.w3c.dom.Node;
|
|
|
|
import org.w3c.dom.NamedNodeMap;
|
|
|
|
import org.w3c.dom.NodeList;
|
|
|
|
import org.w3c.dom.Document;
|
1999-10-25 22:42:40 +00:00
|
|
|
import org.w3c.dom.DOMException;
|
|
|
|
import org.w3c.dom.events.Event;
|
|
|
|
import org.w3c.dom.events.EventTarget;
|
|
|
|
import org.w3c.dom.events.EventListener;
|
|
|
|
import java.util.Vector;
|
1999-11-15 21:12:49 +00:00
|
|
|
import java.util.Hashtable;
|
1999-08-06 00:28:53 +00:00
|
|
|
|
1999-10-25 22:42:40 +00:00
|
|
|
class NodeEventListener {
|
|
|
|
EventListener listener = null;
|
|
|
|
String type = null;
|
|
|
|
boolean useCapture = false;
|
|
|
|
long nativeListener = 0;
|
|
|
|
|
|
|
|
NodeEventListener(String aType, EventListener aListener,
|
|
|
|
boolean aUseCapture, long aNativeListener) {
|
|
|
|
type = aType;
|
|
|
|
listener = aListener;
|
|
|
|
useCapture = aUseCapture;
|
|
|
|
nativeListener = aNativeListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (!(o instanceof NodeEventListener))
|
|
|
|
return false;
|
|
|
|
else {
|
|
|
|
NodeEventListener n = (NodeEventListener) o;
|
|
|
|
if ((useCapture != n.useCapture)
|
|
|
|
|| (type == null) || !type.equals(n.type)
|
|
|
|
|| (listener == null) || !listener.equals(n.listener))
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class NodeImpl implements Node, EventTarget {
|
1999-08-06 00:28:53 +00:00
|
|
|
|
|
|
|
/* The derived classes (Attr, CharacterData, DocumentFragment,
|
|
|
|
Document, Element, EntityReference, NamedNodeMap,
|
|
|
|
ProcessingInstruction) will also use this native pointer, since
|
|
|
|
the nsIDOM coreDom classes follow the same hierarchy */
|
|
|
|
|
|
|
|
private long p_nsIDOMNode = 0;
|
|
|
|
|
1999-11-15 21:12:49 +00:00
|
|
|
// this map stores association of java DOM listeners
|
|
|
|
// with corresponding native Nodes
|
|
|
|
static private Hashtable javaDOMlisteners = new Hashtable();
|
1999-10-25 22:42:40 +00:00
|
|
|
|
1999-08-06 00:28:53 +00:00
|
|
|
// instantiated from JNI only
|
|
|
|
protected NodeImpl() {}
|
2000-01-28 03:45:01 +00:00
|
|
|
protected NodeImpl(long p) {
|
|
|
|
p_nsIDOMNode = p;
|
|
|
|
}
|
1999-08-06 00:28:53 +00:00
|
|
|
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (!(o instanceof NodeImpl))
|
|
|
|
return false;
|
1999-08-24 23:54:26 +00:00
|
|
|
else
|
|
|
|
return (XPCOM_equals(o));
|
|
|
|
}
|
1999-08-06 00:28:53 +00:00
|
|
|
|
1999-08-24 23:54:26 +00:00
|
|
|
public int hashCode(){
|
|
|
|
return XPCOM_hashCode();
|
1999-08-06 00:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public String toString() {
|
|
|
|
return "<" + getNodeName() +
|
|
|
|
" t=" + nodeTypeString(getNodeType()) +
|
|
|
|
" c=org.mozilla.dom.NodeImpl p=" +
|
|
|
|
Long.toHexString(p_nsIDOMNode) + ">";
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String nodeTypeString(int type) {
|
|
|
|
switch (type) {
|
|
|
|
case Node.ELEMENT_NODE: return "ELEMENT";
|
|
|
|
case Node.ATTRIBUTE_NODE: return "ATTRIBUTE";
|
|
|
|
case Node.TEXT_NODE: return "TEXT";
|
|
|
|
case Node.CDATA_SECTION_NODE: return "CDATA_SECTION";
|
|
|
|
case Node.ENTITY_REFERENCE_NODE: return "ENTITY_REFERENCE";
|
|
|
|
case Node.ENTITY_NODE: return "ENTITY";
|
|
|
|
case Node.PROCESSING_INSTRUCTION_NODE: return "PROCESSING_INSTRUCTION";
|
|
|
|
case Node.COMMENT_NODE: return "COMMENT";
|
|
|
|
case Node.DOCUMENT_NODE: return "DOCUMENT";
|
|
|
|
case Node.DOCUMENT_TYPE_NODE: return "DOCUMENT_TYPE";
|
|
|
|
case Node.DOCUMENT_FRAGMENT_NODE: return "DOCUMENT_FRAGMENT";
|
|
|
|
case Node.NOTATION_NODE: return "NOTATION";
|
|
|
|
}
|
|
|
|
return "ERROR";
|
|
|
|
}
|
|
|
|
|
1999-10-25 22:42:40 +00:00
|
|
|
public native Node appendChild(Node newChild) throws DOMException;
|
1999-08-06 00:28:53 +00:00
|
|
|
public native Node cloneNode(boolean deep);
|
|
|
|
public native NamedNodeMap getAttributes();
|
|
|
|
public native NodeList getChildNodes();
|
|
|
|
public native Node getFirstChild();
|
|
|
|
public native Node getLastChild();
|
|
|
|
public native Node getNextSibling();
|
|
|
|
public native String getNodeName();
|
|
|
|
public native short getNodeType();
|
|
|
|
public native String getNodeValue();
|
|
|
|
public native Document getOwnerDocument();
|
|
|
|
public native Node getParentNode();
|
|
|
|
public native Node getPreviousSibling();
|
|
|
|
public native boolean hasChildNodes();
|
1999-10-25 22:42:40 +00:00
|
|
|
public native Node insertBefore(Node newChild, Node refChild) throws DOMException;
|
|
|
|
public native Node removeChild(Node oldChild) throws DOMException;
|
|
|
|
public native Node replaceChild(Node newChild, Node oldChild) throws DOMException;
|
1999-08-06 00:28:53 +00:00
|
|
|
public native void setNodeValue(String nodeValue);
|
|
|
|
|
|
|
|
protected native void finalize();
|
1999-08-24 23:54:26 +00:00
|
|
|
|
|
|
|
private native boolean XPCOM_equals(Object o);
|
|
|
|
private native int XPCOM_hashCode();
|
1999-10-25 22:42:40 +00:00
|
|
|
|
|
|
|
//since DOM level 2
|
|
|
|
public boolean supports(String feature, String version) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getNamespaceURI() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPrefix() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPrefix(String prefix) throws DOMException {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getLocalName() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addEventListener(String type,
|
|
|
|
EventListener listener,
|
|
|
|
boolean useCapture) {
|
|
|
|
|
|
|
|
long nativeListener = addNativeEventListener(type, listener, useCapture);
|
|
|
|
|
1999-11-15 21:12:49 +00:00
|
|
|
Long lnode = new Long(p_nsIDOMNode);
|
|
|
|
|
|
|
|
Vector listeners;
|
|
|
|
|
|
|
|
//in conjunction with internal synchronization of Hashtable and Vector
|
|
|
|
// this should be enough for safe concurrent access
|
|
|
|
synchronized (javaDOMlisteners) {
|
|
|
|
listeners = (Vector) javaDOMlisteners.get(lnode);
|
|
|
|
|
|
|
|
if (listeners == null) {
|
|
|
|
listeners = new Vector();
|
|
|
|
javaDOMlisteners.put(lnode, listeners);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-25 22:42:40 +00:00
|
|
|
if (nativeListener != 0) {
|
|
|
|
|
|
|
|
NodeEventListener l = new NodeEventListener(type,
|
|
|
|
listener,
|
|
|
|
useCapture,
|
|
|
|
nativeListener);
|
|
|
|
listeners.add(l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeEventListener(String type,
|
|
|
|
EventListener listener,
|
|
|
|
boolean useCapture) {
|
1999-11-15 21:12:49 +00:00
|
|
|
|
|
|
|
Vector listeners = (Vector) javaDOMlisteners.get(new Long(p_nsIDOMNode));
|
|
|
|
|
1999-10-25 22:42:40 +00:00
|
|
|
if (listeners == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NodeEventListener l = new NodeEventListener(type,
|
|
|
|
listener, useCapture, 0);
|
|
|
|
|
|
|
|
int idx = listeners.indexOf(l);
|
|
|
|
|
|
|
|
//if trying to remove non-existing listener then return
|
|
|
|
if (idx == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
l = (NodeEventListener) listeners.remove(idx);
|
|
|
|
|
|
|
|
removeNativeEventListener(type, l.nativeListener, useCapture);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean dispatchEvent(Event evt) throws DOMException {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
private native long addNativeEventListener(String type,
|
|
|
|
EventListener listener,
|
|
|
|
boolean useCapture);
|
|
|
|
|
|
|
|
private native void removeNativeEventListener(String type,
|
|
|
|
long nativeListener,
|
|
|
|
boolean useCapture);
|
2000-01-28 03:45:01 +00:00
|
|
|
|
|
|
|
public void normalize() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
};
|
1999-08-06 00:28:53 +00:00
|
|
|
}
|