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