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 *    https://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.DitStructureRule;
027
028
029/**
030 * A parser for RFC 4512 DIT structure rule descriptions.
031 * 
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 */
034public class DitStructureRuleDescriptionSchemaParser extends AbstractSchemaParser<DitStructureRule>
035{
036
037    /**
038     * Creates a schema parser instance.
039     */
040    public DitStructureRuleDescriptionSchemaParser()
041    {
042        super( DitStructureRule.class, I18n.ERR_13836_CANNOT_PARSE_NULL_DSR, I18n.ERR_13837_DSR_PARSING_FAILURE, 
043            I18n.ERR_13838_DSR_DESC_PARSING_FAILURE );
044    }
045
046
047    /**
048     * Parses a DIT structure rule description according to RFC 4512:
049     * 
050     * <pre>
051     * DITStructureRuleDescription = LPAREN WSP
052     *   ruleid                     ; rule identifier
053     *   [ SP "NAME" SP qdescrs ]   ; short names (descriptors)
054     *   [ SP "DESC" SP qdstring ]  ; description
055     *   [ SP "OBSOLETE" ]          ; not active
056     *   SP "FORM" SP oid           ; NameForm
057     *   [ SP "SUP" ruleids ]       ; superior rules
058     *   extensions WSP RPAREN      ; extensions
059     *
060     * ruleids = ruleid / ( LPAREN WSP ruleidlist WSP RPAREN )
061     * ruleidlist = ruleid *( SP ruleid )
062     * ruleid = numbers
063     * </pre>
064     * 
065     * @param ditStructureRuleDescription the DIT structure rule description to be parsed
066     * @return the parsed DITStructureRuleDescription bean
067     * @throws ParseException if there are any recognition errors (bad syntax)
068     */
069    public DitStructureRule parse( String ditStructureRuleDescription ) throws ParseException
070    {
071        DitStructureRule ditStructureRule = fastParser.parseDitStructureRule( ditStructureRuleDescription );
072        ditStructureRule.setSpecification( ditStructureRuleDescription );
073
074        // Update the schemaName
075        updateSchemaName( ditStructureRule );
076
077        return ditStructureRule;
078    }
079}