com.fg.xmleditor
Class FXDocumentModelImpl

java.lang.Object
  extended bycom.fg.ftree.DefaultFTreeModel
      extended bycom.fg.xmleditor.FXDocumentModelImpl
All Implemented Interfaces:
FTreeModel, FXDocumentModel, FXModel

public class FXDocumentModelImpl
extends DefaultFTreeModel
implements FXDocumentModel

XML editor data-model implementation class.

Version:
1.0
Author:
Felix Golubov

Constructor Summary
FXDocumentModelImpl()
           
 
Method Summary
 void addModelStatusListener(FXModelStatusListener listener)
          Registers FXModelStatusListener listener.
 void clear()
          Removes current XML document from data-model.
 void fireTreeModelDataChanged(boolean restructured)
          Method call causes a data-model object to notify all the registered FTreeModelListener listemers about document changes.
 java.lang.String[] getAvailableRootElementNames(java.lang.String ns)
          Returns an array of names of global non-abstract elements names for the given namespace.
 java.lang.String[] getAvailableRootNamespaces()
          Returns an array of namespaces which have global definitions of non-absract elements.
 org.w3c.dom.Document getDocument()
          Returns current XML document as a DOM Tree or null when data-model contains no document.
 java.lang.String getNodeMessage(FToggleNode node)
          Method returns a message for a node (XML element or attribute), which is specified in the respective "appinfo" element of the XML Shema document.
 java.util.Map getNSQualifiers()
          Returns a Map object, which contains namespaces (as keys) and namespace qualifiers (as values).
 java.lang.String getRootElementName()
          Returns a local name of the root XML element.
 java.lang.String getRootNamespace()
          Returns a namespace of the root XML element.
 java.net.URL getSchemaURL()
          Returns a URL of the current XML Schema document.
 java.lang.String getValidityMessage(FToggleNode node, java.lang.Object value)
          Method validates value with validation rules for the specified node and returns null when value is valid and an error message otherwise.
 FToggleNode insertInstance(FToggleNode arrayNode, int index)
          Insert a new FToggleNode instance of Element, Substitution Group or Model Group into an Array folder at the specified position.
 boolean isDocumentChanged()
          Method returns "changed" status for the current XML document.
 boolean isDocumentValid()
          Method returns validity status for the current XML document.
 void newDocument(java.net.URL schemaURL)
          Creates a new empty XML document for the specified XML Schema for the first available root namespace and element name found.
 void newDocument(java.net.URL schemaURL, java.lang.String elementName)
          Creates a new empty XML document for specified XML Schema and name of the root element.
 void newDocument(java.net.URL schemaURL, java.lang.String ns, java.lang.String elementName)
          Creates a new empty XML document for specified XML Schema and namespace and name of the root element.
 java.util.List openDocument(java.net.URL schemaURL, org.w3c.dom.Document doc)
          Opens an existing XML document with specified XML Schema.
 java.util.List openDocument(java.net.URL schemaURL, org.xml.sax.InputSource src)
          Opens an existing XML document with specified XML Schema.
 java.util.List openDocument(java.net.URL schemaURL, java.net.URL docURL)
          Opens an existing XML document with specified XML Schema.
 boolean populateNode(FToggleNode parentNode)
          Populates an empty Element node with all child nodes.
 int removeInstance(FToggleNode node)
          Removes specified FToggleNode instance of Element, Substitution Group or Model Group from an Array folder.
 void removeModelStatusListener(FXModelStatusListener listener)
          Unregisters FXModelStatusListener listener.
 void setDocumentChanged(boolean changed)
          Allows to set "changed" status for the current XML document programaticaly.
 void setFolderBackground(int type, java.awt.Color color)
          Sets background color for specified type of tree folders.
 void setNodeImage(int type, java.awt.Image image)
          Sets an image for the specified type of tree nodes.
 void setNodeValue(FToggleNode node, java.lang.Object newValue)
          Assignes a new value to specified FToggleNode node.
 void setNSQualifier(java.lang.String namespace, java.lang.String qualifier)
          Sets a namespace qualifier.
 void toggleSelectionChanged(FToggleNode node)
          Revalidates a tree after a toggle control (check-box or radio-button) of the specified node was selected or unselected.
 
Methods inherited from class com.fg.ftree.DefaultFTreeModel
addTreeModelListener, getAllowsChildren, getChild, getChildCount, getRoot, removeTreeModelListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.fg.ftree.FTreeModel
addTreeModelListener, getAllowsChildren, getChild, getChildCount, getRoot, removeTreeModelListener
 

Constructor Detail

FXDocumentModelImpl

public FXDocumentModelImpl()
Method Detail

setFolderBackground

public void setFolderBackground(int type,
                                java.awt.Color color)
Sets background color for specified type of tree folders. The folder type is specified by an integer constant declared in the XSRef class (or any number of these constants combined with | - bitwise OR operators).

Parameters:
type - a folder type - an integer constant declared in the XSRef class (or any number of these constants combined with | - bitwise OR operators).
color - a folder background.

