| 1 |
/*
|
| 2 |
* Copyright 2004 The Apache Software Foundation
|
| 3 |
*
|
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
* you may not use this file except in compliance with the License.
|
| 6 |
* You may obtain a copy of the License at
|
| 7 |
*
|
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
*
|
| 10 |
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
* See the License for the specific language governing permissions and
|
| 14 |
* limitations under the License.
|
| 15 |
*
|
| 16 |
*/
|
| 17 |
|
| 18 |
|
| 19 |
package org.apache.ldap.common.subtree;
|
| 20 |
|
| 21 |
|
| 22 |
import java.io.Reader;
|
| 23 |
|
| 24 |
import antlr.CharBuffer;
|
| 25 |
import antlr.LexerSharedInputState;
|
| 26 |
|
| 27 |
|
| 28 |
/**
|
| 29 |
* A reusable lexer class extended from antlr generated lexer for an LDAP
|
| 30 |
* subtree specification as defined by <a href="http://www.faqs.org/rfcs/rfc3672.html">
|
| 31 |
* RFC 3672</a>. This class enables the reuse of the antlr lexer without having to
|
| 32 |
* recreate the it every time as stated in
|
| 33 |
* <a href="http://www.antlr.org:8080/pipermail/antlr-interest/2003-April/003631.html">
|
| 34 |
* a Antlr Interest Group mail</a> .
|
| 35 |
*
|
| 36 |
* @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
|
| 37 |
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
|
| 38 |
* @version $Rev$
|
| 39 |
*/
|
| 40 |
public class ReusableAntlrSubtreeSpecificationLexer extends AntlrSubtreeSpecificationLexer
|
| 41 |
{
|
| 42 |
private boolean savedCaseSensitive;
|
| 43 |
private boolean savedCaseSensitiveLiterals;
|
| 44 |
|
| 45 |
/**
|
| 46 |
* Creates a ReusableAntlrSubtreeSpecificationLexer instance.
|
| 47 |
*
|
| 48 |
* @param in the input to the lexer
|
| 49 |
*/
|
| 50 |
public ReusableAntlrSubtreeSpecificationLexer( Reader in )
|
| 51 |
{
|
| 52 |
super( in );
|
| 53 |
savedCaseSensitive = getCaseSensitive();
|
| 54 |
savedCaseSensitiveLiterals = getCaseSensitiveLiterals();
|
| 55 |
}
|
| 56 |
|
| 57 |
|
| 58 |
/**
|
| 59 |
* Resets the state of an antlr lexer and initializes it with new input.
|
| 60 |
*
|
| 61 |
* @param in the input to the lexer
|
| 62 |
*/
|
| 63 |
public void prepareNextInput( Reader in )
|
| 64 |
{
|
| 65 |
CharBuffer buf = new CharBuffer( in );
|
| 66 |
LexerSharedInputState state = new LexerSharedInputState( buf );
|
| 67 |
this.setInputState(state);
|
| 68 |
|
| 69 |
this.setCaseSensitive(savedCaseSensitive);
|
| 70 |
|
| 71 |
// no set method for this protected field.
|
| 72 |
this.caseSensitiveLiterals = savedCaseSensitiveLiterals;
|
| 73 |
}
|
| 74 |
}
|