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.NamingEnumeration;
023    import javax.naming.NamingException;
024    import javax.naming.directory.Attribute;
025    import javax.naming.directory.Attributes;
026    
027    import org.apache.directory.shared.i18n.I18n;
028    
029    
030    /**
031     * Document me!
032     *
033     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034     * @version $Rev$, $Date$
035     */
036    public class ImmutableAttributesWrapper implements Attributes
037    {
038        private final Attributes wrapped;
039    
040    
041        public ImmutableAttributesWrapper( Attributes wrapped )
042        {
043            this.wrapped = wrapped;
044        }
045    
046    
047        public boolean isCaseIgnored()
048        {
049            return wrapped.isCaseIgnored();
050        }
051    
052    
053        public int size()
054        {
055            return wrapped.size();
056        }
057    
058    
059        public Attribute get( String attrID )
060        {
061            return new ImmutableAttributeWrapper( wrapped.get( attrID ) );
062        }
063    
064    
065        public NamingEnumeration<? extends Attribute> getAll()
066        {
067            return new ImmutableEnumeration( wrapped.getAll() );
068        }
069    
070    
071        public NamingEnumeration<String> getIDs()
072        {
073            return wrapped.getIDs();
074        }
075    
076    
077        public Attribute put( String attrID, Object val )
078        {
079            throw new UnsupportedOperationException( I18n.err( I18n.ERR_04389 ) );
080        }
081    
082    
083        public Attribute put( Attribute attr )
084        {
085            throw new UnsupportedOperationException( I18n.err( I18n.ERR_04389 ) );
086        }
087    
088    
089        public Attribute remove( String attrID )
090        {
091            throw new UnsupportedOperationException( I18n.err( I18n.ERR_04390 ) );
092        }
093    
094    
095        public Object clone()
096        {
097            throw new IllegalStateException( I18n.err( I18n.ERR_04391 ) );
098        }
099    
100    
101        class ImmutableEnumeration implements NamingEnumeration
102        {
103            private NamingEnumeration wrappedEnum;
104    
105    
106            public ImmutableEnumeration( NamingEnumeration<? extends Attribute> all )
107            {
108                wrappedEnum = all;
109            }
110    
111    
112            public Attribute next() throws NamingException
113            {
114                return new ImmutableAttributeWrapper( ( Attribute ) wrappedEnum.next() );
115            }
116    
117    
118            public boolean hasMore() throws NamingException
119            {
120                return wrappedEnum.hasMore();
121            }
122    
123    
124            public void close() throws NamingException
125            {
126                wrappedEnum.close();
127            }
128    
129    
130            public boolean hasMoreElements()
131            {
132                return wrappedEnum.hasMoreElements();
133            }
134    
135    
136            public Attribute nextElement()
137            {
138                return new ImmutableAttributeWrapper( ( Attribute ) wrappedEnum.nextElement() );
139            }
140        }
141    }