VdexReload 1.1.3 API

uk.ac.reload.moonunit.dom
Class ReloadSchemaDocument

java.lang.Object
  extended byuk.ac.reload.moonunit.dom.ReloadDocument
      extended byuk.ac.reload.moonunit.dom.ReloadSchemaDocument
Direct Known Subclasses:
ContentPackage, Metadata, Vocabulary

public abstract class ReloadSchemaDocument
extends ReloadDocument

This encapsulates the JDOM XML Document file and the ReloadSchema associated with it plus helper methods.


Nested Class Summary
protected  class ReloadSchemaDocument.UndoableAddAction
          Handles Undo/Redo for Adding Elements
protected  class ReloadSchemaDocument.UndoableCopyAction
          Handles Undo/Redo for Copying Elements
protected  class ReloadSchemaDocument.UndoableCutAction
          Handles Undo/Redo for Cutting Elements
protected  class ReloadSchemaDocument.UndoableDeleteAction
          Handles Undo/Redo for Deleting Elements
protected  class ReloadSchemaDocument.UndoableMoveAction
          Handles Undo/Redo for Moving Elements
protected  class ReloadSchemaDocument.UndoablePasteAction
          Handles Undo/Redo for Pasting Elements
 
Field Summary
protected  ReloadSchemaController _controller
          The Schema that will be our template
protected  UndoHandler _undoHandler
          The Undo Handler
 
Fields inherited from class uk.ac.reload.moonunit.dom.ReloadDocument
_dirty, _doc, _file
 
Constructor Summary
ReloadSchemaDocument()
          Default Constructor
ReloadSchemaDocument(java.io.File file, org.jdom.Document doc, ReloadSchemaController schemaController)
          Constructor that takes in a an XML filename, JDOM document and a ReloadSchemaController
 
Method Summary
 org.jdom.Attribute addAttribute(java.lang.Object source, org.jdom.Element parentElement, ReloadSchemaAttribute newSchemaAttribute)
          Create and Add a new Attribute to a given Element as per the Schema
protected  void addComments(org.jdom.Document doc)
          Add our signature comments to the XML Document
 org.jdom.Element addElement(java.lang.Object source, org.jdom.Element parentElement, org.jdom.Element childElement, boolean doSelect)
          Just add a new Element.
 org.jdom.Element addElementAtIndex(java.lang.Object source, org.jdom.Element parentElement, org.jdom.Element newElement, int index, boolean doSelect)
          Add an Element at an index Position and Notify listeners
 org.jdom.Element addElementBySchema(java.lang.Object source, org.jdom.Element parentElement, ReloadSchemaElement newSchemaElement, boolean doSelect)
          Add a new Element to the parent Element based on ReloadSchemaElement Create new JDOM Element based on childSchemaElement Insert into the correct position! Set any defaults of the Element Add any default child Elements if needed
 org.jdom.Element addElementBySchemaUndoable(java.lang.Object source, org.jdom.Element parentElement, ReloadSchemaElement newSchemaElement, boolean doSelect)
          Add a new Element to the parent Element based on RELOADSchemaElement and register an Undo event.
 org.jdom.Element addElementUndoable(java.lang.Object source, org.jdom.Element parentElement, org.jdom.Element childElement, boolean doSelect)
          Just add a new Element.
 org.jdom.Element addElementUnique(java.lang.Object source, ReloadSchemaElement newSchemaElement, boolean doSelect)
          Add a new Element given the Path in the ReloadSchemaElement.
 void addReloadDocumentListener(ReloadDocumentListener listener)
          Add a ReloadDocumentListener
 boolean canAddElement(org.jdom.Element parentElement, ReloadSchemaElement childSchemaElement)
          Decide whether a child Element can be added to a parent Element by max amount
 boolean canCopyElement(org.jdom.Element element)
          Decides whether an element can be copied or not - will need to override this
 boolean canCutElement(org.jdom.Element element, ReloadSchemaElement schemaElement)
          Decides whether we can cut an element - will need to override this
 boolean canDeleteElement(org.jdom.Element element, ReloadSchemaElement schemaElement)
          Decide whether a Element can be deleted
 boolean canMoveElementDown(org.jdom.Element element)
          Decides whether we can move the element down by one place
 boolean canMoveElementUp(org.jdom.Element element)
          Decides whether we can move the element up by one place
 boolean canPasteFromClipboard(org.jdom.Element element)
          Decides whether we can paste an element - will need to override this
 void changedElement(java.lang.Object source, org.jdom.Element element)
          Somebody has notified us that they have changed an Element in some way.
 org.jdom.Element copyElementUndoable(java.lang.Object source, org.jdom.Element element, org.jdom.Element newParent, boolean doSelect)
          Copy an Element to a new Parent
 org.jdom.Element cutElementUndoable(java.lang.Object source, org.jdom.Element element)
          Cut a child Element from its parent and notify any listeners and Undo
 org.jdom.Element deleteElementUndoable(java.lang.Object source, org.jdom.Element element)
          Delete a child Element from its parent and notify any listeners and Undo
 void destroy()
          Cleanup
 void fireDocumentSaved()
          Tell our listeners that we have saved
 void fireElementAdded(ReloadDocumentListenerEvent event)
          Tell our listeners that we have added a new Element
 void fireElementChanged(ReloadDocumentListenerEvent event)
          Tell our listeners that we have changed an Element
 void fireElementRemoved(ReloadDocumentListenerEvent event)
          Tell our listeners that we have deleted an Element
