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.io.Reader; 024 025import org.apache.directory.api.ldap.model.schema.syntaxes.AntlrSchemaLexer; 026 027import antlr.CharBuffer; 028import antlr.LexerSharedInputState; 029 030 031/** 032 * A reusable lexer class extended from antlr generated lexer for an LDAP 033 * schema as defined in RFC 4512. This class 034 * enables the reuse of the antlr lexer without having to recreate the it every 035 * time as stated in <a 036 * href="http://www.antlr.org:8080/pipermail/antlr-interest/2003-April/003631.html"> 037 * a Antlr Interest Group mail</a> . 038 * 039 * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a> 040 */ 041public class ReusableAntlrSchemaLexer extends AntlrSchemaLexer 042{ 043 private boolean savedCaseSensitive; 044 045 private boolean savedCaseSensitiveLiterals; 046 047 048 /** 049 * Creates a ReusableAntlrSchemaLexer instance. 050 * 051 * @param in 052 * the input to the lexer 053 */ 054 public ReusableAntlrSchemaLexer( Reader in ) 055 { 056 super( in ); 057 savedCaseSensitive = getCaseSensitive(); 058 savedCaseSensitiveLiterals = getCaseSensitiveLiterals(); 059 } 060 061 062 /** 063 * Resets the state of an antlr lexer and initializes it with new input. 064 * 065 * @param in 066 * the input to the lexer 067 */ 068 public void prepareNextInput( Reader in ) 069 { 070 CharBuffer buf = new CharBuffer( in ); 071 LexerSharedInputState state = new LexerSharedInputState( buf ); 072 this.setInputState( state ); 073 074 this.setCaseSensitive( savedCaseSensitive ); 075 076 // no set method for this protected field. 077 this.caseSensitiveLiterals = savedCaseSensitiveLiterals; 078 } 079}