org.deduced.controller.implementation
Class ControllerUtilities

java.lang.Object
  extended by org.deduced.controller.implementation.ControllerUtilities

public class ControllerUtilities
extends java.lang.Object

ControllerUtilities

Author:
Steve McDuff

Nested Class Summary
static class ControllerUtilities.DynamicFileNameGenerator
          DynamicFileNameFinder
static interface ControllerUtilities.FileNameGenerator
          FileNameGenerator
static class ControllerUtilities.LocalClassLoader
          LocalClassLoader is used to load locally compiled files.
 
Field Summary
private static boolean AUTOMATICALLY_DELETING_GENERATED_CLASS_FILES
          option to automatically delete the compiled class file after they are loaded
private static boolean AUTOMATICALLY_DELETING_GENERATED_JAVA_FILES
          option to automatically delete generated JAVA files after compilation
private static boolean AUTOMATICALLY_DELETING_GENERATED_JAVA_FILES_IF_COMPILE_FAILS
          option to automatically delete java files when compilation fails
static java.lang.String CLASS_FILE_EXTENSION
          class file extension
private static int COUNTER
          counter used to increment the deduction rule class name
static java.lang.String DEDUCED_DYNAMIC_CLASS_NAME
          dynamic class name prefix
static ControllerUtilities.FileNameGenerator FILE_NAME_GENERATOR
          File name finder
private static int FIND_AVAILABLE_FILE_MAX_ATTEMPT_COUNT
          The maximum number of attempts at finding an available file
static java.lang.String JAVA_FILE_EXTENSION
          java file extension
static ControllerUtilities.LocalClassLoader LOADER
          class loader used to load deduction rules
private static java.util.IdentityHashMap<PropertyCollection<?,?>,java.lang.Class<?>> RULE_TO_CLASS_MAP
          map that associates rules to the class that executes them
 
Constructor Summary
ControllerUtilities()
           
 
Method Summary
private static void buildRuleClassContent(PropertyCollection<?,?> rule, java.lang.String className, java.lang.String packageName, java.lang.StringBuilder builder)
          build Rule Class Content
static void checkForErrorOnWriter(java.io.PrintWriter writer)
          check For Error On Writer.
static void compileClass(java.lang.String className, java.lang.String javaFileName, java.lang.String classFileName, java.lang.String packageName, java.lang.String classContent, CompileResult result)
          compile a class
static boolean compileFile(java.io.File outFile, CompileResult result)
          compile a file
static void deleteAllGeneratedClassFiles()
          delete All Generated Class Files
static void deleteAllGeneratedFiles()
          delete All Generated Files
static void deleteAllGeneratedJavaFiles()
          delete All Generated Java Files
static void deleteFileAssertIfFailed(java.io.File fileToDelete)
          delete File Assert If Failed
static PropertyCollectionController findCollectionControllerControllingModel(PropertyCollection collectionControllerList, PropertyCollection controlledModel)
          find Collection Controller Controlling Model
static PropertyController findPropertyControllerControllingPropertyKey(PropertyCollection propertyControllerList, java.lang.Object controlledKey)
          find Property Controller Controlling Property Key
static void getClassFromRule(PropertyCollection rule, CompileResult result)
          get Class From Rule
static java.lang.String getNextAvailableDynamicFileName()
          get Next Available Dynamic File Name will test if a file name is already in use before returning it.
protected static java.lang.String getNextAvailableFileName(ControllerUtilities.FileNameGenerator generator)
          get Next Available File Name
static java.lang.String getNextDynamicFileName()
          get a dynamic file name used to store deduction rules
static java.lang.String getRuleMethodName(PropertyCollection<?,?> rule)
          get Rule Method Name
static boolean isAutomaticallyDeletingGeneratedClassFiles()
           
static boolean isAutomaticallyDeletingGeneratedJavaFiles()
           
static boolean isAutomaticallyDeletingGeneratedJavaFilesIfCompileFails()
           
