verinec.data.repository
Class VerinecRepository

java.lang.Object
  extended by verinec.data.repository.VerinecRepository
All Implemented Interfaces:
IVerinecRepository
Direct Known Subclasses:
FileRepository, VerinecStudio.StudioRepository

public abstract class VerinecRepository
extends Object
implements IVerinecRepository

Abstract class implementing bases for the repository. IVerinecRepository implementors can inherit from this class to save some coding. Bases on a xml document containing all nodes. Classes using this base must make sure to always call super methods for all modifying operations or some methods will operate on outdated information.

Version:
$Revision: 998 $
Author:
david.buchmann at unifr.ch

Field Summary
private  Logger logger
           
protected  Element networks
          The network data.
protected  Document nodes
          The document containing the nodes.
protected  String projectName
          The name of the currently opened project.
protected  SchemaValidator validator
          Validator to check nodes and network before saving and after loading.
 
Constructor Summary
VerinecRepository(String project)
          Constructor for the base repository class.
 
Method Summary
 void drop()
          Drop network, that is remove all network connections and nodes information.
 Element getGlobals()
          Get the globals of the currently active project.
 Element getNode(String name)
          Get a network Node.
 String[] getNodeNames()
          Query all existing node names.
 Element getNodes()
          Get all nodes.
 List getNodesWithInterfaceIp(String ip)
          Get all nodes having a network interface with the specified ip.
 Element getPhysicalNetworks()
          Get the list of physical connections of this project.
 String getProjectName()
          This method is implemented here because normally, concrete implementations won't need added behaviour.
protected  void init()
          Initialise the nodes and networks variables with empty xml.
 void removeNode(String name)
          Remove the node, that is detach it from nodes.
 void setGlobals(Element e)
          Set new globals, overwriting the existing ones.
 void setNode(Element node)
          Set a network Node.
 void setNodes(Element newnodes)
          Overwrite all nodes and global values.
 void setPhysicalNetworks(Element physical)
          Set the physical networks of this project.
protected  void validateNetworks(Element networks)
          Tests a networks document for validity.
protected  void validateNode(Element node)
          Validate a node using the SchemaValidator.
protected  void validatePhysicalNetworks(Element physical)
          Tests a physical network for validity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface verinec.data.repository.IVerinecRepository
getProjectNames
 

Field Detail

logger

private Logger logger

nodes

protected Document nodes
The document containing the nodes. Initialised to empty document.


projectName

protected String projectName
The name of the currently opened project.


validator

protected SchemaValidator validator
Validator to check nodes and network before saving and after loading.


networks

protected Element networks
The network data.

Constructor Detail

VerinecRepository

public VerinecRepository(String project)
Constructor for the base repository class. It is used for setting the project name. Extending classes must have a constructor with this signature, because the RepositoryFactory will look for this one-arg constructor.

Parameters:
project - The name of the project to open.
Method Detail

init

protected void init()
Initialise the nodes and networks variables with empty xml.


getProjectName

public String getProjectName()
                      throws VerinecException
This method is implemented here because normally, concrete implementations won't need added behaviour. Returns the project name stored in the protected member variable projectName.

Specified by:
getProjectName in interface IVerinecRepository
Returns:
the name of the current project.
Throws:
VerinecException - if the project is not valid.

drop

public void drop()
          throws VerinecException
Drop network, that is remove all network connections and nodes information.

Specified by:
drop in interface IVerinecRepository
Throws:
VerinecException - If extending class runs into a problem.

getNodeNames

public String[] getNodeNames()
Query all existing node names.

Specified by:
getNodeNames in interface IVerinecRepository
Returns:
Array of String with names of all nodes that can be retreived using getNode().

getNode

public Element getNode(String name)
                throws VerinecException
Get a network Node. Names are unique within one project.

Specified by:
getNode in interface IVerinecRepository
Parameters:
name - Name of network node to retreived.
Returns:
The Jdom Element containing the specified node.
Throws:
VerinecException - If no node with that name exists in this project or if the stored node is invalid.

getNodesWithInterfaceIp

public List getNodesWithInterfaceIp(String ip)
                             throws VerinecException
Get all nodes having a network interface with the specified ip.

Specified by:
getNodesWithInterfaceIp in interface IVerinecRepository
Parameters:
ip - The ip address.
Returns:
All nodes having an interface with the specified ip.
Throws:
VerinecException - if anything goes wrong with xpath.

setNode

public void setNode(Element node)
             throws VerinecException
Set a network Node. If there is already a node with that name, it is overwritten. The node name is retreived from the passed XML structure.

Specified by:
setNode in interface IVerinecRepository
Parameters:
node - The Jdom Element of the node.
Throws:
VerinecException - If the node is invalid or an io error occurs.

removeNode

public void removeNode(String name)
                throws VerinecException
Remove the node, that is detach it from nodes.

Specified by:
removeNode in interface IVerinecRepository
Parameters:
name - of node to remove.
Throws:
VerinecException - if the node can not be found.

getNodes

public Element getNodes()
                 throws VerinecException
Get all nodes. Returns the internal jdom list.

Specified by:
getNodes in interface IVerinecRepository
Returns:
All nodes.
Throws:
VerinecException - if one of the nodes can not be retreived.

setNodes

public void setNodes(Element newnodes)
              throws VerinecException
Overwrite all nodes and global values. Removes all nodes from the project and adds all nodes under the <nodes> element in the parameter.

Specified by:
setNodes in interface IVerinecRepository
Parameters:
newnodes - Element containing all node elements of the projects and global data.
Throws:
VerinecException - if one of the nodes can not be set.

setGlobals

public void setGlobals(Element e)
                throws VerinecException
Set new globals, overwriting the existing ones. (Be careful to not forget stuff from other namespaces!)

Specified by:
setGlobals in interface IVerinecRepository
Parameters:
e - The nodes element with the new globals. Node children are ignored.
Throws:
VerinecException - if the parameter is not a valid nodes tag or other error occurs.

getGlobals

public Element getGlobals()
                   throws VerinecException
Get the globals of the currently active project.

Specified by:
getGlobals in interface IVerinecRepository
Returns:
Clone of globals under the nodes element
Throws:
VerinecException - if invalid database prevents returning the globals of project this repository is set to.

getPhysicalNetworks

public Element getPhysicalNetworks()
                            throws VerinecException
Get the list of physical connections of this project. Contrary to the nodes, the network data is cached and only read once.

Specified by:
getPhysicalNetworks in interface IVerinecRepository
Returns:
A clone of the "physical" element containing the network connections. This is no clone!
Throws:
VerinecException - if the stored file can not be read properly.

setPhysicalNetworks

public void setPhysicalNetworks(Element physical)
                         throws VerinecException
Set the physical networks of this project. todo: What should we do if the network is invalid because a node has been deleted? We do not want to loose the whole network.

Specified by:
setPhysicalNetworks in interface IVerinecRepository
Parameters:
physical - The new physical network definition for this project. It is cloned so the original parameter remains unchanged.
Throws:
VerinecException - if the networks can not be stored.

validateNode

protected void validateNode(Element node)
                     throws VerinecException
Validate a node using the SchemaValidator.

Parameters:
node - The node to be validated.
Throws:
VerinecException - if validation fails.

validateNetworks

protected void validateNetworks(Element networks)
                         throws VerinecException
Tests a networks document for validity. Adds the network to the node document because the ID/IDREF must be checked.

Parameters:
networks - The network to validate.
Throws:
VerinecException - if validation fails.

validatePhysicalNetworks

protected void validatePhysicalNetworks(Element physical)
                                 throws VerinecException
Tests a physical network for validity. Adds the network to the node document because the ID/IDREF must be checked.

Parameters:
physical - The network to validate.
Throws:
VerinecException - if validation fails.

Copyright © 2005 Verinec, DIUF