uk.org.ogsadai.client.toolkit.activity.files
Class FileWriting

java.lang.Object
  |
  +--uk.org.ogsadai.client.toolkit.activity.RequestComponent
        |
        +--uk.org.ogsadai.client.toolkit.activity.Activity
              |
              +--uk.org.ogsadai.client.toolkit.activity.files.FileWriting
Direct Known Subclasses:
FileAppend, FileDelete, FileInsert, FileReplace

public abstract class FileWriting
extends Activity

An OGSA-DAI file writing activity. This class is the superclass of all activities which use OGSA-DAI's fileWritingActivity activity.

Author:
The OGSA-DAI Project Team

Field Summary
static int APPEND
          Indicates an append action.
static int BOF
          An offset denoting the beginning of the file or a line.
static int DELETE
          Indicates a delete action.
static int EOF
          An offset denoting the end of the file or a file.
static int INSERT
          Indicates an insert action.
protected  int mAction
          The particular kind of file writing that will take place.
protected  java.lang.String mFilename
          The filename of the file to write to.
protected  int mLength
          The number of bytes length over which the writing will occur.
protected  java.lang.String mMatch
          An expression of the instances of matches of the regular expression to deal with.
protected  int mOffset
          The number of bytes offset from which the writing will occur.
protected  boolean mPerLine
          Indicates whether the action will be performed on a per-line or per-file basis.
protected  java.lang.String mRegexp
          The regular expression to use to locate the part of the file to write to.
protected  java.lang.String mText
          The text to use in the file writing.
static int NONE_SPECIFIED
          A value denoting the uninitialised nature of the length or offset.
static boolean PER_FILE
          Denotes that the action should be applied once on the whole file.
static boolean PER_LINE
          Denotes that the action should be applied on each line.
static int REPLACE
          Indicates a replacement action.
static int TO_EOF
          Denotes the remaining length to the end of the file or line.
 
Constructor Summary
FileWriting()
          Default constructor.
 
Method Summary
static java.lang.String actionToString(int action)
          Return a textual description of a given action type.
protected  java.lang.String generateXML()
          Generate a perform document with parameters corresponding to the state of the instance variables.
 java.lang.String getFilename()
          Return the filename of the file to write to.
 int getLength()
          Return the length to use.
 java.lang.String getMatch()
          Return the match expression, if any.
 int getOffset()
          Return the offset to use.
 java.lang.String getRegexp()
          Return the regular expression to be used, if any.
 java.lang.String getText()
          Return the directly quoted input text, if any.
 boolean isPerLine()
          Return whether the action is to be performed on a per-line or per-file basis.
static java.lang.String lengthToString(int length)
          Convert an integer representation of a length into an equivalent string, also taking care to convert the special value TO_EOF into the string "toEOF".
static java.lang.String offsetToString(int offset)
          Convert an integer representation of an offset into an equivalent string, also taking care to convert special values BOF and EOF into corresponding strings.
 void setFilename(java.lang.String string)
          Set the filename of the file to write to.
 void setInput(ActivityOutput input)
          Specify the source from which the input text will be obtained.
 void setLength(int i)
          Set the length to use.
 void setMatch(java.lang.String string)
          Set the match expression.
 void setOffset(int i)
          Set the offset to use.
 void setPerLine(boolean b)
          Return whether the action is to be performed on a per-line or per-file basis.
 void setRegexp(java.lang.String string)
          Set the regular expression to be used.
 void setText(java.lang.String string)
          Specify the input text to use.
protected  void validateParams()
          Test the supplied parameters to check that they are within acceptable bounds.
 
Methods inherited from class uk.org.ogsadai.client.toolkit.activity.Activity
addInput, addOutput, addOutputs, getDataResourceID, getDataServiceStub, getInputParameters, getOutputParameters, getOutputs, replaceSpecialCharacters, setDataResourceID, setDataServiceStub, setInput
 
Methods inherited from class uk.org.ogsadai.client.toolkit.activity.RequestComponent
getName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REPLACE

public static final int REPLACE
Indicates a replacement action.

See Also:
Constant Field Values

DELETE

public static final int DELETE
Indicates a delete action.

See Also:
Constant Field Values

APPEND

public static final int APPEND
Indicates an append action.

See Also:
Constant Field Values

INSERT

public static final int INSERT
Indicates an insert action.

See Also:
Constant Field Values

NONE_SPECIFIED

public static final int NONE_SPECIFIED
A value denoting the uninitialised nature of the length or offset.

See Also:
Constant Field Values

BOF

public static final int BOF
An offset denoting the beginning of the file or a line.

See Also:
Constant Field Values

EOF

public static final int EOF
An offset denoting the end of the file or a file.

See Also:
Constant Field Values

TO_EOF

public static final int TO_EOF
Denotes the remaining length to the end of the file or line.

See Also:
Constant Field Values

PER_LINE

public static final boolean PER_LINE
Denotes that the action should be applied on each line.

See Also:
Constant Field Values

PER_FILE

public static final boolean PER_FILE
Denotes that the action should be applied once on the whole file.

See Also:
Constant Field Values

mAction

protected int mAction
The particular kind of file writing that will take place. One of {REPLACE, DELETE, APPEND, INSERT}.


mFilename

protected java.lang.String mFilename
The filename of the file to write to.


mRegexp

protected java.lang.String mRegexp
The regular expression to use to locate the part of the file to write to.


mMatch

protected java.lang.String mMatch
An expression of the instances of matches of the regular expression to deal with.


mOffset

protected int mOffset
The number of bytes offset from which the writing will occur.


mLength

protected int mLength
The number of bytes length over which the writing will occur.


mText

protected java.lang.String mText
The text to use in the file writing.


mPerLine

protected boolean mPerLine
Indicates whether the action will be performed on a per-line or per-file basis. Iff true, it is performed on a per-line basis, meaning that the offset and length will be treated as per-line offsets, and the regular expression match expression will be interpreted on a per-line basis. The special values EOF, BOF and TO_EOF take on meanings relevant to either files or lines.

Constructor Detail

FileWriting

public FileWriting()
Default constructor. Initialises the dummy output from the activity.

Method Detail

validateParams

protected void validateParams()
Test the supplied parameters to check that they are within acceptable bounds. In particular, the filename must not be null and the offset and length, if supplied, must be non-negative.

Throws:
java.lang.IllegalArgumentException - if any argument is without its bounds

setInput

public void setInput(ActivityOutput input)
Specify the source from which the input text will be obtained.

Parameters:
input - the source of the text
Throws:
java.lang.IllegalArgumentException - if the argument is null

generateXML

protected java.lang.String generateXML()
Generate a perform document with parameters corresponding to the state of the instance variables.

The three main variables here are:

  1. The action type: replace, append, delete or insert
  2. Whether we use regular expressions or an offset and length combination
  3. Whether the input text is directly supplied or sourced from the output of another activity

Specified by:
generateXML in class Activity
Returns:
the XML for the activity

offsetToString

public static java.lang.String offsetToString(int offset)
Convert an integer representation of an offset into an equivalent string, also taking care to convert special values BOF and EOF into corresponding strings.

Parameters:
offset - the integer to convert
Returns:
the string representation of the provided integer

lengthToString

public static java.lang.String lengthToString(int length)
Convert an integer representation of a length into an equivalent string, also taking care to convert the special value TO_EOF into the string "toEOF".

Parameters:
length - the integer to convert
Returns:
the string representation of the provided integer

actionToString

public static java.lang.String actionToString(int action)
Return a textual description of a given action type.

Parameters:
action - an action type; one of {REPLACE, DELETE, APPEND, INSERT}
Returns:
a corresponding string, or "unknownAction" if the supplied parameter is not recognised

getFilename

public java.lang.String getFilename()
Return the filename of the file to write to.

Returns:
the filename

getMatch

public java.lang.String getMatch()
Return the match expression, if any.

Returns:
the match expression or null

isPerLine

public boolean isPerLine()
Return whether the action is to be performed on a per-line or per-file basis.

Returns:
true if the action is to be performed per-line;
false if the action is to be performed per-file.

getRegexp

public java.lang.String getRegexp()
Return the regular expression to be used, if any.

Returns:
the regular expression or null

getText

public java.lang.String getText()
Return the directly quoted input text, if any.

Returns:
the input text or null

setFilename

public void setFilename(java.lang.String string)
Set the filename of the file to write to.

Parameters:
string - the filename

setMatch

public void setMatch(java.lang.String string)
Set the match expression.

Parameters:
string - the match expression

setPerLine

public void setPerLine(boolean b)
Return whether the action is to be performed on a per-line or per-file basis.

Parameters:
b - true if the action is to be performed per-line;
false if the action is to be performed per-file.

setRegexp

public void setRegexp(java.lang.String string)
Set the regular expression to be used.

Parameters:
string - the regular expression

setText

public void setText(java.lang.String string)
Specify the input text to use.

Parameters:
string - the input text

getLength

public int getLength()
Return the length to use.

Returns:
a non-negative integer; or TO_EOF; or NONE_SPECIFIED

getOffset

public int getOffset()
Return the offset to use.

Returns:
a non-negative integer; or EOF; BOF

setLength

public void setLength(int i)
Set the length to use.

Parameters:
i - the length

setOffset

public void setOffset(int i)
Set the offset to use.

Parameters:
i - the offset