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 */ 020package org.apache.directory.api.ldap.model.schema.registries; 021 022 023import java.util.Map; 024 025import org.apache.directory.api.ldap.model.exception.LdapException; 026import org.apache.directory.api.ldap.model.schema.SchemaObject; 027import org.apache.directory.api.ldap.model.schema.SchemaObjectType; 028import org.apache.directory.api.ldap.model.schema.SyntaxChecker; 029import org.slf4j.Logger; 030import org.slf4j.LoggerFactory; 031 032 033/** 034 * SyntaxChecker registry component's service interface. 035 * 036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 037 */ 038public 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 /** 049 * Creates a new default SyntaxCheckerRegistry instance. 050 */ 051 public DefaultSyntaxCheckerRegistry() 052 { 053 super( SchemaObjectType.SYNTAX_CHECKER, new OidRegistry<SyntaxChecker>() ); 054 } 055 056 057 /** 058 * {@inheritDoc} 059 */ 060 @Override 061 public void unregisterSchemaElements( String schemaName ) throws LdapException 062 { 063 if ( schemaName == null ) 064 { 065 return; 066 } 067 068 // Loop on all the SchemaObjects stored and remove those associated 069 // with the give schemaName 070 for ( SyntaxChecker syntaxChecker : this ) 071 { 072 if ( schemaName.equalsIgnoreCase( syntaxChecker.getSchemaName() ) ) 073 { 074 String oid = syntaxChecker.getOid(); 075 SchemaObject removed = unregister( oid ); 076 077 if ( DEBUG ) 078 { 079 LOG.debug( "Removed {} with oid {} from the registry", removed, oid ); 080 } 081 } 082 } 083 } 084 085 086 /** 087 * {@inheritDoc} 088 */ 089 @Override 090 public DefaultSyntaxCheckerRegistry copy() 091 { 092 DefaultSyntaxCheckerRegistry copy = new DefaultSyntaxCheckerRegistry(); 093 094 // Copy the base data 095 copy.copy( this ); 096 097 return copy; 098 } 099 100 101 /** 102 * @see Object#toString() 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, SyntaxChecker> entry : byName.entrySet() ) 113 { 114 if ( isFirst ) 115 { 116 isFirst = false; 117 } 118 else 119 { 120 sb.append( ", " ); 121 } 122 123 SyntaxChecker syntaxChecker = entry.getValue(); 124 125 String fqcn = syntaxChecker.getFqcn(); 126 int lastDotPos = fqcn.lastIndexOf( '.' ); 127 128 sb.append( '<' ).append( syntaxChecker.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}