issrg.utils.gui.xml
Class XMLEditor

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by issrg.utils.gui.xml.XMLEditor
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible
Direct Known Subclasses:
AbstractConfigComponent, PEComponent, PERMISXMLEditorInstantiable, PTComponent, XMLEditorInstantiable

public abstract class XMLEditor
extends javax.swing.JPanel

An Abstract class, that handles core XML editing functions.

Author:
Christian Azzopardi
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 boolean canRedo
          Flag that is used to notify if there is any event on the redo Stack
 boolean canUndo
          Flag that is used to notify if there is any event on the undo Stack
 org.w3c.dom.Document DOM
          org.w3c.dom.Document where the elements are stored
 java.util.Stack done
          Stack that keeps a list of items that can be undone
 PolicyValidator policyValidator
           
 java.util.Stack undone
          Stack that keeps a list of items that can be redone
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
XMLEditor()
          Creates a new instance of XMLEditor
 
Method Summary
 void addItem(org.w3c.dom.Element childNode, org.w3c.dom.Element parentNode)
          Adds the child element to a parent element in XML.
 void addItem(org.w3c.dom.Element childNode, org.w3c.dom.Element parentNode, int childIndex)
          Adds the child element to a parent element in XML, at a specified position.
 void addXMLChangeListener(XMLChangeListener listener)
          Method to add a listener to any XML Change
 void createDOM(byte[] bytesDOM)
          Method to open a Document given an XML byte array input.
 void createDOM(java.io.InputStream bais)
          Method to open a Document given an XML String input.
 void createDOM(java.lang.String xml)
          Method to open a Document given an XML String input.
 void deleteItem(org.w3c.dom.Element childNode, org.w3c.dom.Element parentNode)
          Deletes a child element from the parent element.
protected  void doEvent(XMLChangeEvent ev)
          This method adds to the done stack that something has just been done and calls processEvent with the received XMLChangeEvent
 java.lang.String GenerateXML()
          Calls the previous overloaded method GenerateXML(OutputStream), converts the stream into a string, and returns it.
 void GenerateXML(java.io.OutputStream baos)
          Generates the XML file, with Serializing.
 org.w3c.dom.Document getDocument()
          Returns the Document that this XMLEditor holds.
 org.w3c.dom.Element getElement(java.lang.String name)
          Gets the first element with the specified name in the document.
 void newDoneStack()
          Initializes the done Stack.
 void newUnDoneStack()
          Initializes the undone Stack.
 XMLChangeEvent not(XMLChangeEvent ev)
          Obtains the converse of an XMLChangeEvent.
 void notifyChanges(XMLChangeEvent ev)
          Method that fires XMLChanged notifications to a list of registered listeners.
 void processEvent(XMLChangeEvent ev)
           It will then call notifyChanges, to notify any registered listeners with the changes.
 void redo()
          Method that redoes the first XMLChangeEvent that is on the undone Stack.
 void removeXMLChangeListener(XMLChangeListener listener)
          Method to remove a listener to any XML Change
 void replaceNode(org.w3c.dom.Element parent, org.w3c.dom.Element oldChild, org.w3c.dom.Element newChild)
           
 void setAttributeValue(org.w3c.dom.Element childNode, java.lang.String[] attribs, java.lang.String[] values)
          Constructs the XMLChangeEvent to Modify the Element's Attributes with the list of their respective values.
 void undo()
          Method that undoes the last performed action stored on the done stack.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

canUndo

public boolean canUndo
Flag that is used to notify if there is any event on the undo Stack


canRedo

public boolean canRedo
Flag that is used to notify if there is any event on the redo Stack


done

public java.util.Stack done
Stack that keeps a list of items that can be undone


undone

public java.util.Stack undone
Stack that keeps a list of items that can be redone


DOM

public org.w3c.dom.Document DOM
org.w3c.dom.Document where the elements are stored


policyValidator

public PolicyValidator policyValidator
Constructor Detail

XMLEditor

public XMLEditor()
Creates a new instance of XMLEditor

Method Detail

addXMLChangeListener

public void addXMLChangeListener(XMLChangeListener listener)
Method to add a listener to any XML Change

Parameters:
listener - the component that listens to XML Changes to be added to the listener list.

removeXMLChangeListener

