com.cysols.iodef.transport
Class IodefXMLFileSender

java.lang.Object
  extended by com.cysols.iodef.transport.IodefXMLFileSender

public abstract class IodefXMLFileSender
extends Object

This class provides a IODEF message transfer API via network through the various ways. This class is an abstract class and its concrete sub class implements transport method. An actual way to transport messages is implemented in the method. It is possible to call sendAllXMLFiles method after preparing the concrete transport mehotd; it will send XML files by using Email, FTP, etc. By giving a Properties instance to its constructor, this class can have it as configuration parameter and can use it in the sub class.

sendAllXMLFiles method calls transport method and moves the sent file to COMPLETE_DIR. The dierectory is obtained from the configuration parameter. The sent files will be preserved under the directory.

In sendAllXMLFiles method, "notifySuccess" method is called when the xml file is sent correctly or "notifyFailure" method is called if it is unable to send the xml file. This abstract class has empty implementations of them. The concrete sub class needs their orver-ridden methods in which Logging, Notification or something will be implemented.

The concrete sub class of this abstract class will have the following implementation.

   public class MyOwnSender extends IodefXMLFileSender {
   
       public MyOwnSender(Properties prop) {
           super(prop);
           # Setting configuration parameters...
       }
       
       public  void transport(File xmlFile) throws FileNotFoundException, XMLReaderException, TransportFailedException {
            # Sending the xmlFile by using concrete way like EMail, FTP, etc
       }
       
       public void notifySuccess(File xmlFile) {
            # Logging the succeeded message
       }
       
       public void notifyFailure(File xmlFile, Throwable e) {
            # Logging the failure message.
       }
   
       public static void main(String[] args) {
             IodefXMLFileSender sender = null;

             Properties configuration = new Properties();
             # Prepares parameters and sets it to the configuration instance.

             sender = new MyOwnSender(configuration);
             int result = sender.sendAllXMLFiles();
             # Logging "result number files were sent"
         } 
    }
 


Field Summary
protected  Properties configProp
          A Properties instance variable in which configuration parameters for sending the xml file are kept.
static String DEFAULT_COMPLETED_DIR
          Default Completed directory in which the sent xml file is stored.
 
Constructor Summary
IodefXMLFileSender(Properties configProp)
          A Properties instance is required to its constructor.
IodefXMLFileSender(String configFilePath)
          A constructor with the specified configuration file of IODEF transporting.
 
Method Summary
protected  void copyToCompletedDir(File xmlFile)
          Copies a xml file to the completed dir.
 File[] listQueueDir(String queueDir)
          Returns an array of XML File instances from the specified Queue directory.
 void notifyFailure(File xmlFile, Throwable e)
          Called when the IODEF xml file could not be sent after sendAllXMLFiles method is called.
 void notifySuccess(File xmlFile)
          Called when the IODEF xml file is sent correctly after sendAllXMLFiles method is called.
 int sendAllXMLFiles(File[] xmlFiles)
          Sends the specified XML File instances.
abstract  void transport(File xmlFile)
          Sends a mail with attaching the specifid file.
 void transport(String xmlFilePath)
          Sends a XML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_COMPLETED_DIR

public static final String DEFAULT_COMPLETED_DIR
Default Completed directory in which the sent xml file is stored.

See Also:
Constant Field Values

configProp

protected Properties configProp
A Properties instance variable in which configuration parameters for sending the xml file are kept.

Constructor Detail

IodefXMLFileSender

public IodefXMLFileSender(String configFilePath)
                   throws FileNotFoundException,
                          IOException
A constructor with the specified configuration file of IODEF transporting. The properties file is loaded into configProp variable.

Parameters:
configFilePath - the file path of iodeftrans.conf.
Throws:
FileNotFoundException - the specified file is missing.
IOException - unable to read the specified file.

IodefXMLFileSender

public IodefXMLFileSender(Properties configProp)
A Properties instance is required to its constructor. The specified Properties instance is set into configProp variable.

Parameters:
configProp - properties of the IODEF configuration parameters.
Throws:
NullPointerException - thrown if the properties instance is NULL.
Method Detail

listQueueDir

public File[] listQueueDir(String queueDir)
Returns an array of XML File instances from the specified Queue directory.

Parameters:
queueDir - the specified Queue directory in which IODEF xml file is stored.
Returns:
an array of XML File instances.

sendAllXMLFiles

public int sendAllXMLFiles(File[] xmlFiles)
Sends the specified XML File instances. The results of Sending operation are logged into log dir.

Parameters:
xmlFiles - an array of IODEF XML File instances to be sent.

notifySuccess

public void notifySuccess(File xmlFile)
Called when the IODEF xml file is sent correctly after sendAllXMLFiles method is called. This concrete implementation will be in its sub class.

Parameters:
xmlFile - the sent file instance.

notifyFailure

public void notifyFailure(File xmlFile,
                          Throwable e)
Called when the IODEF xml file could not be sent after sendAllXMLFiles method is called. This concrete implementation will be in its sub class.

Parameters:
xmlFile - the sent file instance.
e - the cause of failure to store

transport

public void transport(String xmlFilePath)
               throws FileNotFoundException,
                      XMLReaderException,
                      TransportFailedException
Sends a XML file.

Parameters:
xmlFilePath - a XML file path
Throws:
FileNotFoundException - the specified file is missing.
XMLReaderException - the specfied XML file cannot be read correctly.
TransportFailedException - unable to send the xml file correctly.

transport

public abstract void transport(File xmlFile)
                        throws FileNotFoundException,
                               XMLReaderException,
                               TransportFailedException
Sends a mail with attaching the specifid file.

Parameters:
xmlFile - a XML File instance.
Throws:
FileNotFoundException - the specified file is missing.
XMLReaderException - the specfied XML file cannot be read correctly.
TransportFailedException - unable to send the xml file correctly.

copyToCompletedDir

protected void copyToCompletedDir(File xmlFile)
                           throws FileNotFoundException,
                                  IOException
Copies a xml file to the completed dir. It will be used after the xml file sending is succeeded. The dir to which the xml file is moved is specified by COMPLEETED_DIR key in configProp Properitis instance, otherwise DEFAULT_COMPLETED_DIR constant is used if it is not defined.

Parameters:
xmlFile - the xml file which is moved to the completed dir.
Throws:
FileNotFoundException - the specified file is missing.
IOException - thrown if IO Error occured.