directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r366401 - in /directory/trunk/ldap-common/src/main/java/org/apache/ldap/common: codec/LdapMessage.java codec/TwixTransformer.java message/EntryChangeControl.java message/PersistentSearchControl.java
Date Fri, 06 Jan 2006 03:13:11 GMT
Author: akarasulu
Date: Thu Jan  5 19:13:07 2006
New Revision: 366401

URL: http://svn.apache.org/viewcvs?rev=366401&view=rev
Log:
changes ...

 o fixed bug in Twix LdapMessage where controls array was not initialized
 o added transformations from standard Control to Twix Control for response 
   control processing 
 o added more functionality to EntryChangeConrol to adjust what is registered
   for (add, delete, modify or moddn)


Added:
    directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/message/EntryChangeControl.java
Modified:
    directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapMessage.java
    directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java
    directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/message/PersistentSearchControl.java

Modified: directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapMessage.java
URL: http://svn.apache.org/viewcvs/directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapMessage.java?rev=366401&r1=366400&r2=366401&view=diff
==============================================================================
--- directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapMessage.java
(original)
+++ directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapMessage.java
Thu Jan  5 19:13:07 2006
@@ -131,6 +131,10 @@
     public void addControl( Control control )
     {
         currentControl = control;
+        if ( this.controls == null )
+        {
+            this.controls = new ArrayList();
+        }
         this.controls.add( control );
     }
 
@@ -559,7 +563,6 @@
         {
             throw new EncoderException("The PDU buffer size is too small !");
         }
-
 
         // The message Id
         Value.encode( bb, messageId);

Modified: directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java
URL: http://svn.apache.org/viewcvs/directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java?rev=366401&r1=366400&r2=366401&view=diff
==============================================================================
--- directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java
(original)
+++ directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java
Thu Jan  5 19:13:07 2006
@@ -26,10 +26,12 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.ModificationItem;
+import javax.naming.ldap.Control;
 
 import org.apache.asn1.codec.DecoderException;
 import org.apache.asn1.Asn1Object;
 import org.apache.asn1.primitives.OID;
+import org.apache.asn1.util.Asn1StringUtils;
 import org.apache.ldap.common.codec.abandon.AbandonRequest;
 import org.apache.ldap.common.codec.add.AddRequest;
 import org.apache.ldap.common.codec.add.AddResponse;
@@ -679,7 +681,8 @@
         	while ( controls.hasNext() )
         	{
                 ControlImpl neutralControl = null;
-        		Control twixControl = (Control)controls.next();
+        		org.apache.ldap.common.codec.Control twixControl = 
+                    (org.apache.ldap.common.codec.Control) controls.next();
                 
                 if ( twixControl.getControlValue() instanceof PSearchControl )
                 {
@@ -1096,7 +1099,10 @@
     	}
         
 		// We also have to transform the controls...
-		//transformControls( twixMessage, msg );
+        if ( ! msg.getControls().isEmpty() )
+        {
+            transformControls( twixMessage, msg );
+        }
 		
     	if (log.isDebugEnabled())
     	{
@@ -1104,5 +1110,29 @@
     	}
     	
     	return twixMessage;
+    }
+    
+ 
+    private void transformControls( org.apache.ldap.common.codec.LdapMessage twixMessage,
Message msg )
+    {
+        Iterator list = msg.getControls().iterator();
+        while ( list.hasNext() )
+        {
+            Control control = ( Control ) list.next();
+            org.apache.ldap.common.codec.Control twixControl = new org.apache.ldap.common.codec.Control();
+            twixMessage.addControl( twixControl );
+            twixControl.setCriticality( control.isCritical() );
+            twixControl.setControlValue( control.getEncodedValue() );
+            twixControl.setEncodedValue( control.getEncodedValue() );
+            try
+            {
+                twixControl.setControlType( new LdapString( Asn1StringUtils.getBytesUtf8(
control.getID() ) ) );
+            }
+            catch ( LdapStringEncodingException e )
+            {
+                log.error( "failed to encode string for control id", e );
+            }
+            twixControl.setParent( twixMessage );
+        }
     }
 }