setNodeImage

public void setNodeImage(int type,
                         java.awt.Image image)
Sets an image for the specified type of tree nodes. The node type is specified by an integer constant declared in the XSRef class (or any number of these constants combined with | - bitwise OR operators).

Parameters:
type - a node type - an integer constant declared in the XSRef class (or any number of these constants combined with | - bitwise OR operators).

addModelStatusListener

public void addModelStatusListener(FXModelStatusListener listener)
Registers FXModelStatusListener listener.

Specified by:
addModelStatusListener in interface FXModel
Parameters:
listener - FXModelStatusListener object.

removeModelStatusListener

public void removeModelStatusListener(FXModelStatusListener listener)
Unregisters FXModelStatusListener listener.

Specified by:
removeModelStatusListener in interface FXModel
Parameters:
listener - FXModelStatusListener object.

isDocumentChanged

public boolean isDocumentChanged()
Method returns "changed" status for the current XML document.

Specified by:
isDocumentChanged in interface FXModel
Returns:
"changed" status for the current XML document.

setDocumentChanged

public void setDocumentChanged(boolean changed)
Allows to set "changed" status for the current XML document programaticaly. For example, the status can be reset to false after the current document is saved.

Specified by:
setDocumentChanged in interface FXDocumentModel
Parameters:
changed - a "changed" boolean value

isDocumentValid

public boolean isDocumentValid()
Method returns validity status for the current XML document.

Specified by:
isDocumentValid in interface FXModel
Returns:
validity status for the current XML document.

fireTreeModelDataChanged

public void fireTreeModelDataChanged(boolean restructured)
Method call causes a data-model object to notify all the registered FTreeModelListener listemers about document changes.

Specified by:
fireTreeModelDataChanged in interface FXModel
Overrides:
fireTreeModelDataChanged in class DefaultFTreeModel
Parameters:
restructured - equals true if document was restructured (some nodes were deleted or added).

getSchemaURL

public java.net.URL getSchemaURL()
Returns a URL of the current XML Schema document.

Specified by:
getSchemaURL in interface FXDocumentModel
Returns:
a URL of the current XML Schema document

getAvailableRootNamespaces

public java.lang.String[] getAvailableRootNamespaces()
Returns an array of namespaces which have global definitions of non-absract elements.

Specified by:
getAvailableRootNamespaces in interface FXDocumentModel
Returns:
an array of namespaces which have global definitions of non-absract elements.

getAvailableRootElementNames

public java.lang.String[] getAvailableRootElementNames(java.lang.String ns)
Returns an array of names of global non-abstract elements names for the given namespace.

Specified by:
getAvailableRootElementNames in interface FXDocumentModel
Parameters:
ns - a namespace URI
Returns:
an array of names of global non-abstract elements names for given namespace.

getRootNamespace

public java.lang.String getRootNamespace()
Returns a namespace of the root XML element.

Specified by:
getRootNamespace in interface FXModel
Returns:
a namespace of the root XML element

getRootElementName

public java.lang.String getRootElementName()
Returns a local name of the root XML element.

Specified by:
getRootElementName in interface FXModel
Returns:
a local name of the root XML element

newDocument

public void newDocument(java.net.URL schemaURL)
                 throws FXModelException
Creates a new empty XML document for the specified XML Schema for the first available root namespace and element name found.

Specified by:
newDocument in interface FXDocumentModel
Parameters:
schemaURL - a URL of the XML Schema document
Throws:
FXModelException - when specified XML document can't be created

newDocument

public void newDocument(java.net.URL schemaURL,
                        java.lang.String elementName)
                 throws FXModelException
Creates a new empty XML document for specified XML Schema and name of the root element. Method tries to find a namespace, which contains definition of the required root element and throws FXModelException when no such namespace found.

Specified by:
newDocument in interface FXDocumentModel
Parameters:
schemaURL - a URL of the XML Schema document
elementName - a local name of the root XML element
Throws:
FXModelException - when specified XML document can't be created

newDocument

public void newDocument(java.net.URL schemaURL,
                        java.lang.String ns,
                        java.lang.String elementName)
                 throws FXModelException
Creates a new empty XML document for specified XML Schema and namespace and name of the root element.

Specified by:
newDocument in interface FXDocumentModel
Parameters:
schemaURL - a URL of the XML Schema document
ns - a namespace of the root XML element
elementName - a local name of the root XML element
Throws:
FXModelException - when specified XML document can't be created

openDocument

public java.util.List openDocument(java.net.URL schemaURL,
                                   org.w3c.dom.Document doc)
                            throws FXModelException
Opens an existing XML document with specified XML Schema. The XML document is passed as a DOM tree.

Specified by:
openDocument in interface FXDocumentModel
Parameters:
schemaURL - a URL of the XML Schema document
doc - a Document object, which holds existing XML document
Returns:
a list of the org.w3c.dom.Element elements, which have not been loaded because of the document structural invalidity or null if the whole document has been loaded successfully.
Throws:
FXModelException - when specified XML document can't be opened with the specified XML Schema.

