directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r226909 - in /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters: AndFilter.java AttributeValueAssertionFilter.java ConnectorFilter.java NotFilter.java OrFilter.java PresentFilter.java
Date Mon, 01 Aug 2005 23:48:10 GMT
Author: elecharny
Date: Mon Aug  1 16:48:03 2005
New Revision: 226909

URL: http://svn.apache.org/viewcvs?rev=226909&view=rev
Log:
Added the encode method

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/AndFilter.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/AttributeValueAssertionFilter.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/ConnectorFilter.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/NotFilter.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/OrFilter.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/PresentFilter.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/AndFilter.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/AndFilter.java?rev=226909&r1=226908&r2=226909&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/AndFilter.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/AndFilter.java
Mon Aug  1 16:48:03 2005
@@ -16,9 +16,13 @@
  */
 package org.apache.asn1.ldap.pojo.filters;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ldap.codec.LdapConstants;
 
 /**
  * And Filter Object to store the And filter.
@@ -59,11 +63,47 @@
      */
     public int computeLength()
     {
-        int filtersLength = super.computeLength();
+        filtersLength = super.computeLength();
         
         return 1 + Length.getNbBytes( filtersLength ) + filtersLength;
     }
     
+    /**
+     * Encode the AndFilter message to a PDU.
+     * 
+     * AndFilter :
+     * 
+     * 0xA0 LL 
+     * filter.encode()
+     * ...
+     * filter.encode()
+     * 
+     * @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 AndFilter Tag
+            buffer.put( (byte)LdapConstants.AND_FILTER_TAG );
+            buffer.put( Length.getBytes( filtersLength ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+        
+        super.encode( buffer );
+
+        return buffer;
+    }
+
     /**
      * Return a string compliant with RFC 2254 representing an AND filter
      *

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/AttributeValueAssertionFilter.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/AttributeValueAssertionFilter.java?rev=226909&r1=226908&r2=226909&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/AttributeValueAssertionFilter.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/AttributeValueAssertionFilter.java
Mon Aug  1 16:48:03 2005
@@ -16,7 +16,13 @@
  */
 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.Value;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.pojo.AttributeValueAssertion;
 
 
@@ -34,6 +40,9 @@
 
     /** The filter type */
     private int filterType;
+    
+    /** The attributeValueAssertion length */
+    private transient int avaLength;
 
     //~ Constructors -------------------------------------------------------------------------------
 
@@ -111,7 +120,7 @@
      */
     public int computeLength()
     {
-        int avaLength = 0;
+        avaLength = 0;
         int attributeDescLength = assertion.getAttributeDesc().length();
         
         avaLength = 1 + Length.getNbBytes( attributeDescLength ) + attributeDescLength;
@@ -123,6 +132,66 @@
         return 1 + Length.getNbBytes( avaLength ) + avaLength;
     }
     
+    /**
+     * Encode the AttributeValueAssertion Filters to a PDU. The 
+     * following filters are to be encoded :
+     *  - equality match 
+     *  - greater or equal
+     *  - less or equal
+     *  - approx match 
+     * 
+     * AttributeValueAssertion filters :
+     * 
+     * 0xA[3, 5, 6, 8] LL attributeDesc
+     * 
+     * @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 AttributeValueAssertion Tag
+            switch (filterType)
+            {
+                case LdapConstants.EQUALITY_MATCH_FILTER :
+                    buffer.put( (byte)LdapConstants.EQUALITY_MATCH_FILTER_TAG );
+                    break;
+                    
+                case LdapConstants.LESS_OR_EQUAL_FILTER :
+                    buffer.put( (byte)LdapConstants.LESS_OR_EQUAL_FILTER_TAG );
+                    break;
+                    
+                case LdapConstants.GREATER_OR_EQUAL_FILTER :
+                    buffer.put( (byte)LdapConstants.GREATER_OR_EQUAL_FILTER_TAG );
+                    break;
+                    
+                case LdapConstants.APPROX_MATCH_FILTER :
+                    buffer.put( (byte)LdapConstants.APPROX_MATCH_FILTER_TAG );
+                    break;
+            }
+            
+            buffer.put( Length.getBytes( avaLength ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+        
+        // The attribute desc
+        Value.encode( buffer, assertion.getAttributeDesc() );
+
+        // The assertion desc
+        Value.encode( buffer, assertion.getAssertionValue() );
+            
+        return buffer;
+    }
+
     /**
      * Return a string compliant with RFC 2254 representing an item filter
      *

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/ConnectorFilter.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/ConnectorFilter.java?rev=226909&r1=226908&r2=226909&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/ConnectorFilter.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/ConnectorFilter.java
Mon Aug  1 16:48:03 2005
@@ -17,7 +17,9 @@
 package org.apache.asn1.ldap.pojo.filters;
 
 import org.apache.asn1.DecoderException;
+import org.apache.asn1.EncoderException;
 
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Iterator;
 
@@ -34,6 +36,9 @@
 
     /** The set of filters used by And/Or filters */
     protected ArrayList filterSet;
