harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r598218 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/internal/nls/ main/java/org/apache/harmony/jndi/provider/ldap/ main/java/org/apache/harmony/jndi/provider/ldap/asn1/ test/java/org/apache/harm...
Date Mon, 26 Nov 2007 10:52:15 GMT
Author: lvjing
Date: Mon Nov 26 02:52:13 2007
New Revision: 598218

URL: http://svn.apache.org/viewvc?rev=598218&view=rev
Log:
Apply patch for HARMONY-5116([classlib][ldap] Implement ldap schema retrieval methods for
ClassDefinition, AttributeDefinition, MatchingRuleDefinition, SyntaxDefinition schema entries
and add scenario test for search method and some textual correction). Merge a magic string
into nls messages.

Added:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaAttrDefContextImpl.java
  (with props)
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaClassDefContextImpl.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapAttribute.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapResult.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.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/SearchOpTest.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties?rev=598218&r1=598217&r2=598218&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
Mon Nov 26 02:52:13 2007
@@ -159,6 +159,7 @@
 jndi.8D=Must supply attributes describing schema
 jndi.8E=Cannot create new entry under schema root
 jndi.8F=Class definition doesn'thave a numeric OID
+jndi.90={0} does not have a syntax associated with it
 jndi.err.00=. The stack trace of the root exception is: 
 ldap.00=Should not be null
 ldap.01=is not an LdapName

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapAttribute.java?rev=598218&r1=598217&r2=598218&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapAttribute.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapAttribute.java
Mon Nov 26 02:52:13 2007
@@ -22,12 +22,14 @@
 import java.util.HashSet;
 import java.util.List;
 
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.DirContext;
 
+import org.apache.harmony.accessibility.internal.nls.Messages;
 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.Utils;
@@ -156,9 +158,9 @@
         if (attributeDefinition != null) {
             return attributeDefinition;
         }
-        // TODO: Not yet implemented
-        throw new NotYetImplementedException();
-
+        attributeDefinition = context
+                .getSchemaAttributeDefinition(getID());
+        return attributeDefinition;
     }
 
     @Override
@@ -166,8 +168,24 @@
         if (attributeSyntaxDefinition != null) {
             return attributeSyntaxDefinition;
         }
-        // TODO: Not yet implemented
-        throw new NotYetImplementedException();
+        //      get the syntax id from the attribute def
+        DirContext schema = context.getSchema("");
+        DirContext attrDef = (DirContext)schema.lookup(
+                LdapSchemaContextImpl.ATTRIBUTE_DEFINITION + "/" + getID());
+
+        Attribute syntaxAttr = attrDef.getAttributes("").get("syntax");
+
+        if (syntaxAttr == null || syntaxAttr.size() == 0) {
+            throw new NameNotFoundException(Messages.getString("jndi.90",
+                    getID()));
+        }
+
+        String syntaxName = (String)syntaxAttr.get();
+
+        // look in the schema tree for the syntax definition
+        return (DirContext)schema.lookup(
+                LdapSchemaContextImpl.SYNTAX_DEFINITION + "/" + syntaxName);
+        
     }
 
     private static boolean isBinary(String name) {

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java?rev=598218&r1=598217&r2=598218&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
Mon Nov 26 02:52:13 2007
@@ -761,10 +761,74 @@
         return getSchema(new CompositeName(s));
     }
 
