public static Object buildNewObjectInstance ( ClassDescriptor cld ) { Object result = null ; // If either the factory class and/or factory method is null, // just follow the normal code path and create via constructor if ( ( cld . getFactoryClass ( ) == null ) || ( cld . getFactoryMethod ( ) == null ) ) { try { // 1. create an empty Object (persistent classes need a public default constructor) Constructor con = cld . getZeroArgumentConstructor ( ) ; if ( con == null ) { throw new ClassNotPersistenceCapableException ( "A zero argument constructor was not provided! Class was '" + cld . getClassNameOfObject ( ) + "'" ) ; } result = ConstructorHelper . instantiate ( con ) ; } catch ( InstantiationException e ) { throw new ClassNotPersistenceCapableException ( "Can't instantiate class '" + cld . getClassNameOfObject ( ) + "'" ) ; } } else { try { // 1. create an empty Object by calling the no-parms factory method Method method = cld . getFactoryMethod ( ) ; if ( Modifier . isStatic ( method . getModifiers ( ) ) ) { // method is static so call it directly result = method . invoke ( null , null ) ; } else { // method is not static, so create an object of the factory first // note that this requires a public no-parameter (default) constructor Object factoryInstance = cld . getFactoryClass ( ) . newInstance ( ) ; result = method . invoke ( factoryInstance , null ) ; } } catch ( Exception ex ) { throw new PersistenceBrokerException ( "Unable to build object instance of class '" + cld . getClassNameOfObject ( ) + "' from factory:" + cld . getFactoryClass ( ) + "." + cld . getFactoryMethod ( ) , ex ) ; } } return result ; }
Builds a new instance for the class represented by the given class descriptor .