You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/09/03 00:09:49 UTC
svn commit: r267332 -
/directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/
Author: elecharny
Date: Fri Sep 2 15:09:42 2005
New Revision: 267332
URL: http://svn.apache.org/viewcvs?rev=267332&view=rev
Log:
Updated the branch to reflect the modifications in the trunk
Added:
directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationLexer.java
directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationParser.java
directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java
Modified:
directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java
directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java
directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java
Modified: directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java?rev=267332&r1=267331&r2=267332&view=diff
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java (original)
+++ directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java Fri Sep 2 15:09:42 2005
@@ -17,10 +17,12 @@
package org.apache.ldap.common.subtree;
+import org.apache.ldap.common.name.LdapName;
import org.apache.ldap.common.filter.ExprNode;
import java.util.Set;
import java.util.Collections;
+import javax.naming.Name;
/**
@@ -35,7 +37,7 @@
private final static String EMPTY = "";
/** the subtree base relative to the administration point */
- private final String base;
+ private final Name base;
/** the set of subordinates entries and their subordinates to exclude */
private final Set chopBefore;
@@ -65,7 +67,7 @@
*/
public BaseSubtreeSpecification()
{
- this.base = "";
+ this.base = new LdapName();
this.minBaseDistance = 0;
@@ -89,7 +91,7 @@
*/
public BaseSubtreeSpecification( ExprNode refinement )
{
- this.base = EMPTY;
+ this.base = new LdapName();
this.minBaseDistance = 0;
@@ -110,7 +112,7 @@
*
* @param base the base of the subtree relative to the administrative point
*/
- public BaseSubtreeSpecification( String base )
+ public BaseSubtreeSpecification( Name base )
{
this.base = base;
@@ -136,7 +138,7 @@
* @param chopAfter the set of subordinates entries whose subordinates are to be excluded
* @param chopBefore the set of subordinates entries and their subordinates to exclude
*/
- public BaseSubtreeSpecification( String base, int minBaseDistance, int maxBaseDistance,
+ public BaseSubtreeSpecification( Name base, int minBaseDistance, int maxBaseDistance,
Set chopAfter, Set chopBefore )
{
this( base, minBaseDistance, maxBaseDistance, chopAfter, chopBefore, null );
@@ -156,7 +158,7 @@
* @param refinement the filter expression only composed of objectClass attribute
* value assertions
*/
- public BaseSubtreeSpecification( String base, int minBaseDistance, int maxBaseDistance,
+ public BaseSubtreeSpecification( Name base, int minBaseDistance, int maxBaseDistance,
Set chopAfter, Set chopBefore, ExprNode refinement )
{
this.base = base;
@@ -185,7 +187,7 @@
// -----------------------------------------------------------------------
- public String getBase()
+ public Name getBase()
{
return this.base;
}
Added: directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationLexer.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationLexer.java?rev=267332&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationLexer.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationLexer.java Fri Sep 2 15:09:42 2005
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+package org.apache.ldap.common.subtree;
+
+
+import java.io.Reader;
+
+import antlr.CharBuffer;
+import antlr.LexerSharedInputState;
+
+
+/**
+ * A reusable lexer class extended from antlr generated lexer for an LDAP
+ * subtree specification as defined by <a href="http://www.faqs.org/rfcs/rfc3672.html">
+ * RFC 3672</a>. This class enables the reuse of the antlr lexer without having to
+ * recreate the it every time as stated in
+ * <a href="http://www.antlr.org:8080/pipermail/antlr-interest/2003-April/003631.html">
+ * a Antlr Interest Group mail</a> .
+ *
+ * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ReusableAntlrSubtreeSpecificationLexer extends AntlrSubtreeSpecificationLexer
+{
+ private boolean savedCaseSensitive;
+ private boolean savedCaseSensitiveLiterals;
+
+ /**
+ * Creates a ReusableAntlrSubtreeSpecificationLexer instance.
+ *
+ * @param in the input to the lexer
+ */
+ public ReusableAntlrSubtreeSpecificationLexer( Reader in )
+ {
+ super( in );
+ savedCaseSensitive = getCaseSensitive();
+ savedCaseSensitiveLiterals = getCaseSensitiveLiterals();
+ }
+
+
+ /**
+ * Resets the state of an antlr lexer and initializes it with new input.
+ *
+ * @param in the input to the lexer
+ */
+ public void prepareNextInput( Reader in )
+ {
+ CharBuffer buf = new CharBuffer( in );
+ LexerSharedInputState state = new LexerSharedInputState( buf );
+ this.setInputState(state);
+
+ this.setCaseSensitive(savedCaseSensitive);
+
+ // no set method for this protected field.
+ this.caseSensitiveLiterals = savedCaseSensitiveLiterals;
+ }
+}
Added: directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationParser.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationParser.java?rev=267332&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationParser.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationParser.java Fri Sep 2 15:09:42 2005
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+package org.apache.ldap.common.subtree;
+
+
+import antlr.TokenStream;
+
+
+/**
+ * A reusable parser class extended from antlr generated parser for an LDAP
+ * subtree specification as defined by <a href="http://www.faqs.org/rfcs/rfc3672.html">
+ * RFC 3672</a>. This class enables the reuse of the antlr parser without having to
+ * recreate the it every time as stated in
+ * <a href="http://www.antlr.org:8080/pipermail/antlr-interest/2003-April/003631.html">
+ * a Antlr Interest Group mail</a> .
+ *
+ * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+class ReusableAntlrSubtreeSpecificationParser extends AntlrSubtreeSpecificationParser
+{
+ /**
+ * Creates a ReusableAntlrSubtreeSpecificationParser instance.
+ */
+ public ReusableAntlrSubtreeSpecificationParser( TokenStream lexer )
+ {
+ super( lexer );
+ }
+
+
+ /**
+ * Resets the state of an antlr parser.
+ */
+ public void resetState()
+ {
+ // no set method for this protected field.
+ this.traceDepth = 0;
+
+ this.getInputState().reset();
+ }
+}
Modified: directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java?rev=267332&r1=267331&r2=267332&view=diff
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java (original)
+++ directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java Fri Sep 2 15:09:42 2005
@@ -20,6 +20,7 @@
import org.apache.ldap.common.filter.ExprNode;
import java.util.Set;
+import javax.naming.Name;
/**
@@ -42,10 +43,11 @@
* a subentry immediately subordinate to dc=apache,dc=org would be relative to
* the dc=apache,dc=org context.
*
- * @return the RDN representing the base of the subtree, or the empty string
- * name if the base is the administrative point
+ * @return the RDN representing the base of the subtree, or the empty name
+ * if the base is the administrative point - note that this Name is not
+ * Normalized according to matchingRules.
*/
- String getBase();
+ Name getBase();
/**
* A set of RDNs relative to the base entry representing chopBefore
@@ -53,7 +55,8 @@
* chopBefore form is used then the specified entry and its subordinates
* are excluded from the subtree or subtree refinement."
*
- * @return a set of relative names to the subtree base or the empty set
+ * @return a set of relative {@link javax.naming.Name}s to the subtree
+ * base or the empty set
*/
Set getChopBeforeExclusions();
@@ -63,7 +66,8 @@
* chopAfter form is used then only the subordinates of the specified
* entry are excluded from the subtree or subtree refinement."
*
- * @return a set of relative names to the subtree base or the empty set
+ * @return a set of relative {@link javax.naming.Name}s to the subtree
+ * base or the empty set
*/
Set getChopAfterExclusions();
Modified: directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java?rev=267332&r1=267331&r2=267332&view=diff
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java (original)
+++ directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java Fri Sep 2 15:09:42 2005
@@ -17,10 +17,12 @@
package org.apache.ldap.common.subtree;
+import org.apache.ldap.common.name.LdapName;
import org.apache.ldap.common.filter.ExprNode;
import java.util.Set;
import java.util.Collections;
+import javax.naming.Name;
/**
@@ -36,7 +38,7 @@
private final static String EMPTY = "";
/** the subtree base relative to the administration point */
- private String base = EMPTY;
+ private Name base = new LdapName();
/** the set of subordinates entries and their subordinates to exclude */
private Set chopBefore = Collections.EMPTY_SET;
@@ -84,7 +86,7 @@
*
* @param base subtree base relative to the administration point
*/
- public void setBase( String base )
+ public void setBase( Name base )
{
this.base = base;
}
Added: directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java?rev=267332&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java Fri Sep 2 15:09:42 2005
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.ldap.common.subtree;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.text.ParseException;
+
+import org.apache.ldap.common.name.NameComponentNormalizer;
+
+import antlr.RecognitionException;
+import antlr.TokenStreamException;
+
+
+/**
+ * A reusable wrapper around the antlr generated parser for an LDAP subtree
+ * specification as defined by <a href="http://www.faqs.org/rfcs/rfc3672.html">
+ * RFC 3672</a>. This class enables the reuse of the antlr parser/lexer pair
+ * without having to recreate the pair every time.
+ *
+ * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SubtreeSpecificationParser
+{
+ /** the antlr generated parser being wrapped */
+ private ReusableAntlrSubtreeSpecificationParser parser;
+ /** the antlr generated lexer being wrapped */
+ private ReusableAntlrSubtreeSpecificationLexer lexer;
+
+ private final boolean isNormalizing;
+
+ /**
+ * Creates a subtree specification parser.
+ */
+ public SubtreeSpecificationParser()
+ {
+ StringReader in = new StringReader(""); // place holder for the first input
+ this.lexer = new ReusableAntlrSubtreeSpecificationLexer( in );
+ this.parser = new ReusableAntlrSubtreeSpecificationParser( lexer );
+ this.parser.init(); // this method MUST be called while we cannot do
+ // constructor overloading for antlr generated parser
+ this.isNormalizing = false;
+ }
+
+ /**
+ * Creates a normalizing subtree specification parser.
+ */
+ public SubtreeSpecificationParser(NameComponentNormalizer normalizer)
+ {
+ StringReader in = new StringReader(""); // place holder for the first input
+ this.lexer = new ReusableAntlrSubtreeSpecificationLexer( in );
+ this.parser = new ReusableAntlrSubtreeSpecificationParser( lexer );
+
+ this.parser.setNormalizer( normalizer );
+ this.parser.init(); // this method MUST be called while we cannot do
+ // constructor overloading for antlr generated parser
+ this.isNormalizing = true;
+ }
+
+
+ /**
+ * Initializes the plumbing by creating a pipe and coupling the parser/lexer
+ * pair with it.
+ *
+ * param spec the specification to be parsed
+ */
+ private synchronized void reset(String spec)
+ {
+ StringReader in = new StringReader( spec + "end" ); // append end of input token
+ this.lexer.prepareNextInput(in);
+ this.parser.resetState();
+ }
+
+
+ /**
+ * Parses a subtree specification without exhausting the parser.
+ *
+ * @param spec the specification to be parsed
+ * @return the specification bean
+ * @throws ParseException if there are any recognition errors (bad syntax)
+ * @throws IOException if there is a problem with underlying streams
+ */
+ public synchronized SubtreeSpecification parse( String spec ) throws ParseException, IOException
+ {
+ SubtreeSpecification ss = null;
+
+ if ( spec == null || spec.trim().equals( "" ) )
+ {
+ return null;
+ }
+
+ reset(spec); // reset and initialize the parser / lexer pair
+
+ try
+ {
+ ss = this.parser.wrapperEntryPoint();
+ }
+ catch ( TokenStreamException e )
+ {
+ String msg = "Parser failure on subtree specification:\n\t" + spec ;
+ msg += "\nAntlr exception trace:\n" + e.getMessage();
+ throw new ParseException( msg, 0 );
+ }
+ catch ( RecognitionException e )
+ {
+ String msg = "Parser failure on subtree specification:\n\t" + spec ;
+ msg += "\nAntlr exception trace:\n" + e.getMessage();
+ throw new ParseException( msg, e.getColumn() );
+ }
+
+ return ss;
+ }
+
+ /**
+ * Tests to see if this parser is normalizing.
+ *
+ * @return true if it normalizes false otherwise
+ */
+ public boolean isNormizing()
+ {
+ return this.isNormalizing ;
+ }
+}