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
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.schema;
028
029
030
031 import org.opends.server.admin.std.server.OrderingMatchingRuleCfg;
032 import org.opends.server.api.OrderingMatchingRule;
033 import org.opends.server.config.ConfigException;
034 import org.opends.server.protocols.asn1.ASN1OctetString;
035 import org.opends.server.types.ByteString;
036 import org.opends.server.types.DirectoryException;
037 import org.opends.server.types.InitializationException;
038 import org.opends.server.util.StaticUtils;
039
040 import static org.opends.server.schema.SchemaConstants.*;
041
042
043
044 /**
045 * This class defines the octetStringOrderingMatch matching rule defined in
046 * X.520. This will be the default ordering matching rule for the binary and
047 * octet string syntaxes.
048 */
049 public class OctetStringOrderingMatchingRule
050 extends OrderingMatchingRule
051 {
052 /**
053 * The serial version identifier required to satisfy the compiler because this
054 * class implements the <CODE>java.io.Serializable</CODE> interface. This
055 * value was generated using the <CODE>serialver</CODE> command-line utility
056 * included with the Java SDK.
057 */
058 private static final long serialVersionUID = 3832343819704649155L;
059
060
061
062 /**
063 * Creates a new instance of this octetStringOrderingMatch matching rule.
064 */
065 public OctetStringOrderingMatchingRule()
066 {
067 super();
068 }
069
070
071
072 /**
073 * {@inheritDoc}
074 */
075 public void initializeMatchingRule(OrderingMatchingRuleCfg configuration)
076 throws ConfigException, InitializationException
077 {
078 // No initialization is required.
079 }
080
081
082
083 /**
084 * Retrieves the common name for this matching rule.
085 *
086 * @return The common name for this matching rule, or <CODE>null</CODE> if
087 * it does not have a name.
088 */
089 public String getName()
090 {
091 return OMR_OCTET_STRING_NAME;
092 }
093
094
095
096 /**
097 * Retrieves the OID for this matching rule.
098 *
099 * @return The OID for this matching rule.
100 */
101 public String getOID()
102 {
103 return OMR_OCTET_STRING_OID;
104 }
105
106
107
108 /**
109 * Retrieves the description for this matching rule.
110 *
111 * @return The description for this matching rule, or <CODE>null</CODE> if
112 * there is none.
113 */
114 public String getDescription()
115 {
116 // There is no standard description for this matching rule.
117 return null;
118 }
119
120
121
122 /**
123 * Retrieves the OID of the syntax with which this matching rule is
124 * associated.
125 *
126 * @return The OID of the syntax with which this matching rule is associated.
127 */
128 public String getSyntaxOID()
129 {
130 return SYNTAX_OCTET_STRING_OID;
131 }
132
133
134
135 /**
136 * Retrieves the normalized form of the provided value, which is best suited
137 * for efficiently performing matching operations on that value.
138 *
139 * @param value The value to be normalized.
140 *
141 * @return The normalized version of the provided value.
142 *
143 * @throws DirectoryException If the provided value is invalid according to
144 * the associated attribute syntax.
145 */
146 public ByteString normalizeValue(ByteString value)
147 throws DirectoryException
148 {
149 return new ASN1OctetString(value.value());
150 }
151
152
153
154 /**
155 * Compares the first value to the second and returns a value that indicates
156 * their relative order.
157 *
158 * @param value1 The normalized form of the first value to compare.
159 * @param value2 The normalized form of the second value to compare.
160 *
161 * @return A negative integer if <CODE>value1</CODE> should come before
162 * <CODE>value2</CODE> in ascending order, a positive integer if
163 * <CODE>value1</CODE> should come after <CODE>value2</CODE> in
164 * ascending order, or zero if there is no difference between the
165 * values with regard to ordering.
166 */
167 public int compareValues(ByteString value1, ByteString value2)
168 {
169 return compare(value1.value(), value2.value());
170 }
171
172
173
174 /**
175 * Compares the contents of the provided byte arrays to determine their
176 * relative order.
177 *
178 * @param b1 The first byte array to use in the comparison.
179 * @param b2 The second byte array to use in the comparison.
180 *
181 * @return A negative integer if <CODE>b1</CODE> should come before
182 * <CODE>b2</CODE> in ascending order, a positive integer if
183 * <CODE>b1</CODE> should come after <CODE>b2</CODE> in ascending
184 * order, or zero if there is no difference between the values with
185 * regard to ordering.
186 */
187 public int compare(byte[] b1, byte[] b2)
188 {
189 return StaticUtils.compare(b1, b2);
190 }
191 }
192