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    
026    import antlr.RecognitionException;
027    import antlr.TokenStreamException;
028    
029    
030    /**
031     * A parser for RFC 4512 DIT content rule descriptons
032     * 
033     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034     * @version $Rev$, $Date$
035     */
036    public class DITContentRuleDescriptionSchemaParser extends AbstractSchemaParser
037    {
038    
039        /**
040         * Creates a schema parser instance.
041         */
042        public DITContentRuleDescriptionSchemaParser()
043        {
044        }
045    
046    
047        /**
048         * Parses a DIT content rule description according to RFC 4512:
049         * 
050         * <pre>
051         * DITContentRuleDescription = LPAREN WSP
052         *    numericoid                 ; object identifier
053         *    [ SP "NAME" SP qdescrs ]   ; short names (descriptors)
054         *    [ SP "DESC" SP qdstring ]  ; description
055         *    [ SP "OBSOLETE" ]          ; not active
056         *    [ SP "AUX" SP oids ]       ; auxiliary object classes
057         *    [ SP "MUST" SP oids ]      ; attribute types
058         *    [ SP "MAY" SP oids ]       ; attribute types
059         *    [ SP "NOT" SP oids ]       ; attribute types
060         *    extensions WSP RPAREN      ; extensions
061         * </pre>
062         * 
063         * @param ditContentRuleDescription the DIT content rule description to be parsed
064         * @return the parsed DITContentRuleDescription bean
065         * @throws ParseException if there are any recognition errors (bad syntax)
066         */
067        public synchronized DITContentRuleDescription parseDITContentRuleDescription( String ditContentRuleDescription )
068            throws ParseException
069        {
070    
071            if ( ditContentRuleDescription == null )
072            {
073                throw new ParseException( "Null", 0 );
074            }
075    
076            reset( ditContentRuleDescription ); // reset and initialize the parser / lexer pair
077    
078            try
079            {
080                DITContentRuleDescription dcrd = parser.ditContentRuleDescription();
081                return dcrd;
082            }
083            catch ( RecognitionException re )
084            {
085                String msg = "Parser failure on DIT content rule description:\n\t" + ditContentRuleDescription;
086                msg += "\nAntlr message: " + re.getMessage();
087                msg += "\nAntlr column: " + re.getColumn();
088                throw new ParseException( msg, re.getColumn() );
089            }
090            catch ( TokenStreamException tse )
091            {
092                String msg = "Parser failure on DIT content rule description:\n\t" + ditContentRuleDescription;
093                msg += "\nAntlr message: " + tse.getMessage();
094                throw new ParseException( msg, 0 );
095            }
096    
097        }
098    
099    
100        public AbstractSchemaDescription parse( String schemaDescription ) throws ParseException
101        {
102            return parseDITContentRuleDescription( schemaDescription );
103        }
104    
105    }