directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r226961 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/ExtensibleMatchFilter.java
Date Tue, 02 Aug 2005 06:03:51 GMT
Author: elecharny
Date: Mon Aug  1 23:03:49 2005
New Revision: 226961

URL: http://svn.apache.org/viewcvs?rev=226961&view=rev
Log:
- fixed the incorrectly calculated length
- added the encoding method

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/ExtensibleMatchFilter.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/ExtensibleMatchFilter.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/ExtensibleMatchFilter.java?rev=226961&r1=226960&r2=226961&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/ExtensibleMatchFilter.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/ExtensibleMatchFilter.java
Mon Aug  1 23:03:49 2005
@@ -16,7 +16,14 @@
  */
 package org.apache.asn1.ldap.pojo.filters;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ber.tlv.UniversalTag;
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
 import org.apache.asn1.primitives.OctetString;
 
@@ -45,6 +52,12 @@
 
     /** The dnAttributes flag */
     private boolean dnAttributes;
+    
+    /** The extensible match length */
+    private transient int extensibleMatchLength;
+    
+    /** The matching Rule Assertion Length */
+    private transient int matchingRuleAssertionLength;
 
     //~ Constructors -------------------------------------------------------------------------------
 
@@ -176,34 +189,113 @@
      */
     public int computeLength()
     {
-        // The type
-        int extensibleMatchLength = 0;
-        
         if ( matchingRule != null )
         {
-            extensibleMatchLength += 1 + Length.getNbBytes( matchingRule.getLength() ) +
matchingRule.getLength(); 
+            matchingRuleAssertionLength = 1 + Length.getNbBytes( matchingRule.getLength()
) + matchingRule.getLength(); 
         }
         
         if ( type != null )
         {
-            extensibleMatchLength += 1 + Length.getNbBytes( type.getLength() ) + type.getLength();

+            matchingRuleAssertionLength += 1 + Length.getNbBytes( type.getLength() ) + type.getLength();
         }
         
         if ( matchValue != null )
         {
-            extensibleMatchLength += 1 + Length.getNbBytes( matchValue.getLength() ) + matchValue.getLength();

+            matchingRuleAssertionLength += 1 + Length.getNbBytes( matchValue.getLength()
) + matchValue.getLength(); 
         }
         
         if ( dnAttributes == true )
         {
-            extensibleMatchLength += 1 + 1 + 1;
+            matchingRuleAssertionLength += 1 + 1 + 1;
         }
 
-        extensibleMatchLength += 1 + Length.getNbBytes( extensibleMatchLength );
+        extensibleMatchLength = 1 + Length.getNbBytes( matchingRuleAssertionLength ) + matchingRuleAssertionLength;
         
         return 1 + Length.getNbBytes( extensibleMatchLength ) + extensibleMatchLength;
     }
     
+    /**
+     * Encode the ExtensibleMatch Filters to a PDU. 
+     * 
+     * ExtensibleMatch filter :
+     * 
+     * 0xA9 LL 
+     * 0x30 LL matchingRuleAssertion
+     *  |     0x81 LL matchingRule
+     *  |    / |   0x82 LL Type  
+     *  |   /  |  /0x83 LL matchValue
+     *  +--+   +-+
+     *  |   \     \
+     *  |    \     0x83 LL MatchValue
+     *  |     0x82 LL type
+     *  |     0x83 LL matchValue
+     *  +--[0x84 0x01 dnAttributes]
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if (buffer == null)
+        {
+            throw new EncoderException("Cannot put a PDU in a null buffer !");
+        }
+
+        try 
+        {
+            // The ExtensibleMatch Tag
+            buffer.put( (byte)LdapConstants.EXTENSIBLE_MATCH_FILTER_TAG );
+            buffer.put( Length.getBytes( extensibleMatchLength ) );
+
+            // The MatchingRuleAssertion sequence tag
+            buffer.put( UniversalTag.SEQUENCE_TAG );
+            buffer.put( Length.getBytes( matchingRuleAssertionLength ) );
+
+            if ( ( matchingRule == null ) && ( type == null ) ) 
+            {
+                throw new EncoderException("Cannot have a null matching rule and a null type");
+            }
+            
+            // The matching rule
+            if ( matchingRule != null ) 
+            {
+                buffer.put( (byte)LdapConstants.SEARCH_MATCHING_RULE_TAG );
+                buffer.put( Length.getBytes( matchingRule.getLength() ) );
+                buffer.put( matchingRule.getData() );                
+            }
+            
+            // The type
+            if ( type != null ) 
+            {
+                buffer.put( (byte)LdapConstants.SEARCH_TYPE_TAG );
+                buffer.put( Length.getBytes( type.getLength() ) );
+                buffer.put( type.getData() );                
+            }
+            
+            // The match value
+            if ( matchValue != null ) 
+            {
+                buffer.put( (byte)LdapConstants.SEARCH_MATCH_VALUE_TAG );
+                buffer.put( Length.getBytes( matchValue.getLength() ) );
+                buffer.put( matchValue.getValue() );                
+            }
+
+            // The dnAttributes flag, if true only
+            if ( dnAttributes == true )
+            {
+                buffer.put( (byte)LdapConstants.DN_ATTRIBUTES_FILTER_TAG );
+                buffer.put( (byte)1 );
+                buffer.put( Value.TRUE_VALUE );                
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+        
+        return buffer;
+    }
+
     /**
      * Return a String representing an extended filter as of RFC 2254
      *



Mime
View raw message