openDocument

public java.util.List openDocument(java.net.URL schemaURL,
                                   java.net.URL docURL)
                            throws FXModelException
Opens an existing XML document with specified XML Schema. The XML document is specified by the URL parameter.

Specified by:
openDocument in interface FXDocumentModel
Parameters:
schemaURL - a URL of the XML Schema document
docURL - a URL of the XML document
Returns:
a list of the org.w3c.dom.Element elements, which have not been loaded because of the document structural invalidity or null if the whole document has been loaded successfully.
Throws:
FXModelException - when specified XML document can't be opened with the specified XML Schema.

openDocument

public java.util.List openDocument(java.net.URL schemaURL,
                                   org.xml.sax.InputSource src)
                            throws FXModelException
Opens an existing XML document with specified XML Schema. The XML document is specified by the InputSource parameter.

Specified by:
openDocument in interface FXDocumentModel
Parameters:
schemaURL - a URL of the XML Schema document
src - an InputSource for the XML document
Returns:
a list of the org.w3c.dom.Element elements, which have not been loaded because of the document structural invalidity or null if the whole document has been loaded successfully.
Throws:
FXModelException - when specified XML document can't be opened with the specified XML Schema.

clear

public void clear()
Removes current XML document from data-model.

Specified by:
clear in interface FXDocumentModel

populateNode

public boolean populateNode(FToggleNode parentNode)
Populates an empty Element node with all child nodes. Performs operation and returns true when operation is allowed and does nothing and returns false otherwise.

Specified by:
populateNode in interface FXModel
Parameters:
parentNode - FToggleNode object, which represents XML Element node.
Returns:
true when operation is allowed and false otherwise.

insertInstance

public FToggleNode insertInstance(FToggleNode arrayNode,
                                  int index)
Insert a new FToggleNode instance of Element, Substitution Group or Model Group into an Array folder at the specified position. If an instance can be inserted, the method returns reference to the new instance, otherwise it returns null.

Specified by:
insertInstance in interface FXModel
Parameters:
arrayNode - FToggleNode object, which represents Array folder node.
Returns:
a reference to the inserted instance or null when operation is not allowed.

removeInstance

public int removeInstance(FToggleNode node)
Removes specified FToggleNode instance of Element, Substitution Group or Model Group from an Array folder. If an instance can be removed, the method returns a former index of the removed instance within Array folder, otherwise it returns -1.

Specified by:
removeInstance in interface FXModel
Parameters:
node - FToggleNode object, which represents instance to be removed.
Returns:
a former index of the removed instance within Array folder or -1 when operation is not allowed.

toggleSelectionChanged

public void toggleSelectionChanged(FToggleNode node)
Revalidates a tree after a toggle control (check-box or radio-button) of the specified node was selected or unselected.

Specified by:
toggleSelectionChanged in interface FXModel
Parameters:
node - FToggleNode object, whose toggle control (check-box or radio-button) node was selected or unselected.

setNodeValue

public void setNodeValue(FToggleNode node,
                         java.lang.Object newValue)
Assignes a new value to specified FToggleNode node.

Specified by:
setNodeValue in interface FXModel
Parameters:
node - FToggleNode object, to which new value will be assigned.
newValue - a value to be assigned to the specified node.

getValidityMessage

public java.lang.String getValidityMessage(FToggleNode node,
                                           java.lang.Object value)
Method validates value with validation rules for the specified node and returns null when value is valid and an error message otherwise.

Specified by:
getValidityMessage in interface FXModel
Parameters:
node - FToggleNode object.
value - an Object value to be validated.
Returns:
null if value is valid and error message otherwise

getNodeMessage

public java.lang.String getNodeMessage(FToggleNode node)
Method returns a message for a node (XML element or attribute), which is specified in the respective "appinfo" element of the XML Shema document.

Specified by:
getNodeMessage in interface FXModel
Parameters:
node - FToggleNode object.

getNSQualifiers

public java.util.Map getNSQualifiers()
Returns a Map object, which contains namespaces (as keys) and namespace qualifiers (as values). The returned Map is a clone of an internal Map, so its changes don't affect the actual data. To assign custom qualifiers use setNSQualifier(String, String) methods.

Specified by:
getNSQualifiers in interface FXModel
Returns:
a Map object, which contains namespaces (as keys) and namespace qualifiers (as values).

setNSQualifier

public void setNSQualifier(java.lang.String namespace,
                           java.lang.String qualifier)
Sets a namespace qualifier.

Specified by:
setNSQualifier in interface FXModel
Parameters:
namespace - a namespace URI
qualifier - a namespace qualifier

getDocument

public org.w3c.dom.Document getDocument()
Returns current XML document as a DOM Tree or null when data-model contains no document.

Specified by:
getDocument in interface FXDocumentModel
Returns:
a Document object.