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.parsers; 021 022 023 import java.text.ParseException; 024 025 import org.apache.directory.shared.i18n.I18n; 026 import org.slf4j.Logger; 027 import org.slf4j.LoggerFactory; 028 029 import antlr.RecognitionException; 030 import antlr.TokenStreamException; 031 032 033 /** 034 * A parser for ApacheDS normalizer descriptions. 035 * 036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 037 * @version $Rev$, $Date$ 038 */ 039 public class NormalizerDescriptionSchemaParser extends AbstractSchemaParser 040 { 041 /** The LoggerFactory used by this class */ 042 protected static final Logger LOG = LoggerFactory.getLogger( NormalizerDescriptionSchemaParser.class ); 043 044 045 /** 046 * Creates a schema parser instance. 047 */ 048 public NormalizerDescriptionSchemaParser() 049 { 050 super(); 051 } 052 053 054 /** 055 * Parses a normalizer description: 056 * 057 * <pre> 058 * NormalizerDescription = LPAREN WSP 059 * numericoid ; object identifier 060 * [ SP "DESC" SP qdstring ] ; description 061 * SP "FQCN" SP fqcn ; fully qualified class name 062 * [ SP "BYTECODE" SP base64 ] ; optional base64 encoded bytecode 063 * extensions WSP RPAREN ; extensions 064 * 065 * base64 = *(4base64-char) 066 * base64-char = ALPHA / DIGIT / "+" / "/" 067 * fqcn = fqcnComponent 1*( DOT fqcnComponent ) 068 * fqcnComponent = ??? 069 * 070 * extensions = *( SP xstring SP qdstrings ) 071 * xstring = "X" HYPHEN 1*( ALPHA / HYPHEN / USCORE ) 072 * </pre> 073 * 074 * @param normalizerDescription the normalizer description to be parsed 075 * @return the parsed NormalizerDescription bean 076 * @throws ParseException if there are any recognition errors (bad syntax) 077 */ 078 public synchronized NormalizerDescription parseNormalizerDescription( String normalizerDescription ) 079 throws ParseException 080 { 081 LOG.debug( "Parsing a Normalizer : {}", normalizerDescription ); 082 083 if ( normalizerDescription == null ) 084 { 085 LOG.error( I18n.err( I18n.ERR_04251 ) ); 086 throw new ParseException( "Null", 0 ); 087 } 088 089 reset( normalizerDescription ); // reset and initialize the parser / lexer pair 090 091 try 092 { 093 NormalizerDescription normalizer = parser.normalizerDescription(); 094 095 // Update the schemaName 096 setSchemaName( normalizer ); 097 098 return normalizer; 099 } 100 catch ( RecognitionException re ) 101 { 102 String msg = I18n.err( I18n.ERR_04252, normalizerDescription, re.getMessage(), re.getColumn() ); 103 LOG.error( msg ); 104 throw new ParseException( msg, re.getColumn() ); 105 } 106 catch ( TokenStreamException tse ) 107 { 108 String msg = I18n.err( I18n.ERR_04253, normalizerDescription, tse.getMessage() ); 109 LOG.error( msg ); 110 throw new ParseException( msg, 0 ); 111 } 112 113 } 114 115 116 /** 117 * Parses a Normalizer description 118 * 119 * @param The Normalizer description to parse 120 * @return An instance of NormalizerDescription 121 */ 122 public NormalizerDescription parse( String schemaDescription ) throws ParseException 123 { 124 return parseNormalizerDescription( schemaDescription ); 125 } 126 }