+    DirContext getSchemaAttributeDefinition(String name) throws NamingException {
+        if (null == ldapSchemaCtx) {
+            getSchema("");
+        }
+        Hashtable<String, Object> attrDef = findSchemaDefInfo(
+                LdapSchemaContextImpl.ATTRIBUTE_TYPES, name);
+
+        return new LdapSchemaAttrDefContextImpl(new CompositeName(name), env,
+                attrDef, this);
+    }
     public DirContext getSchemaClassDefinition(Name name)
             throws NamingException {
-        // TODO not yet implemented
-        throw new NotYetImplementedException();
+        if (null == ldapSchemaCtx) {
+            getSchema(name);
+        }
+
+        Hashtable<String, ArrayList<String>> classTree = new Hashtable<String,
ArrayList<String>>();
+
+        SearchControls searchControls = new SearchControls();
+        searchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
+        searchControls.setReturningAttributes(new String[] { "objectClass", });
+        searchControls.setReturningObjFlag(false);
+        FilterParser parser = new FilterParser("(objectClass=*)");
+        Filter filter = null;
+        try {
+            filter = parser.parse();
+        } catch (ParseException e1) {
+            // Should not throw this excption
+        }
+        String targetDN = getTargetDN(name, contextDn);
+        SearchOp search = new SearchOp(targetDN, searchControls, filter);
+
+        try {
+            client.doOperation(search, requestControls);
+        } catch (IOException e) {
+            CommunicationException ex = new CommunicationException(e
+                    .getMessage());
+            ex.setRootCause(e);
+            if (search.getSearchResult().isEmpty()) {
+                throw ex;
+            }
+            search.getSearchResult().setException(ex);
+        }
+        LdapSearchResult sre = search.getSearchResult();
+        Map<String, Attributes> names = sre.getEntries();
+
+        Set<String> keyset = names.keySet();
+        for (Iterator<String> iterator = keyset.iterator(); iterator.hasNext();) {
+            String key = iterator.next();
+            Attributes as = names.get(key);
+            NamingEnumeration<String> ids = as.getIDs();
+
+            while (ids.hasMoreElements()) {
+                String schemaType = ids.nextElement();
+                if (!classTree.contains(schemaType)) {
+                    classTree.put(schemaType, new ArrayList());
+                }
+                ArrayList<String> classDefs = classTree.get(schemaType);
+                LdapAttribute attribute = (LdapAttribute) as.get(schemaType);
+                for (int i = 0; i < attribute.size(); i++) {
+                    String value = (String) attribute.get(i);
+                    classDefs.add(value);
+                }
+            }
+        }
+
+        return new LdapSchemaClassDefContextImpl(new CompositeName(targetDN),
+                env, classTree, this);
     }
 
     public DirContext getSchemaClassDefinition(String s) throws NamingException {

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapResult.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapResult.java?rev=598218&r1=598217&r2=598218&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapResult.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapResult.java
Mon Nov 26 02:52:13 2007
@@ -143,7 +143,7 @@
      * Retrieves the referrals.
      * 
      * @return A prossibly null array. <code>null</code> means no referrals
-     *         retrieves from server
+     *         retrieved from server
      */
     public String[] getReferrals() {
         return referrals;

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaAttrDefContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaAttrDefContextImpl.java?rev=598218&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaAttrDefContextImpl.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaAttrDefContextImpl.java
Mon Nov 26 02:52:13 2007
@@ -0,0 +1,81 @@
+/* 
+ *  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.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+
+public class LdapSchemaAttrDefContextImpl extends LdapContextImpl {
+
+    private Hashtable<String, Object> attrTree;
+
+    public LdapSchemaAttrDefContextImpl(Name name,
+            Hashtable<Object, Object> env, Hashtable<String, Object> classTree,
+            LdapContextImpl ctx) throws InvalidNameException {
+        super(ctx, env, "");
+        this.attrTree = classTree;
+    }
+
+    public Attributes getAttributes(Name name) throws NamingException {
+        return getAttributes(name, new String[0]);
+    }
+
+    public Attributes getAttributes(Name name, String[] as)
+            throws NamingException {
+        BasicAttributes attributes = new BasicAttributes();
+        Set<String> keySet = attrTree.keySet();
+        Iterator<String> iter = keySet.iterator();
+        while (iter.hasNext()) {
+            String key = iter.next();
+            if (key.equals("orig"))
+                continue;
+            Object value = attrTree.get(key);
+            BasicAttribute attr = new BasicAttribute(key);
+            if (value instanceof ArrayList) {
+                List list = (List) value;
+                for (int i = 0; i < list.size(); i++) {
+                    attr.add(list.get(i));
+                }
+            } else {
+                attr.add(value);
+            }
+            attributes.put(attr);
+        }
+        return attributes;
+    }
+
+    public Attributes getAttributes(String s) throws NamingException {
+        return getAttributes(convertFromStringToName(s));
+    }
+
+    public Attributes getAttributes(String s, String[] as)
+            throws NamingException {
+        return getAttributes(convertFromStringToName(s), as);
+    }
+
+}

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

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaClassDefContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaClassDefContextImpl.java?rev=598218&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaClassDefContextImpl.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaClassDefContextImpl.java
Mon Nov 26 02:52:13 2007
@@ -0,0 +1,77 @@
+/* 
+ *  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.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.SearchResult;
+
+public class LdapSchemaClassDefContextImpl extends LdapContextImpl {
+    
+    private Hashtable<String, ArrayList<String>> classTree;
+    private LdapContextImpl context;
+    public LdapSchemaClassDefContextImpl(
+            Name name,
+            Hashtable<Object, Object> env,
+            Hashtable<String, ArrayList<String>> classTree,
+            LdapContextImpl ctx) throws InvalidNameException {
+        super(ctx, env, "");
+        context = ctx;
+        this.classTree = classTree;
+    }
+
+    public NamingEnumeration<SearchResult> search(Name name,
+            Attributes attributes) throws NamingException {
+        Set<String> keyset = classTree.keySet();
+        LdapNamingEnumeration<SearchResult> enumeration = new LdapNamingEnumeration<SearchResult>(null,
null);
+        Attributes as = null;
+        for (Iterator<String> iter = keyset.iterator(); iter.hasNext();) {
+            ArrayList<String> classes = classTree.get(iter.next());
+            for (int j = 0; j < classes.size(); j++) {
+                String className = classes.get(j);
+                Hashtable<String, Object> classDefInfo = context
+                        .findSchemaDefInfo(LdapSchemaContextImpl.OBJECT_CLASSES,
+                                className);
+                as = new BasicAttributes();
+                Set<String> keySet = classDefInfo.keySet();
+                for (Iterator<String> iterator = keySet.iterator(); iterator
+                        .hasNext();) {
+                    String key = iterator.next();
+                    Object value = classDefInfo.get(key);
+                    as.put(key, value);
+                }
+                SearchResult result = new SearchResult(className, null, as);
+                enumeration.add(result);
+            }
+        }
+        return enumeration;
+    }
+    public NamingEnumeration<SearchResult> search(String name,
+            Attributes attributes) throws NamingException {
+        return search(convertFromStringToName(name), attributes);
+    }
+}

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

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java?rev=598218&r1=598217&r2=598218&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
Mon Nov 26 02:52:13 2007
@@ -17,12 +17,12 @@
 package org.apache.harmony.jndi.provider.ldap;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -49,6 +49,7 @@
 import javax.naming.directory.SearchResult;
 
 import org.apache.harmony.jndi.internal.nls.Messages;
+import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
 import org.apache.harmony.jndi.provider.ldap.parser.FilterParser;
 import org.apache.harmony.jndi.provider.ldap.parser.ParseException;
 
@@ -69,7 +70,7 @@
     public static final String LDAP_SYNTAXES = "ldapsyntaxes";
 
     public static final String MATCHING_RULES = "matchingrules";
-    
+
     protected String subschemasubentry = null;
 
     final private static Hashtable<String, String> schemaJndi2Ldap = new Hashtable<String,
String>();
@@ -94,8 +95,8 @@
 
     private BasicAttributes schemaAttributes;
 
-    public LdapSchemaContextImpl(LdapContextImpl ctx, Hashtable<Object, Object> env,
-            Name dn) throws InvalidNameException {
+    public LdapSchemaContextImpl(LdapContextImpl ctx,
+            Hashtable<Object, Object> env, Name dn) throws InvalidNameException {
         super(ctx, env, dn.getPrefix(0).toString());
         parent = ctx;
         rdn = dn;
@@ -291,7 +292,7 @@
         ModifyOp op = new ModifyOp(targetDN);
         Hashtable<String, Object> classDef = parent.findSchemaDefInfo(
                 schemaJndi2Ldap.get(name.get(0).toLowerCase()), name.get(1));
-        if(null ==classDef) {
+        if (null == classDef) {
             throw new NameNotFoundException(name.toString());
         }
         String oldValue = (String) classDef.get("orig");
@@ -364,7 +365,7 @@
 
         try {
             doBasicOperation(op);
-        } catch(Exception e) {
+        } catch (Exception e) {
             // TODO need to handle referal exception in the future
         }
     }
@@ -440,11 +441,6 @@
     }
 
     public NamingEnumeration<SearchResult> search(Name name,
-            Attributes attributes) throws NamingException {
-        return search(name, attributes, null);
-    }
-
-    public NamingEnumeration<SearchResult> search(Name name,
     // Used to filter attribute value
             Attributes attributes,
             // Used to filter attribute name
@@ -481,7 +477,7 @@
                 attrMatcher.put(newAttr);
             }
         }
-        
+
         // Attribute selector
         TreeSet<String> attrSel = new TreeSet<String>();
 
@@ -490,7 +486,7 @@
                 null, null);
         String schemaType = null;
 
-        LinkedList<String> attrValues = new LinkedList<String>();;
+        LinkedList<String> attrValues = new LinkedList<String>();
         int size = targetDN.size();
         switch (size) {
         case 0:
@@ -564,6 +560,9 @@
             }
             break;
         case 1:
+            if (hasAttributes2Return) {
+                attrSel.addAll(Arrays.asList(as));
+            }
             schemaType = schemaJndi2Ldap.get(name.get(0).toLowerCase());
             if (null == schemaType) {
                 throw new NameNotFoundException(name.toString());
@@ -577,33 +576,41 @@
                     NamingEnumeration<Attribute> filters = attrMatcher.getAll();
                     String id = attrValues.get(i);
                     Hashtable<String, Object> schemaDef = schemas.get(id);
+                    boolean matched = true;
                     while (filters.hasMore()) {
                         Attribute filter = filters.next();
                         Object values = schemaDef.get(filter.getID());
-                        /* 
-                         * Attribute definition will only be retrieved when it is
-                         * designated in attrFilter
-                         */ 
-                        if (match(filter, values)) {
-                            basicAttributes = new BasicAttributes();
-                            for (Iterator<String> iterator = schemaDef.keySet()
-                                    .iterator(); iterator.hasNext();) {
-                                String key = iterator.next();
-                                if (key.equals("orig")) {
-                                    continue;
-                                }
-                                Object value = schemaDef.get(key);
-                                basicAttributes.put(key, value);
+                        /*
+                         * Attribute definition will only be retrieved when it
+                         * is designated in attrFilter
+                         */
+                        if (values == null || !match(filter, values)) {
+                            matched = false;
+                            break;
+                        }
+                    }
+                    if (matched) {
+                        basicAttributes = new BasicAttributes();
+                        for (Iterator<String> iterator = schemaDef.keySet()
+                                .iterator(); iterator.hasNext();) {
+                            String key = iterator.next();
+                            if (key.equals("orig")) {
+                                continue;
+                            }
+                            if (hasAttributes2Return && attrSel.contains(key)
+                                    || !hasAttributes2Return) {
+                                basicAttributes.put(key, schemaDef.get(key));
                             }
-                            SearchResult pair = new SearchResult(id, null,
-                                    basicAttributes);
-                            enumeration.add(pair);
                         }
+                        SearchResult pair = new SearchResult(id, null,
+                                basicAttributes);
+                        enumeration.add(pair);
                     }
                 }
             } else {
                 for (int i = 0; i < attrValues.size(); i++) {
-                    Hashtable<String, Object> schemaDef = schemas.get(attrValues.get(i));
+                    Hashtable<String, Object> schemaDef = schemas
+                            .get(attrValues.get(i));
                     basicAttributes = new BasicAttributes();
                     for (Iterator<String> iterator = schemaDef.keySet()
                             .iterator(); iterator.hasNext();) {
@@ -611,11 +618,13 @@
                         if (key.equals("orig")) {
                             continue;
                         }
-                        Object value = schemaDef.get(key);
-                        basicAttributes.put(key, value);
+                        if (hasAttributes2Return && attrSel.contains(key)
+                                || !hasAttributes2Return) {
+                            basicAttributes.put(key, schemaDef.get(key));
+                        }
                     }
-                    SearchResult pair = new SearchResult(attrValues.get(i), null,
-                            basicAttributes);
+                    SearchResult pair = new SearchResult(attrValues.get(i),
+                            null, basicAttributes);
                     enumeration.add(pair);
                 }
             }
@@ -647,7 +656,7 @@
         while (attrValues.hasMore()) {
             Object attrValue = attrValues.next();
             for (int i = 0; i < v.size(); i++) {
-                if (attrValue.equals(v.get(i))) {
+                if (attrValue.equals("*") || attrValue.equals(v.get(i))) {
                     return true;
                 }
             }
@@ -658,22 +667,25 @@
     public NamingEnumeration<SearchResult> search(Name name, String filter,
             Object[] objs, SearchControls searchControls)
             throws NamingException {
+
         checkName(name);
 
         if (filter == null) {
             throw new NullPointerException(Messages.getString("ldap.28")); //$NON-NLS-1$
         }
-
-        if (objs == null) {
-            objs = new Object[0];
+        if (filter.length() == 0) {
+            throw new StringIndexOutOfBoundsException();
+        }
+        if (!filter.startsWith("(")) {
+            StringBuilder filterWrapper = new StringBuilder("(");
+            filterWrapper.append(filter).append(")");
+            filter = filterWrapper.toString();
         }
 
-        if (searchControls == null) {
+        if (null == searchControls) {
             searchControls = new SearchControls();
         }
 
-        // get absolute dn name
-        String targetDN = getTargetDN(name, contextDn);
         FilterParser filterParser = new FilterParser(filter);
         filterParser.setArgs(objs);
         Filter f = null;
@@ -686,20 +698,28 @@
             throw ex;
         }
 
-        LdapSearchResult result = doSearch(targetDN, f, searchControls);
-
-        List<SearchResult> list = new ArrayList<SearchResult>();
-        Map<String, Attributes> entries = result.getEntries();
-        for (String dn : entries.keySet()) {
-            String relativeName = convertToRelativeName(dn, rdn.toString());
-            SearchResult sr = new SearchResult(relativeName, null, entries
-                    .get(dn));
-            sr.setNameInNamespace(dn);
-            list.add(sr);
-        }
+        BasicAttributes matchingAttrs = new BasicAttributes();
+        extractMatchingAttributes(f, matchingAttrs);
 
-        return new LdapNamingEnumeration<SearchResult>(list, result
-                .getException());
+        return search(name, matchingAttrs, searchControls
+                .getReturningAttributes());
     }
 
+    private void extractMatchingAttributes(Filter f,
+            BasicAttributes matchingAttrs) {
+        if (!f.isLeaf()) {
+            List<Filter> children = f.getChildren();
+            for (Iterator iter = children.iterator(); iter.hasNext();) {
+                extractMatchingAttributes((Filter) iter.next(), matchingAttrs);
+            }
+        } else {
+            Object value = f.getValue();
+            if (value instanceof AttributeTypeAndValuePair) {
+                AttributeTypeAndValuePair pair = (AttributeTypeAndValuePair) value;
+                matchingAttrs.put(pair.getType(), pair.getValue());
+            } else {
+                matchingAttrs.put((String) value, "*");
+            }
+        }
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java?rev=598218&r1=598217&r2=598218&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java
Mon Nov 26 02:52:13 2007
@@ -59,6 +59,13 @@
         values[1] = modifications;
     }
 
+    /**
+     * 
+     * @param type
+     *            ldap modify type, must be one of ModifyOp.ADD, ModifyOp.DELETE
+     *            or ModifyOp.REPLACE
+     * @param attr
+     */
     public void addModification(int type, LdapAttribute attr) {
         if (type >= 0 && type <= 2 && attr != null) {
             modifications.add(new Modification(type, attr));

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=598218&r1=598217&r2=598218&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
Mon Nov 26 02:52:13 2007
@@ -31,8 +31,8 @@
  * OCTET STRING         byte[] (encode: Utils.getBytes(String s)    decode: getString(byte[]
bytes))
  * ENUMERATED           byte[] (encode: ASN1Integer.fromIntValue(int value)  decode: ASN1Integer.toIntValue(Object
decoded))
  * SEQUENCE             Object[] or ASN1Encodable
- * SEQUENCE OF          Collection
- * SET OF               Collection
+ * SEQUENCE OF          java.util.List
+ * SET OF               java.util.List
  * CHOICE               Object[] or ChosenValue
  * </code>
  * 

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=598218&r1=598217&r2=598218&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
Mon Nov 26 02:52:13 2007
@@ -72,21 +72,21 @@
     public static final int OP_EXTENDED_REQUEST = 18;
 
     public static final int OP_EXTENDED_RESPONSE = 19;
-    
+
     public static final ASN1Type Attribute = new ASN1SequenceWrap(
             new ASN1Type[] { ASN1OctetString.getInstance(), // type
                     new ASN1SetOf(ASN1OctetString.getInstance()) }); // vals
-    
+
     public static final ASN1Type AttributeList = new ASN1SequenceOf(
             new ASN1SequenceWrap(new ASN1Type[] {
                     ASN1OctetString.getInstance(), // type
                     new ASN1SetOf(ASN1OctetString.getInstance()) })); // values
-    
+
     public static final ASN1Type AddRequest = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 8, new ASN1SequenceWrap(
                     new ASN1Type[] { ASN1OctetString.getInstance(), // entry
                             AttributeList })); // attributes
-    
+
     public static final ASN1Type SaslCredentials = new ASN1SequenceWrap(
             new ASN1Type[] { ASN1OctetString.getInstance(), // mechanism
                     ASN1OctetString.getInstance() }) { // credentials
@@ -94,14 +94,14 @@
             setOptional(1); // credentials is optional
         }
     };
-    
+
     public static final ASN1Type AuthenticationChoice = new ASN1ChoiceWrap(
             new ASN1Type[] {
                     new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 0, // simple
                             ASN1OctetString.getInstance()),
                     new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 3, // sasl
                             SaslCredentials) });
-    
+
     public static final ASN1Type LDAPResult = new ASN1SequenceWrap(
             new ASN1Type[] { ASN1Enumerated.getInstance(), // resultCode
                     ASN1OctetString.getInstance(), // matchedDN
@@ -115,7 +115,7 @@
     
     public static final ASN1Type AddResponse = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 9, LDAPResult);
-    
+
     public static final ASN1Type Control = new ASN1SequenceWrap(new ASN1Type[] {
             ASN1OctetString.getInstance(), // controlType
             ASN1Boolean.getInstance(), // criticality
@@ -131,7 +131,7 @@
                     new ASN1Type[] { ASN1Integer.getInstance(), // version
                             ASN1OctetString.getInstance(), // name
                             AuthenticationChoice })); // authentication
-    
+
     public static final ASN1Type BindResponse = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 1, Utils.conjoinSequence(
                     (ASN1Sequence) LDAPResult, // result
@@ -142,30 +142,28 @@
                             setOptional(0); // serverSaslCreds is optional
                         }
                     }));
-    
+
     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
-    
+
     public static final ASN1Type AbandonRequest = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 16, ASN1Integer.getInstance());
-    
+
     public static final ASN1Type CompareRequest = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 14, new ASN1SequenceWrap(
                     new ASN1Type[] { ASN1OctetString.getInstance(), // entry
                             AttributeValueAssertion })); // ava
 
-
     public static final ASN1Type CompareResponse = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 15, LDAPResult);
     
     public static final ASN1Type DelRequest = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 10, ASN1OctetString.getInstance());
-    
-    
+
     public static final ASN1Type DelResponse = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 11, LDAPResult);
     
@@ -183,7 +181,6 @@
                 }
             });
 
-
     public static final ASN1Type ExtendedResponse = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 24, Utils.conjoinSequence(
                     (ASN1Sequence) LDAPResult, // LDAPResult
@@ -199,7 +196,7 @@
                             setOptional(1);
                         }
                     }));
-    
+
     public static final ASN1Type ModifyDNRequest = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 12, new ASN1SequenceWrap(
                     new ASN1Type[] {
@@ -214,14 +211,13 @@
                 }
             });
 
-
     public static final ASN1Type ModifyDNResponse = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 13, LDAPResult);
-    
+
     public static final ASN1Type AttributeTypeAndValues = new ASN1SequenceWrap(
             new ASN1Type[] { ASN1OctetString.getInstance(), // type
                     new ASN1SetOf(ASN1OctetString.getInstance()) }); // vals
-    
+
     public static final ASN1Type ModifyRequest = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 6, new ASN1SequenceWrap(
                     new ASN1Type[] {
@@ -231,7 +227,6 @@
                                             ASN1Enumerated.getInstance(), // operation
                                             AttributeTypeAndValues })) })); // modification
 
-
     public static final ASN1Type ModifyResponse = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 7, LDAPResult);
     
@@ -272,7 +267,7 @@
             setDefault(Boolean.FALSE, 3);
         }
     };
-    
+
     public static final ASN1Type Filter = new ASN1ChoiceWrap(new ASN1Type[] {
             new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 0,
                     new ASN1SetOf(new ASN1LdapFilter())),
@@ -294,7 +289,7 @@
                     AttributeValueAssertion),
             new ASN1Implicit(ASN1Constants.CLASS_CONTEXTSPECIFIC, 9,
                     MatchingRuleAssertion) });
-    
+
     public static final ASN1Type SearchRequest = new ASN1Implicit(
             ASN1Constants.CLASS_APPLICATION, 3,
             new ASN1SequenceWrap(new ASN1Type[] {
@@ -306,24 +301,24 @@
                     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(),

Modified: 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=598218&r1=598217&r2=598218&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java
Mon Nov 26 02:52:13 2007
@@ -30,7 +30,7 @@
 public class SearchOpTest extends TestCase {
     public void test_encode_decode() throws Exception {
         SearchControls controls = new SearchControls();
-        Filter filter = new Filter(7);
+        Filter filter = new Filter(Filter.PRESENT_FILTER);
         filter.setValue(Utils.getBytes("objectClass"));
         SearchOp op = new SearchOp("test", controls, filter);
 



Mime
View raw message