String parentAuthorityId = parent.getAuthorityId();
File parentAuthorityDir = this.getAuthorityDir(parentAuthorityId);
if (! parentAuthorityDir.exists()) {
throw new StoreException(StoreException.KEY_NOTFOUND, "Parent authority does not exist.");
}
// create new authority
String authorityId = this.getUUID();
File authorityDir = this.getAuthorityDir(authorityId);
if (authorityDir.exists()) {
throw new StoreException(StoreException.KEY_DUPNAME, "Authority exists already.");
}
FileAuthority authority = new FileAuthority(authorityDir);
try {
authority.internalSetAuthorityId(authorityId);
authority.internalSetNamespace(null);
authority.internalSetLocalAuthService(localAuthService);
authority.internalSetRefs(refs);
authority.internalSetServices(services);
} catch (IOException ex) {
throw new StoreException(ex, StoreException.KEY_DBERR, "Cannot create rootauthority.");
}
// create subsegment
File subSegmentDir = this.getSubSegmentDir(parentAuthorityDir, subSegmentName);
if (subSegmentDir.exists()) {
throw new StoreException(StoreException.KEY_DUPNAME, "Subsegment exists already.");
}
FileSubSegment subSegment = new FileSubSegment(subSegmentDir);
try {
subSegment.internalSetName(subSegmentName);
subSegment.internalSetAuthorityId(authority.getAuthorityId());
subSegment.internalSetParentAuthorityId(parent.getAuthorityId());
} catch (IOException ex) {
throw new StoreException(ex, StoreException.KEY_DBERR, "Cannot create subsegment.");
}
// done
return(subSegment);