+    
+    /** The filters length */
+    protected transient int filtersLength;
 
     //~ Constructors -------------------------------------------------------------------------------
 
@@ -94,6 +99,41 @@
         }
         
         return connectorFilterLength;
+    }
+
+    /**
+     * Encode the ConnectorFilter message to a PDU.
+     * 
+     * ConnectorFilter :
+     * 
+     * filter.encode()
+     * ...
+     * filter.encode()
+     * 
+     * @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 !");
+        }
+
+        // encode each filter
+        if ( ( filterSet != null ) && ( filterSet.size() != 0 ) )
+        {
+            Iterator filterIterator = filterSet.iterator();
+            
+            while ( filterIterator.hasNext() )
+            {
+                Filter filter = (Filter)filterIterator.next();
+                
+                filter.encode( buffer );
+            }
+        }
+            
+        return buffer;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/NotFilter.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/NotFilter.java?rev=226909&r1=226908&r2=226909&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/NotFilter.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/NotFilter.java
Mon Aug  1 16:48:03 2005
@@ -16,8 +16,13 @@
  */
 package org.apache.asn1.ldap.pojo.filters;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
 import org.apache.asn1.DecoderException;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ldap.codec.LdapConstants;
 
 /**
  * Not Filter Object to store the Not filter.
@@ -87,9 +92,43 @@
      */
     public int computeLength()
     {
-        int filtersLength = super.computeLength();
+        filtersLength = super.computeLength();
         
         return 1 + Length.getNbBytes( filtersLength ) + filtersLength;
+    }
+
+    /**
+     * Encode the NotFilter message to a PDU.
+     * 
+     * NotFilter :
+     * 
+     * 0xA2 LL 
+     * filter.encode()
+     * 
+     * @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 NotFilter Tag
+            buffer.put( (byte)LdapConstants.NOT_FILTER_TAG );
+            buffer.put( Length.getBytes( filtersLength ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+        
+        super.encode( buffer );
+            
+        return buffer;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/OrFilter.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/OrFilter.java?rev=226909&r1=226908&r2=226909&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/OrFilter.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/OrFilter.java
Mon Aug  1 16:48:03 2005
@@ -16,9 +16,13 @@
  */
 package org.apache.asn1.ldap.pojo.filters;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ldap.codec.LdapConstants;
 
 
 /**
@@ -61,11 +65,45 @@
      */
     public int computeLength()
     {
-        int filtersLength = super.computeLength();
+        filtersLength = super.computeLength();
         
         return 1 + Length.getNbBytes( filtersLength ) + filtersLength;
     }
     
+    /**
+     * Encode the OrFilter message to a PDU.
+     * 
+     * OrFilter :
+     * 
+     * 0xA1 LL 
+     * filter.encode()
+     * 
+     * @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 OrFilter Tag
+            buffer.put( (byte)LdapConstants.OR_FILTER_TAG );
+            buffer.put( Length.getBytes( filtersLength ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+        
+        super.encode( buffer );
+            
+        return buffer;
+    }
+
     /**
      * Return a string compliant with RFC 2254 representing an OR filter
      *

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/PresentFilter.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/PresentFilter.java?rev=226909&r1=226908&r2=226909&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/PresentFilter.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/filters/PresentFilter.java
Mon Aug  1 16:48:03 2005
@@ -16,7 +16,12 @@
  */
 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.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
 
 
@@ -78,6 +83,40 @@
         return 1 + Length.getNbBytes( attributeDescription.getLength() ) + attributeDescription.getLength();
     }
     
+    /**
+     * Encode the PresentFilter message to a PDU.
+     * 
+     * PresentFilter :
+     * 
+     * 0x87 LL attributeDescription 
+     * 
+     * @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 PresentFilter Tag
+            buffer.put( (byte)LdapConstants.PRESENT_FILTER_TAG );
+            buffer.put( Length.getBytes( attributeDescription.getLength() ) );
+            buffer.put( attributeDescription.getData() );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+        
+        super.encode( buffer );
+            
+        return buffer;
+    }
+
     /**
      * Return a string compliant with RFC 2254 representing a Present filter
      *



Mime
View raw message