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.io.StringReader;
024 import java.text.ParseException;
025
026
027
028 /**
029 *
030 * TODO AbstractSchemaParser.
031 *
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 * @version $Rev$, $Date$
034 */
035 public abstract class AbstractSchemaParser
036 {
037
038 /** the monitor to use for this parser */
039 protected ParserMonitor monitor = new ParserMonitorAdapter();
040
041 /** the antlr generated parser being wrapped */
042 protected ReusableAntlrSchemaParser parser;
043
044 /** the antlr generated lexer being wrapped */
045 protected ReusableAntlrSchemaLexer lexer;
046
047
048 protected AbstractSchemaParser()
049 {
050 lexer = new ReusableAntlrSchemaLexer( new StringReader( "" ) );
051 parser = new ReusableAntlrSchemaParser( lexer );
052 }
053
054
055 /**
056 * Initializes the plumbing by creating a pipe and coupling the parser/lexer
057 * pair with it. param spec the specification to be parsed
058 */
059 protected void reset( String spec )
060 {
061 StringReader in = new StringReader( spec );
062 lexer.prepareNextInput( in );
063 parser.resetState();
064 }
065
066
067 /**
068 * Sets the parser monitor.
069 *
070 * @param monitor the new parser monitor
071 */
072 public void setParserMonitor( ParserMonitor monitor )
073 {
074 this.monitor = monitor;
075 parser.setParserMonitor( monitor );
076 }
077
078
079 /**
080 * Sets the quirks mode.
081 *
082 * If enabled the parser accepts non-numeric OIDs and some
083 * special characters in descriptions.
084 *
085 * @param enabled the new quirks mode
086 */
087 public void setQuirksMode( boolean enabled )
088 {
089 parser.setQuirksMode( enabled );
090 }
091
092
093 /**
094 * Checks if quirks mode is enabled.
095 *
096 * @return true, if is quirks mode is enabled
097 */
098 public boolean isQuirksMode()
099 {
100 return parser.isQuirksMode();
101 }
102
103
104 public abstract AbstractSchemaDescription parse( String schemaDescription ) throws ParseException;
105
106 }