Search in sources :

Example 1 with UserDataHandler

use of org.w3c.dom.UserDataHandler in project webtools.sourceediting by eclipse.

the class NodeImpl method notifyUserDataHandlers.

/**
 * Notifies the UserDataHandlers of the node.
 *
 * @param operation
 * @param destination
 */
protected void notifyUserDataHandlers(short operation, Node destination) {
    if (operation != UserDataHandler.NODE_ADOPTED & operation != UserDataHandler.NODE_CLONED & operation != UserDataHandler.NODE_DELETED & operation != UserDataHandler.NODE_IMPORTED & operation != UserDataHandler.NODE_RENAMED)
        return;
    Map userDataTable = UserData.getInstance().getUserDataTable(this);
    if (userDataTable != null) {
        Iterator entries = userDataTable.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            // should always be a string
            String key = entry.getKey().toString();
            UserDataAndHandler dataAndHandler = (UserDataAndHandler) entry.getValue();
            if (dataAndHandler != null) {
                UserDataHandler dataHandler = dataAndHandler.getHandler();
                if (dataHandler != null) {
                    dataHandler.handle(operation, key, dataAndHandler.getData(), this, destination);
                }
            }
        }
    }
}
Also used : UserDataHandler(org.w3c.dom.UserDataHandler) Iterator(java.util.Iterator) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 2 with UserDataHandler

use of org.w3c.dom.UserDataHandler in project webtools.sourceediting by eclipse.

the class NodeImplTestCase method testNotifyUserDataHandler2.

/*
	 * Test for notifying the UserDataHandler when importing
	 */
public void testNotifyUserDataHandler2() {
    elementToImport = document.createElement("ElementToImport");
    ((NodeImpl) elementToImport).setUserData(KEY, VALUE, new UserDataHandler() {

        public void handle(short operation, String key, Object data, Node src, Node dst) {
            // parameters
            if (operation == UserDataHandler.NODE_IMPORTED) {
                assertEquals(VALUE, data);
                assertEquals(KEY, key);
                assertEquals(src, elementToImport);
                assertEquals(dst, null);
                if (DEBUG)
                    System.out.println("Operation: " + operation + " Key:" + key + " Object:" + data + " SourceNode:" + src.getLocalName() + " DestinationNode:" + dst);
            }
        }
    });
    document.importNode(elementToImport, true);
}
Also used : UserDataHandler(org.w3c.dom.UserDataHandler) NodeImpl(org.eclipse.wst.xml.core.internal.document.NodeImpl) Node(org.w3c.dom.Node)

Example 3 with UserDataHandler

use of org.w3c.dom.UserDataHandler in project webtools.sourceediting by eclipse.

the class NodeImplTestCase method testNotifyUserDataHandler1.

/*
	 * Test for notifying the UserDataHandler when cloning an attribute
	 */
public void testNotifyUserDataHandler1() {
    attribute.setUserData(KEY, VALUE, new UserDataHandler() {

        public void handle(short operation, String key, Object data, Node src, Node dst) {
            assertEquals(UserDataHandler.NODE_CLONED, operation);
            assertEquals(VALUE, data);
            assertEquals(KEY, key);
            assertEquals(src, attribute);
            if (DEBUG)
                System.out.println("Operation: " + operation + " Key:" + key + " Object:" + data + " SourceNode:" + src.getLocalName() + " DestinationNode:" + dst.getLocalName());
        }
    });
    // event occurs before the destinationNode returns....
    destinationNode = (AttrImpl) attribute.cloneNode(true);
}
Also used : UserDataHandler(org.w3c.dom.UserDataHandler) Node(org.w3c.dom.Node)

Aggregations

UserDataHandler (org.w3c.dom.UserDataHandler)3 Node (org.w3c.dom.Node)2 Iterator (java.util.Iterator)1 Map (java.util.Map)1 NodeImpl (org.eclipse.wst.xml.core.internal.document.NodeImpl)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1