protected ManageableCollection createCollection ( CollectionDescriptor desc , Class collectionClass ) { Class fieldType = desc . getPersistentField ( ) . getType ( ) ; ManageableCollection col ; if ( collectionClass == null ) { if ( ManageableCollection . class . isAssignableFrom ( fieldType ) ) { try { col = ( ManageableCollection ) fieldType . newInstance ( ) ; } catch ( Exception e ) { throw new OJBRuntimeException ( "Cannot instantiate the default collection type " + fieldType . getName ( ) + " of collection " + desc . getAttributeName ( ) + " in type " + desc . getClassDescriptor ( ) . getClassNameOfObject ( ) ) ; } } else if ( fieldType . isAssignableFrom ( RemovalAwareCollection . class ) ) { col = new RemovalAwareCollection ( ) ; } else if ( fieldType . isAssignableFrom ( RemovalAwareList . class ) ) { col = new RemovalAwareList ( ) ; } else if ( fieldType . isAssignableFrom ( RemovalAwareSet . class ) ) { col = new RemovalAwareSet ( ) ; } else { throw new MetadataException ( "Cannot determine a default collection type for collection " + desc . getAttributeName ( ) + " in type " + desc . getClassDescriptor ( ) . getClassNameOfObject ( ) ) ; } } else { try { col = ( ManageableCollection ) collectionClass . newInstance ( ) ; } catch ( Exception e ) { throw new OJBRuntimeException ( "Cannot instantiate the collection class " + collectionClass . getName ( ) + " of collection " + desc . getAttributeName ( ) + " in type " + desc . getClassDescriptor ( ) . getClassNameOfObject ( ) ) ; } } return col ; }
Create a collection object of the given collection type . If none has been given OJB uses RemovalAwareList RemovalAwareSet or RemovalAwareCollection depending on the field type .