1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.ArrayList;
26 import java.util.Collection;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Map;
32
33 import org.apache.directory.api.i18n.I18n;
34 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
35 import org.apache.directory.api.ldap.model.exception.LdapException;
36 import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
37 import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
38 import org.apache.directory.api.ldap.model.ldif.LdapLdifException;
39 import org.apache.directory.api.ldap.model.ldif.LdifAttributesReader;
40 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
41 import org.apache.directory.api.ldap.model.name.Dn;
42 import org.apache.directory.api.ldap.model.schema.AttributeType;
43 import org.apache.directory.api.ldap.model.schema.SchemaManager;
44 import org.apache.directory.api.util.Base64;
45 import org.apache.directory.api.util.Strings;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48
49
50
51
52
53
54
55
56
57
58 public final class DefaultEntry implements Entry
59 {
60
61 private static final long serialVersionUID = 2L;
62
63
64 private static final Logger LOG = LoggerFactory.getLogger( DefaultEntry.class );
65
66
67 private Dn dn;
68
69
70 private Map<String, Attribute> attributes = new HashMap<>();
71
72
73 private static AttributeType objectClassAttributeType;
74
75
76 private SchemaManager schemaManager;
77
78
79 private volatile int h;
80
81
82 private static final Object MUTEX = new Object();
83
84
85
86
87
88
89
90
91
92
93 public DefaultEntry()
94 {
95 this( ( SchemaManager ) null );
96 }
97
98
99
100
101
102
103
104
105
106
107
108
109 public DefaultEntry( SchemaManager schemaManager )
110 {
111 this.schemaManager = schemaManager;
112 dn = Dn.EMPTY_DN;
113
114
115 if ( schemaManager != null )
116 {
117 initObjectClassAT();
118 }
119 }
120
121
122
123
124
125
126
127
128 public DefaultEntry( String dn ) throws LdapInvalidDnException
129 {
130 this.dn = new Dn( dn );
131 }
132
133
134
135
136
137
138
139 public DefaultEntry( Dn dn )
140 {
141 this.dn = dn;
142 }
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157 public DefaultEntry( SchemaManager schemaManager, String dn ) throws LdapInvalidDnException
158 {
159 this.schemaManager = schemaManager;
160
161 if ( Strings.isEmpty( dn ) )
162 {
163 this.dn = Dn.EMPTY_DN;
164 }
165 else
166 {
167 this.dn = new Dn( dn );
168 normalizeDN( this.dn );
169 }
170
171
172 initObjectClassAT();
173 }
174
175
176
177
178
179
180
181
182
183
184
185
186
187 public DefaultEntry( SchemaManager schemaManager, Dn dn )
188 {
189 this.schemaManager = schemaManager;
190
191 if ( dn == null )
192 {
193 this.dn = Dn.EMPTY_DN;
194 }
195 else
196 {
197 this.dn = dn;
198 normalizeDN( this.dn );
199 }
200
201
202 initObjectClassAT();
203 }
204
205
206
207
208
209
210
211
212
213
214 public DefaultEntry( String dn, Object... elements ) throws LdapException
215 {
216 this( null, dn, elements );
217 }
218
219
220
221
222
223
224
225
226
227
228 public DefaultEntry( Dn dn, Object... elements ) throws LdapException
229 {
230 this( null, dn, elements );
231 }
232
233
234
235
236
237
238
239
240
241
242
243 public DefaultEntry( SchemaManager schemaManager, String dn, Object... elements ) throws LdapException
244 {
245 this( schemaManager, new Dn( schemaManager, dn ), elements );
246 }
247
248
249
250
251
252
253
254
255
256
257
258 public DefaultEntry( SchemaManager schemaManager, Dn dn, Object... elements ) throws LdapException
259 {
260 DefaultEntry entry = ( DefaultEntry ) createEntry( schemaManager, elements );
261
262 this.dn = dn;
263 this.attributes = entry.attributes;
264 this.schemaManager = schemaManager;
265
266 if ( schemaManager != null )
267 {
268 this.dn.apply( schemaManager );
269 initObjectClassAT();
270 }
271 }
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287 public DefaultEntry( SchemaManager schemaManager, Entry entry ) throws LdapException
288 {
289 this.schemaManager = schemaManager;
290
291
292 initObjectClassAT();
293
294
295 if ( entry.getDn() != null )
296 {
297 dn = entry.getDn();
298 normalizeDN( dn );
299 }
300 else
301 {
302 dn = Dn.EMPTY_DN;
303 }
304
305
306 attributes = new HashMap<>( entry.size() );
307
308
309 for ( Attribute attribute : entry )
310 {
311 try
312 {
313
314 AttributeType attributeType = attribute.getAttributeType();
315
316 if ( attributeType == null )
317 {
318 attributeType = schemaManager.lookupAttributeTypeRegistry( attribute.getId() );
319 }
320
321
322 Attribute serverAttribute = new DefaultAttribute( attributeType, attribute );
323
324
325 add( serverAttribute );
326 }
327 catch ( LdapException ne )
328 {
329
330 LOG.warn( "The attribute '" + attribute.getId() + "' cannot be stored" );
331 throw ne;
332 }
333 }
334 }
335
336
337
338
339
340 private Entry createEntry( SchemaManager schemaManager, Object... elements )
341 throws LdapInvalidAttributeValueException, LdapLdifException
342 {
343 StringBuilder sb = new StringBuilder();
344 int pos = 0;
345 boolean valueExpected = false;
346
347 for ( Object element : elements )
348 {
349 if ( !valueExpected )
350 {
351 if ( !( element instanceof String ) )
352 {
353 throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(
354 I18n.ERR_12085, pos + 1 ) );
355 }
356
357 String attribute = ( String ) element;
358 sb.append( attribute );
359
360 if ( attribute.indexOf( ':' ) != -1 )
361 {
362 sb.append( '\n' );
363 }
364 else
365 {
366 valueExpected = true;
367 }
368 }
369 else
370 {
371 if ( element instanceof String )
372 {
373 sb.append( ": " ).append( ( String ) element ).append( '\n' );
374 }
375 else if ( element instanceof byte[] )
376 {
377 sb.append( ":: " );
378 sb.append( new String( Base64.encode( ( byte[] ) element ) ) );
379 sb.append( '\n' );
380 }
381 else
382 {
383 throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(
384 I18n.ERR_12086, pos + 1 ) );
385 }
386
387 valueExpected = false;
388 }
389 }
390
391 if ( valueExpected )
392 {
393 throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n
394 .err( I18n.ERR_12087 ) );
395 }
396
397 try ( LdifAttributesReader reader = new LdifAttributesReader() )
398 {
399 return reader.parseEntry( schemaManager, sb.toString() );
400 }
401 catch ( IOException e )
402 {
403 throw new LdapLdifException( "Cannot read an entry" );
404 }
405 }
406
407
408
409
410
411 private String getId( String upId )
412 {
413 String id = Strings.trim( Strings.toLowerCaseAscii( upId ) );
414
415
416 if ( Strings.isEmpty( id ) )
417 {
418 String message = I18n.err( I18n.ERR_04133 );
419 LOG.error( message );
420 throw new IllegalArgumentException( message );
421 }
422
423 return id;
424 }
425
426
427
428
429
430
431
432 private String getUpId( String upId, AttributeType attributeType )
433 {
434 String normUpId = Strings.trim( upId );
435
436 if ( attributeType == null )
437 {
438 if ( Strings.isEmpty( normUpId ) )
439 {
440 String message = I18n.err( I18n.ERR_04458 );
441 LOG.error( message );
442 throw new IllegalArgumentException( message );
443 }
444
445 return upId;
446 }
447 else if ( Strings.isEmpty( normUpId ) )
448 {
449 String id = attributeType.getName();
450
451 if ( Strings.isEmpty( id ) )
452 {
453 id = attributeType.getOid();
454 }
455
456 return id;
457 }
458 else
459 {
460 return upId;
461 }
462 }
463
464
465
466
467
468
469
470
471
472
473
474
475
476 private void initObjectClassAT()
477 {
478 if ( schemaManager == null )
479 {
480 return;
481 }
482
483 try
484 {
485 synchronized ( MUTEX )
486 {
487 if ( objectClassAttributeType == null )
488 {
489 objectClassAttributeType = schemaManager
490 .lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );
491 }
492 }
493 }
494 catch ( LdapException ne )
495 {
496
497 }
498 }
499
500
501
502
503
504
505
506 private void normalizeDN( Dn dn )
507 {
508 if ( !dn.isSchemaAware() )
509 {
510 try
511 {
512
513 dn.apply( schemaManager );
514 }
515 catch ( LdapException ne )
516 {
517 LOG.warn( "The Dn '{}' cannot be normalized", dn );
518 }
519 }
520 }
521
522
523
524
525
526 private void rehash()
527 {
528 h = 37;
529 h = h * 17 + dn.hashCode();
530 }
531
532
533
534
535
536
537
538
539
540
541
542
543
544 protected void createAttribute( String upId, AttributeType attributeType, byte[]... values )
545 throws LdapInvalidAttributeValueException
546 {
547 Attribute attribute = new DefaultAttribute( attributeType, values );
548 attribute.setUpId( upId, attributeType );
549 attributes.put( attributeType.getOid(), attribute );
550 }
551
552
553
554
555
556
557
558
559
560
561
562
563
564 protected void createAttribute( String upId, AttributeType attributeType, String... values )
565 throws LdapInvalidAttributeValueException
566 {
567 Attribute attribute = new DefaultAttribute( attributeType, values );
568 attribute.setUpId( upId, attributeType );
569 attributes.put( attributeType.getOid(), attribute );
570 }
571
572
573
574
575
576
577
578
579
580
581
582
583
584 protected void createAttribute( String upId, AttributeType attributeType, Value<?>... values )
585 throws LdapInvalidAttributeValueException
586 {
587 Attribute attribute = new DefaultAttribute( attributeType, values );
588 attribute.setUpId( upId, attributeType );
589 attributes.put( attributeType.getOid(), attribute );
590 }
591
592
593
594
595
596
597
598
599
600 protected AttributeType getAttributeType( String upId ) throws LdapException
601 {
602 if ( Strings.isEmpty( Strings.trim( upId ) ) )
603 {
604 String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
605 LOG.error( message );
606 throw new IllegalArgumentException( message );
607 }
608
609 return schemaManager.lookupAttributeTypeRegistry( upId );
610 }
611
612
613
614
615
616
617
618
619 public Entry add( AttributeType attributeType, byte[]... values ) throws LdapException
620 {
621 if ( attributeType == null )
622 {
623 String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
624 LOG.error( message );
625 throw new IllegalArgumentException( message );
626 }
627
628 if ( ( values == null ) || ( values.length == 0 ) )
629 {
630 String message = I18n.err( I18n.ERR_04478_NO_VALUE_NOT_ALLOWED );
631 LOG.error( message );
632 throw new IllegalArgumentException( message );
633 }
634
635
636 if ( attributeType.equals( objectClassAttributeType ) )
637 {
638 String message = I18n.err( I18n.ERR_04461 );
639 LOG.error( message );
640 throw new UnsupportedOperationException( message );
641 }
642
643 Attribute attribute = attributes.get( attributeType.getOid() );
644
645 if ( attribute != null )
646 {
647
648
649 attribute.add( values );
650 }
651 else
652 {
653
654
655
656 createAttribute( null, attributeType, values );
657 }
658
659 return this;
660 }
661
662
663
664
665
666 @Override
667 public Entry add( AttributeType attributeType, String... values ) throws LdapException
668 {
669 if ( attributeType == null )
670 {
671 String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
672 LOG.error( message );
673 throw new IllegalArgumentException( message );
674 }
675
676 Attribute attribute = attributes.get( attributeType.getOid() );
677
678 if ( attribute != null )
679 {
680
681
682 attribute.add( values );
683 }
684 else
685 {
686
687
688
689 createAttribute( null, attributeType, values );
690 }
691
692 return this;
693 }
694
695
696
697
698
699 @Override
700 public Entry add( AttributeType attributeType, Value<?>... values ) throws LdapException
701 {
702 if ( attributeType == null )
703 {
704 String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
705 LOG.error( message );
706 throw new IllegalArgumentException( message );
707 }
708
709 Attribute attribute = attributes.get( attributeType.getOid() );
710
711 if ( attribute != null )
712 {
713
714
715 attribute.add( values );
716 }
717 else
718 {
719
720
721
722 createAttribute( null, attributeType, values );
723 }
724
725 return this;
726 }
727
728
729
730
731
732 public Entry add( String upId, AttributeType attributeType, byte[]... values ) throws LdapException
733 {
734
735 if ( attributeType.equals( objectClassAttributeType ) )
736 {
737 String message = I18n.err( I18n.ERR_04461 );
738 LOG.error( message );
739 throw new UnsupportedOperationException( message );
740 }
741
742 Attribute attribute = attributes.get( attributeType.getOid() );
743
744 String id = getUpId( upId, attributeType );
745
746 if ( attribute != null )
747 {
748
749
750 attribute.add( values );
751 attribute.setUpId( id, attributeType );
752 }
753 else
754 {
755
756
757 createAttribute( id, attributeType, values );
758 }
759
760 return this;
761 }
762
763
764
765
766
767 @Override
768 public Entry add( String upId, AttributeType attributeType, Value<?>... values ) throws LdapException
769 {
770 if ( attributeType == null )
771 {
772 String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
773 LOG.error( message );
774 throw new IllegalArgumentException( message );
775 }
776
777 String id = getUpId( upId, attributeType );
778
779 Attribute attribute = attributes.get( attributeType.getOid() );
780
781 if ( attribute != null )
782 {
783
784
785 attribute.add( values );
786 attribute.setUpId( id, attributeType );
787 }
788 else
789 {
790 createAttribute( id, attributeType, values );
791 }
792
793 return this;
794 }
795
796
797
798
799
800 @Override
801 public Entry add( String upId, AttributeType attributeType, String... values ) throws LdapException
802 {
803 if ( attributeType == null )
804 {
805 String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
806 LOG.error( message );
807 throw new IllegalArgumentException( message );
808 }
809
810 String id = getUpId( upId, attributeType );
811
812 Attribute attribute = attributes.get( attributeType.getOid() );
813
814 if ( attribute != null )
815 {
816
817
818 attribute.add( values );
819 attribute.setUpId( id, attributeType );
820 }
821 else
822 {
823
824
825 createAttribute( id, attributeType, values );
826 }
827
828 return this;
829 }
830
831
832
833
834
835 @Override
836 public Entry add( Attribute... attributes ) throws LdapException
837 {
838
839 for ( Attribute attribute : attributes )
840 {
841 AttributeType attributeType = attribute.getAttributeType();
842
843 if ( attributeType != null )
844 {
845 String oid = attributeType.getOid();
846
847 if ( this.attributes.containsKey( oid ) )
848 {
849
850
851 Attribute existingAttribute = this.attributes.get( oid );
852
853 for ( Value<?> value : attribute )
854 {
855 existingAttribute.add( value );
856 }
857
858
859 existingAttribute.setUpId( attribute.getUpId() );
860 }
861 else
862 {
863
864 this.attributes.put( oid, attribute );
865 }
866 }
867 else
868 {
869
870 if ( contains( attribute ) )
871 {
872 Attribute existingAttribute = get( attribute.getId() );
873
874
875 for ( Value<?> value : attribute )
876 {
877 existingAttribute.add( value );
878 }
879 }
880 else
881 {
882
883 this.attributes.put( attribute.getId(), attribute );
884 }
885 }
886 }
887
888 return this;
889 }
890
891
892
893
894
895 public Entry add( String upId, byte[]... values ) throws LdapException
896 {
897 if ( Strings.isEmpty( upId ) )
898 {
899 String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
900 LOG.error( message );
901 throw new IllegalArgumentException( message );
902 }
903
904
905 String id = getId( upId );
906
907 if ( schemaManager != null )
908 {
909 add( upId, schemaManager.lookupAttributeTypeRegistry( id ), values );
910 }
911 else
912 {
913
914 Attribute attribute = attributes.get( id );
915
916 if ( attribute != null )
917 {
918
919
920
921 attribute.add( values );
922 attribute.setUpId( upId );
923 }
924 else
925 {
926
927
928 attributes.put( id, new DefaultAttribute( upId, values ) );
929 }
930 }
931
932 return this;
933 }
934
935
936
937
938
939 @Override
940 public Entry add( String upId, String... values ) throws LdapException
941 {
942 if ( Strings.isEmpty( upId ) )
943 {
944 String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
945 LOG.error( message );
946 throw new IllegalArgumentException( message );
947 }
948
949
950 String id = getId( upId );
951
952 if ( schemaManager != null )
953 {
954 add( upId, schemaManager.lookupAttributeTypeRegistry( upId ), values );
955 }
956 else
957 {
958
959 Attribute attribute = attributes.get( id );
960
961 if ( attribute != null )
962 {
963
964
965
966 attribute.add( values );
967 attribute.setUpId( upId );
968 }
969 else
970 {
971
972
973 attributes.put( id, new DefaultAttribute( upId, values ) );
974 }
975 }
976
977 return this;
978 }
979
980
981
982
983
984 @Override
985 public Entry add( String upId, Value<?>... values ) throws LdapException
986 {
987 if ( Strings.isEmpty( upId ) )
988 {
989 String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
990 LOG.error( message );
991 throw new IllegalArgumentException( message );
992 }
993
994
995 String id = getId( upId );
996
997 if ( schemaManager != null )
998 {
999 add( upId, schemaManager.lookupAttributeTypeRegistry( upId ), values );
1000 }
1001 else
1002 {
1003
1004 Attribute attribute = attributes.get( id );
1005
1006 if ( attribute != null )
1007 {
1008
1009
1010
1011 attribute.add( values );
1012 attribute.setUpId( upId );
1013 }
1014 else
1015 {
1016
1017
1018 attributes.put( id, new DefaultAttribute( upId, values ) );
1019 }
1020 }
1021
1022 return this;
1023 }
1024
1025
1026
1027
1028
1029
1030
1031 @Override
1032 public Entry clone()
1033 {
1034
1035 DefaultEntry clone = ( DefaultEntry ) shallowClone();
1036
1037
1038 clone.attributes.clear();
1039
1040 if ( schemaManager != null )
1041 {
1042 for ( Attribute attribute : attributes.values() )
1043 {
1044 String oid = attribute.getAttributeType().getOid();
1045 clone.attributes.put( oid, attribute.clone() );
1046 }
1047 }
1048 else
1049 {
1050 for ( Attribute attribute : attributes.values() )
1051 {
1052 clone.attributes.put( attribute.getId(), attribute.clone() );
1053 }
1054
1055 }
1056
1057
1058 return clone;
1059 }
1060
1061
1062
1063
1064
1065 @SuppressWarnings("unchecked")
1066 @Override
1067 public Entry shallowClone()
1068 {
1069 try
1070 {
1071
1072 DefaultEntry clone = ( DefaultEntry ) super.clone();
1073
1074
1075
1076 clone.dn = dn;
1077
1078
1079 clone.attributes = ( Map<String, Attribute> ) ( ( ( HashMap<String, Attribute> ) attributes )
1080 .clone() );
1081
1082
1083 return clone;
1084 }
1085 catch ( CloneNotSupportedException cnse )
1086 {
1087 return null;
1088 }
1089 }
1090
1091
1092
1093
1094
1095 @Override
1096 public boolean contains( Attribute... attributes )
1097 {
1098 if ( schemaManager == null )
1099 {
1100 for ( Attribute attribute : attributes )
1101 {
1102 if ( attribute == null )
1103 {
1104 return this.attributes.size() == 0;
1105 }
1106
1107 if ( !this.attributes.containsKey( attribute.getId() ) )
1108 {
1109 return false;
1110 }
1111 }
1112 }
1113 else
1114 {
1115 for ( Attribute entryAttribute : attributes )
1116 {
1117 if ( entryAttribute == null )
1118 {
1119 return this.attributes.size() == 0;
1120 }
1121
1122 AttributeType attributeType = entryAttribute.getAttributeType();
1123
1124 if ( ( attributeType == null ) || !this.attributes.containsKey( attributeType.getOid() ) )
1125 {
1126 return false;
1127 }
1128 }
1129 }
1130
1131 return true;
1132 }
1133
1134
1135
1136
1137
1138 @Override
1139 public boolean containsAttribute( String... attributes )
1140 {
1141 if ( schemaManager == null )
1142 {
1143 for ( String attribute : attributes )
1144 {
1145 String id = getId( attribute );
1146
1147 if ( !this.attributes.containsKey( id ) )
1148 {
1149 return false;
1150 }
1151 }
1152
1153 return true;
1154 }
1155 else
1156 {
1157 for ( String attribute : attributes )
1158 {
1159 try
1160 {
1161 if ( !containsAttribute( schemaManager.lookupAttributeTypeRegistry( attribute ) ) )
1162 {
1163 return false;
1164 }
1165 }
1166 catch ( LdapException ne )
1167 {
1168 return false;
1169 }
1170 }
1171
1172 return true;
1173 }
1174 }
1175
1176
1177
1178
1179
1180 @Override
1181 public boolean containsAttribute( AttributeType attributeType )
1182 {
1183 if ( attributeType == null )
1184 {
1185 return false;
1186 }
1187
1188 return attributes.containsKey( attributeType.getOid() );
1189 }
1190
1191
1192
1193
1194
1195 public boolean contains( AttributeType attributeType, byte[]... values )
1196 {
1197 if ( attributeType == null )
1198 {
1199 return false;
1200 }
1201
1202 Attribute attribute = attributes.get( attributeType.getOid() );
1203
1204 if ( attribute != null )
1205 {
1206 return attribute.contains( values );
1207 }
1208 else
1209 {
1210 return false;
1211 }
1212 }
1213
1214
1215
1216
1217
1218 @Override
1219 public boolean contains( AttributeType attributeType, String... values )
1220 {
1221 if ( attributeType == null )
1222 {
1223 return false;
1224 }
1225
1226 Attribute attribute = attributes.get( attributeType.getOid() );
1227
1228 if ( attribute != null )
1229 {
1230 return attribute.contains( values );
1231 }
1232 else
1233 {
1234 return false;
1235 }
1236 }
1237
1238
1239
1240
1241
1242 @Override
1243 public boolean contains( AttributeType attributeType, Value<?>... values )
1244 {
1245 if ( attributeType == null )
1246 {
1247 return false;
1248 }
1249
1250 Attribute attribute = attributes.get( attributeType.getOid() );
1251
1252 if ( attribute != null )
1253 {
1254 return attribute.contains( values );
1255 }
1256 else
1257 {
1258 return false;
1259 }
1260 }
1261
1262
1263
1264
1265
1266 public boolean contains( String upId, byte[]... values )
1267 {
1268 if ( Strings.isEmpty( upId ) )
1269 {
1270 return false;
1271 }
1272
1273 String id = getId( upId );
1274
1275 if ( schemaManager != null )
1276 {
1277 try
1278 {
1279 return contains( schemaManager.lookupAttributeTypeRegistry( id ), values );
1280 }
1281 catch ( LdapException le )
1282 {
1283 return false;
1284 }
1285 }
1286
1287 Attribute attribute = attributes.get( id );
1288
1289 if ( attribute == null )
1290 {
1291 return false;
1292 }
1293
1294 return attribute.contains( values );
1295 }
1296
1297
1298
1299
1300
1301 @Override
1302 public boolean contains( String upId, String... values )
1303 {
1304 if ( Strings.isEmpty( upId ) )
1305 {
1306 return false;
1307 }
1308
1309 String id = getId( upId );
1310
1311 if ( schemaManager != null )
1312 {
1313 try
1314 {
1315 return contains( schemaManager.lookupAttributeTypeRegistry( id ), values );
1316 }
1317 catch ( LdapException le )
1318 {
1319 return false;
1320 }
1321 }
1322
1323 Attribute attribute = attributes.get( id );
1324
1325 if ( attribute == null )
1326 {
1327 return false;
1328 }
1329
1330 return attribute.contains( values );
1331 }
1332
1333
1334
1335
1336
1337 @Override
1338 public boolean contains( String upId, Value<?>... values )
1339 {
1340 if ( Strings.isEmpty( upId ) )
1341 {
1342 return false;
1343 }
1344
1345 String id = getId( upId );
1346
1347 if ( schemaManager != null )
1348 {
1349 try
1350 {
1351 return contains( schemaManager.lookupAttributeTypeRegistry( id ), values );
1352 }
1353 catch ( LdapException le )
1354 {
1355 return false;
1356 }
1357 }
1358
1359 Attribute attribute = attributes.get( id );
1360
1361 if ( attribute == null )
1362 {
1363 return false;
1364 }
1365
1366 return attribute.contains( values );
1367 }
1368
1369
1370
1371
1372
1373 @Override
1374 public Attribute get( String alias )
1375 {
1376 try
1377 {
1378 String id = getId( alias );
1379
1380 if ( schemaManager != null )
1381 {
1382 try
1383 {
1384 AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
1385
1386 return attributes.get( attributeType.getOid() );
1387 }
1388 catch ( LdapException ne )
1389 {
1390 String message = ne.getLocalizedMessage();
1391 LOG.error( message );
1392 return null;
1393 }
1394 }
1395 else
1396 {
1397 return attributes.get( id );
1398 }
1399 }
1400 catch ( IllegalArgumentException iea )
1401 {
1402 LOG.error( I18n.err( I18n.ERR_04134, alias ) );
1403 return null;
1404 }
1405 }
1406
1407
1408
1409
1410
1411 @Override
1412 public Attribute get( AttributeType attributeType )
1413 {
1414 if ( attributeType != null )
1415 {
1416 return attributes.get( attributeType.getOid() );
1417 }
1418 else
1419 {
1420 return null;
1421 }
1422 }
1423
1424
1425
1426
1427
1428 @Override
1429 public Collection<Attribute> getAttributes()
1430 {
1431 return Collections.unmodifiableMap( attributes ).values();
1432 }
1433
1434
1435
1436
1437
1438 public Attribute put( String upId, byte[]... values )
1439 {
1440 if ( Strings.isEmpty( upId ) )
1441 {
1442 String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
1443 LOG.error( message );
1444 throw new IllegalArgumentException( message );
1445 }
1446
1447 if ( schemaManager == null )
1448 {
1449
1450 String id = getId( upId );
1451
1452
1453 Attribute clientAttribute = new DefaultAttribute( upId, values );
1454
1455
1456 return attributes.put( id, clientAttribute );
1457 }
1458 else
1459 {
1460 try
1461 {
1462 return put( upId, getAttributeType( upId ), values );
1463 }
1464 catch ( LdapException ne )
1465 {
1466 String message = I18n.err( I18n.ERR_04464, upId, ne.getLocalizedMessage() );
1467 LOG.error( message );
1468 throw new IllegalArgumentException( message, ne );
1469 }
1470 }
1471 }
1472
1473
1474
1475
1476
1477 @Override
1478 public Attribute put( String upId, String... values )
1479 {
1480 if ( Strings.isEmpty( upId ) )
1481 {
1482 String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
1483 LOG.error( message );
1484 throw new IllegalArgumentException( message );
1485 }
1486
1487 if ( schemaManager == null )
1488 {
1489
1490 String id = getId( upId );
1491
1492
1493 Attribute clientAttribute = new DefaultAttribute( upId, values );
1494
1495
1496 return attributes.put( id, clientAttribute );
1497 }
1498 else
1499 {
1500 try
1501 {
1502 return put( upId, getAttributeType( upId ), values );
1503 }
1504 catch ( LdapException ne )
1505 {
1506 String message = I18n.err( I18n.ERR_04464, upId, ne.getLocalizedMessage() );
1507 LOG.error( message );
1508 throw new IllegalArgumentException( message, ne );
1509 }
1510 }
1511 }
1512
1513
1514
1515
1516
1517 @Override
1518 public Attribute put( String upId, Value<?>... values )
1519 {
1520 if ( Strings.isEmpty( upId ) )
1521 {
1522 String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
1523 LOG.error( message );
1524 throw new IllegalArgumentException( message );
1525 }
1526
1527 if ( schemaManager == null )
1528 {
1529
1530 String id = getId( upId );
1531
1532
1533 Attribute clientAttribute = new DefaultAttribute( upId, values );
1534
1535
1536 return attributes.put( id, clientAttribute );
1537 }
1538 else
1539 {
1540 try
1541 {
1542 return put( upId, getAttributeType( upId ), values );
1543 }
1544 catch ( LdapException ne )
1545 {
1546 String message = I18n.err( I18n.ERR_04464, upId, ne.getLocalizedMessage() );
1547 LOG.error( message );
1548 throw new IllegalArgumentException( message, ne );
1549 }
1550 }
1551 }
1552
1553
1554
1555
1556
1557 @Override
1558 public List<Attribute> put( Attribute... attributes ) throws LdapException
1559 {
1560
1561 List<Attribute> previous = new ArrayList<>();
1562
1563 if ( schemaManager == null )
1564 {
1565 for ( Attribute attribute : attributes )
1566 {
1567 String id = attribute.getId();
1568
1569 if ( containsAttribute( id ) )
1570 {
1571
1572 previous.add( get( id ) );
1573 this.attributes.remove( id );
1574 }
1575
1576
1577 this.attributes.put( id, attribute );
1578 }
1579 }
1580 else
1581 {
1582 for ( Attribute attribute : attributes )
1583 {
1584 if ( attribute == null )
1585 {
1586 String message = I18n.err( I18n.ERR_04462 );
1587 LOG.error( message );
1588 throw new IllegalArgumentException( message );
1589 }
1590
1591 if ( attribute.getAttributeType() == null )
1592 {
1593 AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( attribute.getId() );
1594 attribute.apply( attributeType );
1595 }
1596
1597 Attribute removed = this.attributes.put( attribute.getAttributeType().getOid(), attribute );
1598
1599 if ( removed != null )
1600 {
1601 previous.add( removed );
1602 }
1603 }
1604 }
1605
1606
1607 return previous;
1608 }
1609
1610
1611
1612
1613
1614 public Attribute put( AttributeType attributeType, byte[]... values ) throws LdapException
1615 {
1616 return put( null, attributeType, values );
1617 }
1618
1619
1620
1621
1622
1623 @Override
1624 public Attribute put( AttributeType attributeType, String... values ) throws LdapException
1625 {
1626 return put( null, attributeType, values );
1627 }
1628
1629
1630
1631
1632
1633 @Override
1634 public Attribute put( AttributeType attributeType, Value<?>... values ) throws LdapException
1635 {
1636 return put( null, attributeType, values );
1637 }
1638
1639
1640
1641
1642
1643 public Attribute put( String upId, AttributeType attributeType, byte[]... values ) throws LdapException
1644 {
1645 if ( attributeType == null )
1646 {
1647 try
1648 {
1649 attributeType = getAttributeType( upId );
1650 }
1651 catch ( Exception e )
1652 {
1653 String message = I18n.err( I18n.ERR_04477_NO_VALID_AT_FOR_THIS_ID );
1654 LOG.error( message );
1655 throw new IllegalArgumentException( message, e );
1656 }
1657 }
1658 else
1659 {
1660 if ( !Strings.isEmpty( upId ) )
1661 {
1662 AttributeType tempAT = getAttributeType( upId );
1663
1664 if ( !tempAT.equals( attributeType ) )
1665 {
1666 String message = I18n.err( I18n.ERR_04463, upId, attributeType );
1667 LOG.error( message );
1668 throw new IllegalArgumentException( message );
1669 }
1670 }
1671 else
1672 {
1673 upId = getUpId( upId, attributeType );
1674 }
1675 }
1676
1677 if ( attributeType.equals( objectClassAttributeType ) )
1678 {
1679 String message = I18n.err( I18n.ERR_04461 );
1680 LOG.error( message );
1681 throw new UnsupportedOperationException( message );
1682 }
1683
1684 Attribute attribute = new DefaultAttribute( upId, attributeType, values );
1685
1686 return attributes.put( attributeType.getOid(), attribute );
1687 }
1688
1689
1690
1691
1692
1693 @Override
1694 public Attribute put( String upId, AttributeType attributeType, String... values ) throws LdapException
1695 {
1696 if ( attributeType == null )
1697 {
1698 try
1699 {
1700 attributeType = getAttributeType( upId );
1701 }
1702 catch ( Exception e )
1703 {
1704 String message = I18n.err( I18n.ERR_04477_NO_VALID_AT_FOR_THIS_ID );
1705 LOG.error( message );
1706 throw new IllegalArgumentException( message, e );
1707 }
1708 }
1709 else
1710 {
1711 if ( !Strings.isEmpty( upId ) )
1712 {
1713 AttributeType tempAT = getAttributeType( upId );
1714
1715 if ( !tempAT.equals( attributeType ) )
1716 {
1717 String message = I18n.err( I18n.ERR_04463, upId, attributeType );
1718 LOG.error( message );
1719 throw new IllegalArgumentException( message );
1720 }
1721 }
1722 else
1723 {
1724 upId = getUpId( upId, attributeType );
1725 }
1726 }
1727
1728 Attribute attribute = new DefaultAttribute( upId, attributeType, values );
1729
1730 return attributes.put( attributeType.getOid(), attribute );
1731 }
1732
1733
1734
1735
1736
1737 @Override
1738 public Attribute put( String upId, AttributeType attributeType, Value<?>... values ) throws LdapException
1739 {
1740 if ( attributeType == null )
1741 {
1742 try
1743 {
1744 attributeType = getAttributeType( upId );
1745 }
1746 catch ( Exception e )
1747 {
1748 String message = I18n.err( I18n.ERR_04477_NO_VALID_AT_FOR_THIS_ID );
1749 LOG.error( message );
1750 throw new IllegalArgumentException( message, e );
1751 }
1752 }
1753 else
1754 {
1755 if ( !Strings.isEmpty( upId ) )
1756 {
1757 AttributeType tempAT = getAttributeType( upId );
1758
1759 if ( !tempAT.equals( attributeType ) )
1760 {
1761 String message = I18n.err( I18n.ERR_04463, upId, attributeType );
1762 LOG.error( message );
1763 throw new IllegalArgumentException( message );
1764 }
1765 }
1766 else
1767 {
1768 upId = getUpId( upId, attributeType );
1769 }
1770 }
1771
1772 Attribute attribute = new DefaultAttribute( upId, attributeType, values );
1773
1774 return attributes.put( attributeType.getOid(), attribute );
1775 }
1776
1777
1778
1779
1780
1781 @Override
1782 public List<Attribute> remove( Attribute... attributes ) throws LdapException
1783 {
1784 List<Attribute> removedAttributes = new ArrayList<>();
1785
1786 if ( schemaManager == null )
1787 {
1788 for ( Attribute attribute : attributes )
1789 {
1790 if ( containsAttribute( attribute.getId() ) )
1791 {
1792 this.attributes.remove( attribute.getId() );
1793 removedAttributes.add( attribute );
1794 }
1795 }
1796 }
1797 else
1798 {
1799 for ( Attribute attribute : attributes )
1800 {
1801 AttributeType attributeType = attribute.getAttributeType();
1802
1803 if ( attributeType == null )
1804 {
1805 String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
1806 LOG.error( message );
1807 throw new IllegalArgumentException( message );
1808 }
1809
1810 if ( this.attributes.containsKey( attributeType.getOid() ) )
1811 {
1812 this.attributes.remove( attributeType.getOid() );
1813 removedAttributes.add( attribute );
1814 }
1815 }
1816 }
1817
1818 return removedAttributes;
1819 }
1820
1821
1822
1823
1824
1825 public boolean remove( AttributeType attributeType, byte[]... values ) throws LdapException
1826 {
1827 if ( attributeType == null )
1828 {
1829 return false;
1830 }
1831
1832 try
1833 {
1834 Attribute attribute = attributes.get( attributeType.getOid() );
1835
1836 if ( attribute == null )
1837 {
1838
1839 return false;
1840 }
1841
1842 int nbOldValues = attribute.size();
1843
1844
1845 attribute.remove( values );
1846
1847 if ( attribute.size() == 0 )
1848 {
1849
1850 attributes.remove( attributeType.getOid() );
1851
1852 return true;
1853 }
1854
1855 return nbOldValues != attribute.size();
1856 }
1857 catch ( IllegalArgumentException iae )
1858 {
1859 LOG.error( I18n.err( I18n.ERR_04465, attributeType ) );
1860 return false;
1861 }
1862 }
1863
1864
1865
1866
1867
1868 @Override
1869 public boolean remove( AttributeType attributeType, String... values ) throws LdapException
1870 {
1871 if ( attributeType == null )
1872 {
1873 return false;
1874 }
1875
1876 try
1877 {
1878 Attribute attribute = attributes.get( attributeType.getOid() );
1879
1880 if ( attribute == null )
1881 {
1882
1883 return false;
1884 }
1885
1886 int nbOldValues = attribute.size();
1887
1888
1889 attribute.remove( values );
1890
1891 if ( attribute.size() == 0 )
1892 {
1893
1894 attributes.remove( attributeType.getOid() );
1895
1896 return true;
1897 }
1898
1899 return nbOldValues != attribute.size();
1900 }
1901 catch ( IllegalArgumentException iae )
1902 {
1903 LOG.error( I18n.err( I18n.ERR_04465, attributeType ) );
1904 return false;
1905 }
1906 }
1907
1908
1909
1910
1911
1912 @Override
1913 public boolean remove( AttributeType attributeType, Value<?>... values ) throws LdapException
1914 {
1915 if ( attributeType == null )
1916 {
1917 return false;
1918 }
1919
1920 try
1921 {
1922 Attribute attribute = attributes.get( attributeType.getOid() );
1923
1924 if ( attribute == null )
1925 {
1926
1927 return false;
1928 }
1929
1930 int nbOldValues = attribute.size();
1931
1932
1933 attribute.remove( values );
1934
1935 if ( attribute.size() == 0 )
1936 {
1937
1938 attributes.remove( attributeType.getOid() );
1939
1940 return true;
1941 }
1942
1943 return nbOldValues != attribute.size();
1944 }
1945 catch ( IllegalArgumentException iae )
1946 {
1947 LOG.error( I18n.err( I18n.ERR_04465, attributeType ) );
1948 return false;
1949 }
1950 }
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967 @Override
1968 public void removeAttributes( AttributeType... attributes )
1969 {
1970 if ( ( attributes == null ) || ( attributes.length == 0 ) || ( schemaManager == null ) )
1971 {
1972 return;
1973 }
1974
1975 for ( AttributeType attributeType : attributes )
1976 {
1977 if ( attributeType == null )
1978 {
1979 continue;
1980 }
1981
1982 this.attributes.remove( attributeType.getOid() );
1983 }
1984 }
1985
1986
1987
1988
1989
1990 @Override
1991 public void removeAttributes( String... attributes )
1992 {
1993 if ( attributes.length == 0 )
1994 {
1995 return;
1996 }
1997
1998 if ( schemaManager == null )
1999 {
2000 for ( String attribute : attributes )
2001 {
2002 Attribute attr = get( attribute );
2003
2004 if ( attr != null )
2005 {
2006 this.attributes.remove( attr.getId() );
2007 }
2008 else
2009 {
2010 String message = I18n.err( I18n.ERR_04137, attribute );
2011 LOG.warn( message );
2012 continue;
2013 }
2014 }
2015 }
2016 else
2017 {
2018 for ( String attribute : attributes )
2019 {
2020 AttributeType attributeType = null;
2021
2022 try
2023 {
2024 attributeType = schemaManager.lookupAttributeTypeRegistry( attribute );
2025 }
2026 catch ( LdapException ne )
2027 {
2028 String message = "The attribute '" + attribute + "' does not exist in the entry";
2029 LOG.warn( message );
2030 continue;
2031 }
2032
2033 this.attributes.remove( attributeType.getOid() );
2034 }
2035 }
2036 }
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060 public boolean remove( String upId, byte[]... values ) throws LdapException
2061 {
2062 if ( Strings.isEmpty( upId ) )
2063 {
2064 String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
2065 LOG.info( message );
2066 return false;
2067 }
2068
2069 if ( schemaManager == null )
2070 {
2071 String id = getId( upId );
2072
2073 Attribute attribute = get( id );
2074
2075 if ( attribute == null )
2076 {
2077
2078 return false;
2079 }
2080
2081 int nbOldValues = attribute.size();
2082
2083
2084 attribute.remove( values );
2085
2086 if ( attribute.size() == 0 )
2087 {
2088
2089 attributes.remove( id );
2090
2091 return true;
2092 }
2093
2094 return nbOldValues != attribute.size();
2095 }
2096 else
2097 {
2098 try
2099 {
2100 AttributeType attributeType = getAttributeType( upId );
2101
2102 return remove( attributeType, values );
2103 }
2104 catch ( LdapException ne )
2105 {
2106 LOG.error( I18n.err( I18n.ERR_04465, upId ) );
2107 return false;
2108 }
2109 catch ( IllegalArgumentException iae )
2110 {
2111 LOG.error( I18n.err( I18n.ERR_04466, upId ) );
2112 return false;
2113 }
2114 }
2115
2116 }
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140 @Override
2141 public boolean remove( String upId, String... values ) throws LdapException
2142 {
2143 if ( Strings.isEmpty( upId ) )
2144 {
2145 String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
2146 LOG.info( message );
2147 return false;
2148 }
2149
2150 if ( schemaManager == null )
2151 {
2152 String id = getId( upId );
2153
2154 Attribute attribute = get( id );
2155
2156 if ( attribute == null )
2157 {
2158
2159 return false;
2160 }
2161
2162 int nbOldValues = attribute.size();
2163
2164
2165 attribute.remove( values );
2166
2167 if ( attribute.size() == 0 )
2168 {
2169
2170 attributes.remove( id );
2171
2172 return true;
2173 }
2174
2175 return nbOldValues != attribute.size();
2176 }
2177 else
2178 {
2179 try
2180 {
2181 AttributeType attributeType = getAttributeType( upId );
2182
2183 return remove( attributeType, values );
2184 }
2185 catch ( LdapException ne )
2186 {
2187 LOG.error( I18n.err( I18n.ERR_04465, upId ) );
2188 return false;
2189 }
2190 catch ( IllegalArgumentException iae )
2191 {
2192 LOG.error( I18n.err( I18n.ERR_04466, upId ) );
2193 return false;
2194 }
2195 }
2196 }
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220 @Override
2221 public boolean remove( String upId, Value<?>... values ) throws LdapException
2222 {
2223 if ( Strings.isEmpty( upId ) )
2224 {
2225 String message = I18n.err( I18n.ERR_04457_NULL_ATTRIBUTE_ID );
2226 LOG.info( message );
2227 return false;
2228 }
2229
2230 if ( schemaManager == null )
2231 {
2232 String id = getId( upId );
2233
2234 Attribute attribute = get( id );
2235
2236 if ( attribute == null )
2237 {
2238
2239 return false;
2240 }
2241
2242 int nbOldValues = attribute.size();
2243
2244
2245 attribute.remove( values );
2246
2247 if ( attribute.size() == 0 )
2248 {
2249
2250 attributes.remove( id );
2251
2252 return true;
2253 }
2254
2255 return nbOldValues != attribute.size();
2256 }
2257 else
2258 {
2259 try
2260 {
2261 AttributeType attributeType = getAttributeType( upId );
2262
2263 return remove( attributeType, values );
2264 }
2265 catch ( LdapException ne )
2266 {
2267 LOG.error( I18n.err( I18n.ERR_04465, upId ) );
2268 return false;
2269 }
2270 catch ( IllegalArgumentException iae )
2271 {
2272 LOG.error( I18n.err( I18n.ERR_04466, upId ) );
2273 return false;
2274 }
2275 }
2276 }
2277
2278
2279
2280
2281
2282
2283
2284 @Override
2285 public Dn getDn()
2286 {
2287 return dn;
2288 }
2289
2290
2291
2292
2293
2294 @Override
2295 public void setDn( Dn dn )
2296 {
2297 this.dn = dn;
2298
2299
2300 rehash();
2301 }
2302
2303
2304
2305
2306
2307 @Override
2308 public void setDn( String dn ) throws LdapInvalidDnException
2309 {
2310 setDn( new Dn( dn ) );
2311 }
2312
2313
2314
2315
2316
2317 @Override
2318 public void clear()
2319 {
2320 attributes.clear();
2321 }
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331 @Override
2332 public Iterator<Attribute> iterator()
2333 {
2334 return Collections.unmodifiableMap( attributes ).values().iterator();
2335 }
2336
2337
2338
2339
2340
2341
2342
2343 @Override
2344 public int size()
2345 {
2346 return attributes.size();
2347 }
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369 @Override
2370 public void writeExternal( ObjectOutput out ) throws IOException
2371 {
2372
2373 if ( dn == null )
2374 {
2375
2376 Dn.EMPTY_DN.writeExternal( out );
2377 }
2378 else
2379 {
2380
2381 dn.writeExternal( out );
2382 }
2383
2384
2385
2386 out.writeInt( attributes.size() );
2387
2388
2389 for ( Attribute attribute : attributes.values() )
2390 {
2391
2392 attribute.writeExternal( out );
2393 }
2394
2395 out.flush();
2396 }
2397
2398
2399
2400
2401
2402 @Override
2403 public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
2404 {
2405
2406 dn = new Dn( schemaManager );
2407 dn.readExternal( in );
2408
2409
2410 int nbAttributes = in.readInt();
2411
2412
2413 for ( int i = 0; i < nbAttributes; i++ )
2414 {
2415
2416 Attribute attribute = new DefaultAttribute();
2417 attribute.readExternal( in );
2418
2419 if ( schemaManager != null )
2420 {
2421 try
2422 {
2423 AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( attribute.getId() );
2424 attribute.apply( attributeType );
2425
2426 attributes.put( attributeType.getOid(), attribute );
2427 }
2428 catch ( LdapException le )
2429 {
2430 String message = le.getLocalizedMessage();
2431 LOG.error( message );
2432 throw new IOException( message, le );
2433 }
2434 }
2435 else
2436 {
2437 attributes.put( attribute.getId(), attribute );
2438 }
2439 }
2440 }
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450 @Override
2451 public int hashCode()
2452 {
2453 if ( h == 0 )
2454 {
2455 rehash();
2456 }
2457
2458 return h;
2459 }
2460
2461
2462
2463
2464
2465 @Override
2466 public boolean hasObjectClass( String... objectClasses )
2467 {
2468 if ( ( objectClasses == null ) || ( objectClasses.length == 0 ) || ( objectClasses[0] == null ) )
2469 {
2470 return false;
2471 }
2472
2473 for ( String objectClass : objectClasses )
2474 {
2475 if ( schemaManager != null )
2476 {
2477 if ( !contains( objectClassAttributeType, objectClass ) )
2478 {
2479 return false;
2480 }
2481 }
2482 else
2483 {
2484 if ( !contains( "objectclass", objectClass ) )
2485 {
2486 return false;
2487 }
2488 }
2489 }
2490
2491 return true;
2492 }
2493
2494
2495
2496
2497
2498 @Override
2499 public boolean hasObjectClass( Attribute... objectClasses )
2500 {
2501 if ( ( objectClasses == null ) || ( objectClasses.length == 0 ) || ( objectClasses[0] == null ) )
2502 {
2503 return false;
2504 }
2505
2506 for ( Attribute objectClass : objectClasses )
2507 {
2508
2509 if ( !objectClass.getAttributeType().equals( objectClassAttributeType ) )
2510 {
2511 return false;
2512 }
2513
2514 Attribute attribute = attributes.get( objectClassAttributeType.getOid() );
2515
2516 if ( attribute == null )
2517 {
2518
2519 return false;
2520 }
2521
2522 for ( Value<?> value : objectClass )
2523 {
2524
2525 if ( !attribute.contains( value.getString() ) )
2526 {
2527 return false;
2528 }
2529 }
2530 }
2531
2532 return true;
2533 }
2534
2535
2536
2537
2538
2539 @Override
2540 public boolean isSchemaAware()
2541 {
2542 return schemaManager != null;
2543 }
2544
2545
2546
2547
2548
2549 @Override
2550 public boolean equals( Object o )
2551 {
2552
2553 if ( this == o )
2554 {
2555 return true;
2556 }
2557
2558 if ( !( o instanceof Entry ) )
2559 {
2560 return false;
2561 }
2562
2563 Entry other = ( Entry ) o;
2564
2565
2566 if ( dn == null )
2567 {
2568 if ( other.getDn() != null )
2569 {
2570 return false;
2571 }
2572 }
2573 else
2574 {
2575 if ( !dn.equals( other.getDn() ) )
2576 {
2577 return false;
2578 }
2579 }
2580
2581
2582 if ( size() != other.size() )
2583 {
2584 return false;
2585 }
2586
2587
2588 for ( Attribute attribute : other )
2589 {
2590 if ( !attribute.equals( this.get( attribute.getId() ) ) )
2591 {
2592 return false;
2593 }
2594 }
2595
2596 return true;
2597 }
2598
2599
2600
2601
2602
2603 @Override
2604 public String toString()
2605 {
2606 return toString( "" );
2607 }
2608
2609
2610
2611
2612
2613 @Override
2614 public String toString( String tabs )
2615 {
2616 StringBuilder sb = new StringBuilder();
2617
2618 sb.append( tabs ).append( "Entry\n" );
2619 sb.append( tabs ).append( " dn" );
2620
2621 if ( dn.isSchemaAware() )
2622 {
2623 sb.append( "[n]" );
2624 }
2625
2626 sb.append( ": " );
2627 sb.append( dn.getName() );
2628 sb.append( '\n' );
2629
2630
2631 if ( schemaManager != null )
2632 {
2633
2634 if ( containsAttribute( objectClassAttributeType.getOid() ) )
2635 {
2636 Attribute objectClass = get( objectClassAttributeType );
2637
2638 sb.append( objectClass.toString( tabs + " " ) );
2639 }
2640 }
2641 else
2642 {
2643 if ( containsAttribute( "objectClass" ) )
2644 {
2645 Attribute objectClass = get( "objectclass" );
2646
2647 sb.append( objectClass.toString( tabs + " " ) );
2648 }
2649 }
2650
2651 sb.append( '\n' );
2652
2653 if ( attributes.size() != 0 )
2654 {
2655 for ( Attribute attribute : attributes.values() )
2656 {
2657 String id = attribute.getId();
2658
2659 if ( schemaManager != null )
2660 {
2661 AttributeType attributeType = schemaManager.getAttributeType( id );
2662
2663 if ( attributeType == null )
2664 {
2665 sb.append( tabs ).append( "id: " ).append( id );
2666 }
2667 else if ( !attributeType.equals( objectClassAttributeType ) )
2668 {
2669 sb.append( attribute.toString( tabs + " " ) );
2670 sb.append( '\n' );
2671 continue;
2672 }
2673 }
2674 else
2675 {
2676 if ( !id.equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT )
2677 && !id.equals( SchemaConstants.OBJECT_CLASS_AT_OID ) )
2678 {
2679 sb.append( attribute.toString( tabs + " " ) );
2680 sb.append( '\n' );
2681 continue;
2682 }
2683 }
2684 }
2685 }
2686
2687 return sb.toString();
2688 }
2689 }