static boolean isClassName(java.lang.String codeClassName)
          test if the code points to a class name or not.
static boolean isReferenceMultiple(java.util.List<?> instanceList)
          test if a reference can result in multiple values
static boolean isValidMethodNameCharacter(char value)
          test if a character is valid for a java method name
private static void printReferenceClassType(java.lang.StringBuilder builder, PropertyCollection<?,?> instanceReference)
          print Reference Class Type
private static void printRuleClassHeader(java.lang.String className, java.lang.String packageName, java.lang.StringBuilder builder)
          print Rule Class Header
private static void printRuleGenericMethod(PropertyCollection<?,?> rule, java.lang.StringBuilder builder)
          print Rule Generic Method
private static void printRuleSpecificMethod(PropertyCollection<?,?> rule, java.lang.StringBuilder builder)
          print Rule Specific Method
static void resetClassFromRule(PropertyCollection<?,?> rule)
          reset Class From Rule
static void setAutomaticallyDeletingGeneratedClassFiles(boolean setAutomaticallyDeletingGeneratedClassFiles)
           
static void setAutomaticallyDeletingGeneratedJavaFiles(boolean setAutomaticallyDeletingGeneratedJavaFiles)
           
static void setAutomaticallyDeletingGeneratedJavaFilesIfCompileFails(boolean setAutomaticallyDeletingGeneratedJavaFilesIfCompileFails)
           
static void setControllerEnabled(PropertyCollectionController controller, boolean isEnabled)
          Modify a controller and all it's children to enable or disable them.
static void setControllerEnabled(PropertyController controller, boolean isEnabled)
          Modify a property controller to enable or disable it
static java.io.File writeJavaClass(java.lang.String fileName, java.lang.String classContent)
          write a Java Class
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIND_AVAILABLE_FILE_MAX_ATTEMPT_COUNT

private static final int FIND_AVAILABLE_FILE_MAX_ATTEMPT_COUNT
The maximum number of attempts at finding an available file

See Also:
Constant Field Values

CLASS_FILE_EXTENSION

public static final java.lang.String CLASS_FILE_EXTENSION
class file extension

See Also:
Constant Field Values

JAVA_FILE_EXTENSION

public static final java.lang.String JAVA_FILE_EXTENSION
java file extension

See Also:
Constant Field Values

DEDUCED_DYNAMIC_CLASS_NAME

public static final java.lang.String DEDUCED_DYNAMIC_CLASS_NAME
dynamic class name prefix

See Also:
Constant Field Values

AUTOMATICALLY_DELETING_GENERATED_JAVA_FILES

private static boolean AUTOMATICALLY_DELETING_GENERATED_JAVA_FILES
option to automatically delete generated JAVA files after compilation


AUTOMATICALLY_DELETING_GENERATED_CLASS_FILES

private static boolean AUTOMATICALLY_DELETING_GENERATED_CLASS_FILES
option to automatically delete the compiled class file after they are loaded


AUTOMATICALLY_DELETING_GENERATED_JAVA_FILES_IF_COMPILE_FAILS

private static boolean AUTOMATICALLY_DELETING_GENERATED_JAVA_FILES_IF_COMPILE_FAILS
option to automatically delete java files when compilation fails


RULE_TO_CLASS_MAP

private static java.util.IdentityHashMap<PropertyCollection<?,?>,java.lang.Class<?>> RULE_TO_CLASS_MAP
map that associates rules to the class that executes them


COUNTER

private static int COUNTER
counter used to increment the deduction rule class name


FILE_NAME_GENERATOR

public static final ControllerUtilities.FileNameGenerator FILE_NAME_GENERATOR
File name finder


LOADER

public static final ControllerUtilities.LocalClassLoader LOADER
class loader used to load deduction rules

Constructor Detail

ControllerUtilities

public ControllerUtilities()
Method Detail

deleteAllGeneratedFiles

public static void deleteAllGeneratedFiles()
delete All Generated Files


deleteAllGeneratedJavaFiles

public static void deleteAllGeneratedJavaFiles()
delete All Generated Java Files


deleteAllGeneratedClassFiles

public static void deleteAllGeneratedClassFiles()
delete All Generated Class Files


setControllerEnabled

public static void setControllerEnabled(PropertyCollectionController controller,
                                        boolean isEnabled)
Modify a controller and all it's children to enable or disable them.

Parameters:
controller - the controller to modify
isEnabled - is the controller enabled

setControllerEnabled

public static void setControllerEnabled(PropertyController controller,
                                        boolean isEnabled)
Modify a property controller to enable or disable it

Parameters:
controller - the controller to modify
isEnabled - is the controller enabled or not

compileClass

public static void compileClass(java.lang.String className,
                                java.lang.String javaFileName,
                                java.lang.String classFileName,
                                java.lang.String packageName,
                                java.lang.String classContent,
                                CompileResult result)
compile a class

Parameters:
className - the name of the class to compile
javaFileName - name of the java file to use
classFileName - name of the class file to use
packageName - name of the package for the class
classContent - content of the class
result - the compilation result to fill while compiling

deleteFileAssertIfFailed

public static void deleteFileAssertIfFailed(java.io.File fileToDelete)
delete File Assert If Failed

Parameters:
fileToDelete - file to delete

compileFile

public static boolean compileFile(java.io.File outFile,
                                  CompileResult result)
                           throws java.io.IOException
compile a file

Parameters:
outFile - file to compile
result - the compilation result to fill
Returns:
true if the compilation was successful, false otherwise. See the result parameter for details on the failure.
Throws:
java.io.IOException - any exception generated while running the compiler

writeJavaClass

public static java.io.File writeJavaClass(java.lang.String fileName,
                                          java.lang.String classContent)
                                   throws java.io.IOException
write a Java Class

Parameters:
fileName - the file name to use
classContent - the class content
Returns:
the written file
Throws:
java.io.IOException - if writing the file fails

checkForErrorOnWriter

public static void checkForErrorOnWriter(java.io.PrintWriter writer)
check For Error On Writer. Raise an assertion failure if there are problems.

Parameters:
writer - the writer to verify.

buildRuleClassContent

private static void buildRuleClassContent(PropertyCollection<?,?> rule,
                                          java.lang.String className,
                                          java.lang.String packageName,
                                          java.lang.StringBuilder builder)
build Rule Class Content

Parameters:
rule - the rule to build
className - the class name to use
packageName - the package name to use
builder - the string builder in which to write the class content

printRuleSpecificMethod

private static void printRuleSpecificMethod(PropertyCollection<?,?> rule,
                                            java.lang.StringBuilder builder)
print Rule Specific Method

Parameters:
rule - the rule to print
builder - the string builder in which to write the class content

getRuleMethodName

public static java.lang.String getRuleMethodName(PropertyCollection<?,?> rule)
get Rule Method Name

Parameters:
rule - the rule from which to extract the method name
Returns:
the rule method name

isValidMethodNameCharacter

public static boolean isValidMethodNameCharacter(char value)
test if a character is valid for a java method name

Parameters:
value - the character to test
Returns:
true if the character is valid

printReferenceClassType

private static void printReferenceClassType(java.lang.StringBuilder builder,
                                            PropertyCollection<?,?> instanceReference)
print Reference Class Type

Parameters:
builder - string builder in which to print the content
instanceReference - the instance reference to print

isReferenceMultiple

public static boolean isReferenceMultiple(java.util.List<?> instanceList)
test if a reference can result in multiple values

Parameters:
instanceList - the instance list
Returns:
true if the reference has multiple values

printRuleGenericMethod

private static void printRuleGenericMethod(PropertyCollection<?,?> rule,
                                           java.lang.StringBuilder builder)
print Rule Generic Method

