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