abstract  java.lang.String[] getComments()
          Get the comments to add to the XML document
 org.jdom.Element getElement(DomPath domPath)
          Return the 'first' found Element for the given DOM Path or null if not found return the first found element for the given DOM Path or null if not found
 org.jdom.Element getElement(ReloadSchemaElement schemaElement)
          Return the 'first' found Element for the given DOM Path or null if not found
 org.jdom.Element[] getElements(DomPath domPath)
          Return all Elements for the given DOM Path or null
 org.jdom.Element[] getElements(ReloadSchemaElement schemaElement)
          Return all Elements for the given ReloadSchemaElement Path or an empty array
static int getIndexOfElement(org.jdom.Element element)
          Get the index position of an element in relation to its parent
static int getInsertPositionOfAttribute(org.jdom.Element parentElement, ReloadSchemaAttribute reloadSchemaAttribute)
          Get the correct position to insert an Attribute in an Element according to the Schema
static int getInsertPositionOfElement(org.jdom.Element parentElement, ReloadSchemaElement newSchemaElement)
          Get the correct position to insert an element according to the Schema
 ReloadSchemaController getReloadSchemaController()
          Get the ReloadSchemaController for this Document
 org.jdom.Namespace getSchemaNamespace()
          Get the schema namespace of the document, or the target namespace of there isn't one
 org.jdom.Namespace getTargetNamespace()
          Get the target schema namespace of the document
abstract  java.lang.String getTargetRootElementName()
          Get the Target Root element name
 UndoHandler getUndoHandler()
          Get the undo handler for this document
 boolean isAllowedChild(org.jdom.Element parentElement, org.jdom.Element childElement)
          Decide whether a child is allowed or not depending on the schema rules
 org.jdom.Element moveElementDown(java.lang.Object source, org.jdom.Element element, boolean doSelect)
          Move an Element down one place
 org.jdom.Element moveElementUndoable(java.lang.Object source, org.jdom.Element element, org.jdom.Element newParent, boolean doSelect)
          Move an Element to a new Parent
 org.jdom.Element moveElementUp(java.lang.Object source, org.jdom.Element element, boolean doSelect)
          Move an Element up one place
 org.jdom.Element pasteElementUndoable(java.lang.Object source, org.jdom.Element element, org.jdom.Element newParent, boolean doSelect)
          Paste an Element to a new Parent
 org.jdom.Element removeElement(java.lang.Object source, org.jdom.Element element)
          Remove a child Element from its parent and notify any listeners
 void removeReloadDocumentListener(ReloadDocumentListener listener)
          Remove a ReloadDocumentListener
 void saveDocument()
          This will save the XML IMS file with the existing File ref and notify any listeners
 void setReloadSchemaController(ReloadSchemaController controller)
          Set the ReloadSchemaController
 void setUndoHandler(UndoHandler undoHandler)
          Set the undo handler for this document
 
Methods inherited from class uk.ac.reload.moonunit.dom.ReloadDocument
getDocument, getFile, getRootElement, isDirty, isDocumentNamespace, isMemberOfSameDocument, loadDocument, saveAsDocument, setDirty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_controller

protected ReloadSchemaController _controller
The Schema that will be our template


_undoHandler

protected UndoHandler _undoHandler
The Undo Handler

Constructor Detail

ReloadSchemaDocument

public ReloadSchemaDocument()
Default Constructor


