harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r599807 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/provider/ldap/ test/java/org/apache/harmony/jndi/provider/ldap/
Date Fri, 30 Nov 2007 12:49:59 GMT
Author: lvjing
Date: Fri Nov 30 04:49:47 2007
New Revision: 599807

URL: http://svn.apache.org/viewvc?rev=599807&view=rev
Log:
Apply patch for HARMONY-5230 ([classlib][ldap] Add scenario test on apacheds and correct some
provider behavior)

Modified:
    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/LdapSchemaAttrDefContextImpl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaClassDefContextImpl.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/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImplTest.java

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=599807&r1=599806&r2=599807&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
Fri Nov 30 04:49:47 2007
@@ -726,8 +726,16 @@
         LdapSearchResult result = doSearch(targetDN, filter, controls);
         Iterator<Attributes> it = result.getEntries().values().iterator();
         if (it.hasNext()) {
+            Attributes attributes = it.next();
+            NamingEnumeration<String> ids = attributes.getIDs();
+            while (ids.hasMore()) {
+                LdapAttribute attribute = (LdapAttribute) attributes.get(ids
+                        .next());
+                attribute.setContext(this);
+            }
+
             // FIXME: there must be only one Attributes?
-            return it.next();
+            return attributes;
         } else if (result.getException() != null) {
             throw result.getException();
         }
@@ -1019,7 +1027,7 @@
     public DirContext getSchemaClassDefinition(Name name)
             throws NamingException {
         if (null == ldapSchemaCtx) {
-            getSchema(name);
+            getSchema("");
         }
 
         Hashtable<String, ArrayList<String>> classTree = new Hashtable<String,
ArrayList<String>>();

Modified: 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=599807&r1=599806&r2=599807&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaAttrDefContextImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaAttrDefContextImpl.java
Fri Nov 30 04:49:47 2007
@@ -72,10 +72,4 @@
     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);
-    }
-
 }

Modified: 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=599807&r1=599806&r2=599807&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaClassDefContextImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaClassDefContextImpl.java
Fri Nov 30 04:49:47 2007
@@ -54,8 +54,9 @@
             for (int j = 0; j < classes.size(); j++) {
                 String className = classes.get(j);
                 Hashtable<String, Object> classDefInfo = context
-                        .findSchemaDefInfo(LdapSchemaContextImpl.OBJECT_CLASSES,
-                                className);
+                        .findSchemaDefInfo(
+                                LdapSchemaContextImpl.OBJECT_CLASSES, className
+                                        .toLowerCase());
                 as = new BasicAttributes();
                 Set<String> keySet = classDefInfo.keySet();
                 for (Iterator<String> iterator = keySet.iterator(); iterator

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=599807&r1=599806&r2=599807&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
Fri Nov 30 04:49:47 2007
@@ -181,7 +181,8 @@
 
     public DirContext createSubcontext(String name, Attributes attributes)
             throws NamingException {
-        return createSubcontext(convertFromStringToName(name), attributes);
+        Name n = convertFromStringToName(name);
+        return createSubcontext(n, attributes);
     }
 
     public Attributes getAttributes(Name name) throws NamingException {
@@ -199,8 +200,8 @@
             if (null == schemaType) {
                 throw new NameNotFoundException(name.toString());
             }
-            schemaAttributes.put(new LdapAttribute(new BasicAttribute(
-                    "objectclass", name.get(0).toLowerCase()), parent));
+            schemaAttributes.put(new BasicAttribute("objectclass", name.get(0)
+                    .toLowerCase()));
             break;
         default:
             Hashtable<String, Object> classDef = parent.findSchemaDefInfo(
@@ -216,8 +217,8 @@
                     continue;
                 }
                 Object value = classDef.get(id);
-                schemaAttributes.put(new LdapAttribute(new BasicAttribute(id
-                        .toLowerCase(), value), parent));
+                schemaAttributes
+                        .put(new BasicAttribute(id.toLowerCase(), value));
             }
         }
         return schemaAttributes;
@@ -334,32 +335,36 @@
                 new LdapAttribute(oldAttr, parent));
         op.addModification(jndi2ldap[DirContext.ADD_ATTRIBUTE],
                 new LdapAttribute(newAttr, parent));
