001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.shared.ldap.schema.registries;
021
022
023 import javax.naming.NamingException;
024
025 import org.apache.directory.shared.ldap.schema.SchemaObject;
026 import org.apache.directory.shared.ldap.schema.SchemaObjectType;
027 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
028 import org.slf4j.Logger;
029 import org.slf4j.LoggerFactory;
030
031
032 /**
033 * SyntaxChecker registry component's service interface.
034 *
035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036 * @version $Rev: 831344 $
037 */
038 public class DefaultSyntaxCheckerRegistry extends DefaultSchemaObjectRegistry<SyntaxChecker>
039 implements SyntaxCheckerRegistry
040 {
041 /** static class logger */
042 private static final Logger LOG = LoggerFactory.getLogger( DefaultSyntaxCheckerRegistry.class );
043
044 /** A speedup for debug */
045 private static final boolean DEBUG = LOG.isDebugEnabled();
046
047 /**
048 * Creates a new default SyntaxCheckerRegistry instance.
049 */
050 public DefaultSyntaxCheckerRegistry()
051 {
052 super( SchemaObjectType.SYNTAX_CHECKER, new OidRegistry() );
053 }
054
055
056 /**
057 * {@inheritDoc}
058 */
059 public void unregisterSchemaElements( String schemaName ) throws NamingException
060 {
061 if ( schemaName == null )
062 {
063 return;
064 }
065
066 // Loop on all the SchemaObjects stored and remove those associated
067 // with the give schemaName
068 for ( SyntaxChecker syntaxChecker : this )
069 {
070 if ( schemaName.equalsIgnoreCase( syntaxChecker.getSchemaName() ) )
071 {
072 String oid = syntaxChecker.getOid();
073 SchemaObject removed = unregister( oid );
074
075 if ( DEBUG )
076 {
077 LOG.debug( "Removed {} with oid {} from the registry", removed, oid );
078 }
079 }
080 }
081 }
082
083
084 /**
085 * {@inheritDoc}
086 */
087 public DefaultSyntaxCheckerRegistry copy()
088 {
089 DefaultSyntaxCheckerRegistry copy = new DefaultSyntaxCheckerRegistry();
090
091 // Copy the base data
092 copy.copy( this );
093
094 return copy;
095 }
096
097
098 /**
099 * @see Object#toString()
100 */
101 public String toString()
102 {
103 StringBuilder sb = new StringBuilder();
104
105 sb.append( schemaObjectType ).append( ": " );
106 boolean isFirst = true;
107
108 for ( String name : byName.keySet() )
109 {
110 if ( isFirst )
111 {
112 isFirst = false;
113 }
114 else
115 {
116 sb.append( ", " );
117 }
118
119 SyntaxChecker syntaxChecker = byName.get( name );
120
121 String fqcn = syntaxChecker.getFqcn();
122 int lastDotPos = fqcn.lastIndexOf( '.' );
123
124 sb.append( '<' ).append( syntaxChecker.getOid() ).append( ", " );
125
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 }