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.parsers; 021 022 023import java.text.ParseException; 024 025import org.apache.directory.api.i18n.I18n; 026import org.apache.directory.api.ldap.model.schema.MatchingRuleUse; 027import org.slf4j.Logger; 028import org.slf4j.LoggerFactory; 029 030import antlr.RecognitionException; 031import antlr.TokenStreamException; 032 033 034/** 035 * A parser for RFC 4512 matching rule use descriptions. 036 * 037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 038 */ 039public class MatchingRuleUseDescriptionSchemaParser extends AbstractSchemaParser 040{ 041 /** The LoggerFactory used by this class */ 042 protected static final Logger LOG = LoggerFactory.getLogger( MatchingRuleUseDescriptionSchemaParser.class ); 043 044 045 /** 046 * Creates a schema parser instance. 047 */ 048 public MatchingRuleUseDescriptionSchemaParser() 049 { 050 } 051 052 053 /** 054 * Parses a matching rule use description according to RFC 4512: 055 * 056 * <pre> 057 * MatchingRuleUseDescription = LPAREN WSP 058 * numericoid ; object identifier 059 * [ SP "NAME" SP qdescrs ] ; short names (descriptors) 060 * [ SP "DESC" SP qdstring ] ; description 061 * [ SP "OBSOLETE" ] ; not active 062 * SP "APPLIES" SP oids ; attribute types 063 * extensions WSP RPAREN ; extensions 064 * 065 * extensions = *( SP xstring SP qdstrings ) 066 * xstring = "X" HYPHEN 1*( ALPHA / HYPHEN / USCORE ) 067 * </pre> 068 * 069 * @param matchingRuleUseDescription the matching rule use description to be parsed 070 * @return the parsed MatchingRuleUseDescription bean 071 * @throws ParseException if there are any recognition errors (bad syntax) 072 */ 073 public synchronized MatchingRuleUse parseMatchingRuleUseDescription( String matchingRuleUseDescription ) 074 throws ParseException 075 { 076 LOG.debug( "Parsing a MatchingRuleUse : {}", matchingRuleUseDescription ); 077 078 if ( matchingRuleUseDescription == null ) 079 { 080 LOG.error( I18n.err( I18n.ERR_04245 ) ); 081 throw new ParseException( "Null", 0 ); 082 } 083 084 reset( matchingRuleUseDescription ); // reset and initialize the parser / lexer pair 085 086 try 087 { 088 MatchingRuleUse matchingRuleUse = parser.matchingRuleUseDescription(); 089 090 // Update the schemaName 091 updateSchemaName( matchingRuleUse ); 092 093 return matchingRuleUse; 094 } 095 catch ( RecognitionException re ) 096 { 097 String msg = I18n.err( I18n.ERR_04246, matchingRuleUseDescription, re.getMessage(), re.getColumn() ); 098 LOG.error( msg ); 099 throw new ParseException( msg, re.getColumn() ); 100 } 101 catch ( TokenStreamException tse ) 102 { 103 String msg = I18n.err( I18n.ERR_04247, matchingRuleUseDescription, tse.getMessage() ); 104 LOG.error( msg ); 105 throw new ParseException( msg, 0 ); 106 } 107 108 } 109 110 111 /** 112 * Parses a MatchingRuleUse description. 113 * 114 * @param schemaDescription The MatchingRuleUse description to parse 115 * @return An instance of MatchingRuleUse 116 * @throws ParseException {@inheritDoc} 117 */ 118 public MatchingRuleUse parse( String schemaDescription ) throws ParseException 119 { 120 return parseMatchingRuleUseDescription( schemaDescription ); 121 } 122}