View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
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   * SyntaxChecker registry component's service interface.
33   *
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   */
36  public class DefaultSyntaxCheckerRegistry extends DefaultSchemaObjectRegistry<SyntaxChecker>
37      implements SyntaxCheckerRegistry
38  {
39      /** static class logger */
40      private static final Logger LOG = LoggerFactory.getLogger( DefaultSyntaxCheckerRegistry.class );
41  
42      /** A speedup for debug */
43      private static final boolean DEBUG = LOG.isDebugEnabled();
44  
45  
46      /**
47       * Creates a new default SyntaxCheckerRegistry instance.
48       */
49      public DefaultSyntaxCheckerRegistry()
50      {
51          super( SchemaObjectType.SYNTAX_CHECKER, new OidRegistry<SyntaxChecker>() );
52      }
53  
54  
55      /**
56       * {@inheritDoc}
57       */
58      public void unregisterSchemaElements( String schemaName ) throws LdapException
59      {
60          if ( schemaName == null )
61          {
62              return;
63          }
64  
65          // Loop on all the SchemaObjects stored and remove those associated
66          // with the give schemaName
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       * {@inheritDoc}
85       */
86      public DefaultSyntaxCheckerRegistry copy()
87      {
88          DefaultSyntaxCheckerRegistry copy = new DefaultSyntaxCheckerRegistry();
89  
90          // Copy the base data
91          copy.copy( this );
92  
93          return copy;
94      }
95  
96  
97      /**
98       * @see Object#toString()
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 }