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