ReloadSchemaDocument

public ReloadSchemaDocument(java.io.File file,
                            org.jdom.Document doc,
                            ReloadSchemaController schemaController)
Constructor that takes in a an XML filename, JDOM document and a ReloadSchemaController

Parameters:
file - the XML file, for example an IMS metadata or an IMS VDEX vocabulary file doc the JDOM document of the XML file schemaController the ReloadSchemaController corresponding to the schema of the XML file
Method Detail

setReloadSchemaController

public void setReloadSchemaController(ReloadSchemaController controller)
Set the ReloadSchemaController

Parameters:
controller - the ReloadSchemaController

getReloadSchemaController

public ReloadSchemaController getReloadSchemaController()
Get the ReloadSchemaController for this Document

Returns:
the ReloadSchemaController for this document

saveDocument

public void saveDocument()
                  throws ReloadDomException
This will save the XML IMS file with the existing File ref and notify any listeners

Overrides:
saveDocument in class ReloadDocument
Throws:
ReloadDomException - if an error occurs

getTargetRootElementName

public abstract java.lang.String getTargetRootElementName()
Get the Target Root element name

Returns:
the Target Root Element name

getComments

public abstract java.lang.String[] getComments()
Get the comments to add to the XML document

Returns:
the Comments to add to the XML Document

getSchemaNamespace

public org.jdom.Namespace getSchemaNamespace()
Get the schema namespace of the document, or the target namespace of there isn't one

Overrides:
getSchemaNamespace in class ReloadDocument
Returns:
the Schema Namespace of the Document, or the Target Namespace if there isn't one

getTargetNamespace

public org.jdom.Namespace getTargetNamespace()
Get the target schema namespace of the document

Returns:
the Target Schema Namespace of the Document

getElement

public org.jdom.Element getElement(ReloadSchemaElement schemaElement)
Return the 'first' found Element for the given DOM Path or null if not found

Returns:
the first found element for the given DOM Path or null if not found

getElement

public org.jdom.Element getElement(DomPath domPath)
Return the 'first' found Element for the given DOM Path or null if not found return the first found element for the given DOM Path or null if not found


getElements

public org.jdom.Element[] getElements(ReloadSchemaElement schemaElement)
Return all Elements for the given ReloadSchemaElement Path or an empty array


getElements

public org.jdom.Element[] getElements(DomPath domPath)
Return all Elements for the given DOM Path or null


addComments

protected void addComments(org.jdom.Document doc)
Add our signature comments to the XML Document

Parameters:
doc - the document to which the signature comments has to be added

destroy

public void destroy()
Cleanup


addElementUnique

public org.jdom.Element addElementUnique(java.lang.Object source,
                                         ReloadSchemaElement newSchemaElement,
                                         boolean doSelect)
Add a new Element given the Path in the ReloadSchemaElement. If the Element already exists, it won't be added

Parameters:
source - Who is adding it newSchemaElement the new schema element type we want to add doSelect true or false depending on whether the new added element should be selected or not on the user interface
Returns:
the added Element

addElementBySchemaUndoable

public org.jdom.Element addElementBySchemaUndoable(java.lang.Object source,
                                                   org.jdom.Element parentElement,
                                                   ReloadSchemaElement newSchemaElement,
                                                   boolean doSelect)
Add a new Element to the parent Element based on RELOADSchemaElement and register an Undo event. Create new JDOM Element based on childSchemaElement. Insert into the correct position!. Set any defaults of the Element. Add any default child Elements if needed.

Parameters:
source - who is telling us this
parentElement - the parent Element to add to
newSchemaElement - the Type of Element we want to add
doSelect - true or false depending on whether the new added element should be selected or not on the user interface

addElementBySchema

public org.jdom.Element addElementBySchema(java.lang.Object source,
                                           org.jdom.Element parentElement,
                                           ReloadSchemaElement newSchemaElement,
                                           boolean doSelect)
Add a new Element to the parent Element based on ReloadSchemaElement Create new JDOM Element based on childSchemaElement Insert into the correct position! Set any defaults of the Element Add any default child Elements if needed

Parameters:
source - who is telling us this
parentElement - the parent Element to add to
newSchemaElement - the Type of Element we want to add
doSelect - true or false depending on whether the new added element should be selected or not on the user interface

addElementUndoable

public org.jdom.Element addElementUndoable(java.lang.Object source,
                                           org.jdom.Element parentElement,
                                           org.jdom.Element childElement,
                                           boolean doSelect)
Just add a new Element. Listeners will only be notified once. Undo Event will be fired.

Parameters:
source - tho is telling us this parentElement the parent Element to add to childElement the child element to be added to the parent element doSelect true or false depending on whether the new added element should be selected or not on the user interface

addElement

public org.jdom.Element addElement(java.lang.Object source,
                                   org.jdom.Element parentElement,
                                   org.jdom.Element childElement,
                                   boolean doSelect)
Just add a new Element. Listeners will only be notified once. If the new Element has children it's up to the listener to handle them

Parameters:
source - who is telling us this parentElement the parent Element to add to childElement the child element to be added to the parent element doSelect true or false depending on whether the new added element should be selected or not on the user interface

addElementAtIndex

public org.jdom.Element addElementAtIndex(java.lang.Object source,
                                          org.jdom.Element parentElement,
                                          org.jdom.Element newElement,
                                          int index,
                                          boolean doSelect)
Add an Element at an index Position and Notify listeners

Parameters:
source - who is telling us this parentElement the parent Element to add to newElement the new element to be added to the parent element index the index position at which the new element has to be added doSelect true or false depending on whether the new added element should be selected or not on the user interface

deleteElementUndoable

public org.jdom.Element deleteElementUndoable(java.lang.Object source,
                                              org.jdom.Element element)
Delete a child Element from its parent and notify any listeners and Undo

Parameters:
source - who is telling us this
element - the Element to remove

cutElementUndoable

public org.jdom.Element cutElementUndoable(java.lang.Object source,
                                           org.jdom.Element element)
Cut a child Element from its parent and notify any listeners and Undo

Parameters:
source - who is telling us this
element - the Element to remove

removeElement

public org.jdom.Element removeElement(java.lang.Object source,
                                      org.jdom.Element element)
Remove a child Element from its parent and notify any listeners

Parameters:
source - who is telling us this
element - the Element to remove

moveElementUndoable

public org.jdom.Element moveElementUndoable(java.lang.Object source,
                                            org.jdom.Element element,
                                            org.jdom.Element newParent,
                                            boolean doSelect)
Move an Element to a new Parent

Parameters:
source - who is telling us this element the element to be moved newParent the new parent element doSelect true or false depending on whether the new added element should be selected or not on the user interface
Returns:
the Element moved

copyElementUndoable

public org.jdom.Element copyElementUndoable(java.lang.Object source,
                                            org.jdom.Element element,
                                            org.jdom.Element newParent,
                                            boolean doSelect)
Copy an Element to a new Parent

Parameters:
source - who is telling us this element the element to be copied newParent the new parent element doSelect true or false depending on whether the new added element should be selected or not on the user interface
Returns:
the Element copied

pasteElementUndoable

public org.jdom.Element pasteElementUndoable(java.lang.Object source,
                                             org.jdom.Element element,
                                             org.jdom.Element newParent,
                                             boolean doSelect)
Paste an Element to a new Parent

Parameters:
source - who is telling us this element the element to be pasted newParent the new parent element doSelect true or false depending on whether the new added element should be selected or not on the user interface
Returns:
the Element pasted

moveElementUp

public org.jdom.Element moveElementUp(java.lang.Object source,
                                      org.jdom.Element element,
                                      boolean doSelect)
Move an Element up one place

Parameters:
source - who is telling us this element the element to be moved up doSelect true or false depending on whether the new added element should be selected or not on the user interface
Returns:
the Element moved

moveElementDown

public org.jdom.Element moveElementDown(java.lang.Object source,
                                        org.jdom.Element element,
                                        boolean doSelect)
Move an Element down one place

Parameters:
source - who is telling us this element the element to be moved down doSelect true or false depending on whether the new added element should be selected or not on the user interface
Returns:
the Element moved

changedElement

public void changedElement(java.lang.Object source,
                           org.jdom.Element element)
Somebody has notified us that they have changed an Element in some way. We will notify all listeners.

Parameters:
source - who is telling us this
element - the Element that changed

canAddElement

public boolean canAddElement(org.jdom.Element parentElement,
                             ReloadSchemaElement childSchemaElement)
Decide whether a child Element can be added to a parent Element by max amount

Parameters:
parentElement - the parent Element to which we wish to add
childSchemaElement - the SchemaElement of the child to add
Returns:
true if we can add it, or false if not

isAllowedChild

