use of org.apache.directory.api.ldap.model.schema.registries.Registries 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.Registries 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.Registries in project directory-ldap-api by apache.
the class LdapNetworkConnection method addSchema.
/**
* parses the given schema file present in OpenLDAP schema format
* and adds all the SchemaObjects present in it to the SchemaManager
*
* @param schemaFile the schema file in OpenLDAP schema format
* @throws LdapException in case of any errors while parsing
*/
public void addSchema(File schemaFile) throws LdapException {
try {
if (schemaManager == null) {
loadSchema();
}
if (schemaManager == null) {
throw new LdapException("Cannot load the schema");
}
OpenLdapSchemaParser olsp = new OpenLdapSchemaParser();
olsp.setQuirksMode(true);
olsp.parse(schemaFile);
Registries registries = schemaManager.getRegistries();
List<Throwable> errors = new ArrayList<>();
for (AttributeType atType : olsp.getAttributeTypes()) {
registries.buildReference(errors, atType);
registries.getAttributeTypeRegistry().register(atType);
}
for (ObjectClass oc : olsp.getObjectClassTypes()) {
registries.buildReference(errors, oc);
registries.getObjectClassRegistry().register(oc);
}
LOG.info("successfully loaded the schema from file {}", schemaFile.getAbsolutePath());
} catch (Exception e) {
LOG.error(I18n.err(I18n.ERR_03206_FAIL_LOAD_SCHEMA_FILE, schemaFile.getAbsolutePath()));
throw new LdapException(e);
}
}
use of org.apache.directory.api.ldap.model.schema.registries.Registries in project directory-ldap-api by apache.
the class ApiLdapModelOsgiTest method useBundleClasses.
@Override
protected void useBundleClasses() throws Exception {
// uses FastDnParser
new Dn("dc=example,dc=com");
// uses ComplexDnparser (antlr based)
new Dn("cn=a+sn=b,dc=example,dc=com");
new Value("foo");
new DefaultAttribute("cn");
new DefaultEntry();
AttributeUtils.toJndiAttribute(new DefaultAttribute("cn"));
new BindRequestImpl();
new EqualityNode<String>("cn", "foo");
new LdapUrl("ldap://ldap.example.com:10389/dc=example,dc=com?objectclass");
new ObjectClassDescriptionSchemaParser().parse("( 2.5.6.0 NAME 'top' DESC 'top of the superclass chain' ABSTRACT MUST objectClass )");
SchemaObject schemaObject = new LdapSyntax("1.2.3");
new Registries().getGlobalOidRegistry().register(schemaObject);
new Registries().getLoadedSchemas();
}
use of org.apache.directory.api.ldap.model.schema.registries.Registries in project directory-ldap-api by apache.
the class DefaultSchemaManager method cloneRegistries.
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
/**
* Clone the registries before doing any modification on it. Relax it
* too so that we can update it.
*/
private Registries cloneRegistries() throws LdapException {
try {
// Relax the controls at first
errors = new ArrayList<>();
// Clone the Registries
Registries clonedRegistries = registries.clone();
// And update references. We may have errors, that may be fixed
// by the new loaded schemas.
errors = clonedRegistries.checkRefInteg();
// Now, relax the cloned Registries if there is no error
clonedRegistries.setRelaxed();
return clonedRegistries;
} catch (CloneNotSupportedException cnse) {
throw new LdapOtherException(cnse.getMessage(), cnse);
}
}
Aggregations