protected Collection createCollectionPath ( String collectionPath , Collection rootCollection ) throws PolicyIndexException { try { if ( rootCollection . getParentCollection ( ) != null ) { throw new PolicyIndexException ( "Collection supplied is not a root collection" ) ; } String rootCollectionName = rootCollection . getName ( ) ; if ( ! collectionPath . startsWith ( rootCollectionName ) ) { throw new PolicyIndexException ( "Collection path " + collectionPath + " does not start from root collection - " + rootCollectionName ) ; } // strip root collection from path, obtain each individual collection name in the path String pathToCreate = collectionPath . substring ( rootCollectionName . length ( ) ) ; String [ ] collections = pathToCreate . split ( "/" ) ; // iterate each and create as necessary Collection nextCollection = rootCollection ; for ( String collectionName : collections ) { Collection childCollection = nextCollection . getChildCollection ( collectionName ) ; if ( childCollection != null ) { // child exists childCollection = nextCollection . getChildCollection ( collectionName ) ; } else { // does not exist, create it CollectionManagementService mgtService = ( CollectionManagementService ) nextCollection . getService ( "CollectionManagementService" , "1.0" ) ; childCollection = mgtService . createCollection ( collectionName ) ; log . debug ( "Created collection " + collectionName ) ; } if ( nextCollection . isOpen ( ) ) { nextCollection . close ( ) ; } nextCollection = childCollection ; } return nextCollection ; } catch ( XMLDBException e ) { log . error ( "Error creating collections from path " + e . getMessage ( ) , e ) ; throw new PolicyIndexException ( "Error creating collections from path " + e . getMessage ( ) , e ) ; } }
Create a collection given a full path to the collection . The collection path must include the root collection . Intermediate collections in the path are created if they do not already exist .