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 2010/07/15 12:04:08 UTC
svn commit: r964361 [5/5] - in /directory/shared/trunk:
ldap-schema-manager-tests/
ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/aci/
ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/syntaxCheck...
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/SubtreeSpecificationSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/SubtreeSpecificationSyntaxChecker.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/SubtreeSpecificationSyntaxChecker.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/SubtreeSpecificationSyntaxChecker.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.schema.syntaxCheckers;
+
+import java.text.ParseException;
+
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.SyntaxChecker;
+import org.apache.directory.shared.ldap.subtree.SubtreeSpecificationChecker;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a subtree specification.
+ *
+ * It has been removed in RFC 4517
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SubtreeSpecificationSyntaxChecker extends SyntaxChecker
+{
+ /** A logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( SubtreeSpecificationSyntaxChecker.class );
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /** The associated checker */
+ private static SubtreeSpecificationChecker SUBTREE_SPECIFICATION_CHECKER;
+
+ /**
+ * Creates an instance of SubtreeSpecificationSyntaxChecker
+ */
+ public SubtreeSpecificationSyntaxChecker()
+ {
+ super( SchemaConstants.SUBTREE_SPECIFICATION_SYNTAX );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isValidSyntax( Object value )
+ {
+ String strValue = null;
+
+ if ( value == null )
+ {
+ LOG.debug( "Syntax invalid for 'null'" );
+ return false;
+ }
+
+ if ( value instanceof String )
+ {
+ strValue = ( String ) value;
+ }
+ else if ( value instanceof byte[] )
+ {
+ strValue = StringTools.utf8ToString( ( byte[] ) value );
+ }
+ else
+ {
+ strValue = value.toString();
+ }
+
+ if ( strValue.length() == 0 )
+ {
+ LOG.debug( "Syntax invalid for '{}'", value );
+ return false;
+ }
+
+ try
+ {
+ synchronized( SUBTREE_SPECIFICATION_CHECKER )
+ {
+ SUBTREE_SPECIFICATION_CHECKER.parse( strValue );
+ }
+
+ LOG.debug( "Syntax valid for '{}'", value );
+ return true;
+ }
+ catch ( ParseException pe )
+ {
+ LOG.debug( "Syntax invalid for '{}'", value );
+ return false;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setSchemaManager( SchemaManager schemaManager )
+ {
+ SUBTREE_SPECIFICATION_CHECKER = new SubtreeSpecificationChecker( schemaManager );
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/AndRefinement.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/AndRefinement.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/AndRefinement.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/AndRefinement.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.subtree;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A class holding a AND refinement, as defined in RFC 3672
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AndRefinement implements Refinement
+{
+ /** The set of refinements */
+ private List<Refinement> refinements = new ArrayList<Refinement>();
+
+ /**
+ * Creates a new instance of AndRefinement.
+ *
+ * @param refinements The refinements. We may have more than one
+ */
+ public AndRefinement( List<Refinement> refinements )
+ {
+ this.refinements = refinements;
+ }
+
+
+ /**
+ * @return Gets the set of refinements
+ */
+ public List<Refinement> getRefinements()
+ {
+ return refinements;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "and: { " );
+
+ boolean isFirst = true;
+
+ for ( Refinement refinement:refinements )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ", " );
+ }
+
+ sb.append( refinement );
+ }
+
+ sb.append( " }" );
+ return sb.toString();
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/BaseSubtreeSpecification.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/BaseSubtreeSpecification.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/BaseSubtreeSpecification.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/BaseSubtreeSpecification.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,372 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.subtree;
+
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.name.DN;
+
+
+/**
+ * A simple implementation of the SubtreeSpecification interface.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class BaseSubtreeSpecification implements SubtreeSpecification
+{
+ /** the subtree base relative to the administration point */
+ private final DN base;
+
+ /** the set of subordinates entries and their subordinates to exclude */
+ private final Set<DN> chopBefore;
+
+ /** the set of subordinates entries whose subordinates are to be excluded */
+ private final Set<DN> 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.
+ */
+ @SuppressWarnings("unchecked")
+ public BaseSubtreeSpecification()
+ {
+ this.base = new DN();
+ 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
+ */
+ @SuppressWarnings("unchecked")
+ public BaseSubtreeSpecification( ExprNode refinement )
+ {
+ this.base = new DN();
+ 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
+ */
+ @SuppressWarnings("unchecked")
+ public BaseSubtreeSpecification( DN 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( DN base, int minBaseDistance, int maxBaseDistance,
+ Set<DN> chopAfter, Set<DN> 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(DN, 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( DN base, int minBaseDistance, int maxBaseDistance,
+ Set<DN> chopAfter, Set<DN> 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
+ // -----------------------------------------------------------------------
+ /**
+ * @return The base
+ */
+ public DN getBase()
+ {
+ return this.base;
+ }
+
+ /**
+ * @return The set of ChopBefore exclusions
+ */
+ public Set<DN> getChopBeforeExclusions()
+ {
+ return this.chopBefore;
+ }
+
+
+ /**
+ * @return The set of ChopAfter exclusions
+ */
+ public Set<DN> getChopAfterExclusions()
+ {
+ return this.chopAfter;
+ }
+
+
+ /**
+ * @return The mimimum distance from the base
+ */
+ public int getMinBaseDistance()
+ {
+ return this.minBaseDistance;
+ }
+
+
+ /**
+ * @return The maximum distance from the base
+ */
+ public int getMaxBaseDistance()
+ {
+ return this.maxBaseDistance;
+ }
+
+
+ /**
+ * @return The refinement
+ */
+ public ExprNode getRefinement()
+ {
+ return this.refinement;
+ }
+
+
+ /**
+ * Converts this item into its string representation as stored
+ * in directory.
+ *
+ * @param buffer the string buffer
+ */
+ public void toString( StringBuilder buffer )
+ {
+ buffer.append( toString() );
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ boolean isFirst = true;
+ buffer.append( '{' );
+
+ // The base
+ if ( !base.isEmpty() )
+ {
+ buffer.append( " base \"" );
+ buffer.append( base.getName() );
+ buffer.append( '"' );
+ isFirst = false;
+ }
+
+ // The minimum
+ if ( minBaseDistance > 0 )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ buffer.append( " " );
+ }
+ else
+ {
+ buffer.append( ", " );
+ }
+
+ buffer.append( "minimum " );
+ buffer.append( minBaseDistance );
+ }
+
+ // The maximum
+ if ( maxBaseDistance > UNBOUNDED_MAX )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ buffer.append( " " );
+ }
+ else
+ {
+ buffer.append( ", " );
+ }
+
+ buffer.append( "maximum " );
+ buffer.append( maxBaseDistance );
+ }
+
+ // The chopBefore exclusions
+ if ( !chopBefore.isEmpty() || !chopAfter.isEmpty() )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ buffer.append( " " );
+ }
+ else
+ {
+ buffer.append( ", " );
+ }
+
+ buffer.append( "specificExclusions { " );
+
+ boolean isFirstExclusion = true;
+
+ if ( chopBefore != null )
+ {
+ for ( DN exclusion : chopBefore )
+ {
+ if ( isFirstExclusion )
+ {
+ isFirstExclusion = false;
+ }
+ else
+ {
+ buffer.append( ", " );
+ }
+
+ buffer.append( "chopBefore: \"" );
+ buffer.append( exclusion.getName() );
+ buffer.append( '"' );
+ }
+ }
+
+ if ( chopAfter != null )
+ {
+ for ( DN exclusion : chopAfter )
+ {
+ if ( isFirstExclusion )
+ {
+ isFirstExclusion = false;
+ }
+ else
+ {
+ buffer.append( ", " );
+ }
+
+ buffer.append( "chopAfter: \"" );
+ buffer.append( exclusion.getName() );
+ buffer.append( '"' );
+ }
+ }
+
+ buffer.append( " }" );
+ }
+
+ if ( refinement != null )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ buffer.append( " " );
+ }
+ else
+ {
+ buffer.append( ", " );
+ }
+
+ buffer.append( "specificationFilter " );
+ buffer.append( refinement.toString() );
+ }
+
+ buffer.append( " }" );
+
+ return buffer.toString();
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ItemRefinement.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ItemRefinement.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ItemRefinement.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ItemRefinement.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.subtree;
+
+import org.apache.directory.shared.ldap.schema.ObjectClass;
+
+/**
+ * A class holding a n ITEM refinement, as defined in RFC 3672
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ItemRefinement implements Refinement
+{
+ /** The item */
+ private ObjectClass item;
+
+
+ /**
+ * Creates a new instance of ItemRefinement.
+ *
+ * @param item The ObjectClass associated with this refinement
+ */
+ public ItemRefinement( ObjectClass item )
+ {
+ this.item = item;
+ }
+
+
+ /**
+ * @return the item
+ */
+ public ObjectClass getItem()
+ {
+ return item;
+ }
+
+
+ /**
+ * @param item the item to set
+ */
+ public void setItem( ObjectClass item )
+ {
+ this.item = item;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "item : " );
+ sb.append( item.getName() );
+
+ return sb.toString();
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/NotRefinement.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/NotRefinement.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/NotRefinement.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/NotRefinement.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.subtree;
+
+
+/**
+ * A class holding a NOT refinement, as defined in RFC 3672
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NotRefinement implements Refinement
+{
+ /** The refinement */
+ private Refinement refinement;
+
+ public NotRefinement( Refinement refinement )
+ {
+ this.refinement = refinement;
+ }
+
+
+ /**
+ * @return the refinement
+ */
+ public Refinement getRefinement()
+ {
+ return refinement;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "not: " );
+ sb.append( refinement );
+
+ return sb.toString();
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/OrRefinement.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/OrRefinement.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/OrRefinement.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/OrRefinement.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.subtree;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * A class holding a OR refinement, as defined in RFC 3672
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class OrRefinement implements Refinement
+{
+ /** The set of refinements */
+ private List<Refinement> refinements = new ArrayList<Refinement>();
+
+
+ /**
+ * Creates a new instance of OrRefinement.
+ *
+ * @param refinements The refinements. We may have more than one
+ */
+ public OrRefinement( List<Refinement> refinements )
+ {
+ this.refinements = refinements;
+ }
+
+
+ /**
+ * @return Gets the set of refinements
+ */
+ public List<Refinement> getRefinements()
+ {
+ return refinements;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "or: { " );
+
+ boolean isFirst = true;
+
+ for ( Refinement refinement:refinements )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ", " );
+ }
+
+ sb.append( refinement );
+ }
+
+ sb.append( " }" );
+ return sb.toString();
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/Refinement.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/Refinement.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/Refinement.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/Refinement.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.subtree;
+
+/**
+ * An empty interface used for Refinements.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface Refinement
+{
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationChecker.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationChecker.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationChecker.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.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>
+ */
+class ReusableAntlrSubtreeSpecificationChecker extends AntlrSubtreeSpecificationChecker
+{
+ /**
+ * Creates a ReusableAntlrSubtreeSpecificationParser instance.
+ */
+ public ReusableAntlrSubtreeSpecificationChecker(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();
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationCheckerLexer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationCheckerLexer.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationCheckerLexer.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationCheckerLexer.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.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>
+ */
+public class ReusableAntlrSubtreeSpecificationCheckerLexer extends AntlrSubtreeSpecificationCheckerLexer
+{
+ private boolean savedCaseSensitive;
+
+ private boolean savedCaseSensitiveLiterals;
+
+
+ /**
+ * Creates a ReusableAntlrSubtreeSpecificationLexer instance.
+ *
+ * @param in
+ * the input to the lexer
+ */
+ public ReusableAntlrSubtreeSpecificationCheckerLexer(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/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationLexer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationLexer.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationLexer.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationLexer.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.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>
+ */
+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/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationParser.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationParser.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/ReusableAntlrSubtreeSpecificationParser.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.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>
+ */
+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();
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecification.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecification.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecification.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecification.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.subtree;
+
+
+import java.util.Set;
+
+import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.name.DN;
+
+
+/**
+ * <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a> defined a
+ * subtree specification to be included within subentries.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface SubtreeSpecification
+{
+ /** an unbounded maximum depth value in a subtree specification */
+ int UNBOUNDED_MAX = -1;
+
+
+ /**
+ * Gets an RDN relative to the administrative context where the subtree
+ * scope begins. All subentries containing these specifications are
+ * immediate subordinates to the administrative point, and are considered to
+ * be part of the same naming context. Hence the base for the subtree
+ * specification of 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 name
+ * if the base is the administrative point - note that this Name is
+ * not Normalized according to matchingRules.
+ */
+ DN getBase();
+
+
+ /**
+ * A set of RDNs relative to the base entry representing chopBefore
+ * specificExclusions from the subtree. According to RFC 3672: "If the
+ * chopBefore form is used then the specified entry and its subordinates are
+ * excluded from the subtree or subtree refinement."
+ *
+ * @return a set of relative {@link javax.naming.Name}s to the subtree base
+ * or the empty set
+ */
+ Set<DN> getChopBeforeExclusions();
+
+
+ /**
+ * A set of RDNs relative to the base entry representing chopAfter
+ * specificExclusions from the subtree. According to RFC 3672: "If the
+ * 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 {@link javax.naming.Name}s to the subtree base
+ * or the empty set
+ */
+ Set<DN> getChopAfterExclusions();
+
+
+ /**
+ * Gets the distance at which to start including entries in the subtree. All
+ * entries whose RDN arcs relative to the base are less than the minimum are
+ * excluded from the subtree or subtree refinement. The default is zero and
+ * therefore excludes nothing.
+ *
+ * @return the minimum number of RDN arcs relative to base for inclusion
+ */
+ int getMinBaseDistance();
+
+
+ /**
+ * Gets the distance after which to start excluding entries in the subtree
+ * or subtree refinement. RFC 3672 Section 2.1.3 states: "Entries that are
+ * more than the maximum number of RDN arcs below the base entry are
+ * excluded from the subtree or subtree refinement. An absent maximum
+ * component indicates that there is no upper limit on the number of RDN
+ * arcs below the base entry for entries in the subtree or subtree
+ * refinement." If the maximum is limitless a negative value should be used
+ * to represent the maximum distance - which makes no sense other than to
+ * denote the lack of an upper limit.
+ *
+ * @see #UNBOUNDED_MAX
+ * @return the number of arcs relative to the base after which entries are
+ * excluded
+ */
+ int getMaxBaseDistance();
+
+
+ /**
+ * A subtree refinement represents a non-contiguous selection of entries
+ * using a limited filter expression where attribute assertions are based on
+ * the objectClass of the entries.
+ *
+ * @return a refinement tree or null if one does not exist for this subtree
+ * specification
+ */
+ ExprNode getRefinement();
+
+
+ /**
+ * Converts this item into its string representation as stored
+ * in directory.
+ *
+ * @param buffer the string buffer
+ */
+ void toString( StringBuilder buffer );
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationChecker.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationChecker.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationChecker.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.subtree;
+
+
+import java.io.StringReader;
+import java.text.ParseException;
+
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+
+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>
+ */
+public class SubtreeSpecificationChecker
+{
+ /** the antlr generated parser being wrapped */
+ private ReusableAntlrSubtreeSpecificationChecker parser;
+
+ /** the antlr generated lexer being wrapped */
+ private ReusableAntlrSubtreeSpecificationCheckerLexer lexer;
+
+
+ /**
+ * Creates a normalizing subtree specification parser.
+ */
+ public SubtreeSpecificationChecker( SchemaManager schemaManager )
+ {
+ StringReader in = new StringReader( "" ); // place holder for the
+ // first input
+ this.lexer = new ReusableAntlrSubtreeSpecificationCheckerLexer( in );
+ this.parser = new ReusableAntlrSubtreeSpecificationChecker( lexer );
+ this.parser.init( schemaManager ); // this method MUST be called while we cannot do
+ // constructor overloading for antlr generated parser
+ }
+
+
+ /**
+ * 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
+ * @throws ParseException
+ * if there are any recognition errors (bad syntax)
+ */
+ public synchronized void parse( String spec ) throws ParseException
+ {
+ if ( spec == null || spec.trim().equals( "" ) )
+ {
+ return;
+ }
+
+ reset( spec ); // reset and initialize the parser / lexer pair
+
+ try
+ {
+ this.parser.wrapperEntryPoint();
+ }
+ catch ( TokenStreamException e )
+ {
+ String msg = I18n.err( I18n.ERR_04329, spec, e.getLocalizedMessage() );
+ throw new ParseException( msg, 0 );
+ }
+ catch ( RecognitionException e )
+ {
+ String msg = I18n.err( I18n.ERR_04329, spec, e.getLocalizedMessage() );
+ throw new ParseException( msg, e.getColumn() );
+ }
+ catch ( Exception e )
+ {
+ String msg = I18n.err( I18n.ERR_04329, spec, e.getLocalizedMessage() );
+ throw new ParseException( msg, 0 );
+ }
+ }
+
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationModifier.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationModifier.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationModifier.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationModifier.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.subtree;
+
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.name.DN;
+
+
+/**
+ * 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:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SubtreeSpecificationModifier
+{
+ /** the subtree base relative to the administration point */
+ private DN base = new DN();
+
+ /** the set of subordinates entries and their subordinates to exclude */
+ private Set<DN> chopBefore = Collections.EMPTY_SET;
+
+ /** the set of subordinates entries whose subordinates are to be excluded */
+ private Set<DN> 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 filter;
+
+
+ // -----------------------------------------------------------------------
+ // 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.filter );
+ }
+
+
+ // -----------------------------------------------------------------------
+ // 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( DN 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<DN> 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<DN> 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( I18n.err( I18n.ERR_04330 ) );
+ }
+
+ 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 filter a filter using only assertions on objectClass attributes for
+ * subtree refinement
+ */
+ public void setRefinement( ExprNode filter )
+ {
+ this.filter = filter;
+ }
+
+
+ /**
+ * Sets a filter
+ *
+ * @param filter a filter
+ */
+ public void setFilter( ExprNode filter )
+ {
+ this.filter = filter;
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParser.java?rev=964361&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParser.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParser.java Thu Jul 15 10:04:06 2010
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.subtree;
+
+
+import java.io.StringReader;
+import java.text.ParseException;
+
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.schema.NormalizerMappingResolver;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+
+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>
+ */
+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( SchemaManager schemaManager )
+ {
+ StringReader in = new StringReader( "" ); // place holder for the
+ // first input
+ this.lexer = new ReusableAntlrSubtreeSpecificationLexer( in );
+ this.parser = new ReusableAntlrSubtreeSpecificationParser( lexer );
+ this.parser.init( schemaManager ); // 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( NormalizerMappingResolver resolver, SchemaManager schemaManager )
+ {
+ StringReader in = new StringReader( "" ); // place holder for the
+ // first input
+ this.lexer = new ReusableAntlrSubtreeSpecificationLexer( in );
+ this.parser = new ReusableAntlrSubtreeSpecificationParser( lexer );
+ this.parser.setNormalizerMappingResolver( resolver );
+ this.parser.init( schemaManager ); // 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)
+ */
+ public synchronized SubtreeSpecification parse( String spec ) throws ParseException
+ {
+ 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 = I18n.err( I18n.ERR_04329, spec, e.getLocalizedMessage() );
+ throw new ParseException( msg, 0 );
+ }
+ catch ( RecognitionException e )
+ {
+ String msg = I18n.err( I18n.ERR_04329, spec, e.getLocalizedMessage() );
+ throw new ParseException( msg, e.getColumn() );
+ }
+ catch ( Exception e )
+ {
+ String msg = I18n.err( I18n.ERR_04329, spec, e.getLocalizedMessage() );
+ throw new ParseException( msg, 0 );
+ }
+
+ return ss;
+ }
+
+
+ /**
+ * Tests to see if this parser is normalizing.
+ *
+ * @return true if it normalizes false otherwise
+ */
+ public boolean isNormizing()
+ {
+ return this.isNormalizing;
+ }
+}