mail.communication
Class CPackage

java.lang.Object
  extended by mail.communication.CPackage
Direct Known Subclasses:
Add, ClosestReply, ClosestRequest, MailReply, MailRequest, NameReply, NameRequest, NameStore, NeighborReply, NeighborRequest, NodeReply, NodeRequest, Store

public abstract class CPackage
extends java.lang.Object

Author:
Arne Müller

Field Summary
protected  Communicator comm
          the communicator this package was / will be send with.
static java.util.Hashtable<java.lang.String,java.lang.Class<? extends CPackage>> packages
           
 
Constructor Summary
protected CPackage(Communicator c)
          Initializes this Package with specified Communicator
 
Method Summary
protected abstract  void build(org.w3c.dom.Element main, Address sender)
          Exactly the Information, that was created by buildContent(Document) needs to be parsed.
protected abstract  org.w3c.dom.Element buildContent(org.w3c.dom.Document d)
          builds an Element for the given Document out of this package.
static CPackage buildPackage(Communicator c, org.w3c.dom.Document d, Address sender)
          builds the package specified by the XML-Document.
protected abstract  java.lang.String getName()
           
abstract  void performAction(LocalNode local)
          the data of this package should also have some use, so perform an action on the local node
protected static void registerPackage(java.lang.Class<? extends CPackage> c, java.lang.String name)
           
 org.w3c.dom.Document send()
          parses this Package into a XML-Document, so this package can be send
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

packages

public static java.util.Hashtable<java.lang.String,java.lang.Class<? extends CPackage>> packages

comm

protected Communicator comm
the communicator this package was / will be send with.

Constructor Detail

CPackage

protected CPackage(Communicator c)
Initializes this Package with specified Communicator

Parameters:
c - the Communicator to initialize with
Method Detail

build

protected abstract void build(org.w3c.dom.Element main,
                              Address sender)
                       throws PackageBuildException
Exactly the Information, that was created by buildContent(Document) needs to be parsed.

Parameters:
c - the Communicator, where the Data came from
Throws:
PackageBuildException

buildContent

protected abstract org.w3c.dom.Element buildContent(org.w3c.dom.Document d)
                                             throws PackageBuildException
builds an Element for the given Document out of this package. This needs to be done, to be able to send packages over the network.

Parameters:
d - the Document needed to build the Element
Returns:
the Element containing all essential information about this instance
Throws:
PackageBuildException

send

public org.w3c.dom.Document send()
                          throws PackageBuildException
parses this Package into a XML-Document, so this package can be send

Returns:
the Package ready for sending
Throws:
PackageBuildException

getName

protected abstract java.lang.String getName()

performAction

public abstract void performAction(LocalNode local)
the data of this package should also have some use, so perform an action on the local node

Parameters:
local -

buildPackage

public static CPackage buildPackage(Communicator c,
                                    org.w3c.dom.Document d,
                                    Address sender)
                             throws PackageBuildException
builds the package specified by the XML-Document. The class of the package to load is read and the rest of the loading is left to the Subclass

Parameters:
c - Communicator used for Communication
d - the data
Returns:
the loaded package
Throws:
PackageBuildException

registerPackage

protected static void registerPackage(java.lang.Class<? extends CPackage> c,
                                      java.lang.String name)