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 import static org.opends.server.util.StaticUtils.*; 048 049 050 /** 051 * This class defines the OID syntax, which holds either an identifier name or 052 * a numeric OID. Equality and substring matching will be allowed by default. 053 */ 054 public class OIDSyntax 055 extends AttributeSyntax<AttributeSyntaxCfg> 056 { 057 // The default equality matching rule for this syntax. 058 private EqualityMatchingRule defaultEqualityMatchingRule; 059 060 // The default substring matching rule for this syntax. 061 private SubstringMatchingRule defaultSubstringMatchingRule; 062 063 064 065 /** 066 * Creates a new instance of this syntax. Note that the only thing that 067 * should be done here is to invoke the default constructor for the 068 * superclass. All initialization should be performed in the 069 * <CODE>initializeSyntax</CODE> method. 070 */ 071 public OIDSyntax() 072 { 073 super(); 074 } 075 076 077 078 /** 079 * {@inheritDoc} 080 */ 081 public void initializeSyntax(AttributeSyntaxCfg configuration) 082 throws ConfigException 083 { 084 defaultEqualityMatchingRule = 085 DirectoryServer.getEqualityMatchingRule(EMR_OID_OID); 086 if (defaultEqualityMatchingRule == null) 087 { 088 logError(ERR_ATTR_SYNTAX_UNKNOWN_EQUALITY_MATCHING_RULE.get( 089 EMR_OID_OID, SYNTAX_OID_NAME)); 090 } 091 092 defaultSubstringMatchingRule = 093 DirectoryServer.getSubstringMatchingRule(SMR_CASE_IGNORE_OID); 094 if (defaultSubstringMatchingRule == null) 095 { 096 logError(ERR_ATTR_SYNTAX_UNKNOWN_SUBSTRING_MATCHING_RULE.get( 097 SMR_CASE_IGNORE_OID, SYNTAX_OID_NAME)); 098 } 099 } 100 101 102 103 /** 104 * Retrieves the common name for this attribute syntax. 105 * 106 * @return The common name for this attribute syntax. 107 */ 108 public String getSyntaxName() 109 { 110 return SYNTAX_OID_NAME; 111 } 112 113 114 115 /** 116 * Retrieves the OID for this attribute syntax. 117 * 118 * @return The OID for this attribute syntax. 119 */ 120 public String getOID() 121 { 122 return SYNTAX_OID_OID; 123 } 124 125 126 127 /** 128 * Retrieves a description for this attribute syntax. 129 * 130 * @return A description for this attribute syntax. 131 */ 132 public String getDescription() 133 { 134 return SYNTAX_OID_DESCRIPTION; 135 } 136 137 138 139 /** 140 * Retrieves the default equality matching rule that will be used for 141 * attributes with this syntax. 142 * 143 * @return The default equality matching rule that will be used for 144 * attributes with this syntax, or <CODE>null</CODE> if equality 145 * matches will not be allowed for this type by default. 146 */ 147 public EqualityMatchingRule getEqualityMatchingRule() 148 { 149 return defaultEqualityMatchingRule; 150 } 151 152 153 154 /** 155 * Retrieves the default ordering matching rule that will be used for 156 * attributes with this syntax. 157 * 158 * @return The default ordering matching rule that will be used for 159 * attributes with this syntax, or <CODE>null</CODE> if ordering 160 * matches will not be allowed for this type by default. 161 */ 162 public OrderingMatchingRule getOrderingMatchingRule() 163 { 164 // There is no ordering matching rule by default. 165 return null; 166 } 167 168 169 170 /** 171 * Retrieves the default substring matching rule that will be used for 172 * attributes with this syntax. 173 * 174 * @return The default substring matching rule that will be used for 175 * attributes with this syntax, or <CODE>null</CODE> if substring 176 * matches will not be allowed for this type by default. 177 */ 178 public SubstringMatchingRule getSubstringMatchingRule() 179 { 180 return defaultSubstringMatchingRule; 181 } 182 183 184 185 /** 186 * Retrieves the default approximate matching rule that will be used for 187 * attributes with this syntax. 188 * 189 * @return The default approximate matching rule that will be used for 190 * attributes with this syntax, or <CODE>null</CODE> if approximate 191 * matches will not be allowed for this type by default. 192 */ 193 public ApproximateMatchingRule getApproximateMatchingRule() 194 { 195 // There is no approximate matching rule by default. 196 return null; 197 } 198 199 200 201 /** 202 * Indicates whether the provided value is acceptable for use in an attribute 203 * with this syntax. If it is not, then the reason may be appended to the 204 * provided buffer. 205 * 206 * @param value The value for which to make the determination. 207 * @param invalidReason The buffer to which the invalid reason should be 208 * appended. 209 * 210 * @return <CODE>true</CODE> if the provided value is acceptable for use with 211 * this syntax, or <CODE>false</CODE> if not. 212 */ 213 public boolean valueIsAcceptable(ByteString value, 214 MessageBuilder invalidReason) 215 { 216 String lowerValue = toLowerCase(value.stringValue()); 217 return isValidSchemaElement(lowerValue, 0, lowerValue.length(), 218 invalidReason); 219 } 220 } 221