Search in sources :

Example 1 with SyntaxChecker

use of org.apache.directory.api.ldap.model.schema.SyntaxChecker in project directory-ldap-api by apache.

the class SchemaManagerAddTest method testAddAlreadyExistingSyntaxChecker.

@Test
public void testAddAlreadyExistingSyntaxChecker() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int nrSize = schemaManager.getSyntaxCheckerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String oid = "0.0.0";
    SyntaxChecker syntaxChecker = RegexSyntaxChecker.builder().setOid(oid).build();
    assertTrue(schemaManager.add(syntaxChecker));
    SyntaxChecker added = schemaManager.lookupSyntaxCheckerRegistry(oid);
    assertNotNull(added);
    assertEquals(syntaxChecker.getClass().getName(), added.getFqcn());
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(0, errors.size());
    assertEquals(nrSize + 1, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    SyntaxChecker syntaxChecker2 = RegexSyntaxChecker.builder().setOid(oid).build();
    assertFalse(schemaManager.add(syntaxChecker2));
    errors = schemaManager.getErrors();
    assertEquals(1, errors.size());
    assertEquals(nrSize + 1, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    added = schemaManager.lookupSyntaxCheckerRegistry(oid);
    assertNotNull(added);
    assertEquals(syntaxChecker.getClass().getName(), added.getFqcn());
}
Also used : OctetStringSyntaxChecker(org.apache.directory.api.ldap.model.schema.syntaxCheckers.OctetStringSyntaxChecker) RegexSyntaxChecker(org.apache.directory.api.ldap.model.schema.syntaxCheckers.RegexSyntaxChecker) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 2 with SyntaxChecker

use of org.apache.directory.api.ldap.model.schema.SyntaxChecker in project directory-ldap-api by apache.

the class SchemaManagerDelTest method testDeleteNonExistingSyntaxChecker.

@Test
public void testDeleteNonExistingSyntaxChecker() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int scrSize = schemaManager.getSyntaxCheckerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    SyntaxChecker sc = BooleanSyntaxChecker.builder().setOid("0.0").build();
    assertFalse(schemaManager.delete(sc));
    List<Throwable> errors = schemaManager.getErrors();
    assertFalse(errors.isEmpty());
    assertEquals(scrSize, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : BooleanSyntaxChecker(org.apache.directory.api.ldap.model.schema.syntaxCheckers.BooleanSyntaxChecker) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 3 with SyntaxChecker

use of org.apache.directory.api.ldap.model.schema.SyntaxChecker in project directory-ldap-api by apache.

the class SchemaManagerDelTest method testDeleteExistingSyntaxChecker.

// =========================================================================
// SyntaxChecker deletion tests
// -------------------------------------------------------------------------
@Test
public void testDeleteExistingSyntaxChecker() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int scrSize = schemaManager.getSyntaxCheckerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    SyntaxChecker sc = BooleanSyntaxChecker.builder().setOid("0.1.1").build();
    assertTrue(schemaManager.add(sc));
    assertEquals(scrSize + 1, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    sc = schemaManager.lookupSyntaxCheckerRegistry("0.1.1");
    assertNotNull(sc);
    assertTrue(schemaManager.delete(sc));
    try {
        schemaManager.lookupSyntaxCheckerRegistry("0.1.1");
        fail();
    } catch (Exception e) {
    // expected
    }
    assertEquals(scrSize, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : BooleanSyntaxChecker(org.apache.directory.api.ldap.model.schema.syntaxCheckers.BooleanSyntaxChecker) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test)

Example 4 with SyntaxChecker

use of org.apache.directory.api.ldap.model.schema.SyntaxChecker in project directory-ldap-api by apache.

the class SchemaEntityFactory method getSyntaxChecker.

/**
 * {@inheritDoc}
 */
@Override
public SyntaxChecker getSyntaxChecker(SchemaManager schemaManager, SyntaxCheckerDescription syntaxCheckerDescription, Registries targetRegistries, String schemaName) throws LdapException {
    checkDescription(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
    // The Comparator OID
    String oid = getOid(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
    // Get the schema
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is not loaded. We can't create the requested SyntaxChecker
        String msg = I18n.err(I18n.ERR_16019_CANNOT_ADD_SC, syntaxCheckerDescription.getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    // The FQCN
    String fqcn = getFqcn(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
    // get the byteCode
    Attribute byteCode = getByteCode(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
    // Class load the SyntaxChecker
    SyntaxChecker syntaxChecker = classLoadSyntaxChecker(schemaManager, oid, fqcn, byteCode);
    // Update the common fields
    setSchemaObjectProperties(syntaxChecker, syntaxCheckerDescription, schema);
    return syntaxChecker;
}
Also used : SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema)

Example 5 with SyntaxChecker

use of org.apache.directory.api.ldap.model.schema.SyntaxChecker in project directory-ldap-api by apache.

the class DefaultSchemaManager method addSyntaxCheckers.

/**
 *Add
 * Register all the Schema's SyntaxCheckers
 */
private void addSyntaxCheckers(Schema schema, Registries registries) throws LdapException, IOException {
    if (schema.getSchemaLoader() == null) {
        return;
    }
    for (Entry entry : schema.getSchemaLoader().loadSyntaxCheckers(schema)) {
        SyntaxChecker syntaxChecker = factory.getSyntaxChecker(this, entry, registries, schema.getSchemaName());
        addSchemaObject(registries, syntaxChecker, schema);
    }
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker)

Aggregations

SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)24 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)9 Test (org.junit.Test)9 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)7 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)7 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)7 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)7 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)6 PrepareString (org.apache.directory.api.ldap.model.schema.PrepareString)5 DeepTrimToLowerNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer)5 OctetStringSyntaxChecker (org.apache.directory.api.ldap.model.schema.syntaxCheckers.OctetStringSyntaxChecker)5 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)4 BooleanSyntaxChecker (org.apache.directory.api.ldap.model.schema.syntaxCheckers.BooleanSyntaxChecker)4 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)3 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)3 LdapUnwillingToPerformException (org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)3 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)3 RegexSyntaxChecker (org.apache.directory.api.ldap.model.schema.syntaxCheckers.RegexSyntaxChecker)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2