RbUtils 0.13

org.ktc.rbutils.rb.generation
Class FileGenerator

java.lang.Object
  extended by org.ktc.rbutils.api.i18n.AbstractLocalized
      extended by org.ktc.rbutils.api.audit.AbstractProcessor
          extended by org.ktc.rbutils.api.audit.AbstractFileProcessor
              extended by org.ktc.rbutils.rb.generation.FileGenerator
All Implemented Interfaces:
FileProcessor, Processor, Localized

public class FileGenerator
extends AbstractFileProcessor

Generates a Java RessourceBundle source class using a Properties file.

Package name resolution is proceeded using the relative path of the Properties file from a root directory.

Since:
RbUtils 0.8.0
Version:
$Revision: 1.4 $
Author:
ktcguru
See Also:
MainGenerator

Field Summary
protected static String TAB
          String used for tabulation representation on code generation.
 
Fields inherited from class org.ktc.rbutils.api.audit.AbstractFileProcessor
className, fileLocale, fileName
 
Fields inherited from class org.ktc.rbutils.api.audit.AbstractProcessor
loggers
 
Fields inherited from class org.ktc.rbutils.api.i18n.AbstractLocalized
classResource
 
Constructor Summary
FileGenerator(File propsRootDir, File propsFile, File genRootdir)
          Instanciates a new FileGenerator.
 
Method Summary
protected static String escape(String theString)
          Escapes characters in order to get a String with only Unicode characters.
protected static String escapeKey(String key)
          Escapes the dot character in the String argument into the underscore character.
protected static String getJavaRbClassName(File propsFile)
          Gets the name of the class generated from a Properties file.
protected static File getJavaRbFile(File propsRootDir, File propsFile, File genRootdir)
          Gets the File of the Java ResourceBundle according to the relative path of a properties file from its root directory.
protected  void performGeneration()
          Performs the generation of the Java File.
protected static String tab(int tabNumber)
          Returns a String which contains the number of tabulations specified as argument.
 
Methods inherited from class org.ktc.rbutils.api.audit.AbstractFileProcessor
fireError, fireInformation, fireProcessFileEnded, fireProcessFileStarted
 
Methods inherited from class org.ktc.rbutils.api.audit.AbstractProcessor
addLogger, addLoggers, fireException
 
Methods inherited from class org.ktc.rbutils.api.i18n.AbstractLocalized
getMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.ktc.rbutils.api.audit.Processor
addLogger, addLoggers, fireException
 

Field Detail

TAB

protected static final String TAB
String used for tabulation representation on code generation.

See Also:
Constant Field Values
Constructor Detail

FileGenerator

public FileGenerator(File propsRootDir,
                     File propsFile,
                     File genRootdir)
              throws IOException
Instanciates a new FileGenerator.

propsRootDir and genRootdir must be directories that exist in the filesystem.
propsFile must be a file that exists in the filesystem.

Parameters:
propsRootDir - the root directory of the properties file used to resolve package name.
propsFile - the properties file used to generate the java file.
genRootdir - the target root directory where the java file will be put after package name resolution and file generation.
Throws:
NullArgumentException - if a parameter is null.
FileNotFoundException - if a parameter is a File that does not exist in the filesystem.
NotDirectoryException - if propsRootDir or genRootdir is not a directory in the filesystem.
NotFileException - if propsFile is not a file in the filesystem.
IOException - if problems occured on Properties file load.
Method Detail

performGeneration

protected void performGeneration()
Performs the generation of the Java File.

The contents of the properties file is used to create the data of the java file. Then, the java file is created in the filesystem.


getJavaRbClassName

protected static String getJavaRbClassName(File propsFile)
Gets the name of the class generated from a Properties file.

This is the name of the file without extension.

Parameters:
propsFile - Properties file used for name resolution.
Returns:
the name of the class.

getJavaRbFile

protected static File getJavaRbFile(File propsRootDir,
                                    File propsFile,
                                    File genRootdir)
                             throws FileNotFoundException
Gets the File of the Java ResourceBundle according to the relative path of a properties file from its root directory.

The returned File will be in a parent directory of genRootdir. It will have the same relative path to genRootdir that propsFile to propsRootDir.

Parameters:
propsRootDir - the root directory of the properties file used to resolve relative path.
propsFile - the properties file used to resolve relative path.
genRootdir - the target root directory where the java file will be put.
Returns:
the java resourcebundle File.
Throws:
FileNotFoundException - if one of the argument represent a file that does not exist in the filesystem.

escape

protected static String escape(String theString)
Escapes characters in order to get a String with only Unicode characters.

Parameters:
theString - the String to be escaped.
Returns:
the escaped String.

escapeKey

protected static String escapeKey(String key)
Escapes the dot character in the String argument into the underscore character.

This can be used on field generation in order to avoid compilation error (as the dot character is reserved for accessors).

Parameters:
key - the key to be escaped.
Returns:
the escape key; null if key is null.

tab

protected static String tab(int tabNumber)
Returns a String which contains the number of tabulations specified as argument.

Parameters:
tabNumber - number of tabulations
Returns:
the String which represents the number of tabulations; the empty String is tabNumber is negative.
Since:
RbUtils 0.9.2

Back to the RbUtils Home Page

Copyright © 2005-2009 RbUtils Project. All Rights Reserved.