public boolean isAllowedChild(org.jdom.Element parentElement,
                              org.jdom.Element childElement)
Decide whether a child is allowed or not depending on the schema rules

Parameters:
parentElement - the parent element to which we wish to add childElement the child element to add
Returns:
true if we are allowed (per Schema rules) to add a child, false otherwise

canDeleteElement

public boolean canDeleteElement(org.jdom.Element element,
                                ReloadSchemaElement schemaElement)
Decide whether a Element can be deleted

Parameters:
element - the Element which we wish to delete
schemaElement - the SchemaElement of the Element
Returns:
true if we can delete it, or false if not

canCopyElement

public boolean canCopyElement(org.jdom.Element element)
Decides whether an element can be copied or not - will need to override this

Parameters:
element - the element which we are testing
Returns:
true if we can copy the element, false otherwise

canCutElement

public boolean canCutElement(org.jdom.Element element,
                             ReloadSchemaElement schemaElement)
Decides whether we can cut an element - will need to override this

Parameters:
element - the element which we are testing schemaElement the schemaElement against which we are testing
Returns:
true if we can cut an element, false otherwise

canPasteFromClipboard

public boolean canPasteFromClipboard(org.jdom.Element element)
Decides whether we can paste an element - will need to override this

Parameters:
element - the element which we are testing
Returns:
true if we can paste an element, false otherwise

canMoveElementUp

public boolean canMoveElementUp(org.jdom.Element element)
Decides whether we can move the element up by one place

Parameters:
element - the element which we are testing
Returns:
true if we can move an element, false otherwise

canMoveElementDown

public boolean canMoveElementDown(org.jdom.Element element)
Decides whether we can move the element down by one place

Parameters:
element - the element which we are testing
Returns:
true if we can move the element, false otherwise

addAttribute

public org.jdom.Attribute addAttribute(java.lang.Object source,
                                       org.jdom.Element parentElement,
                                       ReloadSchemaAttribute newSchemaAttribute)
Create and Add a new Attribute to a given Element as per the Schema

Parameters:
source - who is telling us this parentElement the parent element to which we wish to add newSchemaAttribute the new schema attribute we wish to add to the parent element
Returns:
The created attribute or null if it cannot be done

getIndexOfElement

public static int getIndexOfElement(org.jdom.Element element)
Get the index position of an element in relation to its parent

Parameters:
element - the element for which we require the index position
Returns:
the index position of an Element in relation to its parent

getInsertPositionOfElement

public static int getInsertPositionOfElement(org.jdom.Element parentElement,
                                             ReloadSchemaElement newSchemaElement)
Get the correct position to insert an element according to the Schema

Parameters:
parentElement - the parent element to which the new element is to be added newSchemaElement the type of Element we want to add
Returns:
the correct position to insert the element in the parent element

getInsertPositionOfAttribute

public static int getInsertPositionOfAttribute(org.jdom.Element parentElement,
                                               ReloadSchemaAttribute reloadSchemaAttribute)
Get the correct position to insert an Attribute in an Element according to the Schema

Parameters:
parentElement - the parent element to which the new attribute is to be added reloadSchemaAttribute the type of attribute we want to add
Returns:
the correct position to insert the Attribute in the parent Element

addReloadDocumentListener

public void addReloadDocumentListener(ReloadDocumentListener listener)
Add a ReloadDocumentListener

Parameters:
listener - The ReloadDocumentListener

removeReloadDocumentListener

public void removeReloadDocumentListener(ReloadDocumentListener listener)
Remove a ReloadDocumentListener

Parameters:
listener - The ReloadDocumentListener

fireElementAdded

public void fireElementAdded(ReloadDocumentListenerEvent event)
Tell our listeners that we have added a new Element

Parameters:
event - the ReloadDocumentListenerEvent

fireElementRemoved

public void fireElementRemoved(ReloadDocumentListenerEvent event)
Tell our listeners that we have deleted an Element

Parameters:
event - the ReloadDocumentListenerEvent

fireElementChanged

public void fireElementChanged(ReloadDocumentListenerEvent event)
Tell our listeners that we have changed an Element

Parameters:
event - the ReloadDocumentListenerEvent

fireDocumentSaved

public void fireDocumentSaved()
Tell our listeners that we have saved


setUndoHandler

public void setUndoHandler(UndoHandler undoHandler)
Set the undo handler for this document


getUndoHandler

public UndoHandler getUndoHandler()
Get the undo handler for this document


VdexReload 1.1.3 API