harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r590944 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/provider/ldap/ main/java/org/apache/harmony/jndi/provider/ldap/asn1/ test/java/org/apache/harmony/jndi/provider/ldap/ test/java/org/apache/har...
Date Thu, 01 Nov 2007 09:28:43 GMT
Author: leoli
Date: Thu Nov  1 02:28:42 2007
New Revision: 590944

URL: http://svn.apache.org/viewvc?rev=590944&view=rev
Log:
Apply patch for HARMONY-49719([classlib][ldap] Add search function for ldap service provider).

Added:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/Filter.java   (with props)
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java   (with props)
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java   (with props)
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java   (with props)
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Null.java   (with props)
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java   (with props)
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java   (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Decodable.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Encodable.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1TestUtils.java

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/Filter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/Filter.java?rev=590944&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/Filter.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/Filter.java Thu Nov  1 02:28:42 2007
@@ -0,0 +1,263 @@
+/* 
+ *  Licensed to the Apache Software Foundation (ASF) under one or more 
+ *  contributor license agreements.  See the NOTICE file distributed with 
+ *  this work for additional information regarding copyright ownership. 
+ *  The ASF licenses this file to You 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.harmony.jndi.provider.ldap;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1ChoiceWrap;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1ChoiceWrap.ChosenValue;
+
+/**
+ * This class represents Ldap search filter, and can be encoded according to
+ * ASN.1. There are ten differents filter types, and two of them ('and' filter
+ * and 'or' filter) is composited by several filters. So we represent filter by
+ * tree: the branch of the tree should be filter of composited tye, 'and' filter
+ * or 'or' filter. the leaf of the tree should be filter of atom type (contrast
+ * to composited type). For one node tree, the node must be atom type filter.
+ * 
+ * The type number of a filter is the same as index according to Filter type,
+ * defined in RFC 2251, 4.5.1. We haved defined constants for each type, such as
+ * <code>AND_FILTER</code>.
+ * 
+ * @see org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant#Filter
+ * @see org.apache.harmony.jndi.provider.ldap.asn1.ASN1LdapFilter
+ */
+public class Filter implements ASN1Encodable {
+    public static final int AND_FILTER = 0;
+
+    public static final int OR_FILTER = 1;
+
+    public static final int NOT_FILTER = 2;
+
+    public static final int EQUALITY_MATCH_FILTER = 3;
+
+    public static final int SUBSTRINGS_FILTER = 4;
+
+    public static final int GREATER_OR_EQUAL_FILTER = 5;
+
+    public static final int LESS_OR_EQUAL_FILTER = 6;
+
+    public static final int PRESENT_FILTER = 7;
+
+    public static final int APPROX_MATCH_FILTER = 8;
+
+    public static final int EXTENSIBLE_MATCH_FILTER = 9;
+
+    /**
+     * index of the Filter type defined in RFC 2251, 4.5.1, is the same as
+     * number of filter type.
+     */
+    private int index;
+
+    /**
+     * actual data of the filter. We use this variable hold filter data for both
+     * coposite and atom filter. If the filter is composite, <code>value</code>
+     * is <code>List<Filter></code>.
+     */
+    private Object value;
+
+    private boolean isLeaf;
+
+    public Filter(int type) {
+        if (type < 0 || type > 9) {
+            // TODO: it's a internal error, should add the error message to the
+            // resource file?
+            throw new IllegalArgumentException(
+                    "Not a valided filter type: only 0 - 9 is allowed.");
+        }
+
+        this.index = type;
+        if (0 == index || 1 == index) {
+            isLeaf = false;
+            value = new ArrayList<Filter>();
+        } else {
+            isLeaf = true;
+        }
+    }
+
+    public void encodeValues(Object[] values) {
+        Object encoded;
+        if (value instanceof String) {
+            encoded = Utils.getBytes((String) value);
+        } else if (value instanceof AttributeTypeAndValuePair) {
+            AttributeTypeAndValuePair pair = (AttributeTypeAndValuePair) value;
+            Object[] objs = new Object[2];
+            objs[0] = Utils.getBytes(pair.getType());
+            objs[1] = pair.getValue();
+            if (objs[1] instanceof String) {
+                objs[1] = Utils.getBytes((String) objs[1]);
+            }
+            encoded = objs;
+        } else {
+            encoded = value;
+        }
+
+        values[0] = new ASN1ChoiceWrap.ChosenValue(index, encoded);
+    }
+
+    /**
+     * test whether this filter is atom filter.
+     * 
+     * @return true if this filter is atom
+     */
+    public boolean isLeaf() {
+        return isLeaf;
+    }
+
+    /**
+     * get all children filters
+     * 
+     * @return all children filters. If the filter is atom, <code>null</code>
+     *         will be return. If the filter is composite but no child has been
+     *         added, empty of <code>List<Filter></code> will be returned.
+     */
+    @SuppressWarnings("unchecked")
+    public List<Filter> getChildren() {
+        if (!isLeaf) {
+            return (List<Filter>) value;
+        }
+        return null;
+
+    }
+
+    /**
+     * only for composite filter type. if invoked on atom filter, do nothing.
+     * 
+     * @param child
+     *            filter to be added as child, should not be <code>null</code>
+     */
+    @SuppressWarnings("unchecked")
+    public void addChild(Filter child) {
+        if (!isLeaf) {
+            List<Filter> children = (List<Filter>) value;
+            children.add(child);
+        }
+    }
+
+    public void setValue(Object value) {
+        this.value = value;
+    }
+
+    public int getType() {
+        return index;
+    }
+
+    public Object getValue() {
+        return value;
+    }
+
+    public static class MatchingRuleAssertion implements ASN1Encodable {
+
+        private String matchingRule;
+
+        private String type;
+
+        private String matchValue;
+
+        private boolean dnAttributes = false;
+
+        public boolean isDnAttributes() {
+            return dnAttributes;
+        }
+
+        public void setDnAttributes(boolean dnAttributes) {
+            this.dnAttributes = dnAttributes;
+        }
+
+        public String getMatchingRule() {
+            return matchingRule;
+        }
+
+        public void setMatchingRule(String matchingRule) {
+            this.matchingRule = matchingRule;
+        }
+
+        public String getMatchValue() {
+            return matchValue;
+        }
+
+        public void setMatchValue(String matchValue) {
+            this.matchValue = matchValue;
+        }
+
+        public String getType() {
+            return type;
+        }
+
+        public void setType(String type) {
+            this.type = type;
+        }
+
+        public void encodeValues(Object[] values) {
+            values[0] = Utils.getBytes(matchingRule);
+            values[1] = Utils.getBytes(type);
+            values[2] = Utils.getBytes(matchValue);
+            values[3] = Boolean.valueOf(dnAttributes);
+        }
+
+    }
+
+    public static class SubstringFilter implements ASN1Encodable {
+        private String type;
+
+        private List<ChosenValue> substrings;
+
+        public SubstringFilter(String type) {
+            this.type = type;
+            substrings = new ArrayList<ChosenValue>();
+        }
+
+        public List<ChosenValue> getSubstrings() {
+            return substrings;
+        }
+
+        public String getType() {
+            return type;
+        }
+
+        public void addInitial(String initial) {
+            substrings.add(new ChosenValue(0, initial));
+        }
+
+        public void addAny(String any) {
+            substrings.add(new ChosenValue(1, any));
+        }
+
+        public void addFinal(String initial) {
+            substrings.add(new ChosenValue(2, initial));
+        }
+
+        public void encodeValues(Object[] values) {
+            values[0] = Utils.getBytes(type);
+            ArrayList<ChosenValue> encoded = new ArrayList<ChosenValue>(
+                    substrings.size());
+            for (ChosenValue value : substrings) {
+                // FIXME: deal with binary value
+                encoded.add(new ChosenValue(value.getIndex(), Utils
+                        .getBytes((String) value.getValue())));
+            }
+            values[1] = encoded;
+        }
+
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/Filter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java?rev=590944&r1=590943&r2=590944&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java Thu Nov  1 02:28:42 2007
@@ -28,6 +28,8 @@
 
 import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Decodable;
 import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+import org.apache.harmony.security.asn1.ASN1Integer;
 
 /**
  * LdapClient is the actual class used to communicate with Ldap Server.
@@ -108,6 +110,31 @@
         out.flush();
         LdapMessage responseMsg = new LdapMessage(response);
         responseMsg.decode(in);
+        if (opIndex == LdapASN1Constant.OP_SEARCH_REQUEST
+                && responseMsg.getOperationIndex() != LdapASN1Constant.OP_SEARCH_RESULT_DONE) {
+            responseMsg = new LdapMessage(response);
+            responseMsg.decode(in);
+        }
         return responseMsg;
+    }
+    public void abandon(final int messageId, Control[] controls)
+            throws IOException {
+        doOperationWithoutResponse(LdapASN1Constant.OP_ABANDON_REQUEST,
+                new ASN1Encodable() {
+
+                    public void encodeValues(Object[] values) {
+                        values[0] = ASN1Integer.fromIntValue(messageId);
+                    }
+
+                }, controls);
+    }
+    public void doOperationWithoutResponse(int opIndex, ASN1Encodable op,
+            Control[] controls) throws IOException {
+        LdapMessage request = new LdapMessage(opIndex, op, controls);
+        out.write(request.encode());
+        out.flush();
+    }
+    public void close() throws IOException {
+        socket.close();
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java?rev=590944&r1=590943&r2=590944&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java Thu Nov  1 02:28:42 2007
@@ -33,7 +33,7 @@
  * detailed information
  * 
  */
-public class LdapMessage implements ASN1Encodable {
+public class LdapMessage implements ASN1Encodable, ASN1Decodable {
     
     /**
      * operation request which could be encoded using ASN.1 BER
@@ -66,7 +66,14 @@
     public static synchronized int getNextMessageId() {
         return nextMessageId++;
     }
-    
+    /**
+     * Get message id of this message
+     * 
+     * @return id of this message
+     */
+    public int getMessageId() {
+        return messageId;
+    }
     /**
      * Construct a request message. <code>op</code> may not be
      * <code>null</code>. <code>controls</code> is <code>null</code> or a
@@ -131,13 +138,23 @@
         }
         ChosenValue chosen = (ChosenValue) values[1];
         opIndex = chosen.getIndex();
-        responseOp.decodeValues((Object[]) chosen.getValue());
+        if (opIndex == LdapASN1Constant.OP_SEARCH_RESULT_DONE
+                || opIndex == LdapASN1Constant.OP_SEARCH_RESULT_ENTRY
+                || opIndex == LdapASN1Constant.OP_SEARCH_RESULT_REF) {
+            /*
+             * we use LdapSearchResult to decode all types of search responses,
+             * so we need index to determine which type of response to decode
+             */
+            responseOp.decodeValues(new Object[] { chosen });
+        } else {
+            responseOp.decodeValues((Object[]) chosen.getValue());
+        }
 
     }
 
     public void encodeValues(Object[] values) {
         values[0] = ASN1Integer.fromIntValue(messageId);
-        // DelRequest are ASN.1 primitive
+        // Abandon & DelRequest are ASN.1 primitive
         if (opIndex == LdapASN1Constant.OP_ABANDON_REQUEST
                 || opIndex == LdapASN1Constant.OP_DEL_REQUEST) {
             Object[] objs = new Object[1];
@@ -153,7 +170,14 @@
      * 
      * @return id of this message
      */
-    public int getMessageId() {
-        return messageId;
+    /**
+     * Get index of the operation, determine which operation is encapsulated in
+     * this message. If this <code>LdapMessage</code> instance is not initial,
+     * <code>-1</code> will be returned.
+     * 
+     * @return index of the operation encapsulated in the message
+     */
+    public int getOperationIndex() {
+        return opIndex;
     }
 }

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java?rev=590944&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java Thu Nov  1 02:28:42 2007
@@ -0,0 +1,133 @@
+/* 
+ *  Licensed to the Apache Software Foundation (ASF) under one or more 
+ *  contributor license agreements.  See the NOTICE file distributed with 
+ *  this work for additional information regarding copyright ownership. 
+ *  The ASF licenses this file to You 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.harmony.jndi.provider.ldap;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.SearchResult;
+
+import org.apache.harmony.jndi.provider.dns.BasicNamingEnumerator;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1ChoiceWrap.ChosenValue;
+
+public class LdapSearchResult {
+
+    /**
+     * all search result entries
+     */
+    private Map<String, SearchResult> entries = new HashMap<String, SearchResult>();
+
+    /**
+     * SearchResultReference from server
+     * TODO: deal with the references
+     */
+    private List<String> refURLs = new ArrayList<String>();
+
+    private LdapResult result;
+
+    public void decodeSearchResponse(Object[] values) {
+        ChosenValue chosen = (ChosenValue) values[0];
+        switch (chosen.getIndex()) {
+        case LdapASN1Constant.OP_SEARCH_RESULT_ENTRY:
+            decodeEntry(chosen.getValue());
+            break;
+        case LdapASN1Constant.OP_SEARCH_RESULT_REF:
+            decodeRef(chosen.getValue());
+            break;
+        case LdapASN1Constant.OP_SEARCH_RESULT_DONE:
+            decodeDone(chosen.getValue());
+            break;
+        }
+    }
+
+    private void decodeDone(Object value) {
+        result = new LdapResult();
+        result.decodeValues((Object[]) value);
+    }
+
+    private void decodeRef(Object value) {
+        Collection<byte[]> list = (Collection<byte[]>) value;
+        for (byte[] bs : list) {
+            refURLs.add(Utils.getString(bs));
+        }
+    }
+
+    private void decodeEntry(Object value) {
+        Object[] values = (Object[]) value;
+        String name = Utils.getString((byte[]) values[0]);
+        Attributes attrs = null;
+
+        if (entries.containsKey(name)) {
+            attrs = entries.get(name).getAttributes();
+        } else {
+            attrs = new BasicAttributes();
+            entries.put(name, new SearchResult(name, new Object(), attrs));
+        }
+
+        Collection<Object[]> list = (Collection<Object[]>) values[1];
+        for (Object[] objects : list) {
+            LdapAttribute attr = new LdapAttribute();
+            attr.decodeValues(objects);
+            attrs.put(attr);
+        }
+    }
+
+    public NamingEnumeration<SearchResult> getEnumeration() {
+        //TODO: this is simple implementation, need to be completed
+        return new BasicNamingEnumerator<SearchResult>(
+                new Enumeration<SearchResult>() {
+                    private ArrayList<SearchResult> values = new ArrayList<SearchResult>(
+                            entries.values());
+
+                    private int index = -1;
+
+                    public boolean hasMoreElements() {
+                        if (index == -1) {
+                            index = 0;
+                        }
+                        
+                        if (index + 1 <= values.size()) {
+                            return true;
+                        }
+
+                        return false;
+                    }
+
+                    public SearchResult nextElement() {
+                        return values.get(index++);
+                    }
+                });
+    }
+
+    public List<String> getRefURLs() {
+        return refURLs;
+    }
+
+    public LdapResult getResult() {
+        return result;
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java?rev=590944&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java Thu Nov  1 02:28:42 2007
@@ -0,0 +1,102 @@
+/* 
+ *  Licensed to the Apache Software Foundation (ASF) under one or more 
+ *  contributor license agreements.  See the NOTICE file distributed with 
+ *  this work for additional information regarding copyright ownership. 
+ *  The ASF licenses this file to You 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.harmony.jndi.provider.ldap;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.directory.SearchControls;
+
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Decodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+import org.apache.harmony.security.asn1.ASN1Integer;
+
+public class SearchOp implements LdapOperation, ASN1Encodable,
+        ASN1Decodable {
+    private String baseObject;
+
+    private boolean typesOnly = false;
+
+    private Filter filter;
+
+    private SearchControls controls;
+
+    private LdapSearchResult result = new LdapSearchResult();
+
+    public LdapSearchResult getResult() {
+        return result;
+    }
+
+    public SearchOp(String baseObject, SearchControls controls,
+            Filter filter) {
+        this.baseObject = baseObject;
+        this.controls = controls;
+        this.filter = filter;
+    }
+
+    public ASN1Encodable getRequest() {
+        return this;
+    }
+
+    public int getRequestId() {
+        return LdapASN1Constant.OP_SEARCH_REQUEST;
+    }
+
+    public ASN1Decodable getResponse() {
+        return this;
+    }
+
+    public int getResponseId() {
+        return LdapASN1Constant.OP_SEARCH_RESULT_DONE;
+    }
+
+    public void encodeValues(Object[] values) {
+        values[0] = Utils.getBytes(baseObject);
+        values[1] = ASN1Integer.fromIntValue(controls.getSearchScope());
+        if (controls.getDerefLinkFlag()) {
+            // derefAlways
+            values[2] = ASN1Integer.fromIntValue(3);
+        } else {
+            // neverDerefAliases
+            values[2] = ASN1Integer.fromIntValue(0);
+        }
+        values[3] = ASN1Integer.fromIntValue((int) controls.getCountLimit());
+        values[4] = ASN1Integer.fromIntValue(controls.getTimeLimit());
+        values[5] = Boolean.valueOf(typesOnly);
+        values[6] = filter;
+        String[] attributes = controls.getReturningAttributes();
+        if (attributes == null) {
+            attributes = new String[] { "" };
+        }
+
+        List<byte[]> list = new ArrayList<byte[]>(attributes.length);
+        for (String attribute : attributes) {
+            list.add(Utils.getBytes(attribute));
+        }
+        values[7] = list;
+
+    }
+
+    public void decodeValues(Object[] values) {
+        
+        result.decodeSearchResponse(values);
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Decodable.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Decodable.java?rev=590944&r1=590943&r2=590944&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Decodable.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Decodable.java Thu Nov  1 02:28:42 2007
@@ -20,6 +20,9 @@
 /**
  * Retrieves data from ASN.1 data stream.
  * 
+ * @see org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable
+ * @see org.apache.harmony.jndi.provider.ldap.asn1.ASN1ChoiceWrap
+ * @see org.apache.harmony.jndi.provider.ldap.asn1.ASN1SequenceWrap
  */
 public interface ASN1Decodable {
 

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Encodable.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Encodable.java?rev=590944&r1=590943&r2=590944&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Encodable.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Encodable.java Thu Nov  1 02:28:42 2007
@@ -21,6 +21,9 @@
  * This interface is responsible for encoding data according to ASN.1 type schema.
  * Below is type mapping between ASN.1 and Java.
  * <p>
+ * Note: the mapping of SEQUENCE and CHOICE is supported only when using
+ * corresponding wrapped class ASN1SequenceWrap and ASN1ChoiceWrap
+ * <p>
  * <code>
  * ASN.1                Java
  * BOOLEAN              Boolean
@@ -33,6 +36,8 @@
  * CHOICE               Object[] or ChosenValue
  * </code>
  * 
+ * @see org.apache.harmony.jndi.provider.ldap.asn1.ASN1ChoiceWrap
+ * @see org.apache.harmony.jndi.provider.ldap.asn1.ASN1SequenceWrap
  */
 public interface ASN1Encodable {
 

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java?rev=590944&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java Thu Nov  1 02:28:42 2007
@@ -0,0 +1,76 @@
+/* 
+ *  Licensed to the Apache Software Foundation (ASF) under one or more 
+ *  contributor license agreements.  See the NOTICE file distributed with 
+ *  this work for additional information regarding copyright ownership. 
+ *  The ASF licenses this file to You 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.harmony.jndi.provider.ldap.asn1;
+
+import java.io.IOException;
+
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1ChoiceWrap.ChosenValue;
+import org.apache.harmony.security.asn1.ASN1Choice;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+import org.apache.harmony.security.asn1.BerOutputStream;
+
+/**
+ * This class deal with recursive definition of ASN.1 choice type, it's used to
+ * define Ldap Filter type schema.
+ */
+public class ASN1LdapFilter extends ASN1Type {
+
+    private static ASN1Choice type = null;
+
+    public ASN1LdapFilter() {
+        super(TAG_CHOICE); // has not tag number
+    }
+
+    @Override
+    public final boolean checkTag(int identifier) {
+        return true;
+    }
+
+    @Override
+    public Object decode(BerInputStream in) throws IOException {
+        return null;
+    }
+
+    @Override
+    public void encodeASN(BerOutputStream out) {
+        if (type == null) {
+            type = (ASN1Choice) LdapASN1Constant.Filter;
+        }
+        ChosenValue chosen = (ChosenValue) out.content;
+        int index = chosen.getIndex();
+        byte[] bytes = type.type[index].encode(chosen.getValue());
+        out.content = bytes;
+        out.length = bytes.length;
+        // TODO: Any way better to do this(append out.content to out.encoded)?
+        out.encodeString();
+    }
+
+    @Override
+    public void encodeContent(BerOutputStream out) {
+        // FIXME: do nothing if never be called
+        throw new RuntimeException();
+    }
+
+    @Override
+    public void setEncodingContent(BerOutputStream out) {
+        // FIXME: do nothing if never be called
+        throw new RuntimeException();
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Null.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Null.java?rev=590944&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Null.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Null.java Thu Nov  1 02:28:42 2007
@@ -0,0 +1,59 @@
+/* 
+ *  Licensed to the Apache Software Foundation (ASF) under one or more 
+ *  contributor license agreements.  See the NOTICE file distributed with 
+ *  this work for additional information regarding copyright ownership. 
+ *  The ASF licenses this file to You 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.harmony.jndi.provider.ldap.asn1;
+
+import java.io.IOException;
+
+import org.apache.harmony.security.asn1.ASN1Constants;
+import org.apache.harmony.security.asn1.ASN1Primitive;
+import org.apache.harmony.security.asn1.BerInputStream;
+import org.apache.harmony.security.asn1.BerOutputStream;
+
+/**
+ * This class represents ASN.1 Null type.
+ */
+public class ASN1Null extends ASN1Primitive {
+    private static final ASN1Null asn1Null = new ASN1Null();
+
+    public static ASN1Null getInstance() {
+        return asn1Null;
+    }
+
+    private ASN1Null() {
+        super(ASN1Constants.TAG_NULL);
+    }
+
+    @Override
+    public Object decode(BerInputStream in) throws IOException {
+        if (in.tag != ASN1Constants.TAG_NULL || in.getLength() != 0) {
+            throw new IOException();
+        }
+        return new byte[0];
+    }
+
+    @Override
+    public void encodeContent(BerOutputStream out) {
+        // do nothing
+    }
+
+    @Override
+    public void setEncodingContent(BerOutputStream out) {
+        out.length = 0;
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1Null.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java?rev=590944&r1=590943&r2=590944&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/LdapASN1Constant.java Thu Nov  1 02:28:42 2007
@@ -36,34 +36,42 @@
     public static final int OP_BIND_REQUEST = 0;
 
     public static final int OP_BIND_RESPONSE = 1;
+    
+    public static final int OP_SEARCH_REQUEST = 2;
+
+    public static final int OP_SEARCH_RESULT_ENTRY = 3;
 
+    public static final int OP_SEARCH_RESULT_DONE = 4;
+
+    public static final int OP_SEARCH_RESULT_REF = 5;
+    
     // FIXME change them to appropriate index number in the future.
-    public static final int OP_MODIFY_REQUEST = 2;
+    public static final int OP_MODIFY_REQUEST = 6;
     
-    public static final int OP_MODIFY_RESPONSE = 3;
+    public static final int OP_MODIFY_RESPONSE = 7;
 
-    public static final int OP_ADD_REQUEST = 4;
+    public static final int OP_ADD_REQUEST = 8;
     
-    public static final int OP_ADD_RESPONSE = 5;
+    public static final int OP_ADD_RESPONSE = 9;
     
-    public static final int OP_DEL_REQUEST = 6;
+    public static final int OP_DEL_REQUEST = 10;
 
-    public static final int OP_DEL_RESPONSE = 7;
+    public static final int OP_DEL_RESPONSE = 11;
 
-    public static final int OP_MODIFY_DN_REQUEST = 8;
+    public static final int OP_MODIFY_DN_REQUEST = 12;
     
-    public static final int OP_MODIFY_DN_RESPONSE = 9;
+    public static final int OP_MODIFY_DN_RESPONSE = 13;
 
-    public static final int OP_COMPARE_REQUEST = 10;
+    public static final int OP_COMPARE_REQUEST = 14;
     
-    public static final int OP_COMPARE_RESPONSE = 11;
+    public static final int OP_COMPARE_RESPONSE = 15;
 
-    public static final int OP_ABANDON_REQUEST = 12;
+    public static final int OP_ABANDON_REQUEST = 16;
 
-    public static final int OP_EXTENDED_REQUEST = 13;
+    public static final int OP_EXTENDED_REQUEST = 17;
+    
+    public static final int OP_EXTENDED_RESPONSE = 18;
     
-    public static final int OP_EXTENDED_RESPONSE = 14;
-
     public static final ASN1Type Attribute = new ASN1SequenceWrap(
             new ASN1Type[] { ASN1OctetString.getInstance(), // type
                     new ASN1SetOf(ASN1OctetString.getInstance()) }); // vals
@@ -134,6 +142,9 @@
                         }
                     }));
     
+    public static final ASN1Type UnbindRequest = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 2, ASN1Null.getInstance());
+    
     public static final ASN1Type AttributeValueAssertion = new ASN1SequenceWrap(
             new ASN1Type[] { ASN1OctetString.getInstance(), // attributeDesc
                     ASN1OctetString.getInstance() }); // assertionValue
@@ -223,12 +234,105 @@
     public static final ASN1Type ModifyResponse = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 7, LDAPResult);
     
+    public static final ASN1Type SubstringFilter = new ASN1SequenceWrap(
+            new ASN1Type[] {
+                    ASN1OctetString.getInstance(), // type
+                    new ASN1SequenceOf(
+                            new ASN1ChoiceWrap(new ASN1Type[] { // substrings
+                                            new ASN1Implicit(
+                                                    // initial
+                                                    ASN1Constants.CLASS_CONTEXTSPECIFIC,
+                                                    0, ASN1OctetString
+                                                            .getInstance()),
+                                            new ASN1Implicit(
+                                                    // any
+                                                    ASN1Constants.CLASS_CONTEXTSPECIFIC,
+                                                    1, ASN1OctetString
+                                                            .getInstance()),
+                                            new ASN1Implicit(
+                                                    // final
+                                                    ASN1Constants.CLASS_CONTEXTSPECIFIC,
+                                                    2, ASN1OctetString
+                                                            .getInstance()) })) });
+    
+    public static final ASN1Type MatchingRuleAssertion = new ASN1SequenceWrap(
+            new ASN1Type[] {
+                    new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 1, // matchingRule
+                            ASN1OctetString.getInstance()),
+                    new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 2, // type
+                            ASN1OctetString.getInstance()),
+                    new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 3, // matchValue
+                            ASN1OctetString.getInstance()),
+                    new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 4, // dnAttributes
+                            ASN1Boolean.getInstance()) }) {
+        {
+            setOptional(0);
+            setOptional(1);
+            setDefault(Boolean.FALSE, 3);
+        }
+    };
+    
+    public static final ASN1Type Filter = new ASN1ChoiceWrap(new ASN1Type[] {
+            new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 0,
+                    new ASN1SetOf(new ASN1LdapFilter())),
+            new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 1,
+                    new ASN1SetOf(new ASN1LdapFilter())),
+            new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 2,
+                    new ASN1LdapFilter()),
+            new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 3,
+                    AttributeValueAssertion),
+            new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 4,
+                    SubstringFilter),
+            new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 5,
+                    AttributeValueAssertion),
+            new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 6,
+                    AttributeValueAssertion),
+            new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 7,
+                    ASN1OctetString.getInstance()),
+            new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 8,
+                    AttributeValueAssertion),
+            new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 9,
+                    MatchingRuleAssertion) });
+    
+    public static final ASN1Type SearchRequest = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 3,
+            new ASN1SequenceWrap(new ASN1Type[] {
+                    ASN1OctetString.getInstance(), // baseObject
+                    ASN1Enumerated.getInstance(), // scope
+                    ASN1Enumerated.getInstance(), // derefAliases
+                    ASN1Integer.getInstance(), // sizeLimit
+                    ASN1Integer.getInstance(), // timeLimit
+                    ASN1Boolean.getInstance(), // typesonly
+                    Filter, // Filter
+                    new ASN1SequenceOf(ASN1OctetString.getInstance()) })); // attributes
+    
+    public static final ASN1Type PartialAttributeList = new ASN1SequenceOf(
+            new ASN1SequenceWrap(new ASN1Type[] {
+                    ASN1OctetString.getInstance(), // type
+                    new ASN1SetOf(ASN1OctetString.getInstance()) })); // vals
+    
+    public static final ASN1Type SearchResultEntry = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 4, new ASN1SequenceWrap(
+                    new ASN1Type[] { ASN1OctetString.getInstance(), // objectName
+                            PartialAttributeList })); // attributes
+    
+    public static final ASN1Type SearchResultReference = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 19, new ASN1SequenceOf(
+                    ASN1OctetString.getInstance()));
+    
+    public static final ASN1Type SearchResultDone = new ASN1Implicit(
+            ASN1Constants.CLASS_APPLICATION, 5, LDAPResult);
+    
     public static final ASN1Type LDAPMessage = new ASN1SequenceWrap(
             new ASN1Type[] {
                     ASN1Integer.getInstance(),
                     new ASN1ChoiceWrap(new ASN1Type[] { 
                             BindRequest,
                             BindResponse,
+                            SearchRequest,
+                            SearchResultEntry, 
+                            SearchResultDone,
+                            SearchResultReference, 
                             ModifyRequest,
                             ModifyResponse, 
                             AddRequest,

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java?rev=590944&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java Thu Nov  1 02:28:42 2007
@@ -0,0 +1,94 @@
+package org.apache.harmony.jndi.provider.ldap;
+
+import java.util.ArrayList;
+
+import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
+import org.apache.harmony.jndi.provider.ldap.Filter.SubstringFilter;
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1TestUtils;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+
+import junit.framework.TestCase;
+
+public class FilterTest extends TestCase {
+    private Filter filter;
+
+    public void test_constructor_I() {
+        filter = new Filter(Filter.APPROX_MATCH_FILTER);
+        assertTrue(filter.isLeaf());
+        filter = new Filter(Filter.EQUALITY_MATCH_FILTER);
+        assertTrue(filter.isLeaf());
+        filter = new Filter(Filter.EXTENSIBLE_MATCH_FILTER);
+        assertTrue(filter.isLeaf());
+        filter = new Filter(Filter.GREATER_OR_EQUAL_FILTER);
+        assertTrue(filter.isLeaf());
+        filter = new Filter(Filter.LESS_OR_EQUAL_FILTER);
+        assertTrue(filter.isLeaf());
+        filter = new Filter(Filter.NOT_FILTER);
+        assertTrue(filter.isLeaf());
+        filter = new Filter(Filter.PRESENT_FILTER);
+        assertTrue(filter.isLeaf());
+        filter = new Filter(Filter.SUBSTRINGS_FILTER);
+        assertTrue(filter.isLeaf());
+
+        filter = new Filter(Filter.AND_FILTER);
+        assertFalse(filter.isLeaf());
+
+        filter = new Filter(Filter.OR_FILTER);
+        assertFalse(filter.isLeaf());
+
+        try {
+            filter = new Filter(-1);
+            fail("Should throws IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        try {
+            filter = new Filter(10);
+            fail("Should throws IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    public void test_encodeValues() {
+        // simple filter
+        filter = new Filter(Filter.APPROX_MATCH_FILTER);
+        filter.setValue(new AttributeTypeAndValuePair("cn", "test"));
+        ASN1TestUtils.checkEncode(filter, LdapASN1Constant.Filter);
+
+        // composite filter
+        filter = new Filter(Filter.AND_FILTER);
+        Filter equal = new Filter(Filter.EQUALITY_MATCH_FILTER);
+        equal.setValue(new AttributeTypeAndValuePair("sn", "tom"));
+        filter.addChild(equal);
+        
+        Filter substring = new Filter(Filter.SUBSTRINGS_FILTER);
+        SubstringFilter sub = new SubstringFilter("o");
+        sub.addAny("harmony");
+        sub.addFinal("good");
+        substring.setValue(sub);
+        filter.addChild(substring);
+        
+        Filter present = new Filter(Filter.PRESENT_FILTER);
+        present.setValue("objectClass");
+        filter.addChild(present);
+        
+        ASN1TestUtils.checkEncode(filter, LdapASN1Constant.Filter);
+        
+        // more complex filter
+        Filter or = new Filter(Filter.OR_FILTER);
+        Filter not = new Filter(Filter.NOT_FILTER);
+        Filter greater = new Filter(Filter.GREATER_OR_EQUAL_FILTER);
+        greater.setValue(new AttributeTypeAndValuePair("cn", "hello"));
+        not.setValue(greater);
+        or.addChild(not);
+        
+        Filter less = new Filter(Filter.LESS_OR_EQUAL_FILTER);
+        less.setValue(new AttributeTypeAndValuePair("o", "apache"));
+        or.addChild(less);
+        filter.addChild(or);
+        
+        ASN1TestUtils.checkEncode(filter, LdapASN1Constant.Filter);
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java?rev=590944&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java Thu Nov  1 02:28:42 2007
@@ -0,0 +1,37 @@
+/* 
+ *  Licensed to the Apache Software Foundation (ASF) under one or more 
+ *  contributor license agreements.  See the NOTICE file distributed with 
+ *  this work for additional information regarding copyright ownership. 
+ *  The ASF licenses this file to You 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.harmony.jndi.provider.ldap;
+
+import javax.naming.directory.SearchControls;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1TestUtils;
+import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+
+public class SearchOpTest extends TestCase {
+    public void test_encode_decode() throws Exception {
+        SearchControls controls = new SearchControls();
+        Filter filter = new Filter(7);
+        filter.setValue(Utils.getBytes("objectClass"));
+        SearchOp op = new SearchOp("test", controls, filter);
+        
+        ASN1TestUtils.checkEncode(op.getRequest(), LdapASN1Constant.SearchRequest);
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1TestUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1TestUtils.java?rev=590944&r1=590943&r2=590944&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1TestUtils.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1TestUtils.java Thu Nov  1 02:28:42 2007
@@ -66,9 +66,15 @@
             }
         } else if (type instanceof ASN1ChoiceWrap) {
             checkEncodeChoice(value, (ASN1ChoiceWrap) type);
+        }  else if (type instanceof ASN1LdapFilter) {
+            checkEncodeFilter(value, (ASN1LdapFilter) type);
         } else {
             Assert.fail("Not supported ASN.1 type");
         }
+    }
+
+    private static void checkEncodeFilter(Object value, ASN1LdapFilter filter) {
+        checkEncode(value, LdapASN1Constant.Filter);
     }
 
     private static void checkEncodeChoice(Object value, ASN1ChoiceWrap type) {



Mime
View raw message