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.registries; 021 022 023import java.util.Iterator; 024import java.util.Map; 025 026import org.apache.directory.api.i18n.I18n; 027import org.apache.directory.api.ldap.model.exception.LdapException; 028import org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException; 029import org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException; 030import org.apache.directory.api.ldap.model.message.ResultCodeEnum; 031import org.apache.directory.api.ldap.model.schema.AttributeType; 032import org.apache.directory.api.ldap.model.schema.SchemaObjectType; 033import org.apache.directory.api.ldap.model.schema.normalizers.OidNormalizer; 034 035 036/** 037 * An immutable wrapper of the AttributeType registry. 038 * 039 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 040 */ 041public class ImmutableAttributeTypeRegistry implements AttributeTypeRegistry 042{ 043 /** The wrapped AttributeType registry */ 044 AttributeTypeRegistry immutableAttributeTypeRegistry; 045 046 047 /** 048 * Creates a new instance of ImmutableAttributeTypeRegistry. 049 * 050 * @param attributeTypeRegistry The wrapped AttributeType registry 051 */ 052 public ImmutableAttributeTypeRegistry( AttributeTypeRegistry attributeTypeRegistry ) 053 { 054 immutableAttributeTypeRegistry = attributeTypeRegistry; 055 } 056 057 058 /** 059 * {@inheritDoc} 060 */ 061 @Override 062 public Map<String, OidNormalizer> getNormalizerMapping() 063 { 064 return immutableAttributeTypeRegistry.getNormalizerMapping(); 065 } 066 067 068 /** 069 * {@inheritDoc} 070 */ 071 @Override 072 public boolean hasDescendants( String ancestorId ) throws LdapException 073 { 074 return immutableAttributeTypeRegistry.hasDescendants( ancestorId ); 075 } 076 077 078 /** 079 * {@inheritDoc} 080 */ 081 @Override 082 public boolean hasDescendants( AttributeType ancestor ) throws LdapException 083 { 084 return immutableAttributeTypeRegistry.hasDescendants( ancestor ); 085 } 086 087 088 /** 089 * {@inheritDoc} 090 */ 091 @Override 092 public Iterator<AttributeType> descendants( String ancestorId ) throws LdapException 093 { 094 return immutableAttributeTypeRegistry.descendants( ancestorId ); 095 } 096 097 098 /** 099 * {@inheritDoc} 100 */ 101 @Override 102 public Iterator<AttributeType> descendants( AttributeType ancestor ) throws LdapException 103 { 104 return immutableAttributeTypeRegistry.descendants( ancestor ); 105 } 106 107 108 /** 109 * {@inheritDoc} 110 */ 111 @Override 112 public void register( AttributeType attributeType ) throws LdapException 113 { 114 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 115 } 116 117 118 /** 119 * {@inheritDoc} 120 */ 121 @Override 122 public void registerDescendants( AttributeType attributeType, AttributeType ancestor ) throws LdapException 123 { 124 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 125 } 126 127 128 /** 129 * {@inheritDoc} 130 */ 131 @Override 132 public void unregisterDescendants( AttributeType attributeType, AttributeType ancestor ) throws LdapException 133 { 134 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 135 } 136 137 138 /** 139 * {@inheritDoc} 140 */ 141 @Override 142 public AttributeType unregister( String numericOid ) throws LdapException 143 { 144 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, 145 "Cannot modify the AttributeTypeRegistry copy" ); 146 } 147 148 149 /** 150 * {@inheritDoc} 151 */ 152 @Override 153 public void addMappingFor( AttributeType attributeType ) throws LdapException 154 { 155 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 156 } 157 158 159 /** 160 * {@inheritDoc} 161 */ 162 @Override 163 public void removeMappingFor( AttributeType attributeType ) throws LdapException 164 { 165 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 166 } 167 168 169 /** 170 * {@inheritDoc} 171 */ 172 @Override 173 public AttributeType lookup( String oid ) throws LdapException 174 { 175 return immutableAttributeTypeRegistry.lookup( oid ); 176 } 177 178 179 /** 180 * {@inheritDoc} 181 */ 182 @Override 183 public String toString() 184 { 185 return immutableAttributeTypeRegistry.toString(); 186 } 187 188 189 /** 190 * {@inheritDoc} 191 */ 192 @Override 193 public AttributeTypeRegistry copy() 194 { 195 return immutableAttributeTypeRegistry.copy(); 196 } 197 198 199 /** 200 * {@inheritDoc} 201 */ 202 @Override 203 public int size() 204 { 205 return immutableAttributeTypeRegistry.size(); 206 } 207 208 209 /** 210 * {@inheritDoc} 211 */ 212 @Override 213 public Iterator<AttributeType> iterator() 214 { 215 return immutableAttributeTypeRegistry.iterator(); 216 } 217 218 219 /** 220 * {@inheritDoc} 221 */ 222 @Override 223 public Iterator<String> oidsIterator() 224 { 225 return immutableAttributeTypeRegistry.oidsIterator(); 226 } 227 228 229 /** 230 * {@inheritDoc} 231 */ 232 @Override 233 public boolean contains( String oid ) 234 { 235 return immutableAttributeTypeRegistry.contains( oid ); 236 } 237 238 239 /** 240 * {@inheritDoc} 241 */ 242 @Override 243 public String getOidByName( String name ) throws LdapException 244 { 245 try 246 { 247 return immutableAttributeTypeRegistry.getOidByName( name ); 248 } 249 catch ( LdapException le ) 250 { 251 throw new LdapNoSuchAttributeException( le.getMessage(), le ); 252 } 253 } 254 255 256 /** 257 * {@inheritDoc} 258 */ 259 @Override 260 public String getSchemaName( String oid ) throws LdapException 261 { 262 return immutableAttributeTypeRegistry.getSchemaName( oid ); 263 } 264 265 266 /** 267 * {@inheritDoc} 268 */ 269 @Override 270 public SchemaObjectType getType() 271 { 272 return immutableAttributeTypeRegistry.getType(); 273 } 274 275 276 /** 277 * {@inheritDoc} 278 */ 279 @Override 280 public void renameSchema( String originalSchemaName, String newSchemaName ) 281 { 282 // Do nothing 283 } 284 285 286 /** 287 * {@inheritDoc} 288 */ 289 @Override 290 public void unregisterSchemaElements( String schemaName ) throws LdapException 291 { 292 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 293 } 294 295 296 /** 297 * {@inheritDoc} 298 */ 299 @Override 300 public AttributeType get( String oid ) 301 { 302 return immutableAttributeTypeRegistry.get( oid ); 303 } 304 305 306 /** 307 * {@inheritDoc} 308 */ 309 @Override 310 public void clear() throws LdapException 311 { 312 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 313 } 314 315 316 /** 317 * {@inheritDoc} 318 */ 319 @Override 320 public AttributeType unregister( AttributeType schemaObject ) throws LdapException 321 { 322 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 323 } 324}