001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.model.schema; 021 022 023import org.apache.directory.api.i18n.I18n; 024 025 026/** 027 * A matchingRule definition. MatchingRules associate a comparator and a 028 * normalizer, forming the basic tools necessary to assert actions against 029 * attribute values. MatchingRules are associated with a specific Syntax for the 030 * purpose of resolving a normalized form and for comparisons. 031 * <p> 032 * According to ldapbis [MODELS]: 033 * </p> 034 * 035 * <pre> 036 * 4.1.3. Matching Rules 037 * 038 * Matching rules are used by servers to compare attribute values against 039 * assertion values when performing Search and Compare operations. They 040 * are also used to identify the value to be added or deleted when 041 * modifying entries, and are used when comparing a purported 042 * distinguished name with the name of an entry. 043 * 044 * A matching rule specifies the syntax of the assertion value. 045 * 046 * Each matching rule is identified by an object identifier (OID) and, 047 * optionally, one or more short names (descriptors). 048 * 049 * Matching rule definitions are written according to the ABNF: 050 * 051 * MatchingRuleDescription = LPAREN WSP 052 * numericoid ; object identifier 053 * [ SP "NAME" SP qdescrs ] ; short names (descriptors) 054 * [ SP "DESC" SP qdstring ] ; description 055 * [ SP "OBSOLETE" ] ; not active 056 * SP "SYNTAX" SP numericoid ; assertion syntax 057 * extensions WSP RPAREN ; extensions 058 * 059 * where: 060 * [numericoid] is object identifier assigned to this matching rule; 061 * NAME [qdescrs] are short names (descriptors) identifying this 062 * matching rule; 063 * DESC [qdstring] is a short descriptive string; 064 * OBSOLETE indicates this matching rule is not active; 065 * SYNTAX identifies the assertion syntax by object identifier; and 066 * [extensions] describe extensions. 067 * </pre> 068 * 069 * @see <a href="http://www.faqs.org/rfcs/rfc2252.html">RFC 2252 Section 4.5</a> 070 * @see <a 071 * href="http://www.ietf.org/internet-drafts/draft-ietf-ldapbis-models-11.txt">ldapbis 072 * [MODELS]</a> 073 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 074 */ 075public class MutableMatchingRule extends MatchingRule 076{ 077 /** The mandatory serialVersionUID */ 078 public static final long serialVersionUID = 1L; 079 080 081 /** 082 * Creates a new instance of MatchingRule. 083 * 084 * @param oid The MatchingRule OID 085 */ 086 public MutableMatchingRule( String oid ) 087 { 088 super( oid ); 089 } 090 091 092 /** 093 * Sets the Syntax's OID 094 * 095 * @param oid The Syntax's OID 096 */ 097 public void setSyntaxOid( String oid ) 098 { 099 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}