public void removeXMLChangeListener(XMLChangeListener listener)
Method to remove a listener to any XML Change

Parameters:
listener - the component to be removed from the listener list

getDocument

public org.w3c.dom.Document getDocument()
Returns the Document that this XMLEditor holds.

Returns:
a reference to the Document that this editor holds

setAttributeValue

public void setAttributeValue(org.w3c.dom.Element childNode,
                              java.lang.String[] attribs,
                              java.lang.String[] values)
Constructs the XMLChangeEvent to Modify the Element's Attributes with the list of their respective values.

Parameters:
childNode - The Element to modify
attribs - A String Array of attributes to modify
values - The corresponding values of the attributes to set

replaceNode

public void replaceNode(org.w3c.dom.Element parent,
                        org.w3c.dom.Element oldChild,
                        org.w3c.dom.Element newChild)

undo

public void undo()
Method that undoes the last performed action stored on the done stack. This last performed action is taken off the done stack and stored in the undone stack to be able to redo.


redo

public void redo()
Method that redoes the first XMLChangeEvent that is on the undone Stack. This last performed redo action is then taken off the undone stack.


notifyChanges

public void notifyChanges(XMLChangeEvent ev)
Method that fires XMLChanged notifications to a list of registered listeners.


newDoneStack

public void newDoneStack()
Initializes the done Stack.


newUnDoneStack

public void newUnDoneStack()
Initializes the undone Stack.


processEvent

public void processEvent(XMLChangeEvent ev)

It will then call notifyChanges, to notify any registered listeners with the changes.


not

public XMLChangeEvent not(XMLChangeEvent ev)
Obtains the converse of an XMLChangeEvent. This is used in cases were we need to undo/redo. The XMLChangeEvent is popped out of the stack, and the converse is needed to do the opposite action.

Parameters:
ev - the event needed to convert.
Returns:
the converse XMLChangeEvent.

addItem

public void addItem(org.w3c.dom.Element childNode,
                    org.w3c.dom.Element parentNode)
Adds the child element to a parent element in XML.

Parameters:
childNode - The child element to add
parentNode - The parent element to add to

addItem

public void addItem(org.w3c.dom.Element childNode,
                    org.w3c.dom.Element parentNode,
                    int childIndex)
Adds the child element to a parent element in XML, at a specified position. Constructs the necessary XMLChangeEvent.

Parameters:
childNode - The child element to add
parentNode - The parent element to add to
childIndex - The child's position in the parent's set of child nodes

deleteItem

public void deleteItem(org.w3c.dom.Element childNode,
                       org.w3c.dom.Element parentNode)
Deletes a child element from the parent element. Constructs the necessary XMLChangeEvent.

Parameters:
childNode - The child element to delete
parentNode - The parent element to delete from

doEvent

protected void doEvent(XMLChangeEvent ev)
This method adds to the done stack that something has just been done and calls processEvent with the received XMLChangeEvent

Parameters:
ev - The XMLChangeEvent that specifies was is being done.

GenerateXML

public void GenerateXML(java.io.OutputStream baos)
Generates the XML file, with Serializing. This enables better readability when opening a policy in a text editor.

Parameters:
baos - An output stream (file) to write to.

GenerateXML

public java.lang.String GenerateXML()
Calls the previous overloaded method GenerateXML(OutputStream), converts the stream into a string, and returns it.

Returns:
String The current XML

createDOM

public void createDOM(java.lang.String xml)
Method to open a Document given an XML String input. This calls CreateDOM(byte bytesDOM[]).

Parameters:
xml - This String should contain the XML policy to open

createDOM

public void createDOM(byte[] bytesDOM)
Method to open a Document given an XML byte array input. This calls CreateDOM(InputStream bais).

Parameters:
bytesDOM - A byte Array that should contain the XML policy to open

createDOM

public void createDOM(java.io.InputStream bais)
Method to open a Document given an XML String input. This last of 3 overloaded methods has the actual code to verify, the InputStream with the policyValidator provided.

Parameters:
bais - An InputStream containing the XML to open

getElement

public org.w3c.dom.Element getElement(java.lang.String name)
Gets the first element with the specified name in the document. Especially useful if only one such element is present, as this simply gets that element.

Parameters:
name - the name of the element to get
Returns:
the first element in the Document handled by the editor that has the given name.