Added: directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/message/EntryChangeControl.java
URL: http://svn.apache.org/viewcvs/directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/message/EntryChangeControl.java?rev=366401&view=auto
==============================================================================
--- directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/message/EntryChangeControl.java
(added)
+++ directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/message/EntryChangeControl.java
Thu Jan  5 19:13:07 2006
@@ -0,0 +1,167 @@
+/*
+ *   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.ldap.common.message;
+
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1.util.Asn1StringUtils;
+import org.apache.ldap.common.codec.search.controls.ChangeType;
+import org.apache.ldap.common.codec.util.LdapString;
+import org.apache.ldap.common.codec.util.LdapStringEncodingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A response control that may be returned by Persistent Search entry 
+ * responses.  It contains addition change information to descrive the
+ * exact change that occured to an entry.  The exact details of this 
+ * control are covered in section 5 of this (yes) expired draft:
+ * <a href="http://www3.ietf.org/proceedings/01aug/I-D/draft-ietf-ldapext-psearch-03.txt">
+ * Persistent Search Draft v03</a> which is printed out below for 
+ * convenience:
+ * <pre>
+ *   5.  Entry Change Notification Control
+ *   
+ *   This control provides additional information about the change the caused
+ *   a particular entry to be returned as the result of a persistent search.
+ *   The controlType is "2.16.840.1.113730.3.4.7".  If the client set the
+ *   returnECs boolean to TRUE in the PersistentSearch control, servers MUST
+ *   include an EntryChangeNotification control in the Controls portion of
+ *   each SearchResultEntry that is returned due to an entry being added,
+ *   deleted, or modified.
+ *   
+ *              EntryChangeNotification ::= SEQUENCE 
+ *              {
+ *                        changeType ENUMERATED 
+ *                        {
+ *                                add             (1),
+ *                                delete          (2),
+ *                                modify          (4),
+ *                                modDN           (8)
+ *                        },
+ *                        previousDN   LDAPDN OPTIONAL,     -- modifyDN ops. only
+ *                        changeNumber INTEGER OPTIONAL     -- if supported
+ *              }
+ *   
+ *   changeType indicates what LDAP operation caused the entry to be returned.
+ *   
+ *   previousDN is present only for modifyDN operations and gives the DN of
+ *   the entry before it was renamed and/or moved.  Servers MUST include this
+ *   optional field only when returning change notifications as a result of
+ *   modifyDN operations.
+ *
+ *   changeNumber is the change number [CHANGELOG] assigned by a server for
+ *   the change.  If a server supports an LDAP Change Log it SHOULD include
+ *   this field.
+ *   </pre>
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class EntryChangeControl extends ControlImpl
+{
+    private static final long serialVersionUID = -2356861450876343999L;
+    private static final Logger log = LoggerFactory.getLogger( EntryChangeControl.class );
+    public static final String CONTROL_ID = "2.16.840.1.113730.3.4.7";
+    public static final int UNDEFINED_CHANGE_NUMBER = 
+        org.apache.ldap.common.codec.search.controls.EntryChangeControl.UNDEFINED_CHANGE_NUMBER;
+    
+    private ChangeType changeType = ChangeType.ADD;
+    private int changeNumber = UNDEFINED_CHANGE_NUMBER;
+    private LdapString previousDn = null;
+
+    
+    public EntryChangeControl()
+    {
+        super();
+        setType( CONTROL_ID );
+    }
+    
+    
+    public ChangeType getChangeType()
+    {
+        return changeType;
+    }
+    
+
+    public void setChangeType( ChangeType changeType )
+    {
+        this.changeType = changeType;
+    }
+
+    
+    public String getPreviousDn()
+    {
+        return previousDn.getString();
+    }
+    
+    
+    public void setPreviousDn( String previousDn )
+    {
+        try
+        {
+            this.previousDn = new LdapString( Asn1StringUtils.getBytesUtf8( previousDn )
);
+        }
+        catch ( LdapStringEncodingException e )
+        {
+            e.printStackTrace();
+        }
+    }
+    
+    
+    public void setPreviousDn( LdapString previousDn )
+    {
+        this.previousDn = previousDn;
+    }
+    
+    
+    public int getChangeNumber()
+    {
+        return changeNumber;
+    }
+    
+    
+    public void setChangeNumber( int changeNumber )
+    {
+        this.changeNumber = changeNumber;
+    }
+
+    
+    public byte[] getEncodedValue()
+    {
+        if ( getValue() == null )
+        {
+            // should call this codec or something
+            org.apache.ldap.common.codec.search.controls.EntryChangeControl ecc = 
+                new org.apache.ldap.common.codec.search.controls.EntryChangeControl();
+            ecc.setChangeNumber( changeNumber );
+            ecc.setChangeType( changeType );
+            ecc.setPreviousDn( previousDn );
+            
+            try
+            {
+                setValue( ecc.encode( null ).array() );
+            }
+            catch ( EncoderException e )
+            {
+                log.error( "Failed to encode psearch control", e );
+            }
+        }
+        
+        return getValue();
+    }
+}

Modified: directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/message/PersistentSearchControl.java
URL: http://svn.apache.org/viewcvs/directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/message/PersistentSearchControl.java?rev=366401&r1=366400&r2=366401&view=diff
==============================================================================
--- directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/message/PersistentSearchControl.java
(original)
+++ directory/trunk/ldap-common/src/main/java/org/apache/ldap/common/message/PersistentSearchControl.java
Thu Jan  5 19:13:07 2006
@@ -17,6 +17,7 @@
 package org.apache.ldap.common.message;
 
 import org.apache.asn1.codec.EncoderException;
+import org.apache.ldap.common.codec.search.controls.ChangeType;
 import org.apache.ldap.common.codec.search.controls.PSearchControl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,21 +34,23 @@
     private static final long serialVersionUID = -2356861450876343999L;
     private static final Logger log = LoggerFactory.getLogger( PersistentSearchControl.class
);
     public static final String CONTROL_ID = "2.16.840.1.113730.3.4.3";
+    public static final int ALL_CHANGES = 1 | 2 | 4 | 8;
     
     /** 
      * If changesOnly is TRUE, the server MUST NOT return any existing
      * entries that match the search criteria.  Entries are only
      * returned when they are changed (added, modified, deleted, or 
-     * subject to a modifyDN operation).
+     * subject to a modifyDN operation).  By default this is set to
+     * true.
      */
