directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 21084 - in incubator/directory/snickers/trunk: . ber-codec/src/java/org/apache/snickers/ber/digester ldap-ber-provider/src/java/org/apache/snickers/ldap ldap-ber-provider/src/java/org/apache/snickers/ldap/search ldap-ber-provider/src/test/org/apache/snickers/ldap/search
Date Fri, 11 Jun 2004 08:43:14 GMT
Author: akarasulu
Date: Fri Jun 11 01:43:14 2004
New Revision: 21084

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/BaseObjectRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/BaseSearchRequestRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/DerefAliasRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ScopeRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/SearchRequestProcessing.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/SearchRequestRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/SizeLimitRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/TimeLimitRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/TypesOnlyRule.java
  (contents, props changed)
Modified:
   incubator/directory/snickers/trunk/   (props changed)
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/digester/BERDigester.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/search/SearchRequestTest.java
Log:
ommit changes ...
 
 o added framework for working with SearchRequest
 o base class is designed to track state using processing obj
 o rules implemented for everything minus attributes and filter
 o rules added to digester factory
 
To do ...
 
 o something is broken with these rules or they are not correctly
   added to the digester - search request test is still broken
 



Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/digester/BERDigester.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/digester/BERDigester.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/digester/BERDigester.java
Fri Jun 11 01:43:14 2004
@@ -877,6 +877,37 @@
     }
     
     
