📄 xmlchangeevent.java
字号:
/*
* Copyright (c) 2006, University of Kent
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 1. Neither the name of the University of Kent nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED.
*
* 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
* IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
* SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
* SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
* GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
* TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
* IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
* SERIOUS FAULTS, IN THIS SOFTWARE.
*
* 5. This license is governed, except to the extent that local laws
* necessarily apply, by the laws of England and Wales.
*/
/*
* XMLChangeEvent.java
*/
package issrg.utils.xml;
import java.awt.AWTEvent;
import org.w3c.dom.*;
/**
* An event which indicates that a change has occured in the Document (DOM).
* This is a low-level event that is generated when a user creates a new policy,
* or modifies an open policy.
* The event is passed to every <code>XMLChangeListener</code> object
* that is registered to receive such events using the component's
* <code>addXMLChangeListener</code> method.
* <p>
* The object that implements the <code>XMLChangeListener</code> interface
* gets this <code>XMLChangeEvent</code> when the event occurs.
*
* @see XMLChangeListener
*/
public class XMLChangeEvent extends AWTEvent
{
/**
* The XML Editor reference
*/
XMLEditor xmled;
/**
* The child element performing on
*/
Element childNode;
/**
* The parent element performing on
*/
Element parentNode;
/**
*
*/
Element newChildNode;
/**
* The Event's Type
*/
String action = null;
/**
* A sequential array of Names for Attributes
*/
String attribNames[];
/**
* A sequential array of Values for Attributes
*/
String attribValues[];
/**
* A sequential array of old Attribute Values.
*/
String oldAttribValues[];
/**
* The child's position with respect to the parent element
*/
int childIndex;
/**
* Constructs an <code>XMLChangeEvent</code> object.
*
* @param xmled the xml Editor reference from which event has occured
* @param childNode the child Element that the event is occuring on
* @param parentNode the parent Element that the action is occuring on
* @param action string identifying the event type
*/
public XMLChangeEvent(XMLEditor xmled, Element childNode, Element parentNode, String action)
{
this(xmled, childNode, parentNode, action, getIndexOfChild(parentNode, childNode));
}
/**
* Constructs an <code>XMLChangeEvent</code> object.
*
* @param xmled the xml Editor reference from which event has occured
* @param childNode the child Element that the event is occuring on
* @param parentNode the parent Element that the action is occuring on
* @param action string identifying the event type
*/
public XMLChangeEvent(XMLEditor xmled, Element parentNode, Element oldChildNode, Element newChildNode, String action)
{
super(xmled,1);
this.xmled = xmled;
this.action = action;
this.parentNode = parentNode;
this.childNode = oldChildNode;
this.newChildNode = newChildNode;
}
/**
* Constructs an <code>XMLChangeEvent</code> object.
*
* @param xmled the xml Editor reference from which event has occured
* @param childNode the child Element that the event is occuring on
* @param parentNode the parent Element that the action is occuring on
* @param action string identifying the event type
* @param childIndex hierarchical level of the child with respect to the parent
*/
public XMLChangeEvent(XMLEditor xmled, Element childNode, Element parentNode, String action, int childIndex)
{
super(xmled,1);
this.xmled = xmled;
this.action = action;
this.parentNode = parentNode;
this.childNode = childNode;
this.childIndex = childIndex;
}
/**
* Constructs an <code>XMLChangeEvent</code> object, which is normally used
* to delete an Element from a Document.
*
* @param xmled the xml Editor reference from which event has occured
* @param childNode the Element that the event is occuring on
* @param action string identifying the event type
*/
public XMLChangeEvent(XMLEditor xmled, Element childNode, String action)
{
super(xmled,1);
this.xmled = xmled;
this.action = action;
this.childNode = childNode;
}
/**
* Constructs an <code>XMLChangeEvent</code> object, which is normally used
* to modify some attributes of a particular element.
*
* @param xmled the xml Editor reference from which event has occured
* @param parentNode the Element that the action is occuring on
* @param attribNames a sequential array of Names of the Attributes that need to be modified
* @param attribValues a sequential array of Values that will be placed when modified
* @param oldAttribValues a sequential array of old Attribute Values
* @param action string identifying the event type
*/
public XMLChangeEvent(XMLEditor xmled, Element parentNode, String attribNames[], String attribValues[], String oldAttribValues[], String action)
{
super(xmled,1);
this.xmled = xmled;
if (parentNode.getParentNode() instanceof Element)
{
this.parentNode = ((Element)parentNode.getParentNode());
}
this.childNode = parentNode;
this.attribNames = attribNames;
this.attribValues = attribValues;
this.oldAttribValues = oldAttribValues;
this.action = action;
}
/**
* Constructs an <code>XMLChangeEvent</code> object, which is normally used
* only to notify that an XML modification was made, and what type.
*
* @param xmled the xml Editor reference from which event has occured
* @param action string identifying the event type
*/
public XMLChangeEvent(XMLEditor xmled, String action)
{
super(xmled,1);
this.xmled = xmled;
this.action = action;
}
/**
* Static method that is used to determine the hierarchical level of the
* child Node with respect to the parent's Node
*
* @param parent parent node
* @param child child node
* @return this Child's Index
*/
public static int getIndexOfChild(Node parent, Node child)
{
NodeList nlist = parent.getChildNodes();
for (int i = 0; i < nlist.getLength(); i++)
{
if ((nlist.item(i)) == ((Node)child))
{
return i;
}
}
return -1;
}
/**
* Returns the child Element that this event is occuring on. This is usually
* an Element that is being added, being deleted, or being modified.
*
* @return this event's Child Element
*/
public Element getChildNode()
{
return childNode;
}
/**
* Returns the parent Element that this event is occurring on. This is
* usually an Element that we are adding an element to, deleting an element
* from, or modifying a Element From.
*
* @return this event's Parent Element
*/
public Element getParentNode()
{
return parentNode;
}
/**
* Returns the timestamp of when this event occurred. Because an
* ActionEvent is a high-level, semantic event, the timestamp is typically
* the same as an underlying InputEvent.
*
* @return this event's timestamp
* @since 1.4
*/
public XMLEditor getXMLEditor()
{
return xmled;
}
/**
* Returns the type of event. This can have one of four recognized types:
* <ul>
* <li>NODE_ADDED - when a node is being added to XML.
* <li>NODE_DELETED - when a node is being deleted to XML.
* <li>NODE_MODIFIED - when a node is being changed from the XML.
* <li>NEW_XML - when a new policy is created.
* </ul>
* <p>
* Further types can be specified later, although they must modify the
* <code>XMLEditor<code>'s way of processing the event.
*
* @return this event's type
*/
public String getAction()
{
return action.intern();
}
/**
* Returns a sequential list of attributes values of a particular element.
*
* @return a string array of string attribute values
*/
public String[] getAttributeValues()
{
return attribValues;
}
/**
* Returns a sequential list of attribute names and Element has.
*
* @return a string array of string attribute names
*/
public String[] getAttributeNames()
{
return attribNames;
}
/**
* Returns a sequential list of attributes values of a particular element
* that have been modified.
*
* @return an old set of attribute values.
*/
public String[] getOldAttribValues()
{
return oldAttribValues;
}
/**
* Returns an integer value, of the hierarchical level of the child with
* respect to the parent element
*
* @return this Child's Index
*/
public int getChildIndex()
{
return childIndex;
}
public Element getNewChildNode()
{
return newChildNode;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -