it.imolinfo.jbi4corba.webservice.generator
Class Util

java.lang.Object
  extended by it.imolinfo.jbi4corba.webservice.generator.Util

public class Util
extends Object

A collection of utility methods.


Field Summary
static String PROTOCOL
          The platform dependent protocol used to load file and classes.
 
Constructor Summary
Util()
          Default constructor.
 
Method Summary
static boolean buildDirectory(File file)
          Builds the directory.
static Class classLoad(String dir, File classAsFile)
           
static Class classLoad(String dir, String className)
          Load ths class using the class name in the target directory.
static Class classLoad(String dir, String className, boolean addParent)
          Load ths class using the class name in the target directory.
static Class classLoadQuiet(String dir, String className)
          Try to load the class the class name in the target directory; if no class is found, NO EXCEPTION IS THROWN.
static void compileJavaClasses(String workdirsrc, String workdirclasses, List<String> javaSources, List<String> jarFiles, List<String> extraClassPath)
          XXX javadoc.
static void compileRemoteClassesNoValueMethodsOFF(String classesDir, String className, List<String> extraClasspath)
           
static void compileRemoteClassesNoValueMethodsON(String classesDir, String className, List<String> extraClasspath)
           
static void copyInputStream(InputStream in, OutputStream out)
          Copy an input stream to an output.
static File createUniqueDirectory(File rootDir, String seed)
          Creates an unique directory form the seed (seed.tmp) in the rootDir.
static void debug(String message, Collection collection)
           
static void debug(String message, Map map)
           
static Map<String,List<MethodSignature>> extractMethodSignatureOfTheCorbaOperations(String sourceDir)
          This method extracts all the MethodSignature in the 'Operations' source files.
static Long extractSerialVersionUid(Class classToSerialize)
           
static Map<Long,String> extractSerialVersionUid(String classesDir, List<String> pathList)
           
static List<String> findAllDefaultFactory(String basedir)
          This method find all the java source file with the suffix 'DefaultFacoty.java'.
static Set<Class> findAllTypesUsedInIDL(String dir)
          This method extracts all the types used in idl file.
static Set<Class> findClassUsed(String dir, List<File> classList)
          This method extracs all the class used as method's parameter or method's result.
static Set<Class> findClassUsedInTheOperations(String dir)
          This method extracs all the class used as method's parameter or method's result.
protected static Map<String,List<String>> findCorbaEnum(String bin)
          This method find the corba enum.
static List<File> findFilesFromSourceDirectory(String basedirString, String extensionFilter)
          This method find all the files in a directory according to the filter.
static List<Class> findGeneratedClasses(String classesDir, ClassLoader classLoader)
          This method find all the '.class' files in classesDir.
static List<String> findIdlFiles(String basedir)
          Finding the *.idl files in the directory 'basedir'.
static List<String> findJavaSources(String basedir)
          Finding the *.java files in the directory 'basedir'.
static List<String> findJavaSources(String basedir, List<String> exclude)
           
static Map<String,List<String>> findOnewayOperations(String bin)
          This method is used to discover the 'oneway' operations inside a corba stub.
static String generateImplementationClass(ClassLoader urlClassLoader, String remoteClassName, boolean addRemoteSupport)
          This method load the class 'remoteClassName' using the ClassLoader in input and generates an implementation class.
static String generateSpecialEnumClass(String aPackage, String aClassName, List<String> labelList)
          This method generates the source code of a standard enum class with some special features.
protected static String generateTheBodyOfTheMethodForImplTie(MethodSignature methodSignature, boolean addRemoteSupport)
          This method is used to generate the body of the methods of the the class that must be implement the skeleton (tie) previously created.
static List<String> generateValueTypeFactoryJbi4corba(List<String> vtList, String basedir)
          This method generates the new valuetypes factories.
static org.objectweb.asm.ClassReader getAsmCLassReader(String className)
          This method returns the class reader used for the bytecode manipulation.
static org.objectweb.asm.ClassReader getAsmCLassReader(String classesDirName, String className)
           
static String getClassName(File file, String basedir, String extension)
          Gets the class name from the file absolute path, representing both "java" and "class" file names
static String getClassName(String absoluteFilePath, String basedir, String extension)
          Gets the class name from the file absolute path, representing both "java" and "class" file names
static HashMap<String,String> getTypesMap(String dir)
          findAllTypes - finds all types defined in IDL
static String getValueTypeIdFromHelperClass(String helper, ClassLoader cl)
           
static boolean isThrowableSubClass(Class cls)
          isThrowableSubClass
protected static String methodImplementation(List<MethodSignature> msList, boolean addRemoteSupport)
          This method is used to generate the source code of the methods in the list.
static List<String> prepareClassPath(String libDirName)
          The list of names of the jars used in the classpath.
static Map<String,List<String>> replaceCorbaEnumaration(String src, String bin)
          This method finds the corba enumerations and replace them with a standard enum classes.
static String replaceDotWithSeparator(String s)
          This method replaces the dot with a file sperator.
static String replaceSeparatorWithDot(String s)
          This method replaces the file sperator with a dot.
static void saveAsJavaClass(String absoluteFileName, byte[] newBytecode)
           
static void saveAsJavaClass(String classesDirName, String relativeFileName, byte[] newBytecode)
           
static File saveAsJavaSource(String code, String dir, String name)
          This method save a java file.
static File saveFile(String code, String dir, String name)
          This method saves a file.
static Map<String,List<String>> tweakOnewayInspection(String absPath)
          This method is used to inspect the bytecode of a class to discover the corba 'oneway' requests.
static void tweakSerializableDecoration(String absPath, Long newSerialVersionUid)
          This method modify the bytecode of a class: add Serializable interface and set the serial version UID.
static ClassMetaInfo tweakSerializableInspection(String absPath)
          This method inspect a class to verify if it is Serilizable and to extract the serial version UID (if exists).
static Map<String,Object> valueTypeMapHandler(List<String> vtList, String classesDirName, ClassLoader cl)
          XXX javadoc.
static Map<String,Object> valueTypeMapHandlerWithJbi4corbaFactory(List<String> vtList, String classesDirName, ClassLoader cl)
          XXX javadoc.
static List<String> valueTypesImpl(String workdirsrc, boolean addToStringEquals)
          The files with the 'DefaultFactory.java' suffix instantiate a value type but the implementation of this data types must be provided by the developers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL

public static final String PROTOCOL
The platform dependent protocol used to load file and classes.

Constructor Detail

Util

public Util()
Default constructor.

Method Detail

compileRemoteClassesNoValueMethodsON

public static void compileRemoteClassesNoValueMethodsON(String classesDir,
                                                        String className,
                                                        List<String> extraClasspath)
                                                 throws ClassGenerationException
Parameters:
classesDir - The classes dir
className - The class name
extraClasspath - The extra class path
Throws:
ClassGenerationException - The class generation exception

compileRemoteClassesNoValueMethodsOFF

public static void compileRemoteClassesNoValueMethodsOFF(String classesDir,
                                                         String className,
                                                         List<String> extraClasspath)
                                                  throws ClassGenerationException
Parameters:
classesDir - The classes dir
className - The class name
extraClasspath - The extra class path
Throws:
ClassGenerationException - The class generation exception

findJavaSources

public static List<String> findJavaSources(String basedir)
                                    throws Jbi4CorbaException
Finding the *.java files in the directory 'basedir'.

Parameters:
basedir - The directory where the method looks up the files.
Returns:
The list of java source file (canonical path)
Throws:
Jbi4CorbaException - The Jbi4Corba exception

findJavaSources

public static List<String> findJavaSources(String basedir,
                                           List<String> exclude)
                                    throws Jbi4CorbaException
Parameters:
basedir - The basedir
exclude - The exclude
Returns:
The return
Throws:
Jbi4CorbaException - The Jbi4Corba exception

findAllDefaultFactory

public static List<String> findAllDefaultFactory(String basedir)
                                          throws IOException
This method find all the java source file with the suffix 'DefaultFacoty.java'.

Parameters:
basedir - The directory inspected.
Returns:
The list of files found.
Throws:
IOException - The IO exception

findIdlFiles

public static List<String> findIdlFiles(String basedir)
                                 throws Jbi4CorbaException
Finding the *.idl files in the directory 'basedir'.

Parameters:
basedir - The directory where the method looks up the files.
Returns:
The list of IDL file (canonical path)
Throws:
Jbi4CorbaException - The Jbi4Corba exception

findFilesFromSourceDirectory

public static List<File> findFilesFromSourceDirectory(String basedirString,
                                                      String extensionFilter)
This method find all the files in a directory according to the filter. MARCO 23/09/2007: now searches also in the root baseDirString (not only in the subdirectories).

Parameters:
basedirString - The directory where the method works.
extensionFilter - The filter (the suffix of the files).
Returns:
The return

compileJavaClasses

public static void compileJavaClasses(String workdirsrc,
                                      String workdirclasses,
                                      List<String> javaSources,
                                      List<String> jarFiles,
                                      List<String> extraClassPath)
                               throws ClassGenerationException
XXX javadoc.

Parameters:
workdirsrc - The work dir src
workdirclasses - The workdir classes
javaSources - The java sources
jarFiles - The jar files
extraClassPath - The extra class path
Throws:
ClassGenerationException - The class generation exception

extractMethodSignatureOfTheCorbaOperations

public static Map<String,List<MethodSignature>> extractMethodSignatureOfTheCorbaOperations(String sourceDir)
                                                                                    throws ClassGenerationException
This method extracts all the MethodSignature in the 'Operations' source files.

Parameters:
sourceDir - The directory where we find the files.
Returns:
The map of method signature associated to the qualified java name of the class (the key of the map).
Throws:
ClassGenerationException - The class generation exception

findClassUsedInTheOperations

public static Set<Class> findClassUsedInTheOperations(String dir)
                                               throws ClassGenerationException
This method extracs all the class used as method's parameter or method's result.

Parameters:
dir - Where looking for the classes.
Returns:
The set of class found.
Throws:
ClassGenerationException - The class generation exception

findAllTypesUsedInIDL

public static Set<Class> findAllTypesUsedInIDL(String dir)
                                        throws ClassGenerationException
This method extracts all the types used in idl file.

Parameters:
dir - Where looking for the classes.
Returns:
The set of class found.
Throws:
ClassGenerationException - The class generation exception

getTypesMap

public static HashMap<String,String> getTypesMap(String dir)
                                          throws ClassGenerationException
findAllTypes - finds all types defined in IDL

Parameters:
dir -
typeClasses -
Returns:
Throws:
ClassGenerationException

findClassUsed

public static Set<Class> findClassUsed(String dir,
                                       List<File> classList)
                                throws ClassGenerationException
This method extracs all the class used as method's parameter or method's result.

Parameters:
dir - The dir
classList - The class list
Returns:
the return
Throws:
ClassGenerationException - The class generation exception

classLoad

public static Class classLoad(String dir,
                              File classAsFile)
                       throws ClassGenerationException
Parameters:
dir - The dir
classAsFile - The class AsFile
Returns:
The return
Throws:
ClassGenerationException - The class generation exception

classLoad

public static Class classLoad(String dir,
                              String className)
                       throws ClassGenerationException
Load ths class using the class name in the target directory.

Parameters:
dir - The dir
classAsFile - The class AsFile
addParent - if true, link the classLoader with the Util ClassLoader.
Returns:
The return
Throws:
ClassGenerationException - The class generation exception

classLoad

public static Class classLoad(String dir,
                              String className,
                              boolean addParent)
                       throws ClassGenerationException
Load ths class using the class name in the target directory.

Parameters:
dir - The dir
classAsFile - The class AsFile
addParent - if true, link the classLoader with the Util ClassLoader.
Returns:
The return
Throws:
ClassGenerationException - The class generation exception

findGeneratedClasses

public static List<Class> findGeneratedClasses(String classesDir,
                                               ClassLoader classLoader)
                                        throws ClassGenerationException
This method find all the '.class' files in classesDir.

Parameters:
classesDir - The directory to inspect.
classLoader - The class loader used to istantiate the classes.
Returns:
The list of files found.
Throws:
ClassGenerationException - The class generation exception

getClassName

public static String getClassName(String absoluteFilePath,
                                  String basedir,
                                  String extension)
                           throws ClassGenerationException
Gets the class name from the file absolute path, representing both "java" and "class" file names

Parameters:
absoluteFilePath - The file absolute path
basedir - The base dir path
extension - ".class" or ".java"
Returns:
The return
Throws:
ClassGenerationException - The class generation exception

getClassName

public static String getClassName(File file,
                                  String basedir,
                                  String extension)
                           throws ClassGenerationException
Gets the class name from the file absolute path, representing both "java" and "class" file names

Parameters:
file - The file
basedir - The base dir path
extension - ".class" or ".java"
Returns:
The return
Throws:
ClassGenerationException - The class generation exception

getAsmCLassReader

public static org.objectweb.asm.ClassReader getAsmCLassReader(String classesDirName,
                                                              String className)
                                                       throws ClassGenerationException
Parameters:
classesDirName - The classes dir name
className - The class name
Returns:
The return
Throws:
ClassGenerationException - The class generation exception

getAsmCLassReader

public static org.objectweb.asm.ClassReader getAsmCLassReader(String className)
                                                       throws ClassGenerationException
This method returns the class reader used for the bytecode manipulation.

Parameters:
className - The absolute path of the class (eg: /var/Foo.class).
Returns:
The class reader associated to the input class.
Throws:
ClassGenerationException - The class generation exception.

saveAsJavaClass

public static void saveAsJavaClass(String classesDirName,
                                   String relativeFileName,
                                   byte[] newBytecode)
                            throws ClassGenerationException
Parameters:
classesDirName - The classes dir name
relativeFileName - The relative file name
newBytecode - The new Bytecode
Throws:
ClassGenerationException - The class generation exception

saveAsJavaClass

public static void saveAsJavaClass(String absoluteFileName,
                                   byte[] newBytecode)
                            throws ClassGenerationException
Parameters:
absoluteFileName - The absolute file name
newBytecode - The new Byte code
Throws:
ClassGenerationException - The class generation exception

saveAsJavaSource

public static File saveAsJavaSource(String code,
                                    String dir,
                                    String name)
                             throws ClassGenerationException
This method save a java file.

Parameters:
code - The code of the file.
dir - The directory where the file will be save.
name - The name of the file.
Returns:
The new File.
Throws:
ClassGenerationException - The class generation exception.

saveFile

public static File saveFile(String code,
                            String dir,
                            String name)
                     throws ClassGenerationException
This method saves a file.

Parameters:
content - The content of the file stored in a string
dir - The directory where the file will be save.
name - The name of the file.
Returns:
The new File.
Throws:
ClassGenerationException - The class generation exception.

valueTypesImpl

public static List<String> valueTypesImpl(String workdirsrc,
                                          boolean addToStringEquals)
                                   throws ClassGenerationException
The files with the 'DefaultFactory.java' suffix instantiate a value type but the implementation of this data types must be provided by the developers. To automate the process the method creates a new (empty) java source file that extends the class of the value type.

Parameters:
workdirsrc - The directory where the method look for the 'DefaultFactory' java files. The generated files will be placed here.
addToStringEquals - If true the method toString and equals will be added.
Returns:
The list of a full java name of the value types.
Throws:
ClassGenerationException - The class generation exception

replaceSeparatorWithDot

public static String replaceSeparatorWithDot(String s)
This method replaces the file sperator with a dot.

Parameters:
s - The working string.
Returns:
The new string.

replaceDotWithSeparator

public static String replaceDotWithSeparator(String s)
This method replaces the dot with a file sperator.

Parameters:
s - The working path.
Returns:
The new string.

valueTypeMapHandler

public static Map<String,Object> valueTypeMapHandler(List<String> vtList,
                                                     String classesDirName,
                                                     ClassLoader cl)
                                              throws ClassGenerationException
XXX javadoc.

Parameters:
vtList - The vt list
classesDirName - The classes dir name
cl - The class loader
Returns:
The return
Throws:
ClassGenerationException - The class generation exception

valueTypeMapHandlerWithJbi4corbaFactory

public static Map<String,Object> valueTypeMapHandlerWithJbi4corbaFactory(List<String> vtList,
                                                                         String classesDirName,
                                                                         ClassLoader cl)
                                                                  throws ClassGenerationException
XXX javadoc.

Parameters:
vtList - The vt list
classesDirName - The classes dir name
cl - The class loader
Returns:
The return
Throws:
ClassGenerationException - The class generation exception

getValueTypeIdFromHelperClass

public static String getValueTypeIdFromHelperClass(String helper,
                                                   ClassLoader cl)
                                            throws ClassGenerationException
Parameters:
helper - The helper
cl - The class loader
Returns:
The return
Throws:
ClassGenerationException - The class generation exception

prepareClassPath

public static List<String> prepareClassPath(String libDirName)
                                     throws ClassGenerationException
The list of names of the jars used in the classpath.

Parameters:
libDirName - The directory where the jars are located.
Returns:
The list of names of the jars used in the classpath.
Throws:
ClassGenerationException - The class generation exception

generateValueTypeFactoryJbi4corba

public static List<String> generateValueTypeFactoryJbi4corba(List<String> vtList,
                                                             String basedir)
                                                      throws ClassGenerationException
This method generates the new valuetypes factories. For each valuetype we generate a class that extends the default value factory. The created classes have the suffix 'Jbi4corba' (e.g.: MyValueTypeDefaultFactoryJbi4corba.java).

Parameters:
vtList - The list of valuetypes.
basedir - The directory where the sources are located.
Returns:
The list of new factory (as full java name).
Throws:
ClassGenerationException - If the one new factory cannot saved.

tweakSerializableDecoration

public static void tweakSerializableDecoration(String absPath,
                                               Long newSerialVersionUid)
                                        throws ClassGenerationException
This method modify the bytecode of a class: add Serializable interface and set the serial version UID.

Parameters:
absPath - The absolute path of the class to modify.
newSerialVersionUid - The new serialVersionUID.
Throws:
ClassGenerationException - The class generation exception

tweakSerializableInspection

public static ClassMetaInfo tweakSerializableInspection(String absPath)
                                                 throws ClassGenerationException
This method inspect a class to verify if it is Serilizable and to extract the serial version UID (if exists).

Parameters:
absPath - The absolute path of the class to inspect.
Returns:
The meta info of the class visited.
Throws:
ClassGenerationException - The class generation exception

findOnewayOperations

public static Map<String,List<String>> findOnewayOperations(String bin)
                                                     throws ClassGenerationException
This method is used to discover the 'oneway' operations inside a corba stub.

Parameters:
bin - The classes directory.
Returns:
The map key is the full java name of the class inspected and the value is the list of oneway operations associated to the class.
Throws:
ClassGenerationException - The class generation exception

tweakOnewayInspection

public static Map<String,List<String>> tweakOnewayInspection(String absPath)
                                                      throws ClassGenerationException
This method is used to inspect the bytecode of a class to discover the corba 'oneway' requests.

Parameters:
absPath - The absolute path of the corba stub.
Returns:
The map key is the full java name of the class inspected and the value is the list of oneway operations associated to the class.
Throws:
ClassGenerationException - The class generation exception

replaceCorbaEnumaration

public static Map<String,List<String>> replaceCorbaEnumaration(String src,
                                                               String bin)
                                                        throws ClassGenerationException
This method finds the corba enumerations and replace them with a standard enum classes. These classes implement the IDLEntity interface and provide two methods used from the helper classes.

Parameters:
src - The source directory.
bin - The classes directory.
Returns:
The map that contains all the corba enum. The key of the map is the full java name of the corba enum and the value is the list of the associated label.
Throws:
ClassGenerationException - The class generation exception

generateSpecialEnumClass

public static String generateSpecialEnumClass(String aPackage,
                                              String aClassName,
                                              List<String> labelList)
