insensa.optionfilechanger
Class AbstractOptionFileChanger

java.lang.Object
  extended by insensa.optionfilechanger.AbstractOptionFileChanger
All Implemented Interfaces:
OptionFileChanger, java.lang.Runnable
Direct Known Subclasses:
CCopy, CEqualBreaks, CJenksOptimalBreaks, CNormalizing, CQuantileBreaks, CReplaceRasterFileValue, CVariableBreaks, TemplateCut

public abstract class AbstractOptionFileChanger
extends java.lang.Object
implements OptionFileChanger


Field Summary
protected  java.lang.String errorMessage
           
protected  int id
           
protected  java.lang.String oldFileName
           
protected  java.lang.String oldFilePath
           
protected  CRasterFileInformation oldRasterFile
           
protected  float processStatus
           
protected  boolean used
           
protected  WorkerStatus workerStatus
           
protected  java.lang.String XML_ATTR_ID
           
static java.lang.String XML_ATTR_OLD_NAME
           
static java.lang.String XML_ATTR_OLD_PATH
           
protected  java.lang.String XML_ATTR_USED
           
static java.lang.String XML_ELEMENT_SOURCEFILE
           
 
Constructor Summary
AbstractOptionFileChanger()
           
 
Method Summary
 boolean checkApproval(CRasterFileInformation rasterFile)
          Here you can check if it is correct to add this OptionFileChanger to this rasterFile.
 CRasterFileInformation getActualFile()
           
 AttributeTable getData()
           
 java.lang.String getErrorMessage()
          returns the errorMessage if there is any.
 int getId()
           
 java.util.List<java.lang.String> getInfoDependencies()
           
 java.lang.String getOldFileRelativeFilePath()
           
 org.jdom.Element getOptionElement()
          Creates a new Element object that contains all Information that should be saved in a configuration file.
protected  java.lang.String getTemporaryFileName(CRasterFileInformation rasterFile)
           
 boolean isPublic()
           
 boolean isUsed()
           
 void run()
           
protected  void saveRasterFile(CRasterFileInformation tmpRasterFile, CRasterFileInformation actualRasterFile)
           
 void setId(int id)
           
 void setOldRasterFile(CRasterFileInformation oldRasterFile)
           
 void setOptionAttributes(org.jdom.Element eOption)
          Sets all attributes that are saved in the configuration file.
 void setWorkerStatus(WorkerStatus workerStatus)
           
protected  void solveDependencies(CRasterFileInformation actualRasterFile)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface insensa.optionfilechanger.OptionFileChanger
getOptionName, getUsableCount, write
 

Field Detail

XML_ATTR_USED

protected final java.lang.String XML_ATTR_USED
See Also:
Constant Field Values

XML_ATTR_ID

protected final java.lang.String XML_ATTR_ID
See Also:
Constant Field Values

used

protected boolean used

id

protected int id

oldRasterFile

protected CRasterFileInformation oldRasterFile

workerStatus

protected WorkerStatus workerStatus

processStatus

protected float processStatus

errorMessage

protected java.lang.String errorMessage

XML_ATTR_OLD_PATH

public static final java.lang.String XML_ATTR_OLD_PATH
See Also:
Constant Field Values

XML_ATTR_OLD_NAME

public static final java.lang.String XML_ATTR_OLD_NAME
See Also:
Constant Field Values

XML_ELEMENT_SOURCEFILE

public static final java.lang.String XML_ELEMENT_SOURCEFILE
See Also:
Constant Field Values

oldFilePath

protected java.lang.String oldFilePath

oldFileName

protected java.lang.String oldFileName
Constructor Detail

AbstractOptionFileChanger

public AbstractOptionFileChanger()
Method Detail

checkApproval

public boolean checkApproval(CRasterFileInformation rasterFile)
Description copied from interface: OptionFileChanger
Here you can check if it is correct to add this OptionFileChanger to this rasterFile.

Specified by:
checkApproval in interface OptionFileChanger
Returns:
See Also:
OptionFileChanger.checkApproval(insensa.CRasterFileInformation)

getActualFile

public CRasterFileInformation getActualFile()
                                     throws java.io.IOException
Specified by:
getActualFile in interface OptionFileChanger
Returns:
Throws:
java.io.IOException
See Also:
OptionFileChanger.getActualFile()

getOptionElement

public org.jdom.Element getOptionElement()
                                  throws org.jdom.IllegalDataException
Description copied from interface: OptionFileChanger
Creates a new Element object that contains all Information that should be saved in a configuration file.

The configuration file is a xml file that will be saved in the "infos" directory. jdom is used to generate the file. An Element will be represented as a XML Tag in the created file

First you have to create a new Element with the name of the optionFileChanger.
This name must be the same name as you defined in the extensions.xml file
If you inherited and defined the method getOptionName correctly, you can use this function to get the name.

Example:
 Element optionElement = new Element(this.getOptionName());
 
There are TWO attributes which should ALWAYS be saved, the status of the execution (Therefore the same boolean expression that should be used in the method isUsed) and the id of the current optionFileChanger.
Both variables (used and id) are defined in

Specified by:
getOptionElement in interface OptionFileChanger
Returns:
Element with all contents that should be saved in the Configuration File AbstractOptionFileChanger.
The Integer variable id is used internally and just have to be saved and reloaded by the plugin.

Example: Assuming that used is the boolean expression
 optionElement.setAttribute("used",Boolean.toString(used));
 
Besides the used state, you can save what ever you want and it is possible to use the complex methods that jdom gives you. For example: creating subElements (child XML tags)

Note: It is strongly recommended that you define a final variable for every key you need.
The keys used here are also required in the method insensa.optionfilechanger.OptionFileChanger.setInfos and it can be fatal to use wrong keys
 private final string XML_ATTR_USED = "used";
 
Throws:
org.jdom.IllegalDataException
See Also:
OptionFileChanger.getOptionElement()

getOldFileRelativeFilePath

public java.lang.String getOldFileRelativeFilePath()
Specified by:
getOldFileRelativeFilePath in interface OptionFileChanger
Returns:
the relative File Path (with name) of the source RasterFile
See Also:
OptionFileChanger.getOldFileRelativeFilePath()

setOptionAttributes

public void setOptionAttributes(org.jdom.Element eOption)
                         throws java.io.IOException
Description copied from interface: OptionFileChanger
Sets all attributes that are saved in the configuration file.

This method is the counterpart of getOptionElement.

Specified by:
setOptionAttributes in interface OptionFileChanger
Parameters:
eOption - the jdom.Element which holds the attributes
Throws:
java.io.IOException - eOption holds all information that was saved.
The information that should ALWAYS stored in the configuration is the status of the execution and the id of the optionFileChanger
Example:
 
 Attribute attrUsed = element.getAttribute(XML_ATTR_USED);
 Attribute attrID = element.getAttribute(XML_ATTR_ID);
 if(attrUsed==null || attrID==null)
 throw new IOException("one ore more necessary attributes cannot be found");
 try
 {
 used=attrUsed.getBooleanValue();
 id=attrID.getIntegerValue();
 }catch (DataConversionException e)
 {
 throw new IOException(e);
 }
 
 
See Also:
OptionFileChanger.setOptionAttributes(org.jdom.Element)

getData

public AttributeTable getData()
Specified by:
getData in interface OptionFileChanger
Returns:
See Also:
OptionFileChanger.getData()

getErrorMessage

public java.lang.String getErrorMessage()
returns the errorMessage if there is any. After calling this method, the errorMessage will be deleted(set to empty String)

Specified by:
getErrorMessage in interface OptionFileChanger
Returns:

getId

public int getId()
Specified by:
getId in interface OptionFileChanger
Returns:
See Also:
OptionFileChanger.getId()

getInfoDependencies

public java.util.List<java.lang.String> getInfoDependencies()
Specified by:
getInfoDependencies in interface OptionFileChanger
Returns:
See Also:
OptionFileChanger.getInfoDependencies()

getTemporaryFileName

protected java.lang.String getTemporaryFileName(CRasterFileInformation rasterFile)
Parameters:
rasterFile -
Returns:

isPublic

public boolean isPublic()
Specified by:
isPublic in interface OptionFileChanger
Returns:
true if the option should be settable for the user .
See Also:
OptionFileChanger.isPublic()

isUsed

public boolean isUsed()
Specified by:
isUsed in interface OptionFileChanger
Returns:
true if the option has executed successful.
See Also:
OptionFileChanger.isUsed()

run

public void run()
Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

saveRasterFile

protected void saveRasterFile(CRasterFileInformation tmpRasterFile,
                              CRasterFileInformation actualRasterFile)
                       throws java.io.IOException,
                              org.jdom.JDOMException,
                              CRasterFileException
Parameters:
tmpRasterFile -
actualRasterFile -
Throws:
java.io.IOException
org.jdom.JDOMException
CRasterFileException

setId

public void setId(int id)
Specified by:
setId in interface OptionFileChanger
Parameters:
id - a unique id for this option
See Also:
OptionFileChanger.setId(int)

setOldRasterFile

public void setOldRasterFile(CRasterFileInformation oldRasterFile)
Specified by:
setOldRasterFile in interface OptionFileChanger
Parameters:
oldRasterFile - The RasterFileInformation that will use this optionFileChanger
See Also:
OptionFileChanger.setOldRasterFile(insensa.CRasterFileInformation)

setWorkerStatus

public void setWorkerStatus(WorkerStatus workerStatus)
Specified by:
setWorkerStatus in interface OptionFileChanger
Parameters:
workerStatus - the WorkerStatus that should Listen to the execution progress
See Also:
OptionFileChanger.setWorkerStatus(insensa.WorkerStatus)

solveDependencies

protected void solveDependencies(CRasterFileInformation actualRasterFile)
                          throws java.io.IOException
Parameters:
actualRasterFile -
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()