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.AttributeSyntaxCfg; 032 import org.opends.server.api.*; 033 import org.opends.server.config.ConfigException; 034 import org.opends.server.core.DirectoryServer; 035 import org.opends.server.types.ByteString; 036 import org.opends.server.types.AttributeValue; 037 import org.opends.server.types.DirectoryException; 038 039 import static org.opends.server.loggers.ErrorLogger.*; 040 import static org.opends.messages.SchemaMessages.*; 041 import org.opends.messages.MessageBuilder; 042 import static org.opends.server.schema.SchemaConstants.*; 043 044 045 046 /** 047 * This class defines the binary attribute syntax, which is essentially a byte 048 * array using very strict matching. Equality, ordering, and substring matching 049 * will be allowed by default. 050 */ 051 public class BinarySyntax 052 extends AttributeSyntax<AttributeSyntaxCfg> 053 { 054 // The default equality matching rule for this syntax. 055 private EqualityMatchingRule defaultEqualityMatchingRule; 056 057 // The default ordering matching rule for this syntax. 058 private OrderingMatchingRule defaultOrderingMatchingRule; 059 060 // The default substring matching rule for this syntax. 061 private SubstringMatchingRule defaultSubstringMatchingRule; 062 063 064 065 /** 066 * A {@code byte[]} attribute value decoder for this syntax. 067 */ 068 public static final AttributeValueDecoder<byte[]> DECODER = 069 new AttributeValueDecoder<byte[]>() 070 { 071 /** 072 * {@inheritDoc} 073 */ 074 public byte[] decode(AttributeValue value) throws DirectoryException { 075 // Make sure that the value is valid. 076 value.getNormalizedValue(); 077 return value.getValueBytes(); 078 } 079 }; 080 081 082 083 /** 084 * Creates a new instance of this syntax. Note that the only thing that 085 * should be done here is to invoke the default constructor for the 086 * superclass. All initialization should be performed in the 087 * <CODE>initializeSyntax</CODE> method. 088 */ 089 public BinarySyntax() 090 { 091 super(); 092 } 093 094 095 096 /** 097 * {@inheritDoc} 098 */ 099 public void initializeSyntax(AttributeSyntaxCfg configuration) 100 throws ConfigException 101 { 102 defaultEqualityMatchingRule = 103 DirectoryServer.getEqualityMatchingRule(EMR_OCTET_STRING_OID); 104 if (defaultEqualityMatchingRule == null) 105 { 106 logError(ERR_ATTR_SYNTAX_UNKNOWN_EQUALITY_MATCHING_RULE.get( 107 EMR_OCTET_STRING_OID, SYNTAX_BINARY_NAME)); 108 } 109 110 defaultOrderingMatchingRule = 111 DirectoryServer.getOrderingMatchingRule(OMR_OCTET_STRING_OID); 112 if (defaultOrderingMatchingRule == null) 113 { 114 logError(ERR_ATTR_SYNTAX_UNKNOWN_ORDERING_MATCHING_RULE.get( 115 OMR_OCTET_STRING_OID, SYNTAX_BINARY_NAME)); 116 } 117 118 defaultSubstringMatchingRule = 119 DirectoryServer.getSubstringMatchingRule(SMR_OCTET_STRING_OID); 120 if (defaultSubstringMatchingRule == null) 121 { 122 logError(ERR_ATTR_SYNTAX_UNKNOWN_SUBSTRING_MATCHING_RULE.get( 123 SMR_OCTET_STRING_OID, SYNTAX_BINARY_NAME)); 124 } 125 } 126 127 128 129 /** 130 * Retrieves the common name for this attribute syntax. 131 * 132 * @return The common name for this attribute syntax. 133 */ 134 public String getSyntaxName() 135 { 136 return SYNTAX_BINARY_NAME; 137 } 138 139 140 141 /** 142 * Retrieves the OID for this attribute syntax. 143 * 144 * @return The OID for this attribute syntax. 145 */ 146 public String getOID() 147 { 148 return SYNTAX_BINARY_OID; 149 } 150 151 152 153 /** 154 * Retrieves a description for this attribute syntax. 155 * 156 * @return A description for this attribute syntax. 157 */ 158 public String getDescription() 159 { 160 return SYNTAX_BINARY_DESCRIPTION; 161 } 162 163 164 165 /** 166 * Retrieves the default equality matching rule that will be used for 167 * attributes with this syntax. 168 * 169 * @return The default equality matching rule that will be used for 170 * attributes with this syntax, or <CODE>null</CODE> if equality 171 * matches will not be allowed for this type by default. 172 */ 173 public EqualityMatchingRule getEqualityMatchingRule() 174 { 175 return defaultEqualityMatchingRule; 176 } 177 178 179 180 /** 181 * Retrieves the default ordering matching rule that will be used for 182 * attributes with this syntax. 183 * 184 * @return The default ordering matching rule that will be used for 185 * attributes with this syntax, or <CODE>null</CODE> if ordering 186 * matches will not be allowed for this type by default. 187 */ 188 public OrderingMatchingRule getOrderingMatchingRule() 189 { 190 return defaultOrderingMatchingRule; 191 } 192 193 194 195 /** 196 * Retrieves the default substring matching rule that will be used for 197 * attributes with this syntax. 198 * 199 * @return The default substring matching rule that will be used for 200 * attributes with this syntax, or <CODE>null</CODE> if substring 201 * matches will not be allowed for this type by default. 202 */ 203 public SubstringMatchingRule getSubstringMatchingRule() 204 { 205 return defaultSubstringMatchingRule; 206 } 207 208 209 210 /** 211 * Retrieves the default approximate matching rule that will be used for 212 * attributes with this syntax. 213 * 214 * @return The default approximate matching rule that will be used for 215 * attributes with this syntax, or <CODE>null</CODE> if approximate 216 * matches will not be allowed for this type by default. 217 */ 218 public ApproximateMatchingRule getApproximateMatchingRule() 219 { 220 // There is no approximate matching rule by default. 221 return null; 222 } 223 224 225 226 /** 227 * Indicates whether the provided value is acceptable for use in an attribute 228 * with this syntax. If it is not, then the reason may be appended to the 229 * provided buffer. 230 * 231 * @param value The value for which to make the determination. 232 * @param invalidReason The buffer to which the invalid reason should be 233 * appended. 234 * 235 * @return <CODE>true</CODE> if the provided value is acceptable for use with 236 * this syntax, or <CODE>false</CODE> if not. 237 */ 238 public boolean valueIsAcceptable(ByteString value, 239 MessageBuilder invalidReason) 240 { 241 // All values will be acceptable for the binary syntax. 242 return true; 243 } 244 } 245