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.MatchingRule; 027 028 029/** 030 * A parser for RFC 4512 matching rule descriptions. 031 * 032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 033 */ 034public class MatchingRuleDescriptionSchemaParser extends AbstractSchemaParser<MatchingRule> 035{ 036 /** 037 * Creates a schema parser instance. 038 */ 039 public MatchingRuleDescriptionSchemaParser() 040 { 041 super( MatchingRule.class, I18n.ERR_13845_CANNOT_PARSE_NULL_MR, I18n.ERR_13846_MR_PARSING_FAILURE, 042 I18n.ERR_13847_MR_DESC_PARSING_FAILURE ); 043 } 044 045 046 /** 047 * Parses a matching rule description according to RFC 4512: 048 * 049 * <pre> 050 * MatchingRuleDescription = LPAREN WSP 051 * numericoid ; object identifier 052 * [ SP "NAME" SP qdescrs ] ; short names (descriptors) 053 * [ SP "DESC" SP qdstring ] ; description 054 * [ SP "OBSOLETE" ] ; not active 055 * SP "SYNTAX" SP numericoid ; assertion syntax 056 * extensions WSP RPAREN ; extensions 057 * 058 * extensions = *( SP xstring SP qdstrings ) 059 * xstring = "X" HYPHEN 1*( ALPHA / HYPHEN / USCORE ) 060 * </pre> 061 * 062 * @param matchingRuleDescription the matching rule description to be parsed 063 * @return the parsed MatchingRuleDescription bean 064 * @throws ParseException if there are any recognition errors (bad syntax) 065 */ 066 public MatchingRule parse( String matchingRuleDescription ) throws ParseException 067 { 068 MatchingRule matchingRule = fastParser.parseMatchingRule( matchingRuleDescription ); 069 matchingRule.setSpecification( matchingRuleDescription ); 070 071 // Update the schemaName 072 updateSchemaName( matchingRule ); 073 074 return matchingRule; 075 } 076}