Top Description Inners Fields Constructors Methods
org.eclipse.persistence.tools

public Class PackageRenamer

extends Object
Class Inheritance
Imports
org.eclipse.persistence.internal.security.PrivilegedAccessHelper, java.io.BufferedReader, .File, .FileInputStream, .FileNotFoundException, .FileOutputStream, .FileWriter, .IOException, .InputStream, .InputStreamReader, .PrintWriter, java.security.AccessController, .PrivilegedAction, java.util.Arrays, .Date, .Enumeration, .Objects, .Properties, .Vector

This class performs package renaming. It demonstrates the following: a) Reading the properties file to be a reference for changing the package name from your source code. b) Traverse source root directory for creating a corresponding output directory and finding the java source file(s) to be changing the package name. c) Search and replace the old TopLink package name(s) with new one(s) according to the reference. You will be able to see the logging message at the command line window where the PackageRenamer is running.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv static final String
pack-priv File
pack-priv File
pack-priv String
pack-priv int
pack-priv int
pack-priv PrintWriter
pack-priv Properties
pack-priv String
pack-priv BufferedReader
pack-priv String
pack-priv File
pack-priv boolean
protected static final String
pack-priv String[]
pack-priv boolean

Constructor Summary

AccessConstructor and Description
public
PackageRenamer()

The constructor of a PackageRenamer class.

public
PackageRenamer(String propertiesFileName)

public

Method Summary

Modifier and TypeMethod and Description
protected String
public void
binaryCopy(File
The file to copy
inFile
,
File
The destination file
outFile
)

Do a binary copy of the file byte buffer by byte buffer.

protected boolean
bufferContainsNullChar(byte[] buffer, int bufferLength)

public File

Returns:

The destination directory File object
buildAndCheckDestinationFile
(String
The path to the directory File object to create
aDirString
)

INTERNAL Creates a destination directory File object under the path passed, verifying correctness.

public File
public PrintWriter
protected void
public void
createDestinationDirectory(File
The output directory to create
aDirectory
)

This method creates an output directory for post-rename file(s).

public static boolean

Returns:

TRUE if directory2 is a subdirectory of directory1
directoryIsSubdirectory
(File
The higher level directory
directory1
,
File
The lower level directory
directory2
)

Return true if directory2 is contained within directory1.

public File
public static String
public synchronized BufferedReader
public boolean

Returns:

TRUE if the extension is supported
isExtensionSupported
(String
The file extension to check for being supported
extension
)

Return true if the PackageRenamer should work on the given file extension.

public void
logln(String
The String to log
str
)

public static void
main(String[]
Command line arguments
args
)

Main method to run the PackageRenamer

public String

Returns:

The file extension or an empty string if none was found.
parseFileExtension
(File
The file of which to retrieve the extension
aFile
)

Returns the extension of the given file.

protected File

Returns:

The destination directory File object
promptForDestinationDirectory
()

INTERNAL Prompt from System.in for an empty or non-existent directory to use as the destination directory.

public Properties

Returns:

The Properties object containing the renaming information
readChangesFile
(String
The input file to use for the renaming
filename
)

This readChangesFile() method reads the given properties file to be a reference for renaming TopLink package name.

public static String

Returns:

the modified String
replace
(String
The original String
str
,
String
The character pattern to replace
oldChars
,
String
The character pattern to replace the existing with
newChars
)

Do a search and replace in a string.

public String

Returns:

The new filename, regardless of whether is has been changed
returnNewFileNameIfRequired
(String
The original filename
aSourceFileNameWithoutRoot
)

Renames a file based on the properties passed.

public void
run()

This run() method performs, reading the properties file into properties variable to be a reference for changing package name.

public void
runSearchAndReplacePackageName(File
The source file to process
sourceFile
)

This runSearchAndReplacePackageName() reads a pre-rename source file all into string variable and replacing the old package names with the new ones according to the properties file.

protected PrintWriter
public void
traverseSourceDirectory(File
The source root directory to traverse
aDirectoryString
)

This traverseSourceDirectory() traverse source-root-directory, creating an corresponding output directory, and calling another method for replacing old TopLink package name.

public static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUFSIZback to summary
pack-priv int BUFSIZ
CRback to summary
pack-priv static final String CR
destinationRootDirback to summary
pack-priv File destinationRootDir
logFileback to summary
pack-priv File logFile
logFileStringback to summary
pack-priv String logFileString
numberOfChangedFileback to summary
pack-priv int numberOfChangedFile
numberOfTotalFileback to summary
pack-priv int numberOfTotalFile
outLogback to summary
pack-priv PrintWriter outLog
propertiesback to summary
pack-priv Properties properties
propertiesFileNameback to summary
pack-priv String propertiesFileName
readerback to summary
pack-priv BufferedReader reader
sourcePropertiesback to summary
pack-priv String sourceProperties
sourceRootDirFileback to summary
pack-priv File sourceRootDirFile
specifyLogFileback to summary
pack-priv boolean specifyLogFile
SYSTEM_OUTback to summary
protected static final String SYSTEM_OUT
UNSUPPORTED_EXTENSIONSback to summary
pack-priv String[] UNSUPPORTED_EXTENSIONS
VERBOSEback to summary
pack-priv boolean VERBOSE

Constructor Detail

PackageRenamerback to summary
public PackageRenamer()

The constructor of a PackageRenamer class.

PackageRenamerback to summary
public PackageRenamer(String propertiesFileName)
PackageRenamerback to summary
public PackageRenamer(String[] args)

Method Detail

bannerTextback to summary
protected String bannerText()
binaryCopyback to summary
public void binaryCopy(File inFile, File outFile) throws FileNotFoundException, IOException

Do a binary copy of the file byte buffer by byte buffer.

Parameters
inFile:File

The file to copy

outFile:File

The destination file

Exceptions
FileNotFoundException:
if either of the two files does not exist
IOException:
if any other IO related error occurs
bufferContainsNullCharback to summary
protected boolean bufferContainsNullChar(byte[] buffer, int bufferLength)
buildAndCheckDestinationFileback to summary
public File buildAndCheckDestinationFile(String aDirString)

INTERNAL Creates a destination directory File object under the path passed, verifying correctness.

Parameters
aDirString:String

The path to the directory File object to create

Returns:File

The destination directory File object

buildAndCheckExistingDirFileback to summary
public File buildAndCheckExistingDirFile(String aDirString)
buildAndCheckLogWriterback to summary
public PrintWriter buildAndCheckLogWriter(String logFileString)
cleanupback to summary
protected void cleanup()
createDestinationDirectoryback to summary
public void createDestinationDirectory(File aDirectory)

This method creates an output directory for post-rename file(s).

Parameters
aDirectory:File

The output directory to create

directoryIsSubdirectoryback to summary
public static boolean directoryIsSubdirectory(File directory1, File directory2)

Return true if directory2 is contained within directory1. Both directories must be absolute.

Parameters
directory1:File

The higher level directory

directory2:File

The lower level directory

Returns:boolean

TRUE if directory2 is a subdirectory of directory1

existingDirectoryFromPromptback to summary
public File existingDirectoryFromPrompt()
getDefaultPropertiesFileNameback to summary
public static String getDefaultPropertiesFileName()
getReaderback to summary
public synchronized BufferedReader getReader()
isExtensionSupportedback to summary
public boolean isExtensionSupported(String extension)

Return true if the PackageRenamer should work on the given file extension.

Parameters
extension:String

The file extension to check for being supported

Returns:boolean

TRUE if the extension is supported

loglnback to summary
public void logln(String str)
Parameters
str:String

The String to log

mainback to summary
public static void main(String[] args)

Main method to run the PackageRenamer

Parameters
args:String[]

Command line arguments

parseFileExtensionback to summary
public String parseFileExtension(File aFile)

Returns the extension of the given file.

Parameters
aFile:File

The file of which to retrieve the extension

Returns:String

The file extension or an empty string if none was found.

promptForDestinationDirectoryback to summary
protected File promptForDestinationDirectory()

INTERNAL Prompt from System.in for an empty or non-existent directory to use as the destination directory.

Returns:File

The destination directory File object

readChangesFileback to summary
public Properties readChangesFile(String filename)

This readChangesFile() method reads the given properties file to be a reference for renaming TopLink package name.

Parameters
filename:String

The input file to use for the renaming

Returns:Properties

The Properties object containing the renaming information

replaceback to summary
public static String replace(String str, String oldChars, String newChars)

Do a search and replace in a string.

Parameters
str:String

The original String

oldChars:String

The character pattern to replace

newChars:String

The character pattern to replace the existing with

Returns:String

the modified String

returnNewFileNameIfRequiredback to summary
public String returnNewFileNameIfRequired(String aSourceFileNameWithoutRoot)

Renames a file based on the properties passed.

Parameters
aSourceFileNameWithoutRoot:String

The original filename

Returns:String

The new filename, regardless of whether is has been changed

runback to summary
public void run()

This run() method performs, reading the properties file into properties variable to be a reference for changing package name. creating an destination-root-direetory. and, calling traverseSourceDirectory() method.

runSearchAndReplacePackageNameback to summary
public void runSearchAndReplacePackageName(File sourceFile)

This runSearchAndReplacePackageName() reads a pre-rename source file all into string variable and replacing the old package names with the new ones according to the properties file.

Parameters
sourceFile:File

The source file to process

streamForNonExistentFilePromptback to summary
protected PrintWriter streamForNonExistentFilePrompt()
traverseSourceDirectoryback to summary
public void traverseSourceDirectory(File aDirectoryString)

This traverseSourceDirectory() traverse source-root-directory, creating an corresponding output directory, and calling another method for replacing old TopLink package name.

Parameters
aDirectoryString:File

The source root directory to traverse

usageback to summary
public static void usage()
org.eclipse.persistence.tools back to summary

public final Class PackageRenamer.PackageRenamerException

extends RuntimeException
Class Inheritance

Constructor Summary

AccessConstructor and Description
public

Constructor Detail

PackageRenamerExceptionback to summary
public PackageRenamerException(String aMessage)