|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.di.migration.BaseMigrationUtility
public abstract class BaseMigrationUtility
This is a base class which could be extended in order to provide an utility
for migrating configuration files. This class provides the ability to work
with Java properties files (descendant classes can change this). It expects
the child classes to define the changes, that will be done over the
configuration file, using the defineChanges(Map)
method.
Field Summary | |
---|---|
protected static ResourceHash |
resHash
|
protected static String |
SWITCH_HELP
The switch used for requesting help information. |
protected static String |
SWITCH_MIG_FILE
The switch used for providing the source file to be migrated. |
protected static String |
SWITCH_MIG_FILE_BAKUP
The switch used for providing the name of the backup file. |
protected static String |
SWITCH_MIG_FILE_NEW
The switch used for providing the name of the file used for output of the migration. |
protected static String |
SWITCH_VERBOSE
The switch used for enabling verbose output. |
Constructor Summary | |
---|---|
BaseMigrationUtility(String[] args,
org.apache.log4j.Logger log)
Create an instance by passing in the command line arguments. |
Method Summary | |
---|---|
protected void |
applyChanges(StringBuilder sb,
Map<String,String> props,
List<ChangeDescription> chngs)
Called to apply the defined changes to the in-memory buffer. |
protected void |
backupFile()
Called to create a copy of the source file. |
protected abstract List<ChangeDescription> |
defineChanges(Map<String,String> props)
Defines the changes that will be done over the properties of the source file. |
protected List<String> |
getCommandStandaloneValuesList()
|
protected String |
getCommandValueBySwitch(String switchStr)
Requests the value of the switch which have been passed to the command line. |
org.apache.log4j.Logger |
getLog()
|
protected void |
interpretCommandLineOptions()
Called to parse the passed command line arguments. |
boolean |
isHelpRequested()
|
protected boolean |
isSwitch(String arg)
Checks whether the specified string complies with the syntax of a command line switch. |
boolean |
isVerboseMode()
|
void |
migrateFile()
This is the entry point which drives the common flow of a standard migration utility. |
protected void |
parseArgs(String[] args)
Parses the command line arguments by filling commandLineOptions
and commandValuesList structures. |
protected Map<String,String> |
parseFile(File srcFile)
Parses the source file. |
protected Map<String,String> |
parseFile(InputStream source)
Parses the source stream. |
protected void |
performPropertyAddition(StringBuilder sb,
Map<String,String> props,
ChangeDescription change)
Perform actual addition of the new property. |
protected void |
performPropertyCommenting(StringBuilder sb,
Map<String,String> props,
ChangeDescription change)
Perform actual commenting of an existing property. |
protected void |
performPropertyDeletion(StringBuilder sb,
Map<String,String> propsAvailable,
ChangeDescription change)
Perform actual deletion of the existing property. |
protected void |
performPropertyModification(StringBuilder sb,
Map<String,String> props,
ChangeDescription change)
Perform actual modification of the existing property. |
protected void |
performPropertyUncommenting(StringBuilder sb,
Map<String,String> props,
ChangeDescription change)
Perform actual uncommenting of the commented property. |
protected void |
printHelpInformation()
Called to print the help information to the stdOut. |
protected StringBuilder |
readFile(File srcFile)
Called to read the configuration file and put its content into the returned StringBuilder . |
protected void |
setLog(org.apache.log4j.Logger log)
Sets the provided log for this utility. |
protected void |
validateCommandLineOptions()
Called to check whether the parsed arguments are valid enough for the migration utility to continue. |
protected void |
writeFile(StringBuilder sb)
Called to write the in-memory buffer to the destination file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final ResourceHash resHash
protected static final String SWITCH_MIG_FILE
protected static final String SWITCH_MIG_FILE_BAKUP
protected static final String SWITCH_MIG_FILE_NEW
protected static final String SWITCH_VERBOSE
protected static final String SWITCH_HELP
Constructor Detail |
---|
public BaseMigrationUtility(String[] args, org.apache.log4j.Logger log)
args
- the command line arguments passed to the main method of the
implementing class.log
- the destination to log into. If this is null a new log will be
created.Method Detail |
---|
protected void parseArgs(String[] args)
commandLineOptions
and commandValuesList
structures.
args
- the array of all the command line arguments.protected boolean isSwitch(String arg)
arg
- the string to check.
true
if the passed argument is a switch,
false
otherwise.protected List<String> getCommandStandaloneValuesList()
protected String getCommandValueBySwitch(String switchStr)
switchStr
- the switch which value to look for.
null
(meaning no such switch has been
provided).protected void setLog(org.apache.log4j.Logger log)
log
- the log for this utility to use. Could be null
which will create a new log automatically.public org.apache.log4j.Logger getLog()
public boolean isVerboseMode()
true
if the user has requested more verbose logging.public void migrateFile()
SWITCH_HELP
switch this method will return ignoring all the
other switches that might have been provided.printHelpInformation()
validateCommandLineOptions()
backupFile()
parseFile(File)
defineChanges(Map)
readFile(File)
findEndOfLineCharacterSequence(StringBuilder)
#applyChanges(StringBuilder, Map, Map)
writeFile(StringBuilder)
IllegalArgumentException
- if an argument provided to the command line is invalid.
RuntimeException
- if an error occurs while manipulating files.protected void applyChanges(StringBuilder sb, Map<String,String> props, List<ChangeDescription> chngs)
sb
- the in-memory representation of the source fileprops
- the Map
of properties read from the source file.
Note this is an immutable representation of the map.chngs
- the changes defined by the descendant class using the method
defineChanges(Map)
;protected void performPropertyUncommenting(StringBuilder sb, Map<String,String> props, ChangeDescription change)
sb
- the StringBuffer
to perform the change on.props
- the state of the StringBuffer
as a Properties
structure.changeKey
- the key of the property to uncommentprotected void performPropertyCommenting(StringBuilder sb, Map<String,String> props, ChangeDescription change)
sb
- the StringBuffer
to perform the change on.props
- the state of the StringBuffer
as a Properties
structure.change
- .getPropertyKey() the key of the property to commentprotected void performPropertyAddition(StringBuilder sb, Map<String,String> props, ChangeDescription change)
sb
- the StringBuffer
to perform the change on.props
- the state of the StringBuffer
as a Properties
structure.changeKey
- the key of the property to addchangeValue
- specifies how the property should be added as well as its
value.protected void performPropertyModification(StringBuilder sb, Map<String,String> props, ChangeDescription change)
sb
- the StringBuffer
to perform the change on.props
- the state of the StringBuffer
as a Properties
structure.changeKey
- the key of the property to modifynewValue
- the value to set on the existing property.protected void performPropertyDeletion(StringBuilder sb, Map<String,String> propsAvailable, ChangeDescription change)
sb
- the StringBuffer
to perform the change on.props
- the state of the StringBuffer
as a Properties
structure.changeKey
- the key of the property to modifydeletingComments
- protected Map<String,String> parseFile(File srcFile)
Properties
class to parse the
source file.
srcFile
- the file to parse.
Map
of all the properties from the source file.protected Map<String,String> parseFile(InputStream source) throws IOException
Properties
class to parse the
source stream.
source
- the input stream to read from
Map
of all the properties from the source stream.
IOException
protected void interpretCommandLineOptions()
SWITCH_HELP
, SWITCH_MIG_FILE_BAKUP
,
SWITCH_MIG_FILE_NEW
, SWITCH_MIG_FILE
and
SWITCH_VERBOSE
SWITCH_HELP
is checked first, if it is specified then the
rest of the common switches will not be considered.
protected void validateCommandLineOptions()
IllegalArgumentException
should be thrown.
protected void backupFile()
IllegalArgumentException
- if an error occurs manipulating the files provided by the
user.
RuntimeException
- if an error occurs while reading/writing the backup file.protected StringBuilder readFile(File srcFile)
StringBuilder
.
srcFile
- the file to read.
StringBuilder
holding the file content.protected void writeFile(StringBuilder sb)
sb
- the in-memory representation of the source fileprotected void printHelpInformation()
public boolean isHelpRequested()
protected abstract List<ChangeDescription> defineChanges(Map<String,String> props)
props
- the Map
of properties read from the source file.
Note this is an immutable representation of the map.
Map
defining the changes that will be done. The keys of
this map represent the names of the properties. The corresponding
values describe the particular changes that should be done done
over the specific property. Must not be null
ChangeDescription
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |