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    
021    package org.apache.directory.shared.ldap.subtree;
022    
023    
024    import java.io.Reader;
025    
026    import org.apache.directory.shared.ldap.subtree.AntlrSubtreeSpecificationCheckerLexer;
027    
028    import antlr.CharBuffer;
029    import 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     * @version $Rev: 437007 $
044     */
045    public class ReusableAntlrSubtreeSpecificationCheckerLexer extends AntlrSubtreeSpecificationCheckerLexer
046    {
047        private boolean savedCaseSensitive;
048    
049        private boolean savedCaseSensitiveLiterals;
050    
051    
052        /**
053         * Creates a ReusableAntlrSubtreeSpecificationLexer instance.
054         * 
055         * @param in
056         *            the input to the lexer
057         */
058        public ReusableAntlrSubtreeSpecificationCheckerLexer(Reader in)
059        {
060            super( in );
061            savedCaseSensitive = getCaseSensitive();
062            savedCaseSensitiveLiterals = getCaseSensitiveLiterals();
063        }
064    
065    
066        /**
067         * Resets the state of an antlr lexer and initializes it with new input.
068         * 
069         * @param in
070         *            the input to the lexer
071         */
072        public void prepareNextInput( Reader in )
073        {
074            CharBuffer buf = new CharBuffer( in );
075            LexerSharedInputState state = new LexerSharedInputState( buf );
076            this.setInputState( state );
077    
078            this.setCaseSensitive( savedCaseSensitive );
079    
080            // no set method for this protected field.
081            this.caseSensitiveLiterals = savedCaseSensitiveLiterals;
082        }
083    }