You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/06/14 06:07:30 UTC

svn commit: rev 21181 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap java/org/apache/snickers/ldap/search test/org/apache/snickers/ldap/search

Author: akarasulu
Date: Sun Jun 13 21:07:29 2004
New Revision: 21181

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchDnAttributesRule.java   (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchMatchingRule.java   (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchRule.java   (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchTypeRule.java   (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchValueRule.java   (contents, props changed)
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/LdapTag.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/search/SearchRequestTest.java
Log:
Added extensible match rules to digester for handling search


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	Sun Jun 13 21:07:29 2004
@@ -207,7 +207,28 @@
         pattern[1] = LdapTag.CONTEXT_SPECIFIC_TAG_8.getPrimitiveTag();
         digester.addRule( pattern, new ApproxMatchRule() );
 
+        //
+        // Extensible match filter rules
+        //
+        pattern = new int[2];
+        pattern[0] = TagTree.WILDCARD;
+        pattern[1] = LdapTag.CONTEXT_SPECIFIC_TAG_9.getPrimitiveTag();
+        digester.addRule( pattern, new ExtensibleMatchRule() );
 
+        pattern = new int[3];
+        pattern[0] = TagTree.WILDCARD;
+        pattern[1] = LdapTag.CONTEXT_SPECIFIC_TAG_9.getPrimitiveTag();
+        pattern[2] = LdapTag.CONTEXT_SPECIFIC_TAG_1.getPrimitiveTag();
+        digester.addRule( pattern, new ExtensibleMatchMatchingRule() );
+
+        pattern[2] = LdapTag.CONTEXT_SPECIFIC_TAG_2.getPrimitiveTag();
+        digester.addRule( pattern, new ExtensibleMatchTypeRule() );
+
+        pattern[2] = LdapTag.CONTEXT_SPECIFIC_TAG_3.getPrimitiveTag();
+        digester.addRule( pattern, new ExtensibleMatchValueRule() );
+
+        pattern[2] = LdapTag.CONTEXT_SPECIFIC_TAG_4.getPrimitiveTag();
+        digester.addRule( pattern, new ExtensibleMatchDnAttributesRule() );
     }
 
 

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java	(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java	Sun Jun 13 21:07:29 2004
@@ -269,6 +269,8 @@
            CONTEXT_SPECIFIC_TAG_1;
     public static final ContextSpecificTag CONTEXT_SPECIFIC_TAG_2 = 
             new ContextSpecificTag( 2, true ) ;
+    public static final ContextSpecificTag CONTEXT_SPECIFIC_TAG_9 = 
+            new ContextSpecificTag( 9, true ) ;
 
 
     // -----------------------------------------------------------------------

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchDnAttributesRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchDnAttributesRule.java	Sun Jun 13 21:07:29 2004
@@ -0,0 +1,54 @@
+/*
+ *   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.rules.PrimitiveOctetStringRule;
+import org.apache.snickers.ber.digester.rules.PrimitiveBooleanRule;
+import org.apache.snickers.ldap.LdapTag;
+
+
+/**
+ * A helper rule used to build a Extensible match fiter expression.  This rule
+ * accessess the top object on the object stack which it presumes is the rule
+ * it is helping: an instance of the ExtensibleMatchRule class.  It sets the
+ * dnAttributes boolean using the setter on this rule.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class ExtensibleMatchDnAttributesRule extends PrimitiveBooleanRule
+{
+    public ExtensibleMatchDnAttributesRule()
+    {
+        super( LdapTag.CONTEXT_SPECIFIC_TAG_4 );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+        ExtensibleMatchRule rule = ( ExtensibleMatchRule ) getDigester().peek();
+        rule.setDnAttributes( getDigester().popBoolean() );
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchMatchingRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchMatchingRule.java	Sun Jun 13 21:07:29 2004
@@ -0,0 +1,70 @@
+/*
+ *   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.rules.PrimitiveOctetStringRule;
+import org.apache.snickers.ldap.LdapTag;
+
+
+/**
+ * A helper rule used to build a Extensible match fiter expression.  This rule
+ * accessess the top object on the object stack which it presumes is the rule
+ * it is helping: an instance of the ExtensibleMatchRule class.  It sets the
+ * matchingRule value using the setter on this rule.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class ExtensibleMatchMatchingRule extends PrimitiveOctetStringRule
+{
+    public ExtensibleMatchMatchingRule()
+    {
+        super( LdapTag.CONTEXT_SPECIFIC_TAG_1 );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+
+        // pop the ByteBuffer the super method pushed
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+
+        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 ) ;
+        }
+
+        ExtensibleMatchRule rule = ( ExtensibleMatchRule ) getDigester().peek();
+        rule.setMatchingRule( new String( octets ) );
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchRule.java	Sun Jun 13 21:07:29 2004
@@ -0,0 +1,164 @@
+/*
+ *   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.ldap.LdapTag;
+import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ber.digester.AbstractRule;
+
+import org.apache.ldap.common.filter.ExtensibleNode;
+
+
+/**
+ * [*, 0x89000000]
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class ExtensibleMatchRule extends AbstractRule
+{
+    private boolean isEnabled = true;
+    /** optional matching rule property */
+    private String matchingRule = null;
+    /** optional type property */
+    private String type = null;
+    /** required matchingValue property */
+    private String value = null;
+    /** dnAttributes property that defaults to FALSE */
+    private boolean dnAttributes = false;
+
+
+    /*
+     * @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 < 3 )
+        {
+            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 );
+
+        getDigester().push( this );
+    }
+
+
+    /* (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 );
+        }
+    }
+
+
+    /**
+     * Creates a SubstringNode using all the values that have been set by other
+     * helper rules and pushes the node onto the object stack.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        if ( isEnabled )
+        {
+            super.finish();
+            ExtensibleNode node;
+
+            node = new ExtensibleNode( type, value, matchingRule,
+                    dnAttributes );
+
+            if ( getDigester().peek() == this )
+            {
+                getDigester().pop();
+            }
+
+            getDigester().push( node );
+        }
+
+        isEnabled = true;
+        type = null;
+        value = null;
+        matchingRule = null;
+        dnAttributes = false;
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Members called by other rules to populate the fields of this rule
+    // ------------------------------------------------------------------------
+
+
+    public void setMatchingRule( String matchingRule )
+    {
+        this.matchingRule = matchingRule;
+    }
+
+
+    public void setType( String type )
+    {
+        this.type = type;
+    }
+
+
+    public void setValue( String value )
+    {
+        this.value = value;
+    }
+
+
+    public void setDnAttributes( boolean dnAttributes )
+    {
+        this.dnAttributes = dnAttributes;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchTypeRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchTypeRule.java	Sun Jun 13 21:07:29 2004
@@ -0,0 +1,70 @@
+/*
+ *   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.rules.PrimitiveOctetStringRule;
+import org.apache.snickers.ldap.LdapTag;
+
+
+/**
+ * A helper rule used to build a Extensible match fiter expression.  This rule
+ * accessess the top object on the object stack which it presumes is the rule
+ * it is helping: an instance of the ExtensibleMatchRule class.  It sets the
+ * type value using the setter on this rule.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class ExtensibleMatchTypeRule extends PrimitiveOctetStringRule
+{
+    public ExtensibleMatchTypeRule()
+    {
+        super( LdapTag.CONTEXT_SPECIFIC_TAG_2 );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+
+        // pop the ByteBuffer the super method pushed
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+
+        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 ) ;
+        }
+
+        ExtensibleMatchRule rule = ( ExtensibleMatchRule ) getDigester().peek();
+        rule.setType( new String( octets ) );
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchValueRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/ExtensibleMatchValueRule.java	Sun Jun 13 21:07:29 2004
@@ -0,0 +1,70 @@
+/*
+ *   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.rules.PrimitiveOctetStringRule;
+import org.apache.snickers.ldap.LdapTag;
+
+
+/**
+ * A helper rule used to build a Extensible match fiter expression.  This rule
+ * accessess the top object on the object stack which it presumes is the rule
+ * it is helping: an instance of the ExtensibleMatchRule class.  It sets the
+ * value using the setter on this rule.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class ExtensibleMatchValueRule extends PrimitiveOctetStringRule
+{
+    public ExtensibleMatchValueRule()
+    {
+        super( LdapTag.CONTEXT_SPECIFIC_TAG_3 );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+
+        // pop the ByteBuffer the super method pushed
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+
+        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 ) ;
+        }
+
+        ExtensibleMatchRule rule = ( ExtensibleMatchRule ) getDigester().peek();
+        rule.setValue( new String( octets ) );
+    }
+}

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	Sun Jun 13 21:07:29 2004
@@ -399,8 +399,8 @@
 
     /**
      * Tests an search request decode with a simple greaterOrEqual match filter.
-     *
-    public void testSearchRequest7() throws Exception
+     */
+    public void testExtensibleMatch() throws Exception
     {
         SearchRequestImpl req = new SearchRequestImpl( 33 );
         req.setBase( "dc=example,dc=com" );
@@ -415,12 +415,9 @@
         req.addAttribute( "attr2" );
 
 
-        FilterParserImpl parser = new FilterParserImpl();
-        ExprNode node = null ;
-        node = parser.parse(
-                "( age > 30 ) " ) ;
-                //"( & ( ou = Human Resources ) ( l = SunnyVale ) "
-                //+ " ( | ( uid = akarasulu ) ( ! ( uid = jbean ) ) ) )" );
+        ExtensibleNode node = new ExtensibleNode( "cn", "val", "1.1", true );
+        StringBuffer buf0 = new StringBuffer();
+        node.printToBuffer( buf0 );
         req.setFilter( node );
 
         System.out.println( "Generated SearchRequest for test:" );
@@ -450,14 +447,12 @@
         assertFalse( attributes.contains( "(*&#$&#$*@#" ) );
 
         // filter tests
-        node = req.getFilter();
-        StringBuffer buf0 = new StringBuffer();
+        buf0 = new StringBuffer();
         node.printToBuffer( buf0 );
-        node = decoded.getFilter();
+        node = ( ExtensibleNode ) decoded.getFilter();
         StringBuffer buf1 = new StringBuffer();
         node.printToBuffer( buf1 );
         assertEquals(buf0.toString(), buf1.toString()) ;
         System.out.println( buf1.toString() );
     }
-     */
 }