This method generates the source code of a standard enum class with some special features. It implements IDLEntity and provides the methods 'value' and 'from_int'.

Parameters:
aPackage - The package of the class.
aClassName - The simple class name.
labelList - The list of label for the enumaration.
Returns:
The source code generated.

findCorbaEnum

protected static Map<String,List<String>> findCorbaEnum(String bin)
                                                 throws ClassGenerationException
This method find the corba enum.

Parameters:
bin - The classes directory.
Returns:
The corba enums. The key of the map is the path of the class and the value is the ordered list of the possible enum labels.
Throws:
ClassGenerationException - The class generation exception

generateImplementationClass

public static String generateImplementationClass(ClassLoader urlClassLoader,
                                                 String remoteClassName,
                                                 boolean addRemoteSupport)
                                          throws ClassGenerationException
This method load the class 'remoteClassName' using the ClassLoader in input and generates an implementation class. The method expects an interface as imput class.

Parameters:
urlClassLoader - The ClassLoader used to load the class.
remoteClassName - The full name of the Interface to implement.
addRemoteSupport - Check if adding Remote interface to the implementation class is needed
Returns:
The source code generated.
Throws:
ClassGenerationException - When the class name is empty or the class does not exist.

methodImplementation

protected static String methodImplementation(List<MethodSignature> msList,
                                             boolean addRemoteSupport)
This method is used to generate the source code of the methods in the list.

Parameters:
msList - A list of method's signature.
Returns:
The default source code of all the methods.

generateTheBodyOfTheMethodForImplTie

protected static String generateTheBodyOfTheMethodForImplTie(MethodSignature methodSignature,
                                                             boolean addRemoteSupport)
This method is used to generate the body of the methods of the the class that must be implement the skeleton (tie) previously created. The body call the method 'public Object invoke(Object proxy, Method method, Object[] args) throws Throwable;' of a ConsumerInvocationHandler object where - proxy is this class - method is the method to be invoked - args are the parameters of the method invoked. This 'call' may raise a 'Throwable' exception that must be caught. By design the only 2 kind of exception raised are: - Jbi4CorbaRuntimeException; - Jbi4CorbaException. In the first case: - the method caught the exception - extracts the exception's message - throws a RemoteException with the same message. In the second case: - the method caught the exception (in thi case we have a soap fault) - extracts the fault - throws the fault itself

Parameters:
methodSignature - The method's signature.

extractSerialVersionUid

public static Map<Long,String> extractSerialVersionUid(String classesDir,
                                                       List<String> pathList)
                                                throws ClassGenerationException
Throws:
ClassGenerationException

extractSerialVersionUid

public static Long extractSerialVersionUid(Class classToSerialize)

debug

public static void debug(String message,
                         Collection collection)
Parameters:
message - The message
collection - The collection

debug

public static void debug(String message,
                         Map map)
Parameters:
message - The message
map - A map

createUniqueDirectory

public static File createUniqueDirectory(File rootDir,
                                         String seed)
                                  throws IOException
Creates an unique directory form the seed (seed.tmp) in the rootDir.

Parameters:
rootDir -
seed -
Returns:
Throws:
IOException

buildDirectory

public static boolean buildDirectory(File file)
Builds the directory.

Parameters:
file -
Returns:

copyInputStream

public static void copyInputStream(InputStream in,
                                   OutputStream out)
                            throws IOException
Copy an input stream to an output.

Parameters:
in -
out -
Throws:
IOException

classLoadQuiet

public static Class classLoadQuiet(String dir,
                                   String className)
                            throws ClassGenerationException
Try to load the class the class name in the target directory; if no class is found, NO EXCEPTION IS THROWN.

Parameters:
dir - The dir
classAsFile - The class AsFile
Returns:
The return
Throws:
ClassGenerationException - The class generation exception

isThrowableSubClass

public static boolean isThrowableSubClass(Class cls)
isThrowableSubClass

Parameters:
cls -
Returns:


Copyright © 2005-2010 Imola Informatica. All Rights Reserved.