com.bm.utils
Class Ejb3Utils

java.lang.Object
  extended by com.bm.utils.Ejb3Utils

public final class Ejb3Utils
extends java.lang.Object

Util class for ejb3unit.

Author:
Daniel Wiese

Field Summary
static int OSTYPE_LINUX
          This field is used to OSTYPE_LINUX.
static int OSTYPE_MAC
          This field is used to OSTYPE_MAC.
static int OSTYPE_NETWARE
          This field is used to OSTYPE_NETWARE.
static int OSTYPE_OS2
          This field is used to OSTYPE_OS2.
static int OSTYPE_SOLARIS
          This field is used to OSTYPE_SOLARIS.
static int OSTYPE_SUN
          This field is used to OSTYPE_SUN.
static int OSTYPE_UNKNOWN
          This field is used to OSTYPE_UNKNOWN.
static int OSTYPE_WINCE
          This field is used to OSTYPE_WINCE.
static int OSTYPE_WINDOWS
          This field is used to OSTYPE_WINDOWS.
static int OSTYPE_WINNT
          This field is used to OSTYPE_WINNT.
 
Method Summary
static java.lang.reflect.Field[] getAllFields(java.lang.Class forClass)
          Returns all fields (including fields from all superclasses) of a class.
static java.lang.reflect.Method[] getAllMethods(java.lang.Class forClass)
          Returns all fields (including fields from all superclasses) of a class.
static java.lang.String getDecodedFilename(java.net.URL url)
          Decodes an encoded file name in url
static GeneratorType getGeneratorTypeAnnotation(Generator actGenerator)
          Returns a generator type for a given generator.
static java.util.List<java.lang.Class> getLocalRemoteInterfaces(java.lang.Class toAnalyse)
          Returns all business (local, remote) interfaces of the class.
static
<T> T
getNewInstance(java.lang.Class<T> forClass)
          Creates a new instance of a bean, even if it's protected constructor.
static java.lang.Class getNonPrimitiveType(java.lang.Class aktField)
          This method will do the transformation of primitive types if necessary.
static java.lang.Class getNonPrimitiveType(Property aktField)
          This method will do the transformation of primitive types if necessary.
static int getOs()
          Determines the OS.
static java.lang.String getPackageName(java.lang.String longClassName)
          Return a short class name.
static java.lang.reflect.Method getParameterlessMethodByName(java.lang.String name, java.lang.Class inClass)
          Returns a parameterless method.
static java.util.Collection getRightCollectionType(Property forProperty)
          Returns the right collection type for the given property.
static java.io.File getRootPackageDir(java.io.File location, java.lang.String longPackageName)
          Returns the root package directory e.g com.ejb3unit.eg --> returns com.
static java.lang.String getShortClassName(java.lang.Class clazz)
          Return a short class name.
static java.lang.String getShortClassName(java.lang.String longClassName)
          Return a short class name.
static java.io.File getTempDirectory()
          Returns a path to an temp directory.
static boolean hasSuperclassOrInterface(java.lang.Class toCheck, java.lang.Class superclassOrInterface)
          Checks if the current class inherits form the specified class.
static java.lang.String isolateJarName(java.net.URL fileInJar)
          Isolates a jar file when a file was found inside a jar.
static java.util.List<java.lang.String> scanFileNamesInArchive(java.io.InputStream in)
          Scan for files in jar file.
static java.io.InputStream unjar(java.io.InputStream in)
          Extract the first entry in the jar file to an output stream.
static java.util.List<java.io.File> unjar(java.io.InputStream in, java.io.File dest)
          Dump the contents of a JarArchive to the specified destination.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OSTYPE_WINDOWS

public static final int OSTYPE_WINDOWS
This field is used to OSTYPE_WINDOWS.

See Also:
Constant Field Values

OSTYPE_WINNT

public static final int OSTYPE_WINNT
This field is used to OSTYPE_WINNT.

See Also:
Constant Field Values

OSTYPE_WINCE

public static final int OSTYPE_WINCE
This field is used to OSTYPE_WINCE.

See Also:
Constant Field Values

OSTYPE_LINUX

public static final int OSTYPE_LINUX
This field is used to OSTYPE_LINUX.

See Also:
Constant Field Values

OSTYPE_MAC

public static final int OSTYPE_MAC
This field is used to OSTYPE_MAC.

See Also:
Constant Field Values

OSTYPE_SOLARIS

public static final int OSTYPE_SOLARIS
This field is used to OSTYPE_SOLARIS.

See Also:
Constant Field Values

OSTYPE_SUN

public static final int OSTYPE_SUN
This field is used to OSTYPE_SUN.

See Also:
Constant Field Values

OSTYPE_NETWARE

public static final int OSTYPE_NETWARE
This field is used to OSTYPE_NETWARE.

See Also:
Constant Field Values

OSTYPE_OS2

public static final int OSTYPE_OS2
This field is used to OSTYPE_OS2.

See Also:
Constant Field Values

OSTYPE_UNKNOWN

public static final int OSTYPE_UNKNOWN
This field is used to OSTYPE_UNKNOWN.

See Also:
Constant Field Values
Method Detail

isolateJarName

public static java.lang.String isolateJarName(java.net.URL fileInJar)
Isolates a jar file when a file was found inside a jar.

Parameters:
fileInJar - - the path to the file inside the jar file
Returns:
- the name of the jar file

getDecodedFilename

public static java.lang.String getDecodedFilename(java.net.URL url)
Decodes an encoded file name in url

Parameters:
url - the file name
Returns:
the decoded version

getNewInstance

public static <T> T getNewInstance(java.lang.Class<T> forClass)
Creates a new instance of a bean, even if it's protected constructor. (chapter 2.1 page 17), "The entity class must have a no-arg constructor. The entity class may have other constructors as well. The no-arg constructor must be public or protected."

Type Parameters:
T -
Parameters:
forClass - for which class
Returns:
the instrance
Since:
28.03.2007

getOs

public static int getOs()
Determines the OS.

Returns:
an integer identifying the OS (one of the OSTYPE constants)

unjar

public static java.util.List<java.io.File> unjar(java.io.InputStream in,
                                                 java.io.File dest)
                                          throws java.io.IOException
Dump the contents of a JarArchive to the specified destination.

Parameters:
in - - the jar archive as input stream
dest - - the destination (to extract the content)
Returns:
- a list with all extracted files
Throws:
java.io.IOException - - in an error case

unjar

public static java.io.InputStream unjar(java.io.InputStream in)
                                 throws java.io.IOException
Extract the first entry in the jar file to an output stream.

Parameters:
in - - the jar archive as input stream
Throws:
java.io.IOException - - in an error case

scanFileNamesInArchive

public static java.util.List<java.lang.String> scanFileNamesInArchive(java.io.InputStream in)
                                                               throws java.io.IOException
Scan for files in jar file.

Parameters:
in - - the jar archive as input stream
Returns:
- a list with all extracted files
Throws:
java.io.IOException - - in an error case

getLocalRemoteInterfaces

public static java.util.List<java.lang.Class> getLocalRemoteInterfaces(java.lang.Class toAnalyse)
Returns all business (local, remote) interfaces of the class.

Parameters:
toAnalyse - - the session bean /service to analyse
Returns:
- the interfaces
Since:
05.02.2006

getNonPrimitiveType

public static java.lang.Class getNonPrimitiveType(Property aktField)
This method will do the transformation of primitive types if necessary.

Parameters:
aktField - - the field to inspect
Returns:
the declaring type (or primitive representant)

getNonPrimitiveType

public static java.lang.Class getNonPrimitiveType(java.lang.Class aktField)
This method will do the transformation of primitive types if necessary. It also transform all collection types (List, etc to Collection)

Parameters:
aktField - - the field to inspect
Returns:
the declaring type (or primitive representant)

hasSuperclassOrInterface

public static boolean hasSuperclassOrInterface(java.lang.Class toCheck,
                                               java.lang.Class superclassOrInterface)
Checks if the current class inherits form the specified class.

Parameters:
toCheck - the class to check
superclassOrInterface - the superclass
Returns:
true if a supeclass or interface

getGeneratorTypeAnnotation

public static GeneratorType getGeneratorTypeAnnotation(Generator actGenerator)
Returns a generator type for a given generator.

Parameters:
actGenerator - - given generator
Returns:
returns a given generator type
Since:
17.04.2006

getRightCollectionType

public static java.util.Collection getRightCollectionType(Property forProperty)
Returns the right collection type for the given property.

Parameters:
forProperty - - for which property
Returns:
- the right collection type

getAllFields

public static java.lang.reflect.Field[] getAllFields(java.lang.Class forClass)
Returns all fields (including fields from all superclasses) of a class.

Parameters:
forClass - - for which class
Returns:
- all fields

getParameterlessMethodByName

public static java.lang.reflect.Method getParameterlessMethodByName(java.lang.String name,
                                                                    java.lang.Class inClass)
Returns a parameterless method.

Parameters:
name - the name of the method
inClass - in which class
Returns:
the method if found or IllegalArgument exception

getAllMethods

public static java.lang.reflect.Method[] getAllMethods(java.lang.Class forClass)
Returns all fields (including fields from all superclasses) of a class.

Parameters:
forClass - - for which class
Returns:
- all fields

getShortClassName

public static java.lang.String getShortClassName(java.lang.String longClassName)
Return a short class name. E.g. java.util.StringTokenizer will be StringTokenizer

Parameters:
longClassName - - the long fully qualified calss name
Returns:
- short class name

getPackageName

public static java.lang.String getPackageName(java.lang.String longClassName)
Return a short class name. E.g. java.util.StringTokenizer will be StringTokenizer

Parameters:
longClassName - - the long fully qualified class name
Returns:
- short class name

getRootPackageDir

public static java.io.File getRootPackageDir(java.io.File location,
                                             java.lang.String longPackageName)
Returns the root package directory e.g com.ejb3unit.eg --> returns com.

Parameters:
location - - the location of the package
longPackageName - - the long fully qualified class name
Returns:
- root file name

getShortClassName

public static java.lang.String getShortClassName(java.lang.Class clazz)
Return a short class name. E.g. java.util.StringTokenizer will be StringTokenizer

Parameters:
clazz - - for class
Returns:
- short class name

getTempDirectory

public static java.io.File getTempDirectory()
Returns a path to an temp directory.

Returns:
- a path to a temp directory.
Since:
29.06.2006


Copyright © 2008. All Rights Reserved.