-
+        
         try {
             doBasicOperation(op);
-        } catch (ReferralException e) {
-            // TODO handle referral in the future
+        } catch (Exception e) {
+            throw new SchemaViolationException("Cannot modify schema root");
         }
 
     }
 
     public void modifyAttributes(String s, int i, Attributes attributes)
             throws NamingException {
-        modifyAttributes(convertFromStringToName(s), i, attributes);
+        Name name = convertFromStringToName(s);
+        modifyAttributes(name, i, attributes);
     }
 
     public void modifyAttributes(String s, ModificationItem[] modificationItems)
             throws NamingException {
-        modifyAttributes(convertFromStringToName(s), modificationItems);
+        Name name = convertFromStringToName(s);
+        modifyAttributes(name, modificationItems);
 
     }
 
     public Context createSubcontext(Name name) throws NamingException {
-        return createSubcontext(name, null);
+        DirContext subContext = createSubcontext(name, null);
+        return subContext;
     }
 
     public Context createSubcontext(String name) throws NamingException {
-        return createSubcontext(convertFromStringToName(name));
+        Name n = convertFromStringToName(name);
+        return createSubcontext(n);
     }
 
     public void destroySubcontext(Name name) throws NamingException {
@@ -449,16 +454,53 @@
         return list(convertFromStringToName(name));
     }
 
-    public NamingEnumeration<Binding> listBindings(Name n)
+    public NamingEnumeration<Binding> listBindings(Name name)
             throws NamingException {
-        // TODO Auto-generated method stub
-        return null;
+        Name targetDN = name.addAll(rdn);
+
+        LdapNamingEnumeration<Binding> enumeration = new LdapNamingEnumeration<Binding>(
+                null, null);
+        Set<String> keyset = null;
+        int size = targetDN.size();
+        switch (size) {
+        case 0:
+            keyset = LdapContextImpl.schemaTree.keySet();
+            for (Iterator<String> i = keyset.iterator(); i.hasNext();) {
+                String schemaType = i.next();
+                Binding binding = new Binding(schemaLdap2Jndi.get(schemaType
+                        .toLowerCase()), this.getClass().getName(), null);
+                enumeration.add(binding);
+            }
+            break;
+        case 1:
+            String schemaType = schemaJndi2Ldap.get(name.get(0).toLowerCase());
+            if (null == schemaType) {
+                throw new NameNotFoundException(name.toString());
+            }
+            Hashtable<String, Hashtable<String, Object>> schemas = LdapContextImpl.schemaTree
+                    .get(schemaType);
+            keyset = schemas.keySet();
+            for (Iterator<String> i = keyset.iterator(); i.hasNext();) {
+                schemaType = i.next();
+                Binding binding = new Binding(schemaType.toLowerCase(), this
+                        .getClass().getName(), null);
+                enumeration.add(binding);
+            }
+            break;
+        default:
+            schemaType = schemaJndi2Ldap.get(name.getPrefix(1).toString()
+                    .toLowerCase());
+            if (null == schemaType) {
+                throw new NameNotFoundException(name.toString());
+            }
+            list(name.getSuffix(1));
+        }
+        return enumeration;
     }
 
-    public NamingEnumeration<Binding> listBindings(String s)
+    public NamingEnumeration<Binding> listBindings(String name)
             throws NamingException {
-        // TODO Auto-generated method stub
-        return null;
+        return listBindings(convertFromStringToName(name));
     }
 
     public Object lookup(Name n) throws NamingException {

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImplTest.java?rev=599807&r1=599806&r2=599807&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImplTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImplTest.java
Fri Nov 30 04:49:47 2007
@@ -133,5 +133,14 @@
             // expected
         }
     }
+    
+    public void test_getSchemaClassDefinition() throws NamingException {
+        try {
+            context.getSchemaClassDefinition(new CompositeName(""));
+            fail("Should throw OperationNotSupportedException");
+        } catch (OperationNotSupportedException e) {
+            // expected
+        }
+    }
 
 }



Mime
View raw message