1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.schema.bootstrap;
21
22
23 import java.io.Serializable;
24 import java.util.Comparator;
25
26 import javax.naming.NamingException;
27
28 import jdbm.helper.StringComparator;
29
30 import org.apache.directory.server.schema.bootstrap.ProducerTypeEnum;
31 import org.apache.directory.server.schema.registries.Registries;
32 import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
33 import org.apache.directory.shared.ldap.schema.NormalizingComparator;
34 import org.apache.directory.shared.ldap.util.StringTools;
35
36
37
38
39
40
41
42
43
44
45 public class ApachemetaComparatorProducer extends AbstractBootstrapProducer
46 {
47 public ApachemetaComparatorProducer()
48 {
49 super( ProducerTypeEnum.COMPARATOR_PRODUCER );
50 }
51
52
53 public static class DeepTrimToLowerNormalizingComparator extends NormalizingComparator
54 {
55 public DeepTrimToLowerNormalizingComparator()
56 {
57 super( new DeepTrimToLowerNormalizer(), new StringComparator() );
58 }
59 }
60
61
62
63
64
65
66
67
68
69
70 public void produce( Registries registries, ProducerCallback cb )
71 throws NamingException
72 {
73 Comparator comparator = null;
74
75 comparator = new NameOrNumericIdComparator();
76 cb.schemaObjectProduced( this, "1.3.6.1.4.1.18060.0.4.0.1.0", comparator );
77
78 comparator = new ObjectClassTypeComparator();
79 cb.schemaObjectProduced( this, "1.3.6.1.4.1.18060.0.4.0.1.1", comparator );
80
81 comparator = new StringComparator();
82 cb.schemaObjectProduced( this, "1.3.6.1.4.1.18060.0.4.0.1.2", comparator );
83
84 comparator = new DeepTrimToLowerNormalizingComparator();
85 cb.schemaObjectProduced( this, "1.3.6.1.4.1.18060.0.4.0.1.3", comparator );
86
87 comparator = new DeepTrimToLowerNormalizingComparator();
88 cb.schemaObjectProduced( this, "1.3.6.1.4.1.18060.0.4.0.1.4", comparator );
89 }
90
91
92 public static class ObjectClassTypeComparator implements Comparator<Object>, Serializable
93 {
94 private static final long serialVersionUID = 1L;
95
96
97 public int compare( Object o1, Object o2 )
98 {
99 String s1 = getString( o1 );
100 String s2 = getString( o2 );
101
102 if ( s1 == null && s2 == null )
103 {
104 return 0;
105 }
106
107 if ( s1 == null )
108 {
109 return -1;
110 }
111
112 if ( s2 == null )
113 {
114 return 1;
115 }
116
117 return s1.compareTo( s2 );
118 }
119
120
121 String getString( Object obj )
122 {
123 String strValue;
124
125 if ( obj == null )
126 {
127 return null;
128 }
129
130 if ( obj instanceof String )
131 {
132 strValue = ( String ) obj;
133 }
134 else if ( obj instanceof byte[] )
135 {
136 strValue = StringTools.utf8ToString( ( byte[] ) obj );
137 }
138 else
139 {
140 strValue = obj.toString();
141 }
142
143 return strValue;
144 }
145 }
146 }