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.i18n.I18n; 026import org.apache.directory.api.ldap.model.exception.LdapException; 027import org.apache.directory.api.ldap.model.schema.SchemaObject; 028import org.apache.directory.api.ldap.model.schema.SchemaObjectType; 029import org.apache.directory.api.ldap.model.schema.SyntaxChecker; 030import org.slf4j.Logger; 031import org.slf4j.LoggerFactory; 032 033 034/** 035 * SyntaxChecker registry component's service interface. 036 * 037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 038 */ 039public class DefaultSyntaxCheckerRegistry extends DefaultSchemaObjectRegistry<SyntaxChecker> 040 implements SyntaxCheckerRegistry 041{ 042 /** static class logger */ 043 private static final Logger LOG = LoggerFactory.getLogger( DefaultSyntaxCheckerRegistry.class ); 044 045 046 /** 047 * Creates a new default SyntaxCheckerRegistry instance. 048 */ 049 public DefaultSyntaxCheckerRegistry() 050 { 051 super( SchemaObjectType.SYNTAX_CHECKER, new OidRegistry<SyntaxChecker>() ); 052 } 053 054 055 /** 056 * {@inheritDoc} 057 */ 058 @Override 059 public void unregisterSchemaElements( String schemaName ) throws LdapException 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 ( LOG.isDebugEnabled() ) 076 { 077 LOG.debug( I18n.msg( I18n.MSG_13702_REMOVED_FROM_REGISTRY, removed, oid ) ); 078 } 079 } 080 } 081 } 082 083 084 /** 085 * {@inheritDoc} 086 */ 087 @Override 088 public DefaultSyntaxCheckerRegistry copy() 089 { 090 DefaultSyntaxCheckerRegistry copy = new DefaultSyntaxCheckerRegistry(); 091 092 // Copy the base data 093 copy.copy( this ); 094 095 return copy; 096 } 097 098 099 /** 100 * @see Object#toString() 101 */ 102 @Override 103 public String toString() 104 { 105 StringBuilder sb = new StringBuilder(); 106 107 sb.append( schemaObjectType ).append( ": " ); 108 boolean isFirst = true; 109 110 for ( Map.Entry<String, SyntaxChecker> entry : byName.entrySet() ) 111 { 112 if ( isFirst ) 113 { 114 isFirst = false; 115 } 116 else 117 { 118 sb.append( ", " ); 119 } 120 121 SyntaxChecker syntaxChecker = entry.getValue(); 122 123 String fqcn = syntaxChecker.getFqcn(); 124 int lastDotPos = fqcn.lastIndexOf( '.' ); 125 126 sb.append( '<' ).append( syntaxChecker.getOid() ).append( ", " ); 127 128 if ( lastDotPos > 0 ) 129 { 130 sb.append( fqcn.substring( lastDotPos + 1 ) ); 131 } 132 else 133 { 134 sb.append( fqcn ); 135 } 136 137 sb.append( '>' ); 138 } 139 140 return sb.toString(); 141 } 142}