private void ensureCollectionClass ( CollectionDescriptorDef collDef , String checkLevel ) throws ConstraintException { if ( CHECKLEVEL_NONE . equals ( checkLevel ) ) { return ; } if ( collDef . hasProperty ( PropertyHelper . OJB_PROPERTY_ARRAY_ELEMENT_CLASS_REF ) ) { // an array cannot have a collection-class specified if ( collDef . hasProperty ( PropertyHelper . OJB_PROPERTY_COLLECTION_CLASS ) ) { throw new ConstraintException ( "Collection " + collDef . getName ( ) + " in class " + collDef . getOwner ( ) . getName ( ) + " is an array but does specify collection-class" ) ; } else { // no further processing necessary as its an array return ; } } if ( CHECKLEVEL_STRICT . equals ( checkLevel ) ) { InheritanceHelper helper = new InheritanceHelper ( ) ; ModelDef model = ( ModelDef ) collDef . getOwner ( ) . getOwner ( ) ; String specifiedClass = collDef . getProperty ( PropertyHelper . OJB_PROPERTY_COLLECTION_CLASS ) ; String variableType = collDef . getProperty ( PropertyHelper . OJB_PROPERTY_VARIABLE_TYPE ) ; try { if ( specifiedClass != null ) { // if we have a specified class then it has to implement the manageable collection and be a sub type of the variable type if ( ! helper . isSameOrSubTypeOf ( specifiedClass , variableType ) ) { throw new ConstraintException ( "The type " + specifiedClass + " specified as collection-class of the collection " + collDef . getName ( ) + " in class " + collDef . getOwner ( ) . getName ( ) + " is not a sub type of the variable type " + variableType ) ; } if ( ! helper . isSameOrSubTypeOf ( specifiedClass , MANAGEABLE_COLLECTION_INTERFACE ) ) { throw new ConstraintException ( "The type " + specifiedClass + " specified as collection-class of the collection " + collDef . getName ( ) + " in class " + collDef . getOwner ( ) . getName ( ) + " does not implement " + MANAGEABLE_COLLECTION_INTERFACE ) ; } } else { // no collection class specified so the variable type has to be a collection type if ( helper . isSameOrSubTypeOf ( variableType , MANAGEABLE_COLLECTION_INTERFACE ) ) { // we can specify it as a collection-class as it is an manageable collection collDef . setProperty ( PropertyHelper . OJB_PROPERTY_COLLECTION_CLASS , variableType ) ; } else if ( ! helper . isSameOrSubTypeOf ( variableType , JAVA_COLLECTION_INTERFACE ) ) { throw new ConstraintException ( "The collection " + collDef . getName ( ) + " in class " + collDef . getOwner ( ) . getName ( ) + " needs the collection-class attribute as its variable type does not implement " + JAVA_COLLECTION_INTERFACE ) ; } } } catch ( ClassNotFoundException ex ) { throw new ConstraintException ( "Could not find the class " + ex . getMessage ( ) + " on the classpath while checking the collection " + collDef . getName ( ) + " in class " + collDef . getOwner ( ) . getName ( ) ) ; } } }
Ensures that the given collection descriptor has the collection - class property if necessary .