1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.ldap.model.schema; 21 22 23 import org.apache.directory.api.i18n.I18n; 24 25 26 /** 27 * A matchingRule definition. MatchingRules associate a comparator and a 28 * normalizer, forming the basic tools necessary to assert actions against 29 * attribute values. MatchingRules are associated with a specific Syntax for the 30 * purpose of resolving a normalized form and for comparisons. 31 * <p> 32 * According to ldapbis [MODELS]: 33 * </p> 34 * 35 * <pre> 36 * 4.1.3. Matching Rules 37 * 38 * Matching rules are used by servers to compare attribute values against 39 * assertion values when performing Search and Compare operations. They 40 * are also used to identify the value to be added or deleted when 41 * modifying entries, and are used when comparing a purported 42 * distinguished name with the name of an entry. 43 * 44 * A matching rule specifies the syntax of the assertion value. 45 * 46 * Each matching rule is identified by an object identifier (OID) and, 47 * optionally, one or more short names (descriptors). 48 * 49 * Matching rule definitions are written according to the ABNF: 50 * 51 * MatchingRuleDescription = LPAREN WSP 52 * numericoid ; object identifier 53 * [ SP "NAME" SP qdescrs ] ; short names (descriptors) 54 * [ SP "DESC" SP qdstring ] ; description 55 * [ SP "OBSOLETE" ] ; not active 56 * SP "SYNTAX" SP numericoid ; assertion syntax 57 * extensions WSP RPAREN ; extensions 58 * 59 * where: 60 * [numericoid] is object identifier assigned to this matching rule; 61 * NAME [qdescrs] are short names (descriptors) identifying this 62 * matching rule; 63 * DESC [qdstring] is a short descriptive string; 64 * OBSOLETE indicates this matching rule is not active; 65 * SYNTAX identifies the assertion syntax by object identifier; and 66 * [extensions] describe extensions. 67 * </pre> 68 * 69 * @see <a href="http://www.faqs.org/rfcs/rfc2252.html">RFC 2252 Section 4.5</a> 70 * @see <a 71 * href="http://www.ietf.org/internet-drafts/draft-ietf-ldapbis-models-11.txt">ldapbis 72 * [MODELS]</a> 73 * @see DescriptionUtils#getDescription(MutableMatchingRule) 74 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 75 */ 76 public class MutableMatchingRule extends MatchingRule 77 { 78 /** The mandatory serialVersionUID */ 79 public static final long serialVersionUID = 1L; 80 81 82 /** 83 * Creates a new instance of MatchingRule. 84 * 85 * @param oid The MatchingRule OID 86 */ 87 public MutableMatchingRule( String oid ) 88 { 89 super( oid ); 90 } 91 92 93 /** 94 * Sets the Syntax's OID 95 * 96 * @param oid The Syntax's OID 97 */ 98 public void setSyntaxOid( String oid ) 99 { 100 if ( locked ) 101 { 102 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 103 } 104 105 if ( !isReadOnly ) 106 { 107 this.ldapSyntaxOid = oid; 108 } 109 } 110 111 112 /** 113 * Sets the Syntax 114 * 115 * @param ldapSyntax The Syntax 116 */ 117 public void setSyntax( LdapSyntax ldapSyntax ) 118 { 119 if ( locked ) 120 { 121 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 122 } 123 124 if ( !isReadOnly ) 125 { 126 this.ldapSyntax = ldapSyntax; 127 this.ldapSyntaxOid = ldapSyntax.getOid(); 128 } 129 } 130 131 132 /** 133 * Update the associated Syntax, even if the SchemaObject is readOnly 134 * 135 * @param ldapSyntax The Syntax 136 */ 137 public void updateSyntax( LdapSyntax ldapSyntax ) 138 { 139 if ( locked ) 140 { 141 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 142 } 143 144 this.ldapSyntax = ldapSyntax; 145 this.ldapSyntaxOid = ldapSyntax.getOid(); 146 } 147 148 149 /** 150 * Sets the LdapComparator 151 * 152 * @param ldapComparator The LdapComparator 153 */ 154 @SuppressWarnings("unchecked") 155 public void setLdapComparator( LdapComparator<?> ldapComparator ) 156 { 157 if ( locked ) 158 { 159 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 160 } 161 162 if ( !isReadOnly ) 163 { 164 this.ldapComparator = ( LdapComparator<? super Object> ) ldapComparator; 165 } 166 } 167 168 169 /** 170 * Update the associated Comparator, even if the SchemaObject is readOnly 171 * 172 * @param ldapComparator The LdapComparator 173 */ 174 @SuppressWarnings("unchecked") 175 public void updateLdapComparator( LdapComparator<?> ldapComparator ) 176 { 177 if ( locked ) 178 { 179 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 180 } 181 182 this.ldapComparator = ( LdapComparator<? super Object> ) ldapComparator; 183 } 184 185 186 /** 187 * Sets the Normalizer 188 * 189 * @param normalizer The Normalizer 190 */ 191 public void setNormalizer( Normalizer normalizer ) 192 { 193 if ( locked ) 194 { 195 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 196 } 197 198 if ( !isReadOnly ) 199 { 200 this.normalizer = normalizer; 201 } 202 } 203 204 205 /** 206 * Update the associated Normalizer, even if the SchemaObject is readOnly 207 * 208 * @param normalizer The Normalizer 209 */ 210 public void updateNormalizer( Normalizer normalizer ) 211 { 212 if ( locked ) 213 { 214 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 215 } 216 217 this.normalizer = normalizer; 218 } 219 220 221 /** 222 * {@inheritDoc} 223 */ 224 public void clear() 225 { 226 // Clear the common elements 227 super.clear(); 228 229 // Clear the references 230 ldapComparator = null; 231 ldapSyntax = null; 232 normalizer = null; 233 } 234 }