-    private boolean changesOnly;
+    private boolean changesOnly = true;
 
     /**
      * If returnECs is TRUE, the server MUST return an Entry Change 
      * Notification control with each entry returned as the result of
-     * changes.
+     * changes.  By default this is set to false.
      */
-    private boolean returnECs;
+    private boolean returnECs = false;
     
     /**
      * As changes are made to the server, the effected entries MUST be
@@ -55,9 +58,10 @@
      * teria and if the operation that caused the change is included in
      * the changeTypes field.  The changeTypes field is the logical OR
      * of one or more of these values: add (1), delete (2), modify (4),
-     * modDN (8).
+     * modDN (8).  By default this is set to 1 | 2 | 4 | 8 which is the
+     * int value 0x0F or 15.
      */
-    private int changeTypes;
+    private int changeTypes = ALL_CHANGES;
 
 
     public PersistentSearchControl()
@@ -102,7 +106,19 @@
         return changeTypes;
     }
 
+    
+    public boolean isNotificationEnabled( ChangeType changeType )
+    {
+        return ( changeType.getValue() & changeTypes ) > 0;
+    }
+    
 
+    public void enableNotification( ChangeType changeType )
+    {
+        changeTypes |= changeType.getValue();
+    }
+
+    
     public byte[] getEncodedValue()
     {
         if ( getValue() == null )



Mime
View raw message