001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2006-2008 Sun Microsystems, Inc.
015 * Portions Copyright 2012-2016 ForgeRock AS.
016 */
017package org.opends.server.schema;
018
019import static org.opends.server.schema.SchemaConstants.*;
020
021import org.forgerock.opendj.ldap.ByteString;
022import org.forgerock.opendj.ldap.schema.Schema;
023import org.forgerock.opendj.ldap.schema.Syntax;
024import org.forgerock.opendj.server.config.server.AttributeSyntaxCfg;
025import org.opends.server.api.AttributeSyntax;
026import org.opends.server.util.ServerConstants;
027
028/**
029 * This class defines the Boolean attribute syntax, which only allows values of
030 * "TRUE" or "FALSE" (although this implementation is more flexible and will
031 * also allow "YES", "ON", or "1" instead of "TRUE", or "NO", "OFF", or "0"
032 * instead of "FALSE").  Only equality matching is allowed by default for this
033 * syntax.
034 */
035public class BooleanSyntax
036       extends AttributeSyntax<AttributeSyntaxCfg>
037{
038
039  /**
040   * Creates a new instance of this syntax.  Note that the only thing that
041   * should be done here is to invoke the default constructor for the
042   * superclass.  All initialization should be performed in the
043   * <CODE>initializeSyntax</CODE> method.
044   */
045  public BooleanSyntax()
046  {
047    super();
048  }
049
050  /** {@inheritDoc} */
051  @Override
052  public Syntax getSDKSyntax(Schema schema)
053  {
054    return schema.getSyntax(SchemaConstants.SYNTAX_BOOLEAN_OID);
055  }
056
057  /**
058   * Retrieves the common name for this attribute syntax.
059   *
060   * @return  The common name for this attribute syntax.
061   */
062  @Override
063  public String getName()
064  {
065    return SYNTAX_BOOLEAN_NAME;
066  }
067
068  /**
069   * Retrieves the OID for this attribute syntax.
070   *
071   * @return  The OID for this attribute syntax.
072   */
073  @Override
074  public String getOID()
075  {
076    return SYNTAX_BOOLEAN_OID;
077  }
078
079  /**
080   * Retrieves a description for this attribute syntax.
081   *
082   * @return  A description for this attribute syntax.
083   */
084  @Override
085  public String getDescription()
086  {
087    return SYNTAX_BOOLEAN_DESCRIPTION;
088  }
089
090  /**
091   * Retrieves an attribute value containing a representation of the provided
092   * boolean value.
093   *
094   * @param  b  The boolean value for which to retrieve the attribute value.
095   *
096   * @return  The attribute value created from the provided boolean value.
097   */
098  public static ByteString createBooleanValue(boolean b)
099  {
100    return b ? ServerConstants.TRUE_VALUE : ServerConstants.FALSE_VALUE;
101  }
102}
103