directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: r153669 - in incubator/directory/ldap/trunk/snacc-provider: project.xml src/test/PDUGenerator.java src/test/bind.xml
Date Sun, 13 Feb 2005 21:12:33 GMT
Author: vtence
Date: Sun Feb 13 13:12:32 2005
New Revision: 153669

URL: http://svn.apache.org/viewcvs?view=rev&rev=153669
Log:
Removed PDU generation from XML files (no more dependency on xstream)

Removed:
    incubator/directory/ldap/trunk/snacc-provider/src/test/bind.xml
Modified:
    incubator/directory/ldap/trunk/snacc-provider/project.xml
    incubator/directory/ldap/trunk/snacc-provider/src/test/PDUGenerator.java

Modified: incubator/directory/ldap/trunk/snacc-provider/project.xml
URL: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/snacc-provider/project.xml?view=diff&r1=153668&r2=153669
==============================================================================
--- incubator/directory/ldap/trunk/snacc-provider/project.xml (original)
+++ incubator/directory/ldap/trunk/snacc-provider/project.xml Sun Feb 13 13:12:32 2005
@@ -45,15 +45,8 @@
       <artifactId>commons-lang</artifactId>
       <version>2.0</version>
       <url>http://jakarta.apache.org/commons/lang</url>
-    </dependency>
-    
-    <dependency>
-      <groupId>xstream</groupId>
-      <artifactId>xstream</artifactId>
-      <version>1.0.2</version>
-      <url>http://xstream.codehaus.org</url>
     </dependency>
-</dependencies>
+  </dependencies>
     
   <reports>
     <report>maven-changelog-plugin</report>

Modified: incubator/directory/ldap/trunk/snacc-provider/src/test/PDUGenerator.java
URL: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/snacc-provider/src/test/PDUGenerator.java?view=diff&r1=153668&r2=153669
==============================================================================
--- incubator/directory/ldap/trunk/snacc-provider/src/test/PDUGenerator.java (original)
+++ incubator/directory/ldap/trunk/snacc-provider/src/test/PDUGenerator.java Sun Feb 13 13:12:32
2005
@@ -2,17 +2,19 @@
  * Copyright (c) 2005 Your Corporation. All Rights Reserved.
  */
 
-import com.thoughtworks.xstream.XStream;
+import org.apache.ldap.common.filter.BranchNormalizedVisitor;
+import org.apache.ldap.common.filter.ExprNode;
+import org.apache.ldap.common.filter.FilterParserImpl;
+import org.apache.ldap.common.message.DerefAliasesEnum;
 import org.apache.ldap.common.message.Message;
 import org.apache.ldap.common.message.MessageEncoder;
-import org.apache.ldap.common.message.UnbindRequest;
-import org.apache.ldap.common.message.UnbindRequestImpl;
+import org.apache.ldap.common.message.ScopeEnum;
+import org.apache.ldap.common.message.SearchRequestImpl;
 import org.apache.ldap.common.message.spi.Provider;
 
-import java.io.FileReader;
 import java.io.IOException;
-import java.io.Reader;
 import java.nio.ByteBuffer;
+import java.text.ParseException;
 import java.util.Properties;
 
 /**
@@ -23,9 +25,6 @@
  * Proceed by changing the message() method to return the message
  * to encode. The main() method will display the corresponded encoded
  * PDU byte sequence.
- * <p>
- * Another option is to specify a file containing an XStreamed message as
- * an argument. See the bind.xml file for an example.
  */
 public class PDUGenerator
 {
@@ -46,24 +45,7 @@
         ByteBuffer buf = m_encoder.encodeBlocking( msg );
         byte[] bites = new byte[ buf.remaining() ];
         buf.get( bites );
-        /**
-         * For some reason snacc appends PDUs with an A0 00
-         * sequence. Get rid of it.
-         */
-        return removeTrailingSequence( bites );
-    }
-
-    private byte[] removeTrailingSequence( byte[] bites )
-    {
-        byte[] trimmed = new byte[ bites.length - 2 ];
-        System.arraycopy( bites, 0, trimmed, 0, trimmed.length );
-        adjustLengthValue( trimmed, -2 );
-        return trimmed;
-    }
-
-    private void adjustLengthValue( byte[] pdu, int adjustment )
-    {
-        pdu[1] = (byte) (pdu[1] + adjustment);
+        return bites;
     }
 
     private String toString( byte[] bites )
@@ -85,57 +67,39 @@
         return sb.toString();
     }
 
-    public static Message hardCodedMessage()
+    public static Message hardCodedMessage() throws IOException, ParseException
     {
-        UnbindRequest req = new UnbindRequestImpl( 44 ) ;
+        SearchRequestImpl req = new SearchRequestImpl( 33 );
+        req.setBase( "dc=example,dc=com" );
+        req.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        req.setScope( ScopeEnum.BASEOBJECT );
+        req.setSizeLimit( 2);
+        req.setTimeLimit( 3 );
+        req.setTypesOnly( true );
+
+        req.addAttribute( "attr0" );
+        req.addAttribute( "attr1" );
+        req.addAttribute( "attr2" );
+
+        FilterParserImpl parser = new FilterParserImpl();
+        ExprNode node = null ;
+        node = parser.parse(
+                "( | ( ou = Human Resources ) ( l=Santa Clara ) " +
+                "( uid=akarasulu ) ( cn=aok ) ( cn=aok ) ( cn = abok) )" ) ;
+        new BranchNormalizedVisitor().visit( node );
+        req.setFilter( node );
 
         return req;
     }
 
-    public static void main( String[] args )
+    public static void main( String[] args ) throws Exception
     {
-        final Message msg;
-        if (fileNameSpecified( args ))
-        {
-            String fileName = args[0];
-            System.out.println( "Reading message from file: " + fileName );
-            msg = readMessageFromFile( fileName );
-        }
-        else
-        {
-            msg = hardCodedMessage();
-        }
-
+        final Message msg = hardCodedMessage();
         Properties env = new Properties();
         env.setProperty( Provider.BERLIB_PROVIDER,
                 "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
         PDUGenerator generator = new PDUGenerator( env );
 
         System.out.println( generator.generatePDU( msg ) );
-
-    }
-
-    private static boolean fileNameSpecified( String[] args )
-    {
-        return args.length != 0;
-    }
-
-    private static Message readMessageFromFile( String fileName )
-    {
-        XStream xstream = new XStream();
-        Message msg = null;
-        try
-        {
-            Reader reader = new FileReader( fileName );
-            msg = (Message) xstream.fromXML( reader );
-            reader.close();
-        }
-        catch ( IOException e )
-        {
-            e.printStackTrace();
-            System.exit(1);
-        }
-
-        return msg;
     }
 }



Mime
View raw message