View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.directory.api.ldap.model.entry;
20  
21  
22  import java.io.IOException;
23  import java.io.ObjectInput;
24  import java.io.ObjectOutput;
25  import java.util.Collection;
26  import java.util.Iterator;
27  import java.util.List;
28  
29  import org.apache.directory.api.ldap.model.exception.LdapException;
30  import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
31  import org.apache.directory.api.ldap.model.name.Dn;
32  import org.apache.directory.api.ldap.model.schema.AttributeType;
33  import org.apache.directory.api.util.exception.NotImplementedException;
34  
35  
36  /**
37   * A default implementation of a ServerEntry which should suite most
38   * use cases.
39   * 
40   * This class is final, it should not be extended.
41   *
42   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
43   */
44  public class ImmutableEntry implements Entry
45  {
46      /** Used for serialization */
47      private static final long serialVersionUID = 2L;
48  
49      /** The wrapped Entry for this entry */
50      private Entry entry;
51  
52  
53      //-------------------------------------------------------------------------
54      // Constructors
55      //-------------------------------------------------------------------------
56      /**
57       * Creates a new instance of DefaultEntry. 
58       * <p>
59       * This entry <b>must</b> be initialized before being used !
60       */
61      public ImmutableEntry( Entry entry )
62      {
63          this.entry = entry;
64      }
65  
66  
67      //-------------------------------------------------------------------------
68      // Entry methods
69      //-------------------------------------------------------------------------
70      /**
71       * {@inheritDoc}
72       */
73      public Entry add( AttributeType attributeType, byte[]... values ) throws LdapException
74      {
75          new Exception().printStackTrace();
76          throw new NotImplementedException( "Cannot add an attribute : the entry " + entry.getDn() + " is immutable." );
77      }
78  
79  
80      /**
81       * {@inheritDoc}
82       */
83      public Entry add( AttributeType attributeType, String... values ) throws LdapException
84      {
85          new Exception().printStackTrace();
86          throw new NotImplementedException( "Cannot add an attribute : the entry " + entry.getDn() + " is immutable." );
87      }
88  
89  
90      /**
91       * {@inheritDoc}
92       */
93      public Entry add( AttributeType attributeType, Value<?>... values ) throws LdapException
94      {
95          new Exception().printStackTrace();
96          throw new NotImplementedException( "Cannot add an attribute : the entry " + entry.getDn() + " is immutable." );
97      }
98  
99  
100     /**
101      * {@inheritDoc}
102      */
103     public Entry add( String upId, AttributeType attributeType, byte[]... values ) throws LdapException
104     {
105         new Exception().printStackTrace();
106         throw new NotImplementedException( "Cannot add an attribute : the entry " + entry.getDn() + " is immutable." );
107     }
108 
109 
110     /**
111      * {@inheritDoc}
112      */
113     public Entry add( String upId, AttributeType attributeType, Value<?>... values ) throws LdapException
114     {
115         new Exception().printStackTrace();
116         throw new NotImplementedException( "Cannot add an attribute : the entry " + entry.getDn() + " is immutable." );
117     }
118 
119 
120     /**
121      * {@inheritDoc}
122      */
123     public Entry add( String upId, AttributeType attributeType, String... values ) throws LdapException
124     {
125         new Exception().printStackTrace();
126         throw new NotImplementedException( "Cannot add an attribute : the entry " + entry.getDn() + " is immutable." );
127     }
128 
129 
130     /**
131      * {@inheritDoc}
132      */
133     public Entry add( Attribute... attributes ) throws LdapException
134     {
135         new Exception().printStackTrace();
136         throw new NotImplementedException( "Cannot add an attribute : the entry " + entry.getDn() + " is immutable." );
137     }
138 
139 
140     /**
141      * {@inheritDoc}
142      */
143     public Entry add( String upId, byte[]... values ) throws LdapException
144     {
145         new Exception().printStackTrace();
146         throw new NotImplementedException( "Cannot add an attribute : the entry " + entry.getDn() + " is immutable." );
147     }
148 
149 
150     /**
151      * {@inheritDoc}
152      */
153     public Entry add( String upId, String... values ) throws LdapException
154     {
155         new Exception().printStackTrace();
156         throw new NotImplementedException( "Cannot add an attribute : the entry " + entry.getDn() + " is immutable." );
157     }
158 
159 
160     /**
161      * {@inheritDoc}
162      */
163     public Entry add( String upId, Value<?>... values ) throws LdapException
164     {
165         new Exception().printStackTrace();
166         throw new NotImplementedException( "Cannot add an attribute : the entry " + entry.getDn() + " is immutable." );
167     }
168 
169 
170     /**
171      * Clone an entry. All the element are duplicated, so a modification on
172      * the original object won't affect the cloned object, as a modification
173      * on the cloned object has no impact on the original object
174      */
175     public Entry clone()
176     {
177         return entry.clone();
178     }
179 
180 
181     /**
182      * {@inheritDoc}
183      */
184     public Entry shallowClone()
185     {
186         return entry.shallowClone();
187     }
188 
189 
190     /**
191      * {@inheritDoc}
192      */
193     public boolean contains( Attribute... attributes )
194     {
195         return entry.contains( attributes );
196     }
197 
198 
199     /**
200      * {@inheritDoc}
201      */
202     public boolean containsAttribute( String... attributes )
203     {
204         return entry.containsAttribute( attributes );
205     }
206 
207 
208     /**
209      * {@inheritDoc}
210      */
211     public boolean containsAttribute( AttributeType attributeType )
212     {
213         return entry.containsAttribute( attributeType );
214     }
215 
216 
217     /**
218      * {@inheritDoc}
219      */
220     public boolean contains( AttributeType attributeType, byte[]... values )
221     {
222         return entry.contains( attributeType, values );
223     }
224 
225 
226     /**
227      * {@inheritDoc}
228      */
229     public boolean contains( AttributeType attributeType, String... values )
230     {
231         return entry.contains( attributeType, values );
232     }
233 
234 
235     /**
236      * {@inheritDoc}
237      */
238     public boolean contains( AttributeType attributeType, Value<?>... values )
239     {
240         return entry.contains( attributeType, values );
241     }
242 
243 
244     /**
245      * {@inheritDoc}
246      */
247     public boolean contains( String upId, byte[]... values )
248     {
249         return entry.contains( upId, values );
250     }
251 
252 
253     /**
254      * {@inheritDoc}
255      */
256     public boolean contains( String upId, String... values )
257     {
258         return entry.contains( upId, values );
259     }
260 
261 
262     /**
263      * {@inheritDoc}
264      */
265     public boolean contains( String upId, Value<?>... values )
266     {
267         return entry.contains( upId, values );
268     }
269 
270 
271     /**
272      * {@inheritDoc}
273      */
274     public Attribute get( String alias )
275     {
276         return entry.get( alias );
277     }
278 
279 
280     /**
281      * {@inheritDoc}
282      */
283     public Attribute get( AttributeType attributeType )
284     {
285         return entry.get( attributeType );
286     }
287 
288 
289     /**
290      * {@inheritDoc}
291      */
292     public Collection<Attribute> getAttributes()
293     {
294         return entry.getAttributes();
295     }
296 
297 
298     /**
299      * {@inheritDoc}
300      */
301     public Attribute put( String upId, byte[]... values )
302     {
303         new Exception().printStackTrace();
304         throw new NotImplementedException( "Cannot put a value : the entry " + entry.getDn() + " is immutable." );
305     }
306 
307 
308     /**
309      * {@inheritDoc}
310      */
311     public Attribute put( String upId, String... values )
312     {
313         new Exception().printStackTrace();
314         throw new NotImplementedException( "Cannot put a value : the entry " + entry.getDn() + " is immutable." );
315     }
316 
317 
318     /**
319      * {@inheritDoc}
320      */
321     public Attribute put( String upId, Value<?>... values )
322     {
323         new Exception().printStackTrace();
324         throw new NotImplementedException( "Cannot put a value : the entry " + entry.getDn() + " is immutable." );
325     }
326 
327 
328     /**
329      * {@inheritDoc}
330      */
331     public List<Attribute> put( Attribute... attributes ) throws LdapException
332     {
333         new Exception().printStackTrace();
334         throw new NotImplementedException( "Cannot put a value : the entry " + entry.getDn() + " is immutable." );
335     }
336 
337 
338     /**
339      * {@inheritDoc}
340      */
341     public Attribute put( AttributeType attributeType, byte[]... values ) throws LdapException
342     {
343         new Exception().printStackTrace();
344         throw new NotImplementedException( "Cannot put a value : the entry " + entry.getDn() + " is immutable." );
345     }
346 
347 
348     /**
349      * {@inheritDoc}
350      */
351     public Attribute put( AttributeType attributeType, String... values ) throws LdapException
352     {
353         new Exception().printStackTrace();
354         throw new NotImplementedException( "Cannot put a value : the entry " + entry.getDn() + " is immutable." );
355     }
356 
357 
358     /**
359      * {@inheritDoc}
360      */
361     public Attribute put( AttributeType attributeType, Value<?>... values ) throws LdapException
362     {
363         new Exception().printStackTrace();
364         throw new NotImplementedException( "Cannot put a value : the entry " + entry.getDn() + " is immutable." );
365     }
366 
367 
368     /**
369      * {@inheritDoc}
370      */
371     public Attribute put( String upId, AttributeType attributeType, byte[]... values ) throws LdapException
372     {
373         new Exception().printStackTrace();
374         throw new NotImplementedException( "Cannot put a value : the entry " + entry.getDn() + " is immutable." );
375     }
376 
377 
378     /**
379      * {@inheritDoc}
380      */
381     public Attribute put( String upId, AttributeType attributeType, String... values ) throws LdapException
382     {
383         new Exception().printStackTrace();
384         throw new NotImplementedException( "Cannot put a value : the entry " + entry.getDn() + " is immutable." );
385     }
386 
387 
388     /**
389      * {@inheritDoc}
390      */
391     public Attribute put( String upId, AttributeType attributeType, Value<?>... values ) throws LdapException
392     {
393         new Exception().printStackTrace();
394         throw new NotImplementedException( "Cannot put a value : the entry " + entry.getDn() + " is immutable." );
395     }
396 
397 
398     /**
399      * {@inheritDoc}
400      */
401     public List<Attribute> remove( Attribute... attributes ) throws LdapException
402     {
403         new Exception().printStackTrace();
404         throw new NotImplementedException( "Cannot remove a value : the entry " + entry.getDn() + " is immutable." );
405     }
406 
407 
408     /**
409      * {@inheritDoc}
410      */
411     public boolean remove( AttributeType attributeType, byte[]... values ) throws LdapException
412     {
413         new Exception().printStackTrace();
414         throw new NotImplementedException( "Cannot remove a value : the entry " + entry.getDn() + " is immutable." );
415     }
416 
417 
418     /**
419      * {@inheritDoc}
420      */
421     public boolean remove( AttributeType attributeType, String... values ) throws LdapException
422     {
423         new Exception().printStackTrace();
424         throw new NotImplementedException( "Cannot remove a value : the entry " + entry.getDn() + " is immutable." );
425     }
426 
427 
428     /**
429      * {@inheritDoc}
430      */
431     public boolean remove( AttributeType attributeType, Value<?>... values ) throws LdapException
432     {
433         new Exception().printStackTrace();
434         throw new NotImplementedException( "Cannot remove a value : the entry " + entry.getDn() + " is immutable." );
435     }
436 
437 
438     /**
439      * <p>
440      * Removes the attribute with the specified AttributeTypes. 
441      * </p>
442      * <p>
443      * The removed attribute are returned by this method. 
444      * </p>
445      * <p>
446      * If there is no attribute with the specified AttributeTypes,
447      * the return value is <code>null</code>.
448      * </p>
449      *
450      * @param attributes the AttributeTypes to be removed
451      * @return the removed attributes, if any, as a list; otherwise <code>null</code>
452      */
453     public void removeAttributes( AttributeType... attributes )
454     {
455         new Exception().printStackTrace();
456         throw new NotImplementedException( "Cannot remove a value : the entry " + entry.getDn() + " is immutable." );
457     }
458 
459 
460     /**
461      * {@inheritDoc}
462      */
463     public void removeAttributes( String... attributes )
464     {
465         new Exception().printStackTrace();
466         throw new NotImplementedException( "Cannot remove a value : the entry " + entry.getDn() + " is immutable." );
467     }
468 
469 
470     /**
471      * <p>
472      * Removes the specified binary values from an attribute.
473      * </p>
474      * <p>
475      * If at least one value is removed, this method returns <code>true</code>.
476      * </p>
477      * <p>
478      * If there is no more value after having removed the values, the attribute
479      * will be removed too.
480      * </p>
481      * <p>
482      * If the attribute does not exist, nothing is done and the method returns 
483      * <code>false</code>
484      * </p> 
485      *
486      * @param upId The attribute ID  
487      * @param values the values to be removed
488      * @return <code>true</code> if at least a value is removed, <code>false</code>
489      * if not all the values have been removed or if the attribute does not exist. 
490      */
491     public boolean remove( String upId, byte[]... values ) throws LdapException
492     {
493         new Exception().printStackTrace();
494         throw new NotImplementedException( "Cannot remove a value : the entry " + entry.getDn() + " is immutable." );
495     }
496 
497 
498     /**
499      * <p>
500      * Removes the specified String values from an attribute.
501      * </p>
502      * <p>
503      * If at least one value is removed, this method returns <code>true</code>.
504      * </p>
505      * <p>
506      * If there is no more value after having removed the values, the attribute
507      * will be removed too.
508      * </p>
509      * <p>
510      * If the attribute does not exist, nothing is done and the method returns 
511      * <code>false</code>
512      * </p> 
513      *
514      * @param upId The attribute ID  
515      * @param values the attributes to be removed
516      * @return <code>true</code> if at least a value is removed, <code>false</code>
517      * if not all the values have been removed or if the attribute does not exist. 
518      */
519     public boolean remove( String upId, String... values ) throws LdapException
520     {
521         new Exception().printStackTrace();
522         throw new NotImplementedException( "Cannot remove a value : the entry " + entry.getDn() + " is immutable." );
523     }
524 
525 
526     /**
527      * <p>
528      * Removes the specified values from an attribute.
529      * </p>
530      * <p>
531      * If at least one value is removed, this method returns <code>true</code>.
532      * </p>
533      * <p>
534      * If there is no more value after having removed the values, the attribute
535      * will be removed too.
536      * </p>
537      * <p>
538      * If the attribute does not exist, nothing is done and the method returns 
539      * <code>false</code>
540      * </p> 
541      *
542      * @param upId The attribute ID  
543      * @param values the attributes to be removed
544      * @return <code>true</code> if at least a value is removed, <code>false</code>
545      * if not all the values have been removed or if the attribute does not exist. 
546      */
547     public boolean remove( String upId, Value<?>... values ) throws LdapException
548     {
549         new Exception().printStackTrace();
550         throw new NotImplementedException( "Cannot remove a value : the entry " + entry.getDn() + " is immutable." );
551     }
552 
553 
554     /**
555      * Get this entry's Dn.
556      *
557      * @return The entry's Dn
558      */
559     public Dn getDn()
560     {
561         return entry.getDn();
562     }
563 
564 
565     /**
566      * {@inheritDoc}
567      */
568     public void setDn( Dn dn )
569     {
570         new Exception().printStackTrace();
571         throw new NotImplementedException( "Cannot rename the entry " + entry.getDn() + " is immutable." );
572     }
573 
574 
575     /**
576      * {@inheritDoc}
577      */
578     public void setDn( String dn ) throws LdapInvalidDnException
579     {
580         new Exception().printStackTrace();
581         throw new NotImplementedException( "Cannot rename the entry " + entry.getDn() + " is immutable." );
582     }
583 
584 
585     /**
586      * Remove all the attributes for this entry. The Dn is not reset
587      */
588     public void clear()
589     {
590         new Exception().printStackTrace();
591         throw new NotImplementedException( "Cannot clear the entry " + entry.getDn() + " is immutable." );
592     }
593 
594 
595     /**
596      * Returns an enumeration containing the zero or more attributes in the
597      * collection. The behavior of the enumeration is not specified if the
598      * attribute collection is changed.
599      *
600      * @return an enumeration of all contained attributes
601      */
602     public Iterator<Attribute> iterator()
603     {
604         return entry.iterator();
605     }
606 
607 
608     /**
609      * Returns the number of attributes.
610      *
611      * @return the number of attributes
612      */
613     public int size()
614     {
615         return entry.size();
616     }
617 
618 
619     /**
620      * This is the place where we serialize entries, and all theirs
621      * elements.
622      * <br/>
623      * The structure used to store the entry is the following :
624      * <ul>
625      *   <li>
626      *     <b>[Dn]</b> : If it's null, stores an empty Dn
627      *   </li>
628      *   <li>
629      *     <b>[attributes number]</b> : the number of attributes.
630      *   </li>
631      *   <li>
632      *     <b>[attribute]*</b> : each attribute, if we have some
633      *   </li>
634      * </ul>
635      * 
636      * {@inheritDoc} 
637      */
638     public void writeExternal( ObjectOutput out ) throws IOException
639     {
640         entry.writeExternal( out );
641     }
642 
643 
644     /**
645      * {@inheritDoc}
646      */
647     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
648     {
649         new Exception().printStackTrace();
650         throw new NotImplementedException( "Cannot read the entry " + entry.getDn() + " is immutable." );
651     }
652 
653 
654     /**
655      * Serialize an Entry.
656      * 
657      * The structure is the following :
658      * <b>[a byte]</b> : if the Dn is empty 0 will be written else 1
659      * <b>[Rdn]</b> : The entry's Rdn.
660      * <b>[numberAttr]</b> : the bumber of attributes. Can be 0 
661      * <b>[attribute's oid]*</b> : The attribute's OID to get back 
662      * the attributeType on deserialization
663      * <b>[Attribute]*</b> The attribute
664      * 
665      * @param out the buffer in which the data will be serialized
666      * @throws IOException if the serialization failed
667      */
668     public void serialize( ObjectOutput out ) throws IOException
669     {
670         new Exception().printStackTrace();
671         throw new NotImplementedException( "Cannot serialize the entry " + entry.getDn() + " is immutable." );
672     }
673 
674 
675     /**
676      * Deserialize an entry. 
677      * 
678      * @param in The buffer containing the serialized serverEntry
679      * @throws IOException if there was a problem when deserializing
680      * @throws ClassNotFoundException if we can't deserialize an expected object
681      */
682     public void deserialize( ObjectInput in ) throws IOException, ClassNotFoundException
683     {
684         new Exception().printStackTrace();
685         throw new NotImplementedException( "Cannot deserialize the entry " + entry.getDn() + " is immutable." );
686     }
687 
688 
689     /**
690      * Get the hash code of this ClientEntry. The Attributes will be sorted
691      * before the comparison can be done.
692      *
693      * @see java.lang.Object#hashCode()
694      * @return the instance's hash code 
695      */
696     public int hashCode()
697     {
698         return entry.hashCode();
699     }
700 
701 
702     /**
703      * {@inheritDoc}
704      */
705     public boolean hasObjectClass( String... objectClasses )
706     {
707         return entry.hasObjectClass( objectClasses );
708     }
709 
710 
711     /**
712      * {@inheritDoc}
713      */
714     public boolean hasObjectClass( Attribute... objectClasses )
715     {
716         return entry.hasObjectClass( objectClasses );
717     }
718 
719 
720     /**
721      * {@inheritDoc}
722      */
723     public boolean isSchemaAware()
724     {
725         return entry.isSchemaAware();
726     }
727 
728 
729     /**
730      * @see Object#equals(Object)
731      */
732     public boolean equals( Object o )
733     {
734         return entry.equals( o );
735     }
736 
737 
738     /**
739      * @see Object#toString()
740      */
741     public String toString()
742     {
743         return entry.toString();
744     }
745 
746 
747     /**
748      * {@inheritDoc}
749      */
750     public String toString( String tabs )
751     {
752         return entry.toString( tabs );
753     }
754 }