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