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.ApproximateMatchingRule; 033 import org.opends.server.api.AttributeSyntax; 034 import org.opends.server.api.EqualityMatchingRule; 035 import org.opends.server.api.OrderingMatchingRule; 036 import org.opends.server.api.SubstringMatchingRule; 037 import org.opends.server.config.ConfigException; 038 import org.opends.server.core.DirectoryServer; 039 import org.opends.server.types.ByteString; 040 041 042 043 import static org.opends.server.loggers.ErrorLogger.*; 044 import static org.opends.messages.SchemaMessages.*; 045 import org.opends.messages.MessageBuilder; 046 import static org.opends.server.schema.SchemaConstants.*; 047 048 049 /** 050 * This class implements the postal address attribute syntax, which is a list of 051 * UCS (Universal Character Set, as defined in the ISO 10646 specification and 052 * includes UTF-8 and UTF-16) strings separated by dollar signs. By default, 053 * they will be treated in a case-insensitive manner, and equality and substring 054 * matching will be allowed. 055 */ 056 public class PostalAddressSyntax 057 extends AttributeSyntax<AttributeSyntaxCfg> 058 { 059 // The default equality matching rule for this syntax. 060 private EqualityMatchingRule defaultEqualityMatchingRule; 061 062 // The default substring matching rule for this syntax. 063 private SubstringMatchingRule defaultSubstringMatchingRule; 064 065 066 067 /** 068 * Creates a new instance of this syntax. Note that the only thing that 069 * should be done here is to invoke the default constructor for the 070 * superclass. All initialization should be performed in the 071 * <CODE>initializeSyntax</CODE> method. 072 */ 073 public PostalAddressSyntax() 074 { 075 super(); 076 } 077 078 079 080 /** 081 * {@inheritDoc} 082 */ 083 public void initializeSyntax(AttributeSyntaxCfg configuration) 084 throws ConfigException 085 { 086 defaultEqualityMatchingRule = 087 DirectoryServer.getEqualityMatchingRule(EMR_CASE_IGNORE_OID); 088 if (defaultEqualityMatchingRule == null) 089 { 090 logError(ERR_ATTR_SYNTAX_UNKNOWN_EQUALITY_MATCHING_RULE.get( 091 EMR_CASE_IGNORE_OID, SYNTAX_DIRECTORY_STRING_NAME)); 092 } 093 094 defaultSubstringMatchingRule = 095 DirectoryServer.getSubstringMatchingRule(SMR_CASE_IGNORE_OID); 096 if (defaultSubstringMatchingRule == null) 097 { 098 logError(ERR_ATTR_SYNTAX_UNKNOWN_SUBSTRING_MATCHING_RULE.get( 099 SMR_CASE_IGNORE_OID, SYNTAX_DIRECTORY_STRING_NAME)); 100 } 101 } 102 103 104 105 /** 106 * Retrieves the common name for this attribute syntax. 107 * 108 * @return The common name for this attribute syntax. 109 */ 110 public String getSyntaxName() 111 { 112 return SYNTAX_POSTAL_ADDRESS_NAME; 113 } 114 115 116 117 /** 118 * Retrieves the OID for this attribute syntax. 119 * 120 * @return The OID for this attribute syntax. 121 */ 122 public String getOID() 123 { 124 return SYNTAX_POSTAL_ADDRESS_OID; 125 } 126 127 128 129 /** 130 * Retrieves a description for this attribute syntax. 131 * 132 * @return A description for this attribute syntax. 133 */ 134 public String getDescription() 135 { 136 return SYNTAX_POSTAL_ADDRESS_DESCRIPTION; 137 } 138 139 140 141 /** 142 * Retrieves the default equality matching rule that will be used for 143 * attributes with this syntax. 144 * 145 * @return The default equality matching rule that will be used for 146 * attributes with this syntax, or <CODE>null</CODE> if equality 147 * matches will not be allowed for this type by default. 148 */ 149 public EqualityMatchingRule getEqualityMatchingRule() 150 { 151 return defaultEqualityMatchingRule; 152 } 153 154 155 156 /** 157 * Retrieves the default ordering matching rule that will be used for 158 * attributes with this syntax. 159 * 160 * @return The default ordering matching rule that will be used for 161 * attributes with this syntax, or <CODE>null</CODE> if ordering 162 * matches will not be allowed for this type by default. 163 */ 164 public OrderingMatchingRule getOrderingMatchingRule() 165 { 166 // Ordering matching will not be allowed by default. 167 return null; 168 } 169 170 171 172 /** 173 * Retrieves the default substring matching rule that will be used for 174 * attributes with this syntax. 175 * 176 * @return The default substring matching rule that will be used for 177 * attributes with this syntax, or <CODE>null</CODE> if substring 178 * matches will not be allowed for this type by default. 179 */ 180 public SubstringMatchingRule getSubstringMatchingRule() 181 { 182 return defaultSubstringMatchingRule; 183 } 184 185 186 187 /** 188 * Retrieves the default approximate matching rule that will be used for 189 * attributes with this syntax. 190 * 191 * @return The default approximate matching rule that will be used for 192 * attributes with this syntax, or <CODE>null</CODE> if approximate 193 * matches will not be allowed for this type by default. 194 */ 195 public ApproximateMatchingRule getApproximateMatchingRule() 196 { 197 // Approximate matching will not be allowed by default. 198 return null; 199 } 200 201 202 203 /** 204 * Indicates whether the provided value is acceptable for use in an attribute 205 * with this syntax. If it is not, then the reason may be appended to the 206 * provided buffer. 207 * 208 * @param value The value for which to make the determination. 209 * @param invalidReason The buffer to which the invalid reason should be 210 * appended. 211 * 212 * @return <CODE>true</CODE> if the provided value is acceptable for use with 213 * this syntax, or <CODE>false</CODE> if not. 214 */ 215 public boolean valueIsAcceptable(ByteString value, 216 MessageBuilder invalidReason) 217 { 218 // We'll allow any value. 219 return true; 220 } 221 } 222