use of org.apache.directory.api.ldap.model.schema.parsers.OpenLdapSchemaParser 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);
}
}
Aggregations