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 public Map<String, OidNormalizer> getNormalizerMapping() 062 { 063 return immutableAttributeTypeRegistry.getNormalizerMapping(); 064 } 065 066 067 /** 068 * {@inheritDoc} 069 */ 070 public boolean hasDescendants( String ancestorId ) throws LdapException 071 { 072 return immutableAttributeTypeRegistry.hasDescendants( ancestorId ); 073 } 074 075 076 /** 077 * {@inheritDoc} 078 */ 079 public boolean hasDescendants( AttributeType ancestor ) throws LdapException 080 { 081 return immutableAttributeTypeRegistry.hasDescendants( ancestor ); 082 } 083 084 085 /** 086 * {@inheritDoc} 087 */ 088 public Iterator<AttributeType> descendants( String ancestorId ) throws LdapException 089 { 090 return immutableAttributeTypeRegistry.descendants( ancestorId ); 091 } 092 093 094 /** 095 * {@inheritDoc} 096 */ 097 public Iterator<AttributeType> descendants( AttributeType ancestor ) throws LdapException 098 { 099 return immutableAttributeTypeRegistry.descendants( ancestor ); 100 } 101 102 103 /** 104 * {@inheritDoc} 105 */ 106 public void register( AttributeType attributeType ) throws LdapException 107 { 108 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 109 } 110 111 112 /** 113 * {@inheritDoc} 114 */ 115 public void registerDescendants( AttributeType attributeType, AttributeType ancestor ) throws LdapException 116 { 117 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 118 } 119 120 121 /** 122 * {@inheritDoc} 123 */ 124 public void unregisterDescendants( AttributeType attributeType, AttributeType ancestor ) throws LdapException 125 { 126 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 127 } 128 129 130 /** 131 * {@inheritDoc} 132 */ 133 public AttributeType unregister( String numericOid ) throws LdapException 134 { 135 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, 136 "Cannot modify the AttributeTypeRegistry copy" ); 137 } 138 139 140 /** 141 * {@inheritDoc} 142 */ 143 public void addMappingFor( AttributeType attributeType ) throws LdapException 144 { 145 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 146 } 147 148 149 /** 150 * {@inheritDoc} 151 */ 152 public void removeMappingFor( AttributeType attributeType ) throws LdapException 153 { 154 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 155 } 156 157 158 /** 159 * {@inheritDoc} 160 */ 161 public AttributeType lookup( String oid ) throws LdapException 162 { 163 return immutableAttributeTypeRegistry.lookup( oid ); 164 } 165 166 167 /** 168 * {@inheritDoc} 169 */ 170 public String toString() 171 { 172 return immutableAttributeTypeRegistry.toString(); 173 } 174 175 176 /** 177 * {@inheritDoc} 178 */ 179 public AttributeTypeRegistry copy() 180 { 181 return ( AttributeTypeRegistry ) immutableAttributeTypeRegistry.copy(); 182 } 183 184 185 /** 186 * {@inheritDoc} 187 */ 188 public int size() 189 { 190 return immutableAttributeTypeRegistry.size(); 191 } 192 193 194 /** 195 * {@inheritDoc} 196 */ 197 public Iterator<AttributeType> iterator() 198 { 199 return immutableAttributeTypeRegistry.iterator(); 200 } 201 202 203 /** 204 * {@inheritDoc} 205 */ 206 public Iterator<String> oidsIterator() 207 { 208 return immutableAttributeTypeRegistry.oidsIterator(); 209 } 210 211 212 /** 213 * {@inheritDoc} 214 */ 215 public boolean contains( String oid ) 216 { 217 return immutableAttributeTypeRegistry.contains( oid ); 218 } 219 220 221 /** 222 * {@inheritDoc} 223 */ 224 public String getOidByName( String name ) throws LdapException 225 { 226 try 227 { 228 return immutableAttributeTypeRegistry.getOidByName( name ); 229 } 230 catch ( LdapException le ) 231 { 232 throw new LdapNoSuchAttributeException( le.getMessage(), le ); 233 } 234 } 235 236 237 /** 238 * {@inheritDoc} 239 */ 240 public String getSchemaName( String oid ) throws LdapException 241 { 242 return immutableAttributeTypeRegistry.getSchemaName( oid ); 243 } 244 245 246 /** 247 * {@inheritDoc} 248 */ 249 public SchemaObjectType getType() 250 { 251 return immutableAttributeTypeRegistry.getType(); 252 } 253 254 255 /** 256 * {@inheritDoc} 257 */ 258 public void renameSchema( String originalSchemaName, String newSchemaName ) 259 { 260 // Do nothing 261 } 262 263 264 /** 265 * {@inheritDoc} 266 */ 267 public void unregisterSchemaElements( String schemaName ) throws LdapException 268 { 269 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 270 } 271 272 273 /** 274 * {@inheritDoc} 275 */ 276 public AttributeType get( String oid ) 277 { 278 return immutableAttributeTypeRegistry.get( oid ); 279 } 280 281 282 /** 283 * {@inheritDoc} 284 */ 285 public void clear() throws LdapException 286 { 287 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 288 } 289 290 291 /** 292 * {@inheritDoc} 293 */ 294 public AttributeType unregister( AttributeType schemaObject ) throws LdapException 295 { 296 throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) ); 297 } 298}