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 021package org.apache.directory.api.ldap.model.subtree; 022 023 024import java.io.Reader; 025 026import antlr.CharBuffer; 027import antlr.LexerSharedInputState; 028 029 030/** 031 * A reusable lexer class extended from antlr generated lexer for an LDAP 032 * subtree specification as defined by <a 033 * href="http://www.faqs.org/rfcs/rfc3672.html"> RFC 3672</a>. 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 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 041 */ 042public class ReusableAntlrSubtreeSpecificationLexer extends AntlrSubtreeSpecificationLexer 043{ 044 private boolean savedCaseSensitive; 045 046 private boolean savedCaseSensitiveLiterals; 047 048 049 /** 050 * Creates a ReusableAntlrSubtreeSpecificationLexer instance. 051 * 052 * @param in 053 * the input to the lexer 054 */ 055 public ReusableAntlrSubtreeSpecificationLexer( Reader in ) 056 { 057 super( in ); 058 savedCaseSensitive = getCaseSensitive(); 059 savedCaseSensitiveLiterals = getCaseSensitiveLiterals(); 060 } 061 062 063 /** 064 * Resets the state of an antlr lexer and initializes it with new input. 065 * 066 * @param in 067 * the input to the lexer 068 */ 069 public void prepareNextInput( Reader in ) 070 { 071 CharBuffer buf = new CharBuffer( in ); 072 LexerSharedInputState state = new LexerSharedInputState( buf ); 073 this.setInputState( state ); 074 075 this.setCaseSensitive( savedCaseSensitive ); 076 077 // no set method for this protected field. 078 this.caseSensitiveLiterals = savedCaseSensitiveLiterals; 079 } 080}