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 package org.apache.directory.shared.ldap.util;
020
021
022 import javax.naming.directory.Attribute;
023 import javax.naming.directory.DirContext;
024 import javax.naming.NamingEnumeration;
025 import javax.naming.NamingException;
026
027
028 /**
029 * A read only wrapper around an Attributes object.
030 *
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 * @version $Rev$, $Date$
033 */
034 public class ImmutableAttributeWrapper implements Attribute
035 {
036 private final Attribute wrapped;
037
038
039 public ImmutableAttributeWrapper( Attribute wrapped )
040 {
041 this.wrapped = wrapped;
042 }
043
044
045 public NamingEnumeration<?> getAll() throws NamingException
046 {
047 return wrapped.getAll();
048 }
049
050
051 public Object get() throws NamingException
052 {
053 return wrapped.get();
054 }
055
056
057 public int size()
058 {
059 return wrapped.size();
060 }
061
062
063 public String getID()
064 {
065 return wrapped.getID();
066 }
067
068
069 public boolean contains( Object attrVal )
070 {
071 return wrapped.contains( attrVal );
072 }
073
074
075 public boolean add( Object attrVal )
076 {
077 throw new UnsupportedOperationException( "Value addition not supported for immutable attribute" );
078 }
079
080
081 public boolean remove( Object attrval )
082 {
083 throw new UnsupportedOperationException( "Value removal not supported for immutable attribute" );
084 }
085
086
087 public void clear()
088 {
089 throw new UnsupportedOperationException( "Clearing all values not supported for immutable attribute" );
090 }
091
092
093 public DirContext getAttributeSyntaxDefinition() throws NamingException
094 {
095 return wrapped.getAttributeSyntaxDefinition();
096 }
097
098
099 public DirContext getAttributeDefinition() throws NamingException
100 {
101 return wrapped.getAttributeDefinition();
102 }
103
104
105 @SuppressWarnings ( { "CloneDoesntCallSuperClone" } )
106 public Object clone()
107 {
108 throw new IllegalStateException( "Now why would you ever want to clone an immutable object?" );
109 }
110
111
112 public boolean isOrdered()
113 {
114 return wrapped.isOrdered();
115 }
116
117
118 public Object get( int ix ) throws NamingException
119 {
120 return wrapped.get( ix );
121 }
122
123
124 public Object remove( int ix )
125 {
126 throw new UnsupportedOperationException( "Value removal not supported for immutable attribute" );
127 }
128
129
130 public void add( int ix, Object attrVal )
131 {
132 throw new UnsupportedOperationException( "Value addition not supported for immutable attribute" );
133 }
134
135
136 public Object set( int ix, Object attrVal )
137 {
138 throw new UnsupportedOperationException( "Value alteration is not supported for immutable attribute" );
139 }
140 }