org.eclipse.persistence.tools
Class PackageRenamer

java.lang.Object
  extended by org.eclipse.persistence.tools.PackageRenamer

public class PackageRenamer
extends Object

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 Class Summary
 class PackageRenamer.PackageRenamerException
           
 
Constructor Summary
PackageRenamer()
          The constructor of a PackageRenamer class.
PackageRenamer(String propertiesFileName)
           
PackageRenamer(String[] args)
           
 
Method Summary
 void binaryCopy(File inFile, File outFile)
          Do a binary copy of the file byte buffer by byte buffer.
 File buildAndCheckDestinationFile(String aDirString)
          INTERNAL
 File buildAndCheckExistingDirFile(String aDirString)
           
 PrintWriter buildAndCheckLogWriter(String logFileString)
           
 void createDestinationDirectory(File aDirectory)
          This method creates an output directory for post-rename file(s).
static boolean directoryIsSubdirectory(File directory1, File directory2)
          Return true if directory2 is contained within directory1.
 File existingDirectoryFromPrompt()
           
static String getDefaultPropertiesFileName()
           
 BufferedReader getReader()
           
 boolean isExtensionSupported(String extension)
          Return true if the PackageRenamer should work on the given file extension.
 void logln(String str)
           
static void main(String[] args)
          Main method to run the PackageRenamer
 String parseFileExtension(File aFile)
          Returns the extension of the given file.
 Properties readChangesFile(String filename)
          This readChangesFile() method reads the given properties file to be a reference for renaming TopLink package name.
static String replace(String str, String oldChars, String newChars)
          Do a search and replace in a string.
 String returnNewFileNameIfRequired(String aSourceFileNameWithoutRoot)
           
 void run()
          This run() method performs, reading the properties file into properties variable to be a reference for changing package name.
 void runSearchAndReplacePackageName(File sourceFile)
          This runSearchAndReplacePackageName() reads an pre-rename source file all into string variable and replacing the old package names with the new ones according to the properties file.
 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.
static void usage()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PackageRenamer

public PackageRenamer()
The constructor of a PackageRenamer class.


PackageRenamer

public PackageRenamer(String propertiesFileName)

PackageRenamer

public PackageRenamer(String[] args)
Method Detail

binaryCopy

public void binaryCopy(File inFile,
                       File outFile)
                throws FileNotFoundException,
                       IOException
Do a binary copy of the file byte buffer by byte buffer.

Throws:
FileNotFoundException
IOException

buildAndCheckDestinationFile

public File buildAndCheckDestinationFile(String aDirString)
INTERNAL


buildAndCheckExistingDirFile

public File buildAndCheckExistingDirFile(String aDirString)

buildAndCheckLogWriter

public PrintWriter buildAndCheckLogWriter(String logFileString)

createDestinationDirectory

public void createDestinationDirectory(File aDirectory)
This method creates an output directory for post-rename file(s).


directoryIsSubdirectory

public static boolean directoryIsSubdirectory(File directory1,
                                              File directory2)
Return true if directory2 is contained within directory1. Both directories must be absolute.


existingDirectoryFromPrompt

public File existingDirectoryFromPrompt()

getDefaultPropertiesFileName

public static String getDefaultPropertiesFileName()

getReader

public BufferedReader getReader()

isExtensionSupported

public boolean isExtensionSupported(String extension)
Return true if the PackageRenamer should work on the given file extension.


logln

public void logln(String str)

main

public static void main(String[] args)
Main method to run the PackageRenamer


parseFileExtension

public String parseFileExtension(File aFile)
Returns the extension of the given file. Returns and empty string if none was found.


readChangesFile

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


run

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.


runSearchAndReplacePackageName

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


replace

public static String replace(String str,
                             String oldChars,
                             String newChars)
Do a search and replace in a string.

Returns:
the modified String

returnNewFileNameIfRequired

public String returnNewFileNameIfRequired(String aSourceFileNameWithoutRoot)

traverseSourceDirectory

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.


usage

public static void usage()