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 client toolkit activities which provide an interface to the fileWritingActivity activity.

The activity has one optional input - the output of another activity providing any data to insert, append or replace existing data. This can be specified using the setInput method. The activity has one output - a dummy value representing success.

Author:
The OGSA-DAI Project Team

Field Summary
static int APPEND
          Indicates an append action.
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement
static int DELETE
          Indicates a delete action.
static int END
          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 relative path to the file to be modified.
protected  int mLength
          The number of bytes length over which the modification occurs.
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 modification 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 modify.
protected  java.lang.String mText
          Text to insert, append or replace existing text.
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 START
          An offset denoting the beginning of the file or a line.
static int TO_END
          Denotes the remaining length to the end of the file or line.
 
Fields inherited from class uk.org.ogsadai.client.toolkit.activity.Activity
 
Fields inherited from class uk.org.ogsadai.client.toolkit.activity.RequestComponent
 
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()
          Generates the XML representing the activity.
 java.lang.String getFilename()
          Gets the relative path to the file to be modified.
 int getLength()
          Gets the length to use.
 java.lang.String getMatch()
          Gets the match expression, if any.
 int getOffset()
          Gets the offset to use.
 java.lang.String getRegexp()
          Gets the regular expression to be used, if any.
 java.lang.String getText()
          Gets the text to insert/append or replace.
 boolean isPerLine()
          Gets 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_END into the string "toEnd".
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 START and END into corresponding strings.
 void setFilename(java.lang.String filename)
          Sets the relative path to the file to be modified.
 void setInput(ActivityOutput input)
          Sets the input of this activity to be the output from another activity that will provide the data to be appended/inserted or to replace existing data.
 void setLength(int length)
          Sets the length to use.
 void setMatch(java.lang.String match)
          Sets the match expression.
 void setOffset(int offset)
          Sets the offset to use.
 void setPerLine(boolean perLine)
          Sets whether the action is to be performed on a per-line or per-file basis.
 void setRegexp(java.lang.String regexp)
          Set the regular expression to be used.
 void setText(java.lang.String text)
          Sets the text to insert/append or replace.
protected  void validateParams()
          Test the current parameters to check that they are within acceptable bounds.
 
Methods inherited from class uk.org.ogsadai.client.toolkit.activity.Activity
addInput, addOutput, addOutputs, getDataResourceID, getInputParameters, getOutputParameters, getOutputs, replaceSpecialCharacters, setDataResourceID, setInput
 
Methods inherited from class uk.org.ogsadai.client.toolkit.activity.RequestComponent
getDataService, getName, getSession, setDataService, setSession
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT_NOTICE

private static final java.lang.String COPYRIGHT_NOTICE
Copyright statement

See Also:
Constant Field Values

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

START

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

See Also:
Constant Field Values

END

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

See Also:
Constant Field Values

TO_END

public static final int TO_END
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, or INSERT.


mFilename

protected java.lang.String mFilename
The relative path to the file to be modified.


mRegexp

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


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 modification occur.


mLength

protected int mLength
The number of bytes length over which the modification occurs.


mText

protected java.lang.String mText
Text to insert, append or replace existing text.


mPerLine

protected boolean mPerLine
Indicates whether the action will be performed on a per-line or per-file basis. If 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 START, END and TO_END take on meanings relevant to either files or lines.

Constructor Detail

FileWriting

public FileWriting()
Default constructor.

Method Detail

validateParams

protected void validateParams()
Test the current parameters to check that they are within acceptable bounds.

Throws:
java.lang.IllegalArgumentException - If the filename is null, the offset is < 0 or does not equal START, END or NONE_SPECIFIED, or the length is < 0 or does not equal TO_END or NONE_SPECIFIED.

setInput

public void setInput(ActivityOutput input)
Sets the input of this activity to be the output from another activity that will provide the data to be appended/inserted or to replace existing data.

Parameters:
input - Output from another activity.
Throws:
java.lang.IllegalArgumentException - If input is null.

generateXML

protected java.lang.String generateXML()
Description copied from class: RequestComponent
Generates the XML representing the activity. This XML can then be inserted into a perform document that is sent to a data service.

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 START and END 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_END into the string "toEnd".

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()
Gets the relative path to the file to be modified.

Returns:
the filename

setFilename

public void setFilename(java.lang.String filename)
Sets the relative path to the file to be modified.

Parameters:
filename - The filename

getMatch

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

Returns:
the match expression or null

setMatch

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

Parameters:
match - The match expression

isPerLine

public boolean isPerLine()
Gets 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.

setPerLine

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

Parameters:
perLine - 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()
Gets the regular expression to be used, if any.

Returns:
the regular expression or null

setRegexp

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

Parameters:
regexp - The regular expression

getText

public java.lang.String getText()
Gets the text to insert/append or replace.

Returns:
the input text or null

setText

public void setText(java.lang.String text)
Sets the text to insert/append or replace.

Parameters:
text - The text

getLength

public int getLength()
Gets the length to use.

Returns:
a non-negative integer; or TO_END; or NONE_SPECIFIED.

setLength

public void setLength(int length)
Sets the length to use.

Parameters:
length - The length
Throws:
java.lang.IllegalArgumentException - If length is < 0 or does not equal TO_END or NONE_SPECIFIED.

getOffset

public int getOffset()
Gets the offset to use.

Returns:
a non-negative integer; or END; START

setOffset

public void setOffset(int offset)
Sets the offset to use.

Parameters:
offset - The offset.
Throws:
java.lang.IllegalArgumentException - If offset is < 0 or does not equal START, END or NONE_SPECIFIED.