mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Nicolas Capponi
22.58.2015 9defd2349274d077ad120d780a6fac5f6d594c7f
opendj-server-legacy/src/main/java/org/opends/server/schema/ObjectClassSyntax.java
@@ -26,6 +26,12 @@
 */
package org.opends.server.schema;
import static org.opends.messages.SchemaMessages.*;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.schema.SchemaConstants.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
@@ -34,24 +40,18 @@
import java.util.Set;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.schema.ObjectClassType;
import org.opends.server.admin.std.server.AttributeSyntaxCfg;
import org.forgerock.opendj.ldap.schema.MatchingRule;
import org.opends.server.api.AttributeSyntax;
import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ResultCode;
import static org.opends.messages.SchemaMessages.*;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.schema.SchemaConstants.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import org.forgerock.opendj.ldap.schema.ObjectClassType;
import org.forgerock.opendj.ldap.schema.Syntax;
import org.opends.server.admin.std.server.AttributeSyntaxCfg;
import org.opends.server.api.AttributeSyntax;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.AttributeType;
import org.opends.server.types.CommonSchemaElements;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.ObjectClass;
import org.opends.server.types.Schema;
/**
 * This class implements the object class description syntax, which is used to
@@ -61,16 +61,6 @@
public class ObjectClassSyntax
       extends AttributeSyntax<AttributeSyntaxCfg>
{
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  /** The default equality matching rule for this syntax. */
  private MatchingRule defaultEqualityMatchingRule;
  /** The default ordering matching rule for this syntax. */
  private MatchingRule defaultOrderingMatchingRule;
  /** The default substring matching rule for this syntax. */
  private MatchingRule defaultSubstringMatchingRule;
  /**
   * Creates a new instance of this syntax.  Note that the only thing that
@@ -85,35 +75,9 @@
  /** {@inheritDoc} */
  @Override
  public void initializeSyntax(AttributeSyntaxCfg configuration)
         throws ConfigException, InitializationException
  public Syntax getSDKSyntax(org.forgerock.opendj.ldap.schema.Schema schema)
  {
    defaultEqualityMatchingRule =
         DirectoryServer.getMatchingRule(EMR_CASE_IGNORE_OID);
    if (defaultEqualityMatchingRule == null)
    {
      LocalizableMessage message = ERR_ATTR_SYNTAX_UNKNOWN_EQUALITY_MATCHING_RULE.get(
          EMR_CASE_IGNORE_OID, SYNTAX_OBJECTCLASS_NAME);
      throw new InitializationException(message);
    }
    defaultOrderingMatchingRule =
         DirectoryServer.getMatchingRule(OMR_CASE_IGNORE_OID);
    if (defaultOrderingMatchingRule == null)
    {
      LocalizableMessage message = ERR_ATTR_SYNTAX_UNKNOWN_ORDERING_MATCHING_RULE.get(
          OMR_CASE_IGNORE_OID, SYNTAX_OBJECTCLASS_NAME);
      throw new InitializationException(message);
    }
    defaultSubstringMatchingRule =
         DirectoryServer.getMatchingRule(SMR_CASE_IGNORE_OID);
    if (defaultSubstringMatchingRule == null)
    {
      LocalizableMessage message = ERR_ATTR_SYNTAX_UNKNOWN_SUBSTRING_MATCHING_RULE.get(
          SMR_CASE_IGNORE_OID, SYNTAX_OBJECTCLASS_NAME);
      throw new InitializationException(message);
    }
    return schema.getSyntax(SchemaConstants.SYNTAX_OBJECTCLASS_OID);
  }
  /** {@inheritDoc} */
@@ -137,56 +101,6 @@
    return SYNTAX_OBJECTCLASS_DESCRIPTION;
  }
  /** {@inheritDoc} */
  @Override
  public MatchingRule getEqualityMatchingRule()
  {
    return defaultEqualityMatchingRule;
  }
  /** {@inheritDoc} */
  @Override
  public MatchingRule getOrderingMatchingRule()
  {
    return defaultOrderingMatchingRule;
  }
  /** {@inheritDoc} */
  @Override
  public MatchingRule getSubstringMatchingRule()
  {
    return defaultSubstringMatchingRule;
  }
  /** {@inheritDoc} */
  @Override
  public MatchingRule getApproximateMatchingRule()
  {
    // There is no approximate matching rule by default.
    return null;
  }
  /** {@inheritDoc} */
  @Override
  public boolean valueIsAcceptable(ByteSequence value,
                                   LocalizableMessageBuilder invalidReason)
  {
    // We'll use the decodeObjectClass method to determine if the value is
    // acceptable.
    try
    {
      decodeObjectClass(value, DirectoryServer.getSchema(), true);
      return true;
    }
    catch (DirectoryException de)
    {
      logger.traceException(de);
      invalidReason.append(de.getMessageObject());
      return false;
    }
  }
  /**
   * Decodes the contents of the provided ASN.1 octet string as an objectclass
   * definition according to the rules of this syntax.  Note that the provided
@@ -1420,18 +1334,5 @@
    }
    return false;
  }
  /** {@inheritDoc} */
  public boolean isBEREncodingRequired()
  {
    return false;
  }
  /** {@inheritDoc} */
  @Override
  public boolean isHumanReadable()
  {
    return true;
  }
}