use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class SchemaMarker method loadSchemaObjects.
private List<Entry> loadSchemaObjects(String schemaObjectType, Schema... schemas) throws LdapException, IOException {
Map<String, List<Entry>> m = scObjEntryMap.get(schemaObjectType);
List<Entry> atList = new ArrayList<>();
for (Schema s : schemas) {
List<Entry> preLoaded = m.get(s.getSchemaName());
if (preLoaded != null) {
atList.addAll(preLoaded);
}
}
return atList;
}
use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class DefaultSchemaManager method enable.
/**
* {@inheritDoc}
*/
@Override
public boolean enable(Schema... schemas) throws LdapException {
boolean enabled = false;
// Reset the errors if not null
if (errors != null) {
errors.clear();
}
// Work on a cloned and relaxed registries
Registries clonedRegistries = cloneRegistries();
clonedRegistries.setRelaxed();
Set<Schema> disabledSchemas = new HashSet<>();
for (Schema schema : schemas) {
if (schema.getDependencies() != null) {
for (String dependency : schema.getDependencies()) {
Schema dependencySchema = schemaMap.get(dependency);
if (dependencySchema.isDisabled()) {
disabledSchemas.add(dependencySchema);
}
}
}
schema.enable();
load(clonedRegistries, schema);
}
// Revert back the disabled schema to disabled
for (Schema disabledSchema : disabledSchemas) {
if (disabledSchema.isEnabled()) {
disabledSchema.disable();
}
}
// Build the cross references
errors = clonedRegistries.buildReferences();
// Destroy the clonedRegistry
clonedRegistries.clear();
if (errors.isEmpty()) {
// Ok no errors. Check the registries now
errors = clonedRegistries.checkRefInteg();
if (errors.isEmpty()) {
// We are golden : let's apply the schemas in the real registries
for (Schema schema : schemas) {
schema.enable();
load(registries, schema);
}
// Build the cross references
errors = registries.buildReferences();
registries.setStrict();
enabled = true;
}
}
// clear the cloned registries
clonedRegistries.clear();
return enabled;
}
use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class DefaultSchemaManager method loadDepsFirst.
/**
* Recursive method which loads schema's with their dependent schemas first
* and tracks what schemas it has seen so the recursion does not go out of
* control with dependency cycle detection.
*
* @param registries The Registries in which the schemas will be loaded
* @param schema the current schema we are attempting to load
* @throws Exception if there is a cycle detected and/or another
* failure results while loading, producing and or registering schema objects
*/
private void loadDepsFirst(Registries registries, Schema schema) throws LdapException {
if (schema == null) {
LOG.info(I18n.msg(I18n.MSG_16013_SCHEMA_IS_NULL));
return;
}
if (schema.isDisabled() && !registries.isDisabledAccepted()) {
LOG.info(I18n.msg(I18n.MSG_16017_UNACCEPTED_DISABLED_SCHEMA));
return;
}
String schemaName = schema.getSchemaName();
if (registries.isSchemaLoaded(schemaName)) {
LOG.info(I18n.msg(I18n.MSG_16018_SCHEMA_ALREADY_LOADED, schema.getSchemaName()));
return;
}
String[] deps = schema.getDependencies();
// if no deps then load this guy and return
if ((deps == null) || (deps.length == 0)) {
load(registries, schema);
return;
}
/*
* We got deps and need to load them before this schema. We go through
* all deps loading them with their deps first if they have not been
* loaded.
*/
for (String depName : deps) {
if (registries.isSchemaLoaded(depName)) {
// The schema is already loaded. Loop on the next schema
continue;
} else {
// Call recursively this method
Schema schemaDep = schemaMap.get(depName);
loadDepsFirst(registries, schemaDep);
}
}
// Now load the current schema
load(registries, schema);
}
use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class DefaultSchemaManager method verify.
/**
* {@inheritDoc}
*/
@Override
public boolean verify(Schema... schemas) throws LdapException {
// Work on a cloned registries
Registries clonedRegistries = cloneRegistries();
// Loop on all the schemas
for (Schema schema : schemas) {
try {
// Inject the schema
boolean loaded = load(clonedRegistries, schema);
if (!loaded) {
// We got an error : exit
clonedRegistries.clear();
return false;
}
// Now, check the registries
List<Throwable> errorList = clonedRegistries.checkRefInteg();
if (!errorList.isEmpty()) {
// We got an error : exit
clonedRegistries.clear();
return false;
}
} catch (Exception e) {
// We got an error : exit
clonedRegistries.clear();
return false;
}
}
// We can now delete the cloned registries before exiting
clonedRegistries.clear();
return true;
}
use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class DefaultSchemaManager method loadWithDepsRelaxed.
/**
* {@inheritDoc}
*/
@Override
public boolean loadWithDepsRelaxed(Schema... schemas) throws LdapException {
registries.setRelaxed();
// Load the schemas
for (Schema schema : schemas) {
loadDepsFirstRelaxed(schema);
}
// Build the cross references
errors = registries.buildReferences();
// Check the registries now
errors = registries.checkRefInteg();
return true;
}
Aggregations