org.peace_tools.workspace
Class ServerList

java.lang.Object
  extended by org.peace_tools.workspace.ServerList

public class ServerList
extends java.lang.Object

A class to encapsulate information about a list of servers that have already been configured in this work space. This class is instantiated from the Work space class. This class is relatively straightforward in that it merely contains a list of Servers. In addition, it facilitates marshalling and unmarshalling of server data.


Field Summary
private  long seqCounter
          Sequence counter that is maintained on a per-work space basis to generate unique/valid IDs for each new server entry added to this list.
private  java.util.ArrayList<Server> servers
          The list of Server objects that have been configured and added to this list.
 
Constructor Summary
ServerList()
          The default constructor.
 
Method Summary
 void add(Server server)
          Method to add a new server entry to this server list.
static ServerList create(org.w3c.dom.Element serverNode)
          Helper method to utilize data from a DOM tree to create a suitable ServerList entry.
 Server getServer(java.lang.String serverID)
          Obtain reference to a Server object, given its work space wide unique server ID.
 java.util.ArrayList<Server> getServers()
          Obtain the list of Server objects that are currently available in a work space.
 void marshall(org.w3c.dom.Element workspace)
          Method to marshall the data stored in this object to become part of a DOM tree element passed in.
 void marshall(java.io.PrintWriter out)
          Method to marshall the data stored in this object directly to a XML fragement.
 void remove(Server server)
          Method to remove a server entry to this server list.
 java.lang.String reserveServerID()
          Reserves the next server ID for use in a server object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

servers

private java.util.ArrayList<Server> servers
The list of Server objects that have been configured and added to this list. This list is populated either via the create method or new entries are added via the addServer() method in this class.


seqCounter

private long seqCounter
Sequence counter that is maintained on a per-work space basis to generate unique/valid IDs for each new server entry added to this list.

Constructor Detail

ServerList

public ServerList()
The default constructor. It merely initializes all the instance variables to their default initial value.

Method Detail

create

public static ServerList create(org.w3c.dom.Element serverNode)
                         throws java.lang.Exception
Helper method to utilize data from a DOM tree to create a suitable ServerList entry. This method is typically used to create a suitable ServerList entry using data from a given DOM element. For each Server entry this method uses the Server.createServer method to create suitable Server entries.

Parameters:
serverNode - The DOM element to be used for creating the server list and to be used for creating the Server entries.
Returns:
The newly created ServerList entry based on the DOM data.
Throws:
java.lang.Exception - This method throws an exception when errors occur during reading and processing elements from the DOM node.

reserveServerID

public java.lang.String reserveServerID()
Reserves the next server ID for use in a server object. This method is used only when a new server object is added by the user. Server objects loaded from a file have their own server IDs.

Returns:
A new, unique (within the work space) server ID for use with a new Server object instance.

add

public void add(Server server)
Method to add a new server entry to this server list. This method sets a new server ID for the entry and fires a WorkspaceEvent indicating the addition of the new server entry to all listeners.

Parameters:
server - The new server entry to be added.

remove

public void remove(Server server)
Method to remove a server entry to this server list. This method must be used to remove a server entry from the server list. Once the entry has been removed, this method fires a WorkspaceEvent indicating the removal of the server entry to all listeners.

Parameters:
server - The new server entry to be removed.

getServer

public Server getServer(java.lang.String serverID)
Obtain reference to a Server object, given its work space wide unique server ID. This method does a linear search on the serverList to locate the server entry (if you have 1000s of server entries in one workspace then you are missing the concept of a workspace).

Parameters:
serverID - The generated work space wide unique server ID. Note that checks are case sensitive.
Returns:
Reference to a Server object whose serverID is the same as the supplied serverID. If a matching object was not found then this method returns null.

getServers

public java.util.ArrayList<Server> getServers()
Obtain the list of Server objects that are currently available in a work space.

Returns:
The list of Server objects that are currently available in this work space.

marshall

public final void marshall(org.w3c.dom.Element workspace)
Method to marshall the data stored in this object to become part of a DOM tree element passed in. This method assumes that the element passed in corresponds to the parent Workspace node in the DOM tree.

Parameters:
workspace - The DOM element corresponding to the Workspace node that contains this entry.

marshall

public final void marshall(java.io.PrintWriter out)
Method to marshall the data stored in this object directly to a XML fragement. The XML fragement is guaranteed to be compatible with the PEACE work space configuration data. This method provides better control on the XML formatting to generate a more readable XML output when compared to the DOM tree.

Parameters:
out - The stream to which the XML must be serialized.