+    // ------------------------------------------------------------------------
+    // Read Only Tag Stack (Primitive IntStack) Operations
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Return the current depth of the Tag stack.
+     *
+     * @return the size of the Tag stack
+     */
+    public int getTagCount()
+    {
+        return tagStack.size() ;
+    }
+
+
+    /**
+     * Return the n'th tag down the Tag stack, where 0 is the top element and
+     * [getCount()-1] is the bottom element.
+     *
+     * @param n the Tag index
+     * @return the Tag at the index
+     * @throws EmptyStackException if there are no more int Tags left
+     * @throws IndexOutOfBoundsException if the index is out of bounds
+     */
+    public int getTag( int n )
+    {
+        return ( tagStack.peek( n ) ) ;
+    }
+
+
     /**
      * Gets the raw int for the tag of the TLV currently being processed hence
      * the tag on the top of the stack.  The tag's int has the primitive flag
@@ -897,6 +928,11 @@
     }
 
     
+    // ------------------------------------------------------------------------
+    // ClassLoader Related Methods
+    // ------------------------------------------------------------------------
+
+
     /**
      * Return the class loader to be used for instantiating application objects
      * when required.  This is determined based upon the following rules:

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
Fri Jun 11 01:43:14 2004
@@ -110,6 +110,7 @@
         addModifyDnResponseRules( digester ) ;
         addModifyRequestRules( digester ) ;
         addModifyResponseRules( digester ) ;
+        adddeletes( digester ) ;
         addSearchResponseDoneRules( digester ) ;
         addSearchResponseReferenceRules( digester ) ;
         addSearchResponseEntryRules( digester ) ;
@@ -118,11 +119,40 @@
     }
 
 
+    private void adddeletes( BERDigester digester )
+    {
+        int[] pattern = new int[2] ;
+
+        // set pattern and addRule for the SearchRequest
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.SEARCH_REQUEST.getPrimitiveTag() ;
+        digester.addRule( pattern, new SearchRequestRule() ) ;
+
+        // setup pattern to set the dn of the entry added
+        pattern = new int[3];
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag();
+        pattern[1] = LdapTag.SEARCH_REQUEST.getPrimitiveTag();
+        pattern[2] = UniversalTag.OCTET_STRING.getPrimitiveTag();
+        digester.addRule( pattern, new BaseObjectRule() );
+
+        pattern[2] = UniversalTag.ENUMERATED.getPrimitiveTag();
+        digester.addRule( pattern, new ScopeRule() );
+        digester.addRule( pattern, new DerefAliasRule() );
+
+        pattern[2] = UniversalTag.INTEGER.getPrimitiveTag();
+        digester.addRule( pattern, new SizeLimitRule() );
+        digester.addRule( pattern, new TimeLimitRule() );
+
+        pattern[2] = UniversalTag.BOOLEAN.getPrimitiveTag();
+        digester.addRule( pattern, new TypesOnlyRule() );
+    }
+
+
     private void addModifyRequestRules( BERDigester digester )
     {
         int[] pattern = new int[2] ;
 
-        // set pattern and addRule for the AddRequest
+        // set pattern and addRule for the ModifyRequest
         pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
         pattern[1] = LdapTag.MODIFY_REQUEST.getPrimitiveTag() ;
         digester.addRule( pattern, new ModifyRequestRule() ) ;

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/BaseObjectRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/BaseObjectRule.java
Fri Jun 11 01:43:14 2004
@@ -0,0 +1,82 @@
+/*
+ *   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.snickers.ldap.search;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.snickers.ber.primitives.UniversalTag;
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule;
+
+import org.apache.ldap.common.message.SearchRequestImpl;
+
+
+/**
+ * Populates the baseObject field of the SearchRequest.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class BaseObjectRule extends PrimitiveOctetStringRule
+{
+    public BaseObjectRule()
+    {
+        super( UniversalTag.OCTET_STRING ) ;
+    }
+
+
+    /**
+     * Allows the super method to push a ByteBuffer onto the top of the stack
+     * which contains the drained contents of the superclass' ByteAccumulator.
+     * This ByteBuffer is popped first then used to populate the credentials.
+     * There is no need to copy this buffer since it will not be used again
+     * by the ByteAccumulator of the superclass so we should be able to use
+     * the byte[] based backing store if one is present.  However it might
+     * have to be copied even then.  Situations requiring a copy are when the
+     * buffer has a limit less than the capacity or when there is no
+     * accessible array to the buffer.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        // pushes a ByteBuffer onto the stack
+        super.finish() ;
+
+        // pop the ByteBuffer the super method pushed
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+        // peek at SearchRequest underneath processing obj whose octets we set
+        SearchRequestImpl req = ( SearchRequestImpl ) getDigester().peek( 1 );
+
+        byte[] octets = null ;
+        if ( buf.limit() == buf.capacity() && buf.hasArray() )
+        {
+            // use the backing store
+            octets = buf.array() ;
+        }
+        else
+        {
+            // copy because we don't have accessible array or data < array
+            octets = new byte[buf.remaining()];
+            buf.get( octets );
+        }
+
+        req.setBase( new String( octets ) );
+        ( ( SearchRequestProcessing ) getDigester().peek() ).next();
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/BaseSearchRequestRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/BaseSearchRequestRule.java
Fri Jun 11 01:43:14 2004
@@ -0,0 +1,215 @@
+/*
+ *   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.snickers.ldap.search;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.commons.lang.Validate;
+
+import org.apache.snickers.ldap.LdapTag;
+import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ber.digester.AbstractRule;
+import org.apache.ldap.common.message.SearchRequestImpl;
+
+
+/**
+ * A base class for all SearchRequest processing rules.  This rule turns itself
+ * off and on based on the nesting pattern of certain rule firings.  It has
+ * the ability to bypass a firing this way if it was not triggered in the
+ * proper scope.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class BaseSearchRequestRule extends AbstractRule
+{
+    /**
+     * Determines whether or not this rule is enabled for a specific firing.
+     * This will be reset every time to true after a rule's final() stage
+     * method completes.
+     */
+    private boolean isEnabled = true;
+    /**
+     * The minimum number of tag's required in the tag stack of the digester
+     * to enable this rule for a firing.  This is initialized in the protected
+     * constructor.  So different rules can operate at different levels even
+     * if they match the same pattern.
+     */
+    private final int minTagCount;
+    /**
+     * A handle on the search request currently being processed for this
+     * firing.  This reference is set when tag() completes and nulled out when
+     * the rule's final() stage method completes.
+     */
+    private SearchRequestImpl req;
+    /**
+     * A handle on the search request processing object used to track
+     * processing state.  This reference is set when tag() completes and
+     * nulled out when the rule's final() stage method completes.
+     */
+    private SearchRequestProcessing processing;
+
+
+    /**
+     * Creates a rule used to process some part of a search request.
+     *
+     * @param minTagCount the minimum number of tags required in the digester
+     * tag stack to enable this rule
+     */
+    protected BaseSearchRequestRule( int minTagCount )
+    {
+        Validate.isTrue( minTagCount >= 2,
+                "minimum tag count must be 2 or more" );
+        this.minTagCount = minTagCount;
+    }
+
+
+    /**
+     * Gets the SearchRequest object being processed.
+     *
+     * @return the SearchRequest object being processed
+     */
+    protected SearchRequestImpl getRequest()
+    {
+        return req;
+    }
+
+
+    /**
+     * Gets the SearchRequestProcessing object tracking processing state.
+     *
+     * @return the SearchRequestProcessing object tracking processing state
+     */
+    protected SearchRequestProcessing getProcessing()
+    {
+        return processing;
+    }
+
+
+    /**
+     * Checks to see if this rule is enabled for the rest of this firing.
+     *
+     * @return true if the rule is enabled for this firing false otherwise
+     */
+    public boolean isEnabled()
+    {
+        return isEnabled;
+    }
+
+
+    /**
+     * Sets whether or not this rule is disabled for the rest of this firing.
+     *
+     * @param enabled true if rule is enabled for this firing false otherwise
+     */
+    protected void setEnabled( boolean enabled )
+    {
+        isEnabled = enabled;
+    }
+
+
+    /**
+     * It's a good idea to call this method first before anything else to
+     * make sure the enabled flag gets set.  This guy sets the enabled flag
+     * based on the tag nesting pattern.  Also check to make sure the rule is
+     * enabled before writing code in any overloaded stage method like this
+     * one.
+     *
+     * Also note that all tag overrides should after calling this method check
+     * things like the processing state to determine if this rule needs to be
+     * disabled.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        // check to see we are within limits - have the right number of tags
+        int tagCount = getDigester().getTagCount();
+        if ( tagCount < minTagCount )
+        {
+            this.isEnabled = false;
+            return;
+        }
+
+        /*
+         * check to see that we're dealing within a search request - this is
+         * done by making sure the tag right above the bottom tag is equal
+         * to the SEARCH_REQUEST tag. If not we must disable this rule.
+         */
+        if ( getDigester().getTag( tagCount - 2 ) !=
+                LdapTag.SEARCH_REQUEST.getPrimitiveTag() )
+        {
+            this.isEnabled = false;
+            return;
+        }
+
+        super.tag( id, isPrimitive, typeClass );
+
+        /*
+         * Now that we're ready to go lets get a handle on the search request
+         * and it's current processing state.  The processing state may be used
+         * to determine the 'salience' of some competing rules.
+         */
+        int ii = getDigester().getCount() - 1 ;
+        req = ( SearchRequestImpl ) getDigester().peek( ii ) ;
+        processing = ( SearchRequestProcessing ) getDigester().peek( ii - 1 ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( isEnabled )
+        {
+            super.length( length );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        if ( isEnabled )
+        {
+            super.value( buf );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        if ( isEnabled )
+        {
+            super.finish();
+        }
+
+        req = null;
+        isEnabled = true;
+        processing.next(); 
+        processing = null;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/DerefAliasRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/DerefAliasRule.java
Fri Jun 11 01:43:14 2004
@@ -0,0 +1,159 @@
+/*
+ *   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.snickers.ldap.search;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ber.primitives.UniversalTag;
+import org.apache.snickers.ber.primitives.PrimitiveUtils;
+
+import org.apache.ldap.common.message.DerefAliasesEnum;
+
+
+/**
+ * A rule used to set the derefAlias field of a SearchRequest.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class DerefAliasRule extends BaseSearchRequestRule
+{
+    /** the bytes used to form the Java primitive integer */
+    private final byte[] value = new byte[4] ;
+    /** the current 8 bit position to fill in the integer */
+    private int pos ;
+    /** the number of bytes we must read */
+    private int length ;
+
+
+    public DerefAliasRule()
+    {
+        super( 3 );
+    }
+
+
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        super.tag( id, isPrimitive, typeClass );
+
+        if ( getDigester().getTopTag() !=
+                UniversalTag.ENUMERATED.getPrimitiveTag() )
+        {
+            setEnabled( false );
+        }
+
+        if ( getProcessing().getState() != getProcessing().DEREF_ALIAS_STATE )
+        {
+            setEnabled( false );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( ! isEnabled() )
+        {
+            return ;
+        }
+
+        if ( length > 4 || length < 0 )
+        {
+            throw new IllegalArgumentException( "The target primitive for this "
+                + "rule can only hold integers of 32 bits or 4 bytes.  "
+                + "The length of the field however is " + length ) ;
+        }
+
+        this.length = length ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        if ( ! isEnabled() )
+        {
+            return ;
+        }
+
+        if ( buf == null )
+        {
+            return ;
+        }
+
+        while ( buf.hasRemaining() && ( pos + 1 ) <= length )
+        {
+            value[pos] = buf.get() ;
+            pos++ ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        if ( ! isEnabled() )
+        {
+            // cleanup
+            this.pos = 0 ;
+            this.length = 0 ;
+            super.finish();
+            return ;
+        }
+
+        // decode and push primitive integer onto stack
+        int numba = PrimitiveUtils.decodeInt( this.value, 0, this.length ) ;
+
+        switch( numba )
+        {
+            case 0:
+                getRequest().setDerefAliases(
+                        DerefAliasesEnum.NEVERDEREFALIASES );
+                break;
+            case 1:
+                getRequest().setDerefAliases(
+                        DerefAliasesEnum.DEREFINSEARCHING );
+                break;
+            case 2:
+                getRequest().setDerefAliases(
+                        DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+                break;
+            case 3:
+                getRequest().setDerefAliases(
+                        DerefAliasesEnum.DEREFALWAYS );
+                break;
+            default:
+                throw new IllegalStateException(
+                        "expected 0, 1, 2, or 3 for derefAliases but got "
+                        + numba ) ;
+        }
+
+        // cleanup
+        this.pos = 0 ;
+        this.length = 0 ;
+        super.finish();
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ScopeRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ScopeRule.java
Fri Jun 11 01:43:14 2004
@@ -0,0 +1,151 @@
+/*
+ *   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.snickers.ldap.search;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ber.primitives.UniversalTag;
+import org.apache.snickers.ber.primitives.PrimitiveUtils;
+
+import org.apache.ldap.common.message.ScopeEnum;
+
+
+/**
+ * A rule used to set the scope of a SearchRequest.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class ScopeRule extends BaseSearchRequestRule
+{
+    /** the bytes used to form the Java primitive integer */
+    private final byte[] value = new byte[4] ;
+    /** the current 8 bit position to fill in the integer */
+    private int pos ;
+    /** the number of bytes we must read */
+    private int length ;
+
+
+    public ScopeRule()
+    {
+        super( 3 );
+    }
+
+
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        super.tag( id, isPrimitive, typeClass );
+
+        if ( getDigester().getTopTag() !=
+                UniversalTag.ENUMERATED.getPrimitiveTag() )
+        {
+            setEnabled( false );
+        }
+
+        if ( getProcessing().getState() != getProcessing().SCOPE_STATE )
+        {
+            setEnabled( false );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( ! isEnabled() )
+        {
+            return ;
+        }
+
+        if ( length > 4 || length < 0 )
+        {
+            throw new IllegalArgumentException( "The target primitive for this "
+                + "rule can only hold integers of 32 bits or 4 bytes.  "
+                + "The length of the field however is " + length ) ;
+        }
+
+        this.length = length ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        if ( ! isEnabled() )
+        {
+            return ;
+        }
+
+        if ( buf == null )
+        {
+            return ;
+        }
+
+        while ( buf.hasRemaining() && ( pos + 1 ) <= length )
+        {
+            value[pos] = buf.get() ;
+            pos++ ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        if ( ! isEnabled() )
+        {
+            // cleanup
+            this.pos = 0 ;
+            this.length = 0 ;
+            super.finish();
+            return ;
+        }
+
+        // decode and push primitive integer onto stack
+        int numba = PrimitiveUtils.decodeInt( this.value, 0, this.length ) ;
+
+        switch( numba )
+        {
+            case 0:
+                getRequest().setScope( ScopeEnum.BASEOBJECT );
+                break;
+            case 1:
+                getRequest().setScope( ScopeEnum.SINGLELEVEL );
+                break;
+            case 2:
+                getRequest().setScope( ScopeEnum.WHOLESUBTREE );
+                break;
+            default:
+                throw new IllegalStateException(
+                        "expected 0, 1, or 2 for scope but got " + numba ) ;
+        }
+
+        // cleanup
+        this.pos = 0 ;
+        this.length = 0 ;
+        super.finish();
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/SearchRequestProcessing.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/SearchRequestProcessing.java
Fri Jun 11 01:43:14 2004
@@ -0,0 +1,179 @@
+/*
+ *   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.snickers.ldap.search;
+
+
+/**
+ * Document this class.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class SearchRequestProcessing
+{
+    // ------------------------------------------------------------------------
+    // States used by this instance
+    // ------------------------------------------------------------------------
+
+    /** state for filling in the baseObject field */
+    public final State BASE_OBJECT_STATE = new BaseObjectState() ;
+    /** state for filling in the scope field */
+    public final State SCOPE_STATE = new ScopeState() ;
+    /** state for filling in the derefAliases field */
+    public final State DEREF_ALIAS_STATE = new DerefAliasState() ;
+    /** state for filling in the sizeLimit field */
+    public final State SIZE_LIMIT_STATE = new SizeLimitState() ;
+    /** state for filling in the timeLimit field */
+    public final State TIME_LIMIT_STATE = new TimeLimitState() ;
+    /** state for filling in the typesOnly field */
+    public final State TYPES_ONLY_STATE = new TypesOnlyState() ;
+    /** state for filling in the filter field */
+    public final State FILTER_STATE = new FilterState() ;
+    /** state for filling in the controls field */
+    public final State CONTROLS_STATE = new ControlsState() ;
+
+
+    /** the current request processing state */
+    private State state = BASE_OBJECT_STATE ;
+
+
+    /** gets the state of SearchRequest processing */
+    public State getState()
+    {
+        return state;
+    }
+
+
+    /** resets state to the start state */
+    public void reset()
+    {
+        state = BASE_OBJECT_STATE ;
+    }
+
+
+    /** sets the state to the next in line or back to the start state */
+    public void next()
+    {
+        state.next() ;
+    }
+
+
+    /**
+     * State base class.
+     */
+    public abstract class State
+    {
+        protected abstract void next() ;
+    }
+
+
+    /**
+     * State class for filling in the baseObject field.
+     */
+    protected class BaseObjectState extends State
+    {
+        protected void next()
+        {
+            state = SCOPE_STATE ;
+        }
+    }
+
+
+    /**
+     * State class for filling in the scope field.
+     */
+    protected class ScopeState extends State
+    {
+        protected void next()
+        {
+            state = DEREF_ALIAS_STATE ;
+        }
+    }
+
+
+    /**
+     * State class for filling in the derefAliases field.
+     */
+    protected class DerefAliasState extends State
+    {
+        protected void next()
+        {
+            state = SIZE_LIMIT_STATE ;
+        }
+    }
+
+
+    /**
+     * State class for filling in the sizeLimit field.
+     */
+    protected class SizeLimitState extends State
+    {
+        protected void next()
+        {
+            state = TIME_LIMIT_STATE ;
+        }
+    }
+
+
+    /**
+     * State class for filling in the timeLimit field.
+     */
+    protected class TimeLimitState extends State
+    {
+        protected void next()
+        {
+            state = TYPES_ONLY_STATE ;
+        }
+    }
+
+
+    /**
+     * State class for filling in the typesOnly field.
+     */
+    protected class TypesOnlyState extends State
+    {
+        protected void next()
+        {
+            state = FILTER_STATE ;
+        }
+    }
+
+
+    /**
+     * State class for filling in the filter.
+     */
+    protected class FilterState extends State
+    {
+        protected void next()
+        {
+            state = CONTROLS_STATE ;
+        }
+    }
+
+
+    /**
+     * State class for filling in the controls.
+     */
+    protected class ControlsState extends State
+    {
+        protected void next()
+        {
+            state = BASE_OBJECT_STATE ;
+        }
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/SearchRequestRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/SearchRequestRule.java
Fri Jun 11 01:43:14 2004
@@ -0,0 +1,76 @@
+/*
+ *   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.snickers.ldap.search;
+
+
+import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ber.digester.AbstractRule;
+
+import org.apache.snickers.ldap.LdapTag;
+import org.apache.ldap.common.message.SearchRequestImpl;
+
+
+/**
+ * A rule used to instantiate an empty SearchRequest, push it and ultimately
+ * pop it off of the digester stack once it has been populated. An intermediate
+ * processing state tracking object an instance of the SearchRequestProcessing
+ * class is pushed onto the object stack with tag() right after the request
+ * is pushed on; it is also popped off right before the request is popped.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class SearchRequestRule extends AbstractRule
+{
+    /** used to manage processing state */
+    private final SearchRequestProcessing processing =
+            new SearchRequestProcessing();
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        super.tag( id, isPrimitive, typeClass );
+
+        LdapTag tag = LdapTag.getLdapTagById( id );
+
+        if ( LdapTag.SEARCH_REQUEST != tag )
+        {
+            throw new IllegalArgumentException( "Expected a SEARCH_REQUEST tag "
+                + "id but got a " + tag );
+        }
+
+        SearchRequestImpl req;
+        req = new SearchRequestImpl( getDigester().popInt() );
+        getDigester().push( req );
+        getDigester().push( processing );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish();
+        getDigester().pop();
+        getDigester().pop();
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/SizeLimitRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/SizeLimitRule.java
Fri Jun 11 01:43:14 2004
@@ -0,0 +1,134 @@
+/*
+ *   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.snickers.ldap.search;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ber.primitives.UniversalTag;
+import org.apache.snickers.ber.primitives.PrimitiveUtils;
+
+
+/**
+ * A rule used to set the sizeLimit of a SearchRequest.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class SizeLimitRule extends BaseSearchRequestRule
+{
+    /** the bytes used to form the Java primitive integer */
+    private final byte[] value = new byte[4] ;
+    /** the current 8 bit position to fill in the integer */
+    private int pos ;
+    /** the number of bytes we must read */
+    private int length ;
+
+
+    public SizeLimitRule()
+    {
+        super( 3 );
+    }
+
+
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        super.tag( id, isPrimitive, typeClass );
+
+        if ( getDigester().getTopTag() !=
+                UniversalTag.INTEGER.getPrimitiveTag() )
+        {
+            setEnabled( false );
+        }
+
+        if ( getProcessing().getState() != getProcessing().SIZE_LIMIT_STATE )
+        {
+            setEnabled( false );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( ! isEnabled() )
+        {
+            return ;
+        }
+
+        if ( length > 4 || length < 0 )
+        {
+            throw new IllegalArgumentException( "The target primitive for this "
+                + "rule can only hold integers of 32 bits or 4 bytes.  "
+                + "The length of the field however is " + length ) ;
+        }
+
+        this.length = length ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        if ( ! isEnabled() )
+        {
+            return ;
+        }
+
+        if ( buf == null )
+        {
+            return ;
+        }
+
+        while ( buf.hasRemaining() && ( pos + 1 ) <= length )
+        {
+            value[pos] = buf.get() ;
+            pos++ ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        if ( ! isEnabled() )
+        {
+            // cleanup
+            this.pos = 0;
+            this.length = 0;
+            super.finish();
+            return;
+        }
+
+        // decode and push primitive integer onto stack
+        int numba = PrimitiveUtils.decodeInt( this.value, 0, this.length );
+        getRequest().setSizeLimit( numba );
+
+        // cleanup
+        this.pos = 0;
+        this.length = 0;
+        super.finish();
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/TimeLimitRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/TimeLimitRule.java
Fri Jun 11 01:43:14 2004
@@ -0,0 +1,134 @@
+/*
+ *   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.snickers.ldap.search;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ber.primitives.UniversalTag;
+import org.apache.snickers.ber.primitives.PrimitiveUtils;
+
+
+/**
+ * A rule used to set the timeLimit field of a SearchRequest.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class TimeLimitRule extends BaseSearchRequestRule
+{
+    /** the bytes used to form the Java primitive integer */
+    private final byte[] value = new byte[4] ;
+    /** the current 8 bit position to fill in the integer */
+    private int pos ;
+    /** the number of bytes we must read */
+    private int length ;
+
+
+    public TimeLimitRule()
+    {
+        super( 3 );
+    }
+
+
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        super.tag( id, isPrimitive, typeClass );
+
+        if ( getDigester().getTopTag() !=
+                UniversalTag.INTEGER.getPrimitiveTag() )
+        {
+            setEnabled( false );
+        }
+
+        if ( getProcessing().getState() != getProcessing().TIME_LIMIT_STATE )
+        {
+            setEnabled( false );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( ! isEnabled() )
+        {
+            return ;
+        }
+
+        if ( length > 4 || length < 0 )
+        {
+            throw new IllegalArgumentException( "The target primitive for this "
+                + "rule can only hold integers of 32 bits or 4 bytes.  "
+                + "The length of the field however is " + length ) ;
+        }
+
+        this.length = length ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        if ( ! isEnabled() )
+        {
+            return ;
+        }
+
+        if ( buf == null )
+        {
+            return ;
+        }
+
+        while ( buf.hasRemaining() && ( pos + 1 ) <= length )
+        {
+            value[pos] = buf.get() ;
+            pos++ ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        if ( ! isEnabled() )
+        {
+            // cleanup
+            this.pos = 0;
+            this.length = 0;
+            super.finish();
+            return;
+        }
+
+        // decode and push primitive integer onto stack
+        int numba = PrimitiveUtils.decodeInt( this.value, 0, this.length );
+        getRequest().setTimeLimit( numba );
+
+        // cleanup
+        this.pos = 0;
+        this.length = 0;
+        super.finish();
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/TypesOnlyRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/TypesOnlyRule.java
Fri Jun 11 01:43:14 2004
@@ -0,0 +1,118 @@
+/*
+ *   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.snickers.ldap.search;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.snickers.ber.digester.AbstractRule;
+import org.apache.snickers.ber.primitives.UniversalTag;
+import org.apache.snickers.ber.primitives.PrimitiveUtils;
+import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ber.TagEnum;
+import org.apache.ldap.common.message.SearchRequestImpl;
+
+
+/**
+ * Rule used to set the typesOnly field of a SearchRequest.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class TypesOnlyRule extends AbstractRule
+{
+    /** the octet for the Java primitive boolean */
+    private byte value = 0 ;
+    /** boolean flag to determine if we have read the single octet */
+    private boolean octetSet = false ;
+    /** the tag this rule accepts */
+    private final TagEnum tag = UniversalTag.BOOLEAN  ;
+
+
+    // -----------------------------------------------------------------------
+    // Rule Implementation
+    // -----------------------------------------------------------------------
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        if ( id != tag.getTagId() )
+        {
+            throw new IllegalArgumentException(
+                    "Expecting " + tag.getName()
+                    + " with an id of " + tag.getTagId()
+                    + " but instead got a tag id of " + id ) ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( length != 1 )
+        {
+            throw new IllegalArgumentException( "The target primitive for this "
+                + "rule only requires a single octet with a length of 1.  "
+                + "The length of the field however is " + length ) ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        if ( octetSet )
+        {
+            throw new IllegalArgumentException( "The target primitive for this "
+                + "rule only requires a single octet with a length of 1.  "
+                + "That octet has already been set." ) ;
+        }
+
+        while ( buf.hasRemaining() )
+        {
+            value = buf.get() ;
+            octetSet = true ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        // peek at SearchRequest underneath processing obj whose octets we set
+        SearchRequestImpl req = ( SearchRequestImpl ) getDigester().peek( 1 );
+        req.setTypesOnly( PrimitiveUtils.berDecodeBoolean( value ) );
+
+        // switch state
+        ( ( SearchRequestProcessing ) getDigester().peek() ).next();
+
+        // cleanup
+        this.value = 0 ;
+        this.octetSet = false ;
+    }
+}

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/search/SearchRequestTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/search/SearchRequestTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/search/SearchRequestTest.java
Fri Jun 11 01:43:14 2004
@@ -54,28 +54,36 @@
         req.setTimeLimit( 3 ) ;
         req.setTypesOnly( true ) ;
 
-        req.addAttribute( "attr0" ) ;
-        req.addAttribute( "attr1" ) ;
-        req.addAttribute( "attr2" ) ;
+        //req.addAttribute( "attr0" ) ;
+        //req.addAttribute( "attr1" ) ;
+        //req.addAttribute( "attr2" ) ;
 
 
         FilterParserImpl parser = new FilterParserImpl() ;
         ExprNode node = null ;
-        node = parser.parse( "( & ( ou = Human Resources ) ( l = SunnyVale ) "
-                + " ( | ( uid = akarasulu ) ( ! ( uid = jbean ) ) ) )" ) ;
+        node = parser.parse(
+                  "(ou=Human Resources)" ) ;
+                //"( & ( ou = Human Resources ) ( l = SunnyVale ) "
+                //+ " ( | ( uid = akarasulu ) ( ! ( uid = jbean ) ) ) )" ) ;
         req.setFilter( node ) ;
 
         System.out.println( "Generated SearchRequest for test:" ) ;
         System.out.println( TestUtils.printTupleTree( req ) ) ;
 
-        /*
-
-        NOT COMPLETE YET!
-
         SearchRequest decoded = ( SearchRequest )
                 snickersDecode( snaccEncode( req ) ) ;
         assertNotNull( decoded ) ;
         assertEquals( req.getBase(), decoded.getBase() ) ;
+        assertEquals( req.getScope(), decoded.getScope() ) ;
+        assertEquals( req.getDerefAliases(), decoded.getDerefAliases() ) ;
+        assertEquals( req.getSizeLimit(), decoded.getSizeLimit() ) ;
+        assertEquals( req.getTimeLimit(), decoded.getTimeLimit() ) ;
+        assertEquals( req.getTypesOnly(), decoded.getTypesOnly() ) ;
+
+        /*
+
+        NOT COMPLETE YET!
+
         */
     }
 }

Mime
View raw message