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 */
019package org.apache.directory.api.ldap.model.entry;
020
021
022import java.io.IOException;
023import java.io.ObjectInput;
024import java.io.ObjectOutput;
025import java.util.Collection;
026import java.util.Iterator;
027import java.util.List;
028
029import org.apache.directory.api.i18n.I18n;
030import org.apache.directory.api.ldap.model.exception.LdapException;
031import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
032import org.apache.directory.api.ldap.model.name.Dn;
033import org.apache.directory.api.ldap.model.schema.AttributeType;
034import org.apache.directory.api.util.exception.NotImplementedException;
035
036
037/**
038 * A default implementation of a ServerEntry which should suite most
039 * use cases.
040 *
041 * This class is final, it should not be extended.
042 *
043 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
044 */
045public class ImmutableEntry implements Entry
046{
047    /** Used for serialization */
048    private static final long serialVersionUID = 2L;
049
050    /** The wrapped Entry for this entry */
051    private Entry entry;
052
053
054    //-------------------------------------------------------------------------
055    // Constructors
056    //-------------------------------------------------------------------------
057    /**
058     * Creates a new instance of DefaultEntry.
059     * <p>
060     * This entry <b>must</b> be initialized before being used !
061     *
062     * @param entry The encapsulated entry
063     */
064    public ImmutableEntry( Entry entry )
065    {
066        this.entry = entry;
067    }
068
069
070    //-------------------------------------------------------------------------
071    // Entry methods
072    //-------------------------------------------------------------------------
073    /**
074     * {@inheritDoc}
075     */
076    @Override
077    public Entry add( AttributeType attributeType, byte[]... values ) throws LdapException
078    {
079        new Exception().printStackTrace();
080        throw new NotImplementedException( I18n.err( I18n.ERR_13236_ENTRY_IMMUTABLE_CANT_ADD_ATTRIBUTE, entry.getDn() ) );
081    }
082
083
084    /**
085     * {@inheritDoc}
086     */
087    @Override
088    public Entry add( AttributeType attributeType, String... values ) throws LdapException
089    {
090        new Exception().printStackTrace();
091        throw new NotImplementedException( I18n.err( I18n.ERR_13236_ENTRY_IMMUTABLE_CANT_ADD_ATTRIBUTE, entry.getDn() ) );
092    }
093
094
095    /**
096     * {@inheritDoc}
097     */
098    @Override
099    public Entry add( AttributeType attributeType, Value... values ) throws LdapException
100    {
101        new Exception().printStackTrace();
102        throw new NotImplementedException( I18n.err( I18n.ERR_13236_ENTRY_IMMUTABLE_CANT_ADD_ATTRIBUTE, entry.getDn() ) );
103    }
104
105
106    /**
107     * {@inheritDoc}
108     */
109    @Override
110    public Entry add( String upId, AttributeType attributeType, byte[]... values ) throws LdapException
111    {
112        new Exception().printStackTrace();
113        throw new NotImplementedException( I18n.err( I18n.ERR_13236_ENTRY_IMMUTABLE_CANT_ADD_ATTRIBUTE, entry.getDn() ) );
114    }
115
116
117    /**
118     * {@inheritDoc}
119     */
120    @Override
121    public Entry add( String upId, AttributeType attributeType, Value... values ) throws LdapException
122    {
123        new Exception().printStackTrace();
124        throw new NotImplementedException( I18n.err( I18n.ERR_13236_ENTRY_IMMUTABLE_CANT_ADD_ATTRIBUTE, entry.getDn() ) );
125    }
126
127
128    /**
129     * {@inheritDoc}
130     */
131    @Override
132    public Entry add( String upId, AttributeType attributeType, String... values ) throws LdapException
133    {
134        new Exception().printStackTrace();
135        throw new NotImplementedException( I18n.err( I18n.ERR_13236_ENTRY_IMMUTABLE_CANT_ADD_ATTRIBUTE, entry.getDn() ) );
136    }
137
138
139    /**
140     * {@inheritDoc}
141     */
142    @Override
143    public Entry add( Attribute... attributes ) throws LdapException
144    {
145        new Exception().printStackTrace();
146        throw new NotImplementedException( I18n.err( I18n.ERR_13236_ENTRY_IMMUTABLE_CANT_ADD_ATTRIBUTE, entry.getDn() ) );
147    }
148
149
150    /**
151     * {@inheritDoc}
152     */
153    @Override
154    public Entry add( String upId, byte[]... values ) throws LdapException
155    {
156        new Exception().printStackTrace();
157        throw new NotImplementedException( I18n.err( I18n.ERR_13236_ENTRY_IMMUTABLE_CANT_ADD_ATTRIBUTE, entry.getDn() ) );
158    }
159
160
161    /**
162     * {@inheritDoc}
163     */
164    @Override
165    public Entry add( String upId, String... values ) throws LdapException
166    {
167        new Exception().printStackTrace();
168        throw new NotImplementedException( I18n.err( I18n.ERR_13236_ENTRY_IMMUTABLE_CANT_ADD_ATTRIBUTE, entry.getDn() ) );
169    }
170
171
172    /**
173     * {@inheritDoc}
174     */
175    @Override
176public Entry add( String upId, Value... values ) throws LdapException
177    {
178        new Exception().printStackTrace();
179        throw new NotImplementedException( I18n.err( I18n.ERR_13236_ENTRY_IMMUTABLE_CANT_ADD_ATTRIBUTE, entry.getDn() ) );
180    }
181
182
183    /**
184     * Clone an entry. All the element are duplicated, so a modification on
185     * the original object won't affect the cloned object, as a modification
186     * on the cloned object has no impact on the original object
187     */
188    @Override
189    public Entry clone()
190    {
191        return entry.clone();
192    }
193
194
195    /**
196     * {@inheritDoc}
197     */
198    @Override
199    public Entry shallowClone()
200    {
201        return entry.shallowClone();
202    }
203
204
205    /**
206     * {@inheritDoc}
207     */
208    @Override
209    public boolean contains( Attribute... attributes )
210    {
211        return entry.contains( attributes );
212    }
213
214
215    /**
216     * {@inheritDoc}
217     */
218    @Override
219    public boolean containsAttribute( String... attributes )
220    {
221        return entry.containsAttribute( attributes );
222    }
223
224
225    /**
226     * {@inheritDoc}
227     */
228    @Override
229    public boolean containsAttribute( AttributeType attributeType )
230    {
231        return entry.containsAttribute( attributeType );
232    }
233
234
235    /**
236     * {@inheritDoc}
237     */
238    @Override
239    public boolean contains( AttributeType attributeType, byte[]... values )
240    {
241        return entry.contains( attributeType, values );
242    }
243
244
245    /**
246     * {@inheritDoc}
247     */
248    @Override
249    public boolean contains( AttributeType attributeType, String... values )
250    {
251        return entry.contains( attributeType, values );
252    }
253
254
255    /**
256     * {@inheritDoc}
257     */
258    @Override
259    public boolean contains( AttributeType attributeType, Value... values )
260    {
261        return entry.contains( attributeType, values );
262    }
263
264
265    /**
266     * {@inheritDoc}
267     */
268    @Override
269    public boolean contains( String upId, byte[]... values )
270    {
271        return entry.contains( upId, values );
272    }
273
274
275    /**
276     * {@inheritDoc}
277     */
278    @Override
279    public boolean contains( String upId, String... values )
280    {
281        return entry.contains( upId, values );
282    }
283
284
285    /**
286     * {@inheritDoc}
287     */
288    @Override
289    public boolean contains( String upId, Value... values )
290    {
291        return entry.contains( upId, values );
292    }
293
294
295    /**
296     * {@inheritDoc}
297     */
298    @Override
299    public Attribute get( String alias )
300    {
301        return entry.get( alias );
302    }
303
304
305    /**
306     * {@inheritDoc}
307     */
308    @Override
309    public Attribute get( AttributeType attributeType )
310    {
311        return entry.get( attributeType );
312    }
313
314
315    /**
316     * {@inheritDoc}
317     */
318    @Override
319    public Collection<Attribute> getAttributes()
320    {
321        return entry.getAttributes();
322    }
323
324
325    /**
326     * {@inheritDoc}
327     */
328    @Override
329    public Attribute put( String upId, byte[]... values )
330    {
331        new Exception().printStackTrace();
332        throw new NotImplementedException( I18n.err( I18n.ERR_13237_ENTRY_IMMUTABLE_CANT_PUT_VALUE, entry.getDn() ) );
333    }
334
335
336    /**
337     * {@inheritDoc}
338     */
339    @Override
340    public Attribute put( String upId, String... values )
341    {
342        new Exception().printStackTrace();
343        throw new NotImplementedException( I18n.err( I18n.ERR_13237_ENTRY_IMMUTABLE_CANT_PUT_VALUE, entry.getDn() ) );
344    }
345
346
347    /**
348     * {@inheritDoc}
349     */
350    @Override
351    public Attribute put( String upId, Value... values )
352    {
353        new Exception().printStackTrace();
354        throw new NotImplementedException( I18n.err( I18n.ERR_13237_ENTRY_IMMUTABLE_CANT_PUT_VALUE, entry.getDn() ) );
355    }
356
357
358    /**
359     * {@inheritDoc}
360     */
361    @Override
362    public List<Attribute> put( Attribute... attributes ) throws LdapException
363    {
364        new Exception().printStackTrace();
365        throw new NotImplementedException( I18n.err( I18n.ERR_13237_ENTRY_IMMUTABLE_CANT_PUT_VALUE, entry.getDn() ) );
366    }
367
368
369    /**
370     * {@inheritDoc}
371     */
372    @Override
373    public Attribute put( AttributeType attributeType, byte[]... values ) throws LdapException
374    {
375        new Exception().printStackTrace();
376        throw new NotImplementedException( I18n.err( I18n.ERR_13237_ENTRY_IMMUTABLE_CANT_PUT_VALUE, entry.getDn() ) );
377    }
378
379
380    /**
381     * {@inheritDoc}
382     */
383    @Override
384    public Attribute put( AttributeType attributeType, String... values ) throws LdapException
385    {
386        new Exception().printStackTrace();
387        throw new NotImplementedException( I18n.err( I18n.ERR_13237_ENTRY_IMMUTABLE_CANT_PUT_VALUE, entry.getDn() ) );
388    }
389
390
391    /**
392     * {@inheritDoc}
393     */
394    @Override
395    public Attribute put( AttributeType attributeType, Value... values ) throws LdapException
396    {
397        new Exception().printStackTrace();
398        throw new NotImplementedException( I18n.err( I18n.ERR_13237_ENTRY_IMMUTABLE_CANT_PUT_VALUE, entry.getDn() ) );
399    }
400
401
402    /**
403     * {@inheritDoc}
404     */
405    @Override
406    public Attribute put( String upId, AttributeType attributeType, byte[]... values ) throws LdapException
407    {
408        new Exception().printStackTrace();
409        throw new NotImplementedException( I18n.err( I18n.ERR_13237_ENTRY_IMMUTABLE_CANT_PUT_VALUE, entry.getDn() ) );
410    }
411
412
413    /**
414     * {@inheritDoc}
415     */
416    @Override
417    public Attribute put( String upId, AttributeType attributeType, String... values ) throws LdapException
418    {
419        new Exception().printStackTrace();
420        throw new NotImplementedException( I18n.err( I18n.ERR_13237_ENTRY_IMMUTABLE_CANT_PUT_VALUE, entry.getDn() ) );
421    }
422
423
424    /**
425     * {@inheritDoc}
426     */
427    @Override
428    public Attribute put( String upId, AttributeType attributeType, Value... values ) throws LdapException
429    {
430        new Exception().printStackTrace();
431        throw new NotImplementedException( I18n.err( I18n.ERR_13237_ENTRY_IMMUTABLE_CANT_PUT_VALUE, entry.getDn() ) );
432    }
433
434
435    /**
436     * {@inheritDoc}
437     */
438    @Override
439    public List<Attribute> remove( Attribute... attributes ) throws LdapException
440    {
441        new Exception().printStackTrace();
442        throw new NotImplementedException( I18n.err( I18n.ERR_13238_ENTRY_IMMUTABLE_CANT_REMOVE_VALUE, entry.getDn() ) );
443    }
444
445
446    /**
447     * {@inheritDoc}
448     */
449    @Override
450    public boolean remove( AttributeType attributeType, byte[]... values ) throws LdapException
451    {
452        new Exception().printStackTrace();
453        throw new NotImplementedException( I18n.err( I18n.ERR_13238_ENTRY_IMMUTABLE_CANT_REMOVE_VALUE, entry.getDn() ) );
454    }
455
456
457    /**
458     * {@inheritDoc}
459     */
460    @Override
461    public boolean remove( AttributeType attributeType, String... values ) throws LdapException
462    {
463        new Exception().printStackTrace();
464        throw new NotImplementedException( I18n.err( I18n.ERR_13238_ENTRY_IMMUTABLE_CANT_REMOVE_VALUE, entry.getDn() ) );
465    }
466
467
468    /**
469     * {@inheritDoc}
470     */
471    @Override
472    public boolean remove( AttributeType attributeType, Value... values ) throws LdapException
473    {
474        new Exception().printStackTrace();
475        throw new NotImplementedException( I18n.err( I18n.ERR_13238_ENTRY_IMMUTABLE_CANT_REMOVE_VALUE, entry.getDn() ) );
476    }
477
478
479    /**
480     * <p>
481     * Removes the attribute with the specified AttributeTypes.
482     * </p>
483     * <p>
484     * The removed attribute are returned by this method.
485     * </p>
486     * <p>
487     * If there is no attribute with the specified AttributeTypes,
488     * the return value is <code>null</code>.
489     * </p>
490     *
491     * @param attributes the AttributeTypes to be removed
492     */
493    @Override
494    public void removeAttributes( AttributeType... attributes )
495    {
496        new Exception().printStackTrace();
497        throw new NotImplementedException( I18n.err( I18n.ERR_13238_ENTRY_IMMUTABLE_CANT_REMOVE_VALUE, entry.getDn() ) );
498    }
499
500
501    /**
502     * {@inheritDoc}
503     */
504    @Override
505    public void removeAttributes( String... attributes )
506    {
507        new Exception().printStackTrace();
508        throw new NotImplementedException( I18n.err( I18n.ERR_13238_ENTRY_IMMUTABLE_CANT_REMOVE_VALUE, entry.getDn() ) );
509    }
510
511
512    /**
513     * <p>
514     * Removes the specified binary values from an attribute.
515     * </p>
516     * <p>
517     * If at least one value is removed, this method returns <code>true</code>.
518     * </p>
519     * <p>
520     * If there is no more value after having removed the values, the attribute
521     * will be removed too.
522     * </p>
523     * <p>
524     * If the attribute does not exist, nothing is done and the method returns
525     * <code>false</code>
526     * </p>
527     *
528     * @param upId The attribute ID
529     * @param values the values to be removed
530     * @return <code>true</code> if at least a value is removed, <code>false</code>
531     * if not all the values have been removed or if the attribute does not exist.
532     */
533    @Override
534    public boolean remove( String upId, byte[]... values ) throws LdapException
535    {
536        new Exception().printStackTrace();
537        throw new NotImplementedException( I18n.err( I18n.ERR_13238_ENTRY_IMMUTABLE_CANT_REMOVE_VALUE, entry.getDn() ) );
538    }
539
540
541    /**
542     * <p>
543     * Removes the specified String values from an attribute.
544     * </p>
545     * <p>
546     * If at least one value is removed, this method returns <code>true</code>.
547     * </p>
548     * <p>
549     * If there is no more value after having removed the values, the attribute
550     * will be removed too.
551     * </p>
552     * <p>
553     * If the attribute does not exist, nothing is done and the method returns
554     * <code>false</code>
555     * </p>
556     *
557     * @param upId The attribute ID
558     * @param values the attributes to be removed
559     * @return <code>true</code> if at least a value is removed, <code>false</code>
560     * if not all the values have been removed or if the attribute does not exist.
561     */
562    @Override
563    public boolean remove( String upId, String... values ) throws LdapException
564    {
565        new Exception().printStackTrace();
566        throw new NotImplementedException( I18n.err( I18n.ERR_13238_ENTRY_IMMUTABLE_CANT_REMOVE_VALUE, entry.getDn() ) );
567    }
568
569
570    /**
571     * <p>
572     * Removes the specified values from an attribute.
573     * </p>
574     * <p>
575     * If at least one value is removed, this method returns <code>true</code>.
576     * </p>
577     * <p>
578     * If there is no more value after having removed the values, the attribute
579     * will be removed too.
580     * </p>
581     * <p>
582     * If the attribute does not exist, nothing is done and the method returns
583     * <code>false</code>
584     * </p>
585     *
586     * @param upId The attribute ID
587     * @param values the attributes to be removed
588     * @return <code>true</code> if at least a value is removed, <code>false</code>
589     * if not all the values have been removed or if the attribute does not exist.
590     */
591    @Override
592    public boolean remove( String upId, Value... values ) throws LdapException
593    {
594        new Exception().printStackTrace();
595        throw new NotImplementedException( I18n.err( I18n.ERR_13238_ENTRY_IMMUTABLE_CANT_REMOVE_VALUE, entry.getDn() ) );
596    }
597
598
599    /**
600     * Get this entry's Dn.
601     *
602     * @return The entry's Dn
603     */
604    @Override
605    public Dn getDn()
606    {
607        return entry.getDn();
608    }
609
610
611    /**
612     * {@inheritDoc}
613     */
614    @Override
615    public void setDn( Dn dn )
616    {
617        new Exception().printStackTrace();
618        throw new NotImplementedException( I18n.err( I18n.ERR_13239_ENTRY_IMMUTABLE_CANT_RENAME_ENTRY, entry.getDn() ) );
619    }
620
621
622    /**
623     * {@inheritDoc}
624     */
625    @Override
626    public void setDn( String dn ) throws LdapInvalidDnException
627    {
628        new Exception().printStackTrace();
629        throw new NotImplementedException( I18n.err( I18n.ERR_13239_ENTRY_IMMUTABLE_CANT_RENAME_ENTRY, entry.getDn() ) );
630    }
631
632
633    /**
634     * Remove all the attributes for this entry. The Dn is not reset
635     */
636    @Override
637    public void clear()
638    {
639        new Exception().printStackTrace();
640        throw new NotImplementedException( I18n.err( I18n.ERR_13240_ENTRY_IMMUTABLE_CANT_CLEAR_ENTRY, entry.getDn() ) );
641    }
642
643
644    /**
645     * Returns an enumeration containing the zero or more attributes in the
646     * collection. The behavior of the enumeration is not specified if the
647     * attribute collection is changed.
648     *
649     * @return an enumeration of all contained attributes
650     */
651    @Override
652    public Iterator<Attribute> iterator()
653    {
654        return entry.iterator();
655    }
656
657
658    /**
659     * Returns the number of attributes.
660     *
661     * @return the number of attributes
662     */
663    @Override
664    public int size()
665    {
666        return entry.size();
667    }
668
669
670    /**
671     * This is the place where we serialize entries, and all theirs
672     * elements.
673     * <br>
674     * The structure used to store the entry is the following :
675     * <ul>
676     *   <li>
677     *     <b>[Dn]</b> : If it's null, stores an empty Dn
678     *   </li>
679     *   <li>
680     *     <b>[attributes number]</b> : the number of attributes.
681     *   </li>
682     *   <li>
683     *     <b>[attribute]*</b> : each attribute, if we have some
684     *   </li>
685     * </ul>
686     *
687     * {@inheritDoc}
688     */
689    @Override
690    public void writeExternal( ObjectOutput out ) throws IOException
691    {
692        entry.writeExternal( out );
693    }
694
695
696    /**
697     * {@inheritDoc}
698     */
699    @Override
700    public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
701    {
702        new Exception().printStackTrace();
703        throw new NotImplementedException( I18n.err( I18n.ERR_13241_ENTRY_IMMUTABLE_CANT_READ_ENTRY, entry.getDn() ) );
704    }
705
706
707    /**
708     * Serialize an Entry.
709     *
710     * The structure is the following :
711     * <b>[a byte]</b> : if the Dn is empty 0 will be written else 1
712     * <b>[Rdn]</b> : The entry's Rdn.
713     * <b>[numberAttr]</b> : the bumber of attributes. Can be 0
714     * <b>[attribute's oid]*</b> : The attribute's OID to get back
715     * the attributeType on deserialization
716     * <b>[Attribute]*</b> The attribute
717     *
718     * @param out the buffer in which the data will be serialized
719     * @throws IOException if the serialization failed
720     */
721    public void serialize( ObjectOutput out ) throws IOException
722    {
723        new Exception().printStackTrace();
724        throw new NotImplementedException( I18n.err( I18n.ERR_13242_ENTRY_IMMUTABLE_CANT_SERIALIZE, entry.getDn() ) );
725    }
726
727
728    /**
729     * Deserialize an entry.
730     *
731     * @param in The buffer containing the serialized serverEntry
732     * @throws IOException if there was a problem when deserializing
733     * @throws ClassNotFoundException if we can't deserialize an expected object
734     */
735    public void deserialize( ObjectInput in ) throws IOException, ClassNotFoundException
736    {
737        new Exception().printStackTrace();
738        throw new NotImplementedException( I18n.err( I18n.ERR_13243_ENTRY_IMMUTABLE_CANT_DESERIALIZE, entry.getDn() ) );
739    }
740
741
742    /**
743     * Get the hash code of this ClientEntry. The Attributes will be sorted
744     * before the comparison can be done.
745     *
746     * @see java.lang.Object#hashCode()
747     * @return the instance's hash code
748     */
749    @Override
750    public int hashCode()
751    {
752        return entry.hashCode();
753    }
754
755
756    /**
757     * {@inheritDoc}
758     */
759    @Override
760    public boolean hasObjectClass( String... objectClasses )
761    {
762        return entry.hasObjectClass( objectClasses );
763    }
764
765
766    /**
767     * {@inheritDoc}
768     */
769    @Override
770    public boolean hasObjectClass( Attribute... objectClasses )
771    {
772        return entry.hasObjectClass( objectClasses );
773    }
774
775
776    /**
777     * {@inheritDoc}
778     */
779    @Override
780    public boolean isSchemaAware()
781    {
782        return entry.isSchemaAware();
783    }
784
785
786    /**
787     * @see Object#equals(Object)
788     */
789    @Override
790    public boolean equals( Object o )
791    {
792        return entry.equals( o );
793    }
794
795
796    /**
797     * @see Object#toString()
798     */
799    @Override
800    public String toString()
801    {
802        return entry.toString();
803    }
804
805
806    /**
807     * {@inheritDoc}
808     */
809    @Override
810    public String toString( String tabs )
811    {
812        return entry.toString( tabs );
813    }
814}