org.bibalex.daf.entities.phase
Class FileElement

java.lang.Object
  extended by org.bibalex.daf.entities.phase.PhysicalElement
      extended by org.bibalex.daf.entities.phase.FileElement

public class FileElement
extends PhysicalElement

Represents the file definition within the physical section of a phase.
The FileElement capabilities are not limited to parsing XML and converting it to an object.
The following are also included:
1) Count the number of the files that match the definition in a given folder. See getFilesCount().
2) Copy the files that match the defintion form a given folder to another. See uploadFiles() and downloadFiles().
3) Get the number of modified files after a given date. See getModifiedFilesCount()

Author:
Shehab.Kamal

Field Summary
 boolean checkName
          The 'CheckName' property of the element.
 java.lang.String checkPattern
          The 'CheckPattern' of the element.
 java.lang.String compare
          The 'Compare' property of the element.
 java.lang.String count
          The 'Count' property of the element.
 java.lang.String name
          The 'Name' property of the element.
 boolean toDestination
          The 'ToDestination' property of the element.
 java.lang.String type
          The 'Type' property of the element.
 
Constructor Summary
FileElement()
          Creates a new instance of FileElement.
FileElement(org.w3c.dom.Node node)
          Creates a new instance of FileElement.
FileElement(java.lang.String nodeRep)
          Creates a new instance of FileElement.
FileElement(java.lang.String name, java.lang.String type, java.lang.String count, boolean toDestination, java.lang.String compare, boolean checkName, java.lang.String chekPattern)
          Creates a new instance of FileElement.
 
Method Summary
private  void createElementFromNode(org.w3c.dom.Node node)
          Creates the file element by supplying its XmlNode represenation.
 boolean downloadFiles(java.lang.String source, java.lang.String destination, FileHandler handler)
          Download the files that match this definition from the source folder to the destination folder.
 int getFilesCount(java.lang.String path, FileHandler handler, java.lang.String jobName)
          Gets the number of files within the given folder that match the FileElement.
 int getModifiedFilesCount(java.lang.String path, FileHandler handler, java.util.Date startDate)
          Gets the number of the files, macthing the defintion, modified after startDate within the given folder.
private  boolean isValidFileName(java.lang.String fileName, java.lang.String jobName)
          Determines if the given file name is valid or not.
A valid file name is the one matching the 'CheckPattern' attribute.
 void makeReadOnly(java.lang.String path, FileHandler handler)
          Tries to make the given files, matching the definition, read only.
 java.lang.String toString()
          Returns the string representation of this object.
 java.lang.String toXmlString()
          Returns a String representing the FileElement in xml format.
 boolean uploadFiles(java.lang.String source, java.lang.String destination, FileHandler handler)
          Upload the files that match this definition from the source folder to the destination folder.
 
Methods inherited from class org.bibalex.daf.entities.phase.PhysicalElement
createElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public java.lang.String name
The 'Name' property of the element.


toDestination

public boolean toDestination
The 'ToDestination' property of the element.


type

public java.lang.String type
The 'Type' property of the element.


count

public java.lang.String count
The 'Count' property of the element.


compare

public java.lang.String compare
The 'Compare' property of the element.


checkName

public boolean checkName
The 'CheckName' property of the element.


checkPattern

public java.lang.String checkPattern
The 'CheckPattern' of the element.

Constructor Detail

FileElement

public FileElement(java.lang.String name,
                   java.lang.String type,
                   java.lang.String count,
                   boolean toDestination,
                   java.lang.String compare,
                   boolean checkName,
                   java.lang.String chekPattern)
Creates a new instance of FileElement.

Parameters:
name - The 'Name' property of the element.
toDestination - The 'ToDestination' property of the element.
type - The 'Type' property of the element.
count - The 'Count' property of the element.
compare - The 'Compare' property of the element.
checkName - The 'CheckName' property of the element.
chekPattern - The 'CheckPattern' property of the element.

FileElement

public FileElement()
Creates a new instance of FileElement.


FileElement

public FileElement(org.w3c.dom.Node node)
            throws PhaseDefinitionException
Creates a new instance of FileElement.

Parameters:
node - The Xml Node representing this element.
Throws:
PhaseDefinitionException - If the given node couldn't be parsed.

FileElement

public FileElement(java.lang.String nodeRep)
            throws PhaseDefinitionException
Creates a new instance of FileElement.

Parameters:
nodeRep - The Xml String representing this element.
Throws:
PhaseDefinitionException - If the given String couldn't be parsed.
Method Detail

createElementFromNode

private void createElementFromNode(org.w3c.dom.Node node)
                            throws PhaseDefinitionException
Creates the file element by supplying its XmlNode represenation.

Parameters:
node - The Xml Node representing this element.
Throws:
PhaseDefinitionException - If the node name is not 'File' or attributes are missing.

toString

public java.lang.String toString()
Returns the string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
The string representation of this object.

toXmlString

public java.lang.String toXmlString()
Returns a String representing the FileElement in xml format.

Specified by:
toXmlString in class PhysicalElement
Returns:
A String representing the FileElement in xml format.

getFilesCount

public int getFilesCount(java.lang.String path,
                         FileHandler handler,
                         java.lang.String jobName)
Gets the number of files within the given folder that match the FileElement. Notes:
If the FileElement 'CheckName' attribute is set to true the files names is validated against the pattern described in 'CheckPattern' attribute.

Parameters:
path - The path of the folder containing the files.
handler - The handler to get the count of files.
jobName - The name of the job. It is used to validate the file names.
Returns:
The number of files within the given folder that match the defintion.

isValidFileName

private boolean isValidFileName(java.lang.String fileName,
                                java.lang.String jobName)
Determines if the given file name is valid or not.
A valid file name is the one matching the 'CheckPattern' attribute.

Parameters:
fileName - The name of the file including the extension.
jobName - The name of the job folder.
Note: The jobName is assumed to be a valid integer.
Returns:
True if the file name is valid otherwise false.

downloadFiles

public boolean downloadFiles(java.lang.String source,
                             java.lang.String destination,
                             FileHandler handler)
Download the files that match this definition from the source folder to the destination folder.

Parameters:
source - The complete path of the source folder to download the files from.
destination - The complete path of the destination folder to download the files to.
handler - The FileHandler used to download the files.
Returns:
True if the files has been downloaded successfully otherwise false.

uploadFiles

public boolean uploadFiles(java.lang.String source,
                           java.lang.String destination,
                           FileHandler handler)
Upload the files that match this definition from the source folder to the destination folder.

Parameters:
source - The complete path of the source folder to uplaod the files from.
destination - The complete path of the destination folder to upload the files to.
handler - The FileHandler used to upload the files.
Returns:
True if the files has been uploaded successfully otherwise false.

getModifiedFilesCount

public int getModifiedFilesCount(java.lang.String path,
                                 FileHandler handler,
                                 java.util.Date startDate)
Gets the number of the files, macthing the defintion, modified after startDate within the given folder.

Parameters:
path - The path of the folder containing the files.
handler - The handler to get the count of files.
startDate - The date to count the files modified after it. This parameter can be null.
Returns:
The number of files modified after the given date.
If the start date is not specified all the files are considered as modified.
-1 in the following cases: 1) If path is null or empty string 2) If handler is null 3) If the files within the folder couldn't be obtained.

makeReadOnly

public void makeReadOnly(java.lang.String path,
                         FileHandler handler)
Tries to make the given files, matching the definition, read only.

Parameters:
path - The path of the folder containing the files.
handler - The FileHandler used to get the files.