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