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 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 74 */ 75 public class MutableMatchingRule extends MatchingRule 76 { 77 /** The mandatory serialVersionUID */ 78 public static final long serialVersionUID = 1L; 79 80 81 /** 82 * Creates a new instance of MatchingRule. 83 * 84 * @param oid The MatchingRule OID 85 */ 86 public MutableMatchingRule( String oid ) 87 { 88 super( oid ); 89 } 90 91 92 /** 93 * Sets the Syntax's OID 94 * 95 * @param oid The Syntax's OID 96 */ 97 public void setSyntaxOid( String oid ) 98 { 99 if ( locked ) 100 { 101 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 102 } 103 104 if ( !isReadOnly ) 105 { 106 this.ldapSyntaxOid = oid; 107 } 108 } 109 110 111 /** 112 * Sets the Syntax 113 * 114 * @param ldapSyntax The Syntax 115 */ 116 public void setSyntax( LdapSyntax ldapSyntax ) 117 { 118 if ( locked ) 119 { 120 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 121 } 122 123 if ( !isReadOnly ) 124 { 125 this.ldapSyntax = ldapSyntax; 126 this.ldapSyntaxOid = ldapSyntax.getOid(); 127 } 128 } 129 130 131 /** 132 * Update the associated Syntax, even if the SchemaObject is readOnly 133 * 134 * @param ldapSyntax The Syntax 135 */ 136 public void updateSyntax( LdapSyntax ldapSyntax ) 137 { 138 if ( locked ) 139 { 140 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 141 } 142 143 this.ldapSyntax = ldapSyntax; 144 this.ldapSyntaxOid = ldapSyntax.getOid(); 145 } 146 147 148 /** 149 * Sets the LdapComparator 150 * 151 * @param ldapComparator The LdapComparator 152 */ 153 @SuppressWarnings("unchecked") 154 public void setLdapComparator( LdapComparator<?> ldapComparator ) 155 { 156 if ( locked ) 157 { 158 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 159 } 160 161 if ( !isReadOnly ) 162 { 163 this.ldapComparator = ( LdapComparator<? super Object> ) ldapComparator; 164 } 165 } 166 167 168 /** 169 * Update the associated Comparator, even if the SchemaObject is readOnly 170 * 171 * @param ldapComparator The LdapComparator 172 */ 173 @SuppressWarnings("unchecked") 174 public void updateLdapComparator( LdapComparator<?> ldapComparator ) 175 { 176 if ( locked ) 177 { 178 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 179 } 180 181 this.ldapComparator = ( LdapComparator<? super Object> ) ldapComparator; 182 } 183 184 185 /** 186 * Sets the Normalizer 187 * 188 * @param normalizer The Normalizer 189 */ 190 public void setNormalizer( Normalizer normalizer ) 191 { 192 if ( locked ) 193 { 194 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 195 } 196 197 if ( !isReadOnly ) 198 { 199 this.normalizer = normalizer; 200 } 201 } 202 203 204 /** 205 * Update the associated Normalizer, even if the SchemaObject is readOnly 206 * 207 * @param normalizer The Normalizer 208 */ 209 public void updateNormalizer( Normalizer normalizer ) 210 { 211 if ( locked ) 212 { 213 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04441, getName() ) ); 214 } 215 216 this.normalizer = normalizer; 217 } 218 219 220 /** 221 * {@inheritDoc} 222 */ 223 @Override 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 }