You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2005/05/23 23:09:47 UTC
svn commit: r178025 - in /directory/shared/ldap/trunk/common: ./ src/antlr/
src/java/org/apache/ldap/common/schema/
src/java/org/apache/ldap/common/subtree/
src/test/org/apache/ldap/common/subtree/
Author: akarasulu
Date: Mon May 23 14:09:45 2005
New Revision: 178025
URL: http://svn.apache.org/viewcvs?rev=178025&view=rev
Log:
changes ...
o antlr now generates bogus subtree-specification.g grammar (setup)
o added a simple test case class for the most basic subtree spec
o moved everything to a new subtree package rather than keeping it with filter
o added concrete base class implementation for SubtreeSpecification
o added spec class creating modifier
Added:
directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g
directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/
directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java
directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java
- copied, changed from r178013, directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/SubtreeSpecification.java
directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java
directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/
directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeParserTest.java
Removed:
directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/SubtreeSpecification.java
Modified:
directory/shared/ldap/trunk/common/maven.xml
Modified: directory/shared/ldap/trunk/common/maven.xml
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/maven.xml?rev=178025&r1=178024&r2=178025&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/maven.xml (original)
+++ directory/shared/ldap/trunk/common/maven.xml Mon May 23 14:09:45 2005
@@ -36,6 +36,10 @@
<delete file="${user.dir}/DnCommonTokenTypes.txt"/>
<delete file="${user.dir}/antlrValueTokenTypes.txt"/>
+
+ <j:set var="maven.antlr.grammars" value="subtree-specification.g"/>
+ <attainGoal name="antlr:generate" />
+
</preGoal>
<preGoal name="jar:jar">
@@ -78,3 +82,4 @@
</preGoal>
</project>
+
Added: directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g?rev=178025&view=auto
==============================================================================
--- directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g (added)
+++ directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g Mon May 23 14:09:45 2005
@@ -0,0 +1,138 @@
+header
+{
+/*
+ * Copyright 2002-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.
+ */
+
+/*
+ * Keep the semicolon right next to org.apache.ldap.common.filter or else there
+ * will be a bug that comes into the foreground in the new antlr release.
+ */
+package org.apache.ldap.common.subtree;
+}
+
+
+
+
+
+// ----------------------------------------------------------------------------
+// parser class definition
+// ----------------------------------------------------------------------------
+
+/**
+ * The antlr generated subtree specification parser.
+ *
+ * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
+ * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
+ */
+class AntlrSubtreeSpecificationParser extends Parser;
+
+
+// ----------------------------------------------------------------------------
+// parser class members
+// ----------------------------------------------------------------------------
+
+{
+ /** blah */
+ public static final String BLAH = "blah";
+}
+
+
+// ----------------------------------------------------------------------------
+// parser productions
+// ----------------------------------------------------------------------------
+
+
+subtreeSpecification returns [SubtreeSpecification spec]
+{
+ spec = null;
+}
+ : LBRACKET RBRACKET { spec = new BaseSubtreeSpecification(); } ;
+
+
+
+// ----------------------------------------------------------------------------
+// lexer class definition
+// ----------------------------------------------------------------------------
+
+/**
+ * The parser's primary lexer.
+ *
+ * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
+ * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
+ */
+class AntlrSubtreeSpecificationLexer extends Lexer;
+
+
+// ----------------------------------------------------------------------------
+// lexer options
+// ----------------------------------------------------------------------------
+
+options
+{
+ k=5;
+
+ charVocabulary='\u0001'..'\u0127';
+}
+
+
+// ----------------------------------------------------------------------------
+// lexer class members
+// ----------------------------------------------------------------------------
+
+{
+ /** the selector key used by this class of lexer */
+ public static final String SELECTOR_KEY = "refinementLexer";
+}
+
+
+// ----------------------------------------------------------------------------
+// attribute description lexer rules from models
+// ----------------------------------------------------------------------------
+
+
+SP : ( ' ' )
+ {$setType(Token.SKIP);} //ignore this token
+ ;
+
+LBRACKET: '{';
+
+RBRACKET: '}';
+
+COMMA: ',';
+
+OR: "or:";
+
+AND: "and:";
+
+NOT: "not:";
+
+ITEM: "item:";
+
+protected DIGIT: '0' | LDIGIT;
+
+protected LDIGIT: '1'..'9';
+
+protected ALPHA: 'A'..'Z' | 'a'..'z';
+
+protected NUMBER: DIGIT | ( LDIGIT ( DIGIT )+ );
+
+protected NUMERICOID: NUMBER ( '.' NUMBER )+;
+
+protected DESCR: ALPHA ( ALPHA | DIGIT | '-' )*;
+
+OID: DESCR | NUMERICOID;
+
+
Added: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java?rev=178025&view=auto
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java (added)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java Mon May 23 14:09:45 2005
@@ -0,0 +1,222 @@
+/*
+ * 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 org.apache.ldap.common.name.LdapName;
+import org.apache.ldap.common.filter.ExprNode;
+
+import javax.naming.Name;
+
+import java.util.Set;
+import java.util.Collections;
+
+
+/**
+ * A simple implementation of the SubtreeSpecification interface.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BaseSubtreeSpecification implements SubtreeSpecification
+{
+ /** the subtree base relative to the administration point */
+ private final Name base;
+
+ /** the set of subordinates entries and their subordinates to exclude */
+ private final Set chopBefore;
+
+ /** the set of subordinates entries whose subordinates are to be excluded */
+ private final Set chopAfter;
+
+ /** the minimum distance below base to start including entries */
+ private final int minBaseDistance;
+
+ /** the maximum distance from base past which entries are excluded */
+ private final int maxBaseDistance;
+
+ /** a filter using only assertions on objectClass attributes for subtree refinement */
+ private final ExprNode refinement;
+
+
+ // -----------------------------------------------------------------------
+ // C O N S T R U C T O R S
+ // -----------------------------------------------------------------------
+
+
+ /**
+ * Creates a simple subtree whose administrative point is necessarily the base
+ * and all subordinates underneath (excluding those that are part of inner areas)
+ * are part of the the subtree.
+ */
+ public BaseSubtreeSpecification()
+ {
+ this.base = new LdapName();
+
+ this.minBaseDistance = 0;
+
+ this.maxBaseDistance = UNBOUNDED_MAX;
+
+ this.chopAfter = Collections.EMPTY_SET;
+
+ this.chopBefore = Collections.EMPTY_SET;
+
+ this.refinement = null;
+ }
+
+
+ /**
+ * Creates a simple subtree refinement whose administrative point is necessarily
+ * the base and only those subordinates selected by the refinement filter are
+ * included.
+ *
+ * @param refinement the filter expression only composed of objectClass attribute
+ * value assertions
+ */
+ public BaseSubtreeSpecification( ExprNode refinement )
+ {
+ this.base = new LdapName();
+
+ this.minBaseDistance = 0;
+
+ this.maxBaseDistance = UNBOUNDED_MAX;
+
+ this.chopAfter = Collections.EMPTY_SET;
+
+ this.chopBefore = Collections.EMPTY_SET;
+
+ this.refinement = refinement;
+ }
+
+
+ /**
+ * Creates a simple subtree whose administrative point above the base and all
+ * subordinates underneath the base (excluding those that are part of inner
+ * areas) are part of the the subtree.
+ *
+ * @param base the base of the subtree relative to the administrative point
+ */
+ public BaseSubtreeSpecification( Name base )
+ {
+ this.base = base;
+
+ this.minBaseDistance = 0;
+
+ this.maxBaseDistance = UNBOUNDED_MAX;
+
+ this.chopAfter = Collections.EMPTY_SET;
+
+ this.chopBefore = Collections.EMPTY_SET;
+
+ this.refinement = null;
+ }
+
+
+ /**
+ * Creates a subtree without a refinement filter where all other aspects
+ * can be varied.
+ *
+ * @param base the base of the subtree relative to the administrative point
+ * @param minBaseDistance the minimum distance below base to start including entries
+ * @param maxBaseDistance the maximum distance from base past which entries are excluded
+ * @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( Name base, int minBaseDistance, int maxBaseDistance,
+ Set chopAfter, Set chopBefore )
+ {
+ this( base, minBaseDistance, maxBaseDistance, chopAfter, chopBefore, null );
+ }
+
+
+ /**
+ * Creates a subtree which may be a refinement filter where all aspects of the
+ * specification can be set. If the refinement filter is null this defaults to
+ * {@link BaseSubtreeSpecification#BaseSubstreeSpecification(Name, int, int, Set, Set)}.
+ *
+ * @param base the base of the subtree relative to the administrative point
+ * @param minBaseDistance the minimum distance below base to start including entries
+ * @param maxBaseDistance the maximum distance from base past which entries are excluded
+ * @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
+ * @param refinement the filter expression only composed of objectClass attribute
+ * value assertions
+ */
+ public BaseSubtreeSpecification( Name base, int minBaseDistance, int maxBaseDistance,
+ Set chopAfter, Set chopBefore, ExprNode refinement )
+ {
+ this.base = base;
+
+ this.minBaseDistance = minBaseDistance;
+
+ if ( maxBaseDistance < 0 )
+ {
+ this.maxBaseDistance = UNBOUNDED_MAX;
+ }
+ else
+ {
+ this.maxBaseDistance = maxBaseDistance;
+ }
+
+ this.chopAfter = chopAfter;
+
+ this.chopBefore = chopBefore;
+
+ this.refinement = refinement;
+ }
+
+
+ // -----------------------------------------------------------------------
+ // A C C E S S O R S
+ // -----------------------------------------------------------------------
+
+
+ public Name getBase()
+ {
+ return this.base;
+ }
+
+
+ public Set getChopBeforeExclusions()
+ {
+ return this.chopBefore;
+ }
+
+
+ public Set getChopAfterExclusions()
+ {
+ return this.chopAfter;
+ }
+
+
+ public int getMinBaseDistance()
+ {
+ return this.minBaseDistance;
+ }
+
+
+ public int getMaxBaseDistance()
+ {
+ return this.maxBaseDistance;
+ }
+
+
+ public ExprNode getRefinement()
+ {
+ return this.refinement;
+ }
+}
Copied: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java (from r178013, directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/SubtreeSpecification.java)
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java?p2=directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java&p1=directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/SubtreeSpecification.java&r1=178013&r2=178025&rev=178025&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/SubtreeSpecification.java (original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java Mon May 23 14:09:45 2005
@@ -14,7 +14,7 @@
* limitations under the License.
*
*/
-package org.apache.ldap.common.schema;
+package org.apache.ldap.common.subtree;
import org.apache.ldap.common.filter.ExprNode;
Added: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java?rev=178025&view=auto
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java (added)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java Mon May 23 14:09:45 2005
@@ -0,0 +1,158 @@
+/*
+ * 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 org.apache.ldap.common.filter.ExprNode;
+import org.apache.ldap.common.name.LdapName;
+
+import javax.naming.Name;
+
+import java.util.Set;
+import java.util.Collections;
+
+
+/**
+ * SubtreeSpecification contains no setters so they must be built by a modifiable
+ * object containing all the necessary parameters to build the base object.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SubtreeSpecificationModifier
+{
+ /** the subtree base relative to the administration point */
+ private Name base = new LdapName();
+
+ /** the set of subordinates entries and their subordinates to exclude */
+ private Set chopBefore = Collections.EMPTY_SET;
+
+ /** the set of subordinates entries whose subordinates are to be excluded */
+ private Set chopAfter = Collections.EMPTY_SET;
+
+ /** the minimum distance below base to start including entries */
+ private int minBaseDistance = 0;
+
+ /** the maximum distance from base past which entries are excluded */
+ private int maxBaseDistance = SubtreeSpecification.UNBOUNDED_MAX;
+
+ /** a filter using only assertions on objectClass attributes for subtree refinement */
+ private ExprNode refinement = null;
+
+
+ // -----------------------------------------------------------------------
+ // F A C T O R Y M E T H O D
+ // -----------------------------------------------------------------------
+
+
+ /**
+ * Creates a SubtreeSpecification using any of the default paramters that may
+ * have been modified from their defaults.
+ *
+ * @return the newly created subtree specification
+ */
+ public SubtreeSpecification getSubtreeSpecification()
+ {
+
+ return new BaseSubtreeSpecification( this.base, this.minBaseDistance,
+ this.maxBaseDistance, this.chopAfter,
+ this.chopBefore, this.refinement );
+ }
+
+
+ // -----------------------------------------------------------------------
+ // M U T A T O R S
+ // -----------------------------------------------------------------------
+
+
+ /**
+ * Sets the subtree base relative to the administration point.
+ *
+ * @param base subtree base relative to the administration point
+ */
+ public void setBase( Name base )
+ {
+ this.base = base;
+ }
+
+
+ /**
+ * Sets the set of subordinates entries and their subordinates to exclude.
+ *
+ * @param chopBefore the set of subordinates entries and their subordinates to exclude
+ */
+ public void setChopBeforeExclusions( Set chopBefore )
+ {
+ this.chopBefore = chopBefore;
+ }
+
+
+ /**
+ * Sets the set of subordinates entries whose subordinates are to be excluded.
+ *
+ * @param chopAfter the set of subordinates entries whose subordinates are to be excluded
+ */
+ public void setChopAfterExclusions( Set chopAfter )
+ {
+ this.chopAfter = chopAfter;
+ }
+
+
+ /**
+ * Sets the minimum distance below base to start including entries.
+ *
+ * @param minBaseDistance the minimum distance below base to start including entries
+ */
+ public void setMinBaseDistance( int minBaseDistance )
+ {
+ if ( minBaseDistance < 0 )
+ {
+ throw new IllegalArgumentException( "A negative minimum base distance is undefined!" );
+ }
+
+ this.minBaseDistance = minBaseDistance;
+ }
+
+
+ /**
+ * Sets the maximum distance from base past which entries are excluded.
+ *
+ * @param maxBaseDistance the maximum distance from base past which entries are excluded
+ */
+ public void setMaxBaseDistance( int maxBaseDistance )
+ {
+ if ( maxBaseDistance < 0 )
+ {
+ this.maxBaseDistance = SubtreeSpecification.UNBOUNDED_MAX;
+ }
+ else
+ {
+ this.maxBaseDistance = maxBaseDistance;
+ }
+ }
+
+
+ /**
+ * Sets a filter using only assertions on objectClass attributes for subtree refinement.
+ *
+ * @param refinement a filter using only assertions on objectClass attributes for subtree refinement
+ */
+ public void setRefinement( ExprNode refinement )
+ {
+ this.refinement = refinement;
+ }
+}
Added: directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeParserTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeParserTest.java?rev=178025&view=auto
==============================================================================
--- directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeParserTest.java (added)
+++ directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeParserTest.java Mon May 23 14:09:45 2005
@@ -0,0 +1,52 @@
+/*
+ * 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 junit.framework.TestCase;
+
+import java.io.StringReader;
+
+import antlr.TokenStreamException;
+import antlr.RecognitionException;
+
+
+/**
+ * Document this class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SubtreeParserTest extends TestCase
+{
+ /** A valid empty specification test case */
+ private static final String EMPTY_SPEC = "{ }";
+
+
+ public void testEmptySpecTest() throws TokenStreamException, RecognitionException
+ {
+ StringReader in = new StringReader( EMPTY_SPEC );
+
+ AntlrSubtreeSpecificationLexer lexer = new AntlrSubtreeSpecificationLexer( in );
+
+ AntlrSubtreeSpecificationParser parser = new AntlrSubtreeSpecificationParser( lexer );
+
+ SubtreeSpecification spec = parser.subtreeSpecification();
+
+ assertNotNull( spec );
+ }
+}