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.Normalizer;
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 DefaultNormalizerRegistry extends DefaultSchemaObjectRegistry<Normalizer>
39 implements NormalizerRegistry
40 {
41
42 private static final Logger LOG = LoggerFactory.getLogger( DefaultNormalizerRegistry.class );
43
44
45 private static final boolean DEBUG = LOG.isDebugEnabled();
46
47
48
49
50
51 public DefaultNormalizerRegistry()
52 {
53 super( SchemaObjectType.NORMALIZER, new OidRegistry<Normalizer>() );
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 ( Normalizer normalizer : this )
71 {
72 if ( schemaName.equalsIgnoreCase( normalizer.getSchemaName() ) )
73 {
74 String oid = normalizer.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 DefaultNormalizerRegistry copy()
91 {
92 DefaultNormalizerRegistry copy = new DefaultNormalizerRegistry();
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, Normalizer> entry : byName.entrySet() )
113 {
114 if ( isFirst )
115 {
116 isFirst = false;
117 }
118 else
119 {
120 sb.append( ", " );
121 }
122
123 Normalizer normalizer = entry.getValue();
124
125 String fqcn = normalizer.getFqcn();
126 int lastDotPos = fqcn.lastIndexOf( '.' );
127
128 sb.append( '<' ).append( normalizer.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 }