1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.model.schema.registries;
21
22
23 import java.util.Map;
24
25 import org.apache.directory.api.ldap.model.exception.LdapException;
26 import org.apache.directory.api.ldap.model.schema.LdapComparator;
27 import org.apache.directory.api.ldap.model.schema.SchemaObject;
28 import org.apache.directory.api.ldap.model.schema.SchemaObjectType;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36
37
38 public class DefaultComparatorRegistry extends DefaultSchemaObjectRegistry<LdapComparator<?>>
39 implements ComparatorRegistry
40 {
41
42 private static final Logger LOG = LoggerFactory.getLogger( DefaultComparatorRegistry.class );
43
44
45 private static final boolean DEBUG = LOG.isDebugEnabled();
46
47
48
49
50
51 public DefaultComparatorRegistry()
52 {
53 super( SchemaObjectType.COMPARATOR, new OidRegistry<LdapComparator<?>>() );
54 }
55
56
57
58
59
60 @Override
61 public void unregisterSchemaElements( String schemaName ) throws LdapException
62 {
63 if ( schemaName == null )
64 {
65 return;
66 }
67
68
69
70 for ( LdapComparator<?> comparator : this )
71 {
72 if ( schemaName.equalsIgnoreCase( comparator.getSchemaName() ) )
73 {
74 String oid = comparator.getOid();
75 SchemaObject removed = unregister( oid );
76
77 if ( DEBUG )
78 {
79 LOG.debug( "Removed {} with oid {} from the registry", removed, oid );
80 }
81 }
82 }
83 }
84
85
86
87
88
89 @Override
90 public DefaultComparatorRegistry copy()
91 {
92 DefaultComparatorRegistry copy = new DefaultComparatorRegistry();
93
94
95 copy.copy( this );
96
97 return copy;
98 }
99
100
101
102
103
104 @Override
105 public String toString()
106 {
107 StringBuilder sb = new StringBuilder();
108
109 sb.append( schemaObjectType ).append( ": " );
110 boolean isFirst = true;
111
112 for ( Map.Entry<String, LdapComparator<?>> entry : byName.entrySet() )
113 {
114 if ( isFirst )
115 {
116 isFirst = false;
117 }
118 else
119 {
120 sb.append( ", " );
121 }
122
123 LdapComparator<?> comparator = entry.getValue();
124
125 String fqcn = comparator.getFqcn();
126 int lastDotPos = fqcn.lastIndexOf( '.' );
127
128 sb.append( '<' ).append( comparator.getOid() ).append( ", " );
129
130 if ( lastDotPos > 0 )
131 {
132 sb.append( fqcn.substring( lastDotPos + 1 ) );
133 }
134 else
135 {
136 sb.append( fqcn );
137 }
138
139 sb.append( '>' );
140 }
141
142 return sb.toString();
143 }
144 }