Parameters:
rule - the rule to print
builder - the string builder in which to print the content

printRuleClassHeader

private static void printRuleClassHeader(java.lang.String className,
                                         java.lang.String packageName,
                                         java.lang.StringBuilder builder)
print Rule Class Header

Parameters:
className - the class name
packageName - the package name
builder - the string builder in which to print the content

resetClassFromRule

public static void resetClassFromRule(PropertyCollection<?,?> rule)
reset Class From Rule

Parameters:
rule - the rule to reset

getClassFromRule

public static void getClassFromRule(PropertyCollection rule,
                                    CompileResult result)
get Class From Rule

Parameters:
rule - the rule
result - the compilation result containing the class that will be returned.

isClassName

public static boolean isClassName(java.lang.String codeClassName)
test if the code points to a class name or not.

Parameters:
codeClassName - the class name to test
Returns:
true if the code points to a class name.

getNextDynamicFileName

public static java.lang.String getNextDynamicFileName()
get a dynamic file name used to store deduction rules

Returns:
a unique dynamic file name

getNextAvailableDynamicFileName

public static java.lang.String getNextAvailableDynamicFileName()
get Next Available Dynamic File Name will test if a file name is already in use before returning it.

Returns:
the next available dynamic file name

getNextAvailableFileName

protected static java.lang.String getNextAvailableFileName(ControllerUtilities.FileNameGenerator generator)
get Next Available File Name

Parameters:
generator - name finder
Returns:
the next available file name using the specified file name generator

findCollectionControllerControllingModel

public static PropertyCollectionController findCollectionControllerControllingModel(PropertyCollection collectionControllerList,
                                                                                    PropertyCollection controlledModel)
find Collection Controller Controlling Model

Parameters:
collectionControllerList - the collection controller list
controlledModel - the controlled model to find
Returns:
the collection controller controlling the specified model

findPropertyControllerControllingPropertyKey

public static PropertyController findPropertyControllerControllingPropertyKey(PropertyCollection propertyControllerList,
                                                                              java.lang.Object controlledKey)
find Property Controller Controlling Property Key

Parameters:
propertyControllerList - the collection controller list
controlledKey - the controlled property key to find
Returns:
the property controller controlling the specified key

setAutomaticallyDeletingGeneratedJavaFiles

public static void setAutomaticallyDeletingGeneratedJavaFiles(boolean setAutomaticallyDeletingGeneratedJavaFiles)
Parameters:
setAutomaticallyDeletingGeneratedJavaFiles - the Automatically Deleting Generated Java Files flag

isAutomaticallyDeletingGeneratedJavaFiles

public static boolean isAutomaticallyDeletingGeneratedJavaFiles()
Returns:
the Automatically Deleting Generated Java Files flag

setAutomaticallyDeletingGeneratedClassFiles

public static void setAutomaticallyDeletingGeneratedClassFiles(boolean setAutomaticallyDeletingGeneratedClassFiles)
Parameters:
setAutomaticallyDeletingGeneratedClassFiles - the Automatically Deleting Generated Class Files flag

isAutomaticallyDeletingGeneratedClassFiles

public static boolean isAutomaticallyDeletingGeneratedClassFiles()
Returns:
the Automatically Deleting Generated Class Files flag

setAutomaticallyDeletingGeneratedJavaFilesIfCompileFails

public static void setAutomaticallyDeletingGeneratedJavaFilesIfCompileFails(boolean setAutomaticallyDeletingGeneratedJavaFilesIfCompileFails)
Parameters:
setAutomaticallyDeletingGeneratedJavaFilesIfCompileFails - the Automatically Deleting Generated Java Files if compile fails flag

isAutomaticallyDeletingGeneratedJavaFilesIfCompileFails

public static boolean isAutomaticallyDeletingGeneratedJavaFilesIfCompileFails()
Returns:
the Automatically Deleting Generated Java Files if compile fails flag