harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r596127 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/internal/nls/ main/java/org/apache/harmony/jndi/provider/ldap/ test/java/org/apache/harmony/jndi/provider/ldap/
Date Sun, 18 Nov 2007 20:28:27 GMT
Author: tellison
Date: Sun Nov 18 12:28:25 2007
New Revision: 596127

URL: http://svn.apache.org/viewvc?rev=596127&view=rev
Log:
Apply patch for HARMONY-5115 ([classlib][ldap] Implement ldap getSchema methods)

Added:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java   (with props)
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImplTest.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/LdapNamingEnumeration.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/AddOpTest.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.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=596127&r1=596126&r2=596127&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 Sun Nov 18 12:28:25 2007
@@ -156,6 +156,9 @@
 jndi.8A=Invalid method number: {0}
 jndi.8B=attrs must not be null
 jndi.8C=component must not be null
+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.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=596127&r1=596126&r2=596127&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 Sun Nov 18 12:28:25 2007
@@ -56,6 +56,8 @@
      * whether the value of attribute is binary
      */
     private boolean isBinary;
+    
+    private LdapContextImpl context = null;
 
     private static HashSet<String> BINARY_ATTRIBUTE = new HashSet<String>();
     static {
@@ -83,9 +85,14 @@
         super("", false); //$NON-NLS-1$
     }
 
-    public LdapAttribute(String id) {
+    public LdapAttribute(String id, LdapContextImpl ctx) {
         super(id, false);
         isBinary = isBinary(id);
+        context = ctx;
+    }
+    
+    void setContext(LdapContextImpl ctx) {
+        context = ctx;
     }
 
     /**
@@ -95,7 +102,7 @@
      *            may never be <code>null</code>
      * @throws NamingException
      */
-    public LdapAttribute(Attribute attr) throws NamingException {
+    public LdapAttribute(Attribute attr, LdapContextImpl ctx) throws NamingException {
         super(attr.getID(), attr.isOrdered());
         isBinary = isBinary(getID());
         NamingEnumeration<?> enu = attr.getAll();
@@ -106,6 +113,7 @@
 
         attributeDefinition = null;
         attributeSyntaxDefinition = null;
+        context = ctx;
     }
 
     @SuppressWarnings("unchecked")

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=596127&r1=596126&r2=596127&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 Sun Nov 18 12:28:25 2007
@@ -23,6 +23,8 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
 
 import javax.naming.Binding;
 import javax.naming.CannotProceedException;
@@ -57,7 +59,6 @@
 import javax.naming.spi.DirectoryManager;
 import javax.naming.spi.NamingManager;
 
-import org.apache.harmony.jndi.internal.Util;
 import org.apache.harmony.jndi.internal.nls.Messages;
 import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
 import org.apache.harmony.jndi.internal.parser.LdapNameParser;
@@ -80,7 +81,7 @@
     /**
      * name of the context
      */
-    private Name contextDn;
+    protected Name contextDn;
 
     private Control[] requestControls;
 
@@ -89,7 +90,7 @@
     /**
      * environment properties for this context
      */
-    private Hashtable<Object, Object> env;
+    protected Hashtable<Object, Object> env;
 
     /**
      * name parser for this context
@@ -294,7 +295,7 @@
 
         if (attributes == null) {
             attributes = new BasicAttributes();
-            Attribute attr = new LdapAttribute("objectClass");
+            Attribute attr = new LdapAttribute("objectClass", this);
             attr.add("top");
             attr.add("javaContainer");
             attributes.put(attr);
@@ -310,7 +311,7 @@
         List<LdapAttribute> la = new ArrayList<LdapAttribute>(attrs.size());
         NamingEnumeration<? extends Attribute> enu = attrs.getAll();
         while (enu.hasMore()) {
-            la.add(new LdapAttribute(enu.next()));
+            la.add(new LdapAttribute(enu.next(), this));
         }
 
         // do add operation
@@ -374,7 +375,7 @@
             return first;
         }
 
-        Attribute attr = new LdapAttribute(first.getID());
+        Attribute attr = new LdapAttribute(first.getID(), this);
         NamingEnumeration<?> enu = first.getAll();
         while (enu.hasMore()) {
             attr.add(enu.next());
@@ -459,13 +460,234 @@
         return getAttributes(convertFromStringToName(s), as);
     }
 
+
+    public static Hashtable<String, Hashtable<String, Hashtable<String, Object>>> schemaTree = new Hashtable<String, Hashtable<String, Hashtable<String, Object>>>();
+
+    private LdapSchemaContextImpl ldapSchemaCtx = null;
+
+    protected String subschemasubentry = null;
+
     public DirContext getSchema(Name name) throws NamingException {
-        // TODO not yet implemented
-        throw new NotYetImplementedException();
+        checkName(name);
+        if (null != ldapSchemaCtx)
+            return ldapSchemaCtx;
+
+        SearchControls searchControls = new SearchControls();
+        SearchOp search = null;
+        Filter filter = null;
+        FilterParser filterParser = null;
+        LdapSearchResult sre = null;
+        Map<String, Attributes> names = null;
+        Set<String> keyset = null;
+
+        if (name.size() != 0) {
+            subschemasubentry = name.toString() + "," + contextDn.toString();
+        }
+        if (null == subschemasubentry) {
+            filterParser = new FilterParser("(objectClass=*)");
+            try {
+                filter = filterParser.parse();
+            } catch (ParseException e) {
+                InvalidSearchFilterException ex = new InvalidSearchFilterException(
+                        Messages.getString("ldap.29")); //$NON-NLS-1$
+                ex.setRootCause(e);
+                throw ex;
+            }
+
+            searchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
+            searchControls.setReturningAttributes(new String[] {
+                    "namingContexts", "subschemaSubentry", "altServer", });
+            search = new SearchOp("", 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);
+            }
+
+            sre = search.getSearchResult();
+            names = sre.getEntries();
+
+            keyset = names.keySet();
+            for (Iterator<String> iterator = keyset.iterator(); iterator
+                    .hasNext();) {
+                String key = iterator.next();
+                Attributes as = names.get(key);
+                subschemasubentry = (String) as.get("subschemasubentry").get();
+            }
+        }
+
+        searchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
+        searchControls.setReturningAttributes(new String[] { "objectclasses",
+                "attributetypes", "matchingrules", "ldapsyntaxes" });
+        searchControls.setReturningObjFlag(true);
+        filterParser = new FilterParser("(objectClass=subschema)");
+        try {
+            filter = filterParser.parse();
+        } catch (ParseException e) {
+            InvalidSearchFilterException ex = new InvalidSearchFilterException(
+                    Messages.getString("ldap.29")); //$NON-NLS-1$
+            ex.setRootCause(e);
+            throw ex;
+        }
+        search = new SearchOp(subschemasubentry, 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);
+        }
+        if (search.getResult().getResultCode() == LdapResult.INVALID_DN_SYNTAX) {
+            throw new InvalidNameException(Messages.getString("ldap.34"));
+        }
+        sre = search.getSearchResult();
+        names = sre.getEntries();
+
+        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 (!schemaTree.contains(schemaType)) {
+                    schemaTree.put(schemaType,
+                            new Hashtable<String, Hashtable<String, Object>>());
+                }
+                Hashtable<String, Hashtable<String, Object>> schemaDefs = schemaTree
+                        .get(schemaType);
+                LdapAttribute attribute = (LdapAttribute) as.get(schemaType);
+                for (int i = 0; i < attribute.size(); i++) {
+                    String value = (String) attribute.get(i);
+                    parseValue(value, schemaDefs);
+                }
+            }
+        }
+        ldapSchemaCtx = new LdapSchemaContextImpl(this, env, name);
+        return ldapSchemaCtx;
+    }
+
+    Hashtable<String, Object> findSchemaDefInfo(String schemaType,
+            String className) {
+        Hashtable<String, Hashtable<String, Object>> schemaDefs = schemaTree
+                .get(schemaType);
+        Hashtable<String, Object> schemaDef = schemaDefs.get(className);
+        return schemaDef;
+    }
+
+    /*
+     * Sample schema value from Openldap server is ( 2.5.13.8 NAME
+     * 'numericStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 ) TODO check
+     * with RFC to see whether all the schema definition has been catered for
+     */
+    private static void parseValue(String value,
+            Hashtable<String, Hashtable<String, Object>> schemaDefs) {
+        StringTokenizer st = new StringTokenizer(value);
+        // Skip (
+        st.nextToken();
+
+        String oid = st.nextToken();
+
+        Hashtable<String, Object> schemaDef = new Hashtable<String, Object>();
+        schemaDef.put("orig", value);
+        schemaDef.put("numericoid", oid);
+        String token = null;
+        ArrayList<String> values = null;
+        StringBuilder desc = new StringBuilder();
+        while (st.hasMoreTokens()) {
+            String attrName = st.nextToken();
+            if (attrName.startsWith("x-")) {
+                token = st.nextToken();
+                // remove the ending ' symbol
+                token = token.substring(0, token.length() - 1);
+                schemaDef.put(attrName, token);
+            }
+            if (attrName.equals("usage") || attrName.equals("equality")
+                    || attrName.equals("syntax") || attrName.equals("ordering")
+                    || attrName.equals("substr")) {
+                token = st.nextToken();
+                schemaDef.put(attrName, token);
+            }
+            if (attrName.equals("desc")) {
+                token = st.nextToken();
+
+                // remove the leading ' symbol
+                if (token.startsWith("'"))
+                    token = token.substring(1);
+                while (!token.endsWith("'")) {
+                    desc.append(token).append(" ");
+                    token = st.nextToken();
+                }
+
+                // remove the ending ' symbol
+                desc.append(token.substring(0, token.length() - 1));
+                schemaDef.put(attrName, desc.toString());
+                desc.delete(0, desc.length());
+            }
+            if (attrName.equals("name")) {
+                token = st.nextToken();
+                values = new ArrayList<String>();
+                // Name has multiple values
+                if (token.startsWith("(")) {
+                    token = st.nextToken();
+                    while (!token.equals(")")) {
+                        // remove enclosing quotation
+                        token = token.substring(1, token.length() - 1);
+                        values.add(token);
+                        token = st.nextToken();
+                    }
+                } else {
+                    // remove enclosing quotation
+                    token = token.substring(1, token.length() - 1);
+                    values.add(token);
+                }
+                schemaDef.put(attrName, values);
+                schemaDefs.put(values.get(0), schemaDef);
+            }
+            if (attrName.equals("must") || attrName.equals("sup")
+                    || attrName.equals("may")) {
+                token = st.nextToken();
+                values = new ArrayList<String>();
+                // has multiple values
+                if (token.startsWith("(")) {
+                    token = st.nextToken();
+                    while (!token.equals(")")) {
+                        if (!token.equals("$"))
+                            values.add(token);
+                        token = st.nextToken();
+                    }
+                } else {
+                    values.add(token);
+                }
+                schemaDef.put(attrName, values);
+            }
+            if (attrName.equals("abstract") || attrName.equals("structual")
+                    || attrName.equals("auxiliary")
+                    || attrName.equals("single-value")
+                    || attrName.equals("no-user-modification")) {
+                schemaDef.put(attrName, "true");
+            }
+        }
+        if (!schemaDef.keySet().contains("name")) {
+            schemaDefs.put(oid, schemaDef);
+        }
     }
 
     public DirContext getSchema(String s) throws NamingException {
-        return getSchema(convertFromStringToName(s));
+        return getSchema(new CompositeName(s));
     }
 
     public DirContext getSchemaClassDefinition(Name name)
@@ -536,13 +758,13 @@
         for (ModificationItem item : modificationItems) {
             switch (item.getModificationOp()) {
             case DirContext.ADD_ATTRIBUTE:
-                op.addModification(0, new LdapAttribute(item.getAttribute()));
+                op.addModification(0, new LdapAttribute(item.getAttribute(), this));
                 break;
             case DirContext.REMOVE_ATTRIBUTE:
-                op.addModification(1, new LdapAttribute(item.getAttribute()));
+                op.addModification(1, new LdapAttribute(item.getAttribute(), this));
                 break;
             case DirContext.REPLACE_ATTRIBUTE:
-                op.addModification(2, new LdapAttribute(item.getAttribute()));
+                op.addModification(2, new LdapAttribute(item.getAttribute(), this));
                 break;
             default:
                 throw new IllegalArgumentException(Messages.getString(
@@ -1027,7 +1249,7 @@
      *            base dn of the relative name
      * @return dn relatived to the <code>dn</code> of <code>base</code>
      */
-    private String convertToRelativeName(String dn, String base) {
+    protected String convertToRelativeName(String dn, String base) {
 
         if (base.equals("")) {
             return dn;
@@ -1041,7 +1263,7 @@
         return dn.substring(0, index - 1);
     }
 
-    private String getTargetDN(Name name, Name prefix) throws NamingException,
+    protected String getTargetDN(Name name, Name prefix) throws NamingException,
             InvalidNameException {
         Name target = null;
         if (name.size() == 0) {
@@ -1057,7 +1279,7 @@
         return target.toString();
     }
 
-    private Context findNnsContext(Name name) throws NamingException {
+    protected Context findNnsContext(Name name) throws NamingException {
         CannotProceedException cpe = null;
         if (env.containsKey(NamingManager.CPE)) {
             cpe = (CannotProceedException) env.get(NamingManager.CPE);
@@ -1147,7 +1369,7 @@
      * @throws InvalidNameException
      *             occurs error while converting
      */
-    private Name convertFromStringToName(String s) throws InvalidNameException {
+    protected Name convertFromStringToName(String s) throws InvalidNameException {
         if (s == null) {
             // jndi.2E=The name is null
             throw new NullPointerException(Messages.getString("jndi.2E")); //$NON-NLS-1$
@@ -1251,7 +1473,7 @@
      * @param op
      * @throws NamingException
      */
-    private void doBasicOperation(LdapOperation op) throws NamingException {
+    protected void doBasicOperation(LdapOperation op) throws NamingException {
         LdapMessage message = null;
         try {
             message = client.doOperation(op, requestControls);

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapNamingEnumeration.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapNamingEnumeration.java?rev=596127&r1=596126&r2=596127&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapNamingEnumeration.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapNamingEnumeration.java Sun Nov 18 12:28:25 2007
@@ -115,5 +115,9 @@
     protected void setException(NamingException exception) {
         this.exception = exception;
     }
+    
+    void add(T pair) {
+        values.add(pair);
+    }
 
 }

Added: 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=596127&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java Sun Nov 18 12:28:25 2007
@@ -0,0 +1,705 @@
+/* 
+ *  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.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;
+
+import javax.naming.Binding;
+import javax.naming.ConfigurationException;
+import javax.naming.Context;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
+import javax.naming.ReferralException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InvalidSearchFilterException;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SchemaViolationException;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.harmony.jndi.internal.nls.Messages;
+import org.apache.harmony.jndi.provider.ldap.parser.FilterParser;
+import org.apache.harmony.jndi.provider.ldap.parser.ParseException;
+
+public class LdapSchemaContextImpl extends LdapContextImpl {
+
+    public static final String CLASS_DEFINITION = "classdefinition";
+
+    public static final String ATTRIBUTE_DEFINITION = "attributedefinition";
+
+    public static final String SYNTAX_DEFINITION = "syntaxdefinition";
+
+    public static final String MATCHING_RULE = "matchingrule";
+
+    public static final String OBJECT_CLASSES = "objectclasses";
+
+    public static final String ATTRIBUTE_TYPES = "attributetypes";
+
+    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>();
+    static {
+        schemaJndi2Ldap.put(CLASS_DEFINITION, OBJECT_CLASSES);
+        schemaJndi2Ldap.put(ATTRIBUTE_DEFINITION, ATTRIBUTE_TYPES);
+        schemaJndi2Ldap.put(SYNTAX_DEFINITION, LDAP_SYNTAXES);
+        schemaJndi2Ldap.put(MATCHING_RULE, MATCHING_RULES);
+    }
+
+    final private static Hashtable<String, String> schemaLdap2Jndi = new Hashtable<String, String>();
+    static {
+        schemaLdap2Jndi.put(OBJECT_CLASSES, CLASS_DEFINITION);
+        schemaLdap2Jndi.put(ATTRIBUTE_TYPES, ATTRIBUTE_DEFINITION);
+        schemaLdap2Jndi.put(LDAP_SYNTAXES, SYNTAX_DEFINITION);
+        schemaLdap2Jndi.put(MATCHING_RULES, MATCHING_RULE);
+    }
+
+    private LdapContextImpl parent;
+
+    private Name rdn = null;
+
+    private BasicAttributes schemaAttributes;
+
+    public LdapSchemaContextImpl(LdapContextImpl ctx, Hashtable<Object, Object> env,
+            Name dn) throws InvalidNameException {
+        super(ctx, env, dn.getPrefix(0).toString());
+        parent = ctx;
+        rdn = dn;
+    }
+
+    public DirContext getSchema(Name name) throws NamingException {
+        throw new OperationNotSupportedException();
+    }
+
+    public DirContext getSchema(String name) throws NamingException {
+        throw new OperationNotSupportedException();
+    }
+
+    public DirContext getSchemaClassDefinition(Name name)
+            throws NamingException {
+        throw new OperationNotSupportedException();
+    }
+
+    public DirContext getSchemaClassDefinition(String name)
+            throws NamingException {
+        throw new OperationNotSupportedException();
+    }
+
+    public String getNameInNamespace() throws NamingException {
+        throw new OperationNotSupportedException();
+    }
+
+    public DirContext createSubcontext(Name name, Attributes attributes)
+            throws NamingException {
+        checkName(name);
+
+        Name schemaType = name.getPrefix(name.size() - 1);
+
+        if (null == attributes || attributes.size() == 0) {
+            throw new SchemaViolationException(Messages.getString("jndi.8D"));
+        }
+
+        if (!LdapContextImpl.schemaTree.keySet().contains(
+                schemaJndi2Ldap.get(schemaType.toString().toLowerCase()))) {
+            throw new SchemaViolationException(Messages.getString("jndi.8E"));
+        }
+        String targetDN = rdn.toString() + parent.subschemasubentry;
+        StringBuilder builder = new StringBuilder("( ");
+        NamingEnumeration<String> ids = attributes.getIDs();
+
+        // FIXME what if attribute value has \' or \", or can Attributes be used
+        // directly
+        boolean hasNOID = false;
+        while (ids.hasMoreElements()) {
+            String id = ids.nextElement();
+            Attribute attribute = attributes.get(id);
+            if (id.equalsIgnoreCase("NUMERICOID")) {
+                builder.append(attribute);
+                builder.append(" ");
+                hasNOID = true;
+            } else {
+                builder.append(id);
+                builder.append(" ");
+                builder.append(attribute);
+                builder.append(" ");
+            }
+        }
+        builder.append(")");
+        if (!hasNOID) {
+            throw new ConfigurationException(Messages.getString("jndi.8F"));
+        }
+
+        ModifyOp op = new ModifyOp(targetDN);
+        BasicAttribute schemaEntry = new LdapAttribute(new BasicAttribute(
+                schemaJndi2Ldap.get(schemaType.toString().toLowerCase()),
+                builder.toString()), parent);
+        op.addModification(jndi2ldap[DirContext.ADD_ATTRIBUTE],
+                new LdapAttribute(schemaEntry, parent));
+
+        try {
+            doBasicOperation(op);
+        } catch (ReferralException e) {
+            // TODO
+        }
+        return new LdapSchemaContextImpl(parent, parent.env, name);
+    }
+
+    public DirContext createSubcontext(String name, Attributes attributes)
+            throws NamingException {
+        return createSubcontext(convertFromStringToName(name), attributes);
+    }
+
+    public Attributes getAttributes(Name name) throws NamingException {
+        if (null != schemaAttributes) {
+            return schemaAttributes;
+        }
+        Name schemaName = name;
+        if (schemaName.size() == 0) {
+            schemaName = rdn;
+        }
+        if (schemaName.size() != 2) {
+            throw new NameNotFoundException(name.toString());
+        }
+        Hashtable<String, Object> schemaDef = parent.findSchemaDefInfo(
+                schemaJndi2Ldap.get(schemaName.get(0).toLowerCase()),
+                schemaName.get(1).toLowerCase());
+        if (null == schemaDef) {
+            throw new NameNotFoundException(name.toString());
+        }
+        schemaAttributes = new BasicAttributes();
+        Enumeration<String> keys = schemaDef.keys();
+        while (keys.hasMoreElements()) {
+            String id = keys.nextElement();
+            if (id.equals("orig")) {
+                continue;
+            }
+            Object value = schemaDef.get(id);
+            schemaAttributes.put(new LdapAttribute(
+                    new BasicAttribute(id, value), parent));
+        }
+        return schemaAttributes;
+    }
+
+    public Attributes getAttributes(Name name, String[] as)
+            throws NamingException {
+        Attributes attrs = getAttributes(name);
+        Attribute attr = null;
+        Attributes filteredAttrs = new BasicAttributes();
+        for (int i = 0; i < as.length; i++) {
+            attr = attrs.get(as[i]);
+            if (attr != null) {
+                filteredAttrs.put(attr);
+            }
+        }
+        return filteredAttrs;
+    }
+
+    public Attributes getAttributes(String attributeName)
+            throws NamingException {
+        Name name = convertFromStringToName(attributeName);
+        return getAttributes(name);
+    }
+
+    public Attributes getAttributes(String name, String[] as)
+            throws NamingException {
+        return getAttributes(convertFromStringToName(name), as);
+    }
+
+    private void checkName(Name name) {
+        if (name == null) {
+            // jndi.2E=The name is null
+            throw new NullPointerException(Messages.getString("jndi.2E")); //$NON-NLS-1$
+        }
+    }
+
+    public void modifyAttributes(Name name, int i, Attributes attributes)
+            throws NamingException {
+        checkName(name);
+        if (attributes == null) {
+            // jndi.13=Non-null attribute is required for modification
+            throw new NullPointerException(Messages.getString("jndi.13")); //$NON-NLS-1$
+        }
+
+        if (i != DirContext.ADD_ATTRIBUTE && i != DirContext.REMOVE_ATTRIBUTE
+                && i != DirContext.REPLACE_ATTRIBUTE) {
+            /*
+             * jndi.14=Modification code {0} must be one of
+             * DirContext.ADD_ATTRIBUTE, DirContext.REPLACE_ATTRIBUTE and
+             * DirContext.REMOVE_ATTRIBUTE
+             */
+            throw new IllegalArgumentException(Messages.getString("jndi.14", i)); //$NON-NLS-1$
+        }
+
+        NamingEnumeration<? extends Attribute> enu = attributes.getAll();
+        ModificationItem[] items = new ModificationItem[attributes.size()];
+        int index = 0;
+        while (enu.hasMore()) {
+            items[index++] = new ModificationItem(i, enu.next());
+        }
+
+        modifyAttributes(name, items);
+
+    }
+
+    private static final int jndi2ldap[] = { -1, 0, 2, 1, };
+
+    public void modifyAttributes(Name name, ModificationItem[] modificationItems)
+            throws NamingException {
+        checkName(name);
+
+        if (modificationItems == null) {
+            // FIXME: spec say ModificationItem may not be null, but ri
+            // silence in this case
+            throw new NullPointerException(Messages.getString("ldap.27")); //$NON-NLS-1$
+        }
+
+        String targetDN = rdn.toString() + parent.subschemasubentry;
+        ModifyOp op = new ModifyOp(targetDN);
+        Hashtable<String, Object> classDef = parent.findSchemaDefInfo(
+                schemaJndi2Ldap.get(name.get(0).toLowerCase()), name.get(1));
+        if(null ==classDef) {
+            throw new NameNotFoundException(name.toString());
+        }
+        String oldValue = (String) classDef.get("orig");
+        BasicAttribute oldAttr = new LdapAttribute(new BasicAttribute(
+                OBJECT_CLASSES, oldValue), parent);
+        StringBuilder addValue = new StringBuilder();
+        for (ModificationItem item : modificationItems) {
+            Attribute attr = item.getAttribute();
+            addValue.append(attr.getID()).append(" ").append(attr.get());
+        }
+        addValue.append(" )");
+        BasicAttribute newAttr = new LdapAttribute(new BasicAttribute(
+                OBJECT_CLASSES, oldValue.replace(")", addValue.toString())),
+                this);
+        op.addModification(jndi2ldap[DirContext.REMOVE_ATTRIBUTE],
+                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
+        }
+
+    }
+
+    public void modifyAttributes(String s, int i, Attributes attributes)
+            throws NamingException {
+        modifyAttributes(convertFromStringToName(s), i, attributes);
+    }
+
+    public void modifyAttributes(String s, ModificationItem[] modificationItems)
+            throws NamingException {
+        modifyAttributes(convertFromStringToName(s), modificationItems);
+
+    }
+
+    public Context createSubcontext(Name name) throws NamingException {
+        return createSubcontext(name, null);
+    }
+
+    public Context createSubcontext(String name) throws NamingException {
+        return createSubcontext(convertFromStringToName(name));
+    }
+
+    public void destroySubcontext(Name name) throws NamingException {
+        checkName(name);
+
+        // Name schemaType = name.getPrefix(name.size() - 1);
+        String targetDN = rdn.toString() + parent.subschemasubentry;
+        ModifyOp op = new ModifyOp(targetDN);
+        String schemaType = null;
+        try {
+            schemaType = schemaJndi2Ldap.get(name.getPrefix(name.size() - 1)
+                    .toString().toLowerCase());
+        } catch (IndexOutOfBoundsException e) {
+            throw new ArrayIndexOutOfBoundsException();
+        }
+
+        Hashtable<String, Object> classDef = parent.findSchemaDefInfo(
+                schemaType, name.get(1));
+        if (null == classDef) {
+            return;
+        }
+        String oldValue = (String) classDef.get("orig");
+        LdapAttribute oldAttr = new LdapAttribute(new BasicAttribute(
+                schemaType, oldValue), parent);
+        op.addModification(jndi2ldap[DirContext.REMOVE_ATTRIBUTE], oldAttr);
+
+        try {
+            doBasicOperation(op);
+        } catch(Exception e) {
+            // TODO need to handle referal exception in the future
+        }
+    }
+
+    public void destroySubcontext(String name) throws NamingException {
+        destroySubcontext(convertFromStringToName(name));
+    }
+
+    public NamingEnumeration<NameClassPair> list(Name n) throws NamingException {
+        Set<String> keyset = LdapContextImpl.schemaTree.keySet();
+        LdapNamingEnumeration<NameClassPair> enumeration = new LdapNamingEnumeration<NameClassPair>(
+                null, null);
+        for (Iterator<String> i = keyset.iterator(); i.hasNext();) {
+            String schemaType = i.next();
+            NameClassPair pair = new NameClassPair(schemaLdap2Jndi
+                    .get(schemaType.toLowerCase()), this.getClass().getName());
+            enumeration.add(pair);
+        }
+        return enumeration;
+    }
+
+    public NamingEnumeration<NameClassPair> list(String name)
+            throws NamingException {
+        // TODO name supposed to be "" string, what about the situation when
+        // name is not ""
+        return list(convertFromStringToName(name));
+    }
+
+    public NamingEnumeration<Binding> listBindings(Name n)
+            throws NamingException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public NamingEnumeration<Binding> listBindings(String s)
+            throws NamingException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Object lookup(Name n) throws NamingException {
+        if (n.size() == 0) {
+            return this;
+        }
+        if (n.size() == 1) {
+            throw new NameNotFoundException(n.toString());
+        }
+        Hashtable<String, Object> schemaDef = parent.findSchemaDefInfo(
+        // mapping jndi schema type name to ldap native name
+                schemaJndi2Ldap.get(
+                // get [0, 1) as the jndi schema type name
+                        n.getPrefix(1).toString().toLowerCase()),
+                // schema name
+                n.getSuffix(1).toString().toLowerCase()); // find SchemaDef
+        // Info.
+
+        if (null == schemaDef) {
+            throw new NameNotFoundException(n.toString());
+        }
+        return new LdapSchemaContextImpl(parent, env, n.addAll(rdn));
+    }
+
+    public Object lookup(String name) throws NamingException {
+        return lookup(convertFromStringToName(name));
+    }
+
+    public void rename(Name nOld, Name nNew) throws NamingException {
+        throw new SchemaViolationException(Messages.getString("jndi.err.01"));
+    }
+
+    public void rename(String sOld, String sNew) throws NamingException {
+        throw new SchemaViolationException(Messages.getString("jndi.err.01"));
+    }
+
+    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
+            String[] as) throws NamingException {
+        checkName(name);
+
+        Name targetDN = name.addAll(rdn);
+
+        /*
+         * Formalize attributes, change all ids to lowercase, if attributes is
+         * non-null
+         */
+
+        boolean hasMatchingAttributes = (null != attributes && 0 != attributes
+                .size());
+        boolean hasAttributes2Return = (null != as && 0 != as.length);
+
+        // Attribute matcher
+        BasicAttributes attrMatcher = new BasicAttributes();
+        if (hasMatchingAttributes) {
+            NamingEnumeration<? extends Attribute> attrEnum = attributes
+                    .getAll();
+            while (attrEnum.hasMore()) {
+                Attribute old = attrEnum.next();
+                BasicAttribute newAttr = new BasicAttribute(old.getID()
+                        .toLowerCase());
+                for (int i = 0; i < old.size(); i++) {
+                    if (old.get(i) instanceof String) {
+                        newAttr.add(((String) old.get(i)).toLowerCase());
+                    } else {
+                        newAttr.add(old.get(i));
+                    }
+                }
+                attrMatcher.put(newAttr);
+            }
+        }
+        
+        // Attribute selector
+        TreeSet<String> attrSel = new TreeSet<String>();
+
+        // Construct result NamingEnumeration
+        LdapNamingEnumeration<SearchResult> enumeration = new LdapNamingEnumeration<SearchResult>(
+                null, null);
+        String schemaType = null;
+
+        LinkedList<String> attrValues = new LinkedList<String>();;
+        int size = targetDN.size();
+        switch (size) {
+        case 0:
+            /*
+             * Name is a empty string, search against root, may return schema
+             * types: (classdefinition, attributedefinition, syntaxdefinition,
+             * matchingrule)
+             */
+            attrValues.addAll(LdapContextImpl.schemaTree.keySet());
+            /*
+             * Filter attribute names - whether the single attribute name
+             * 'objectclass' is chosen.
+             */
+            int objectclassIndex = -1;
+            if (hasAttributes2Return) {
+                for (int i = 0; i < as.length; i++) {
+                    if (as[i].equalsIgnoreCase("objectclass")) {
+                        objectclassIndex = i;
+                        break;
+                    }
+                }
+            }
+            attrSel.add("objectclass");
+
+            /*
+             * Filter attribute values - choose from (classdefinition,
+             * attributedefinition, syntaxdefinition, matchingrule)
+             */
+            if (hasMatchingAttributes) {
+                Attribute attribute = attrMatcher.get("objectclass");
+                if (null == attribute) {
+                    return enumeration;
+                }
+                for (int i = 0; i < attrValues.size(); i++) {
+                    schemaType = schemaLdap2Jndi.get(attrValues.get(i));
+                    /*
+                     * RI's behavior is odd here - it only retrieves the first
+                     * encountered attribute value,
+                     */
+                    if (attribute.contains(schemaType)) {
+                        BasicAttributes basicAttributes = new BasicAttributes();
+                        /*
+                         * if(objectclassIndex == -1), then No name was choose,
+                         * which means SearchResult will have empty
+                         * BasicAttributes.
+                         */
+                        if (objectclassIndex != -1) {
+                            basicAttributes.put("objectclass", schemaType);
+                        }
+                        SearchResult pair = new SearchResult(schemaType, null,
+                                basicAttributes);
+                        enumeration.add(pair);
+                        break;
+                    }
+                }
+            } else {
+                for (int i = 0; i < attrValues.size(); i++) {
+                    schemaType = schemaLdap2Jndi.get(attrValues.get(i));
+                    BasicAttributes basicAttributes = new BasicAttributes();
+                    /*
+                     * if(objectclassIndex == -1), then No name was choose,
+                     * which means SearchResult will have empty BasicAttributes.
+                     */
+                    if (objectclassIndex != -1) {
+                        basicAttributes.put("objectclass", schemaType);
+                    }
+                    SearchResult pair = new SearchResult(schemaType, null,
+                            basicAttributes);
+                    enumeration.add(pair);
+                }
+            }
+            break;
+        case 1:
+            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);
+            attrValues.addAll(schemas.keySet());
+            BasicAttributes basicAttributes = null;
+            if (hasMatchingAttributes) {
+                for (int i = 0; i < attrValues.size(); i++) {
+                    NamingEnumeration<Attribute> filters = attrMatcher.getAll();
+                    String id = attrValues.get(i);
+                    Hashtable<String, Object> schemaDef = schemas.get(id);
+                    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);
+                            }
+                            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));
+                    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);
+                    }
+                    SearchResult pair = new SearchResult(attrValues.get(i), null,
+                            basicAttributes);
+                    enumeration.add(pair);
+                }
+            }
+            break;
+
+        default:
+            schemaType = schemaJndi2Ldap.get(name.getPrefix(1).toString()
+                    .toLowerCase());
+            if (null == schemaType) {
+                throw new NameNotFoundException(name.toString());
+            }
+            search(name.getSuffix(1), attributes, as);
+        }
+        return enumeration;
+
+    }
+
+    private boolean match(Attribute filter, Object values)
+            throws NamingException {
+        NamingEnumeration<?> attrValues = filter.getAll();
+        ArrayList v = null;
+        if (values instanceof ArrayList) {
+            v = (ArrayList) values;
+        } else {
+            v = new ArrayList();
+            v.add(values);
+        }
+
+        while (attrValues.hasMore()) {
+            Object attrValue = attrValues.next();
+            for (int i = 0; i < v.size(); i++) {
+                if (attrValue.equals(v.get(i))) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    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 (searchControls == null) {
+            searchControls = new SearchControls();
+        }
+
+        // get absolute dn name
+        String targetDN = getTargetDN(name, contextDn);
+        FilterParser filterParser = new FilterParser(filter);
+        filterParser.setArgs(objs);
+        Filter f = null;
+        try {
+            f = filterParser.parse();
+        } catch (ParseException e) {
+            InvalidSearchFilterException ex = new InvalidSearchFilterException(
+                    Messages.getString("ldap.29")); //$NON-NLS-1$
+            ex.setRootCause(e);
+            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);
+        }
+
+        return new LdapNamingEnumeration<SearchResult>(list, result
+                .getException());
+    }
+
+}

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

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/AddOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/AddOpTest.java?rev=596127&r1=596126&r2=596127&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/AddOpTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/AddOpTest.java Sun Nov 18 12:28:25 2007
@@ -29,7 +29,7 @@
 
         ASN1TestUtils.checkEncode(op.getRequest(), LdapASN1Constant.AddRequest);
 
-        LdapAttribute attr = new LdapAttribute("attr1");
+        LdapAttribute attr = new LdapAttribute("attr1", null);
 
         op.addAttribute(attr);
         ASN1TestUtils.checkEncode(op.getRequest(), LdapASN1Constant.AddRequest);

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java?rev=596127&r1=596126&r2=596127&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java Sun Nov 18 12:28:25 2007
@@ -35,7 +35,7 @@
         byte[] v1 = Utils.getBytes("value1");
         byte[] v2 = Utils.getBytes("value2");
         byte[] v3 = Utils.getBytes("value3");
-        LdapAttribute attr = new LdapAttribute(id);
+        LdapAttribute attr = new LdapAttribute(id, null);
         attr.add(v1);
         attr.add(v2);
         attr.add(v3);
@@ -43,7 +43,7 @@
 
         Object[] encoded = new Object[2];
         attr.encodeValues(encoded);
-        LdapAttribute decoded = new LdapAttribute("");
+        LdapAttribute decoded = new LdapAttribute("", null);
         decoded.decodeValues(encoded);
 
         assertEquals(attr.getID(), decoded.getID());
@@ -54,7 +54,7 @@
         BasicAttribute attr = new BasicAttribute("cn");
         attr.add("test");
         attr.add("harmony");
-        LdapAttribute la = new LdapAttribute(attr);
+        LdapAttribute la = new LdapAttribute(attr, null);
 
         ASN1TestUtils.checkEncode(la, LdapASN1Constant.Attribute);
 

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java?rev=596127&r1=596126&r2=596127&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java Sun Nov 18 12:28:25 2007
@@ -26,6 +26,7 @@
 import javax.naming.Context;
 import javax.naming.InvalidNameException;
 import javax.naming.Name;
+import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttribute;
@@ -37,12 +38,29 @@
 import javax.naming.ldap.Control;
 import javax.naming.ldap.LdapName;
 
-import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
-
 import junit.framework.TestCase;
 
+import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
+
 public class LdapContextImplTest extends TestCase {
     private LdapContextImpl context;
+    
+    public void test_getSchema() throws NamingException {
+        context = new LdapContextImpl(new MockLdapClient(), null, "");
+        try {
+            context.getSchema((Name) null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            context.getSchema((String) null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
 
     public void test_composeName_LNameLName() throws Exception {
         context = new LdapContextImpl(new MockLdapClient(), null, "");

Added: 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=596127&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImplTest.java Sun Nov 18 12:28:25 2007
@@ -0,0 +1,127 @@
+/* 
+ *  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.Hashtable;
+
+import javax.naming.CompositeName;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SchemaViolationException;
+
+import junit.framework.TestCase;
+
+public class LdapSchemaContextImplTest extends TestCase {
+	public LdapSchemaContextImpl context;
+
+	protected void setUp() throws Exception {
+		super.setUp();
+		LdapContextImpl impl = new LdapContextImpl(
+				new MockLdapClient(), null, "");
+		CompositeName name = new CompositeName("ou=mock");
+		context = new LdapSchemaContextImpl(impl,
+				new Hashtable<Object, Object>(), name);
+		LdapSchemaContextImpl.schemaTree = new Hashtable<String, Hashtable<String, Hashtable<String, Object>>>();
+		LdapSchemaContextImpl.schemaTree.put(LdapSchemaContextImpl.ATTRIBUTE_TYPES,
+				new Hashtable<String, Hashtable<String, Object>>());
+		LdapSchemaContextImpl.schemaTree.put(LdapSchemaContextImpl.OBJECT_CLASSES,
+				new Hashtable<String, Hashtable<String, Object>>());
+		LdapSchemaContextImpl.schemaTree.put(LdapSchemaContextImpl.LDAP_SYNTAXES,
+				new Hashtable<String, Hashtable<String, Object>>());
+		LdapSchemaContextImpl.schemaTree.put(LdapSchemaContextImpl.MATCHING_RULES,
+				new Hashtable<String, Hashtable<String, Object>>());
+		context = new LdapSchemaContextImpl(context,
+				new Hashtable<Object, Object>(), name);
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		
+	}
+
+	public void test_CreateSubcontext_LName_LAttributes()
+			throws NamingException {
+		try {
+			context.createSubcontext((Name) null, new BasicAttributes());
+			fail("Should throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		try {
+			context.createSubcontext(new CompositeName(""), null);
+			fail("Should throw ArrayIndexOutOfBoundsException");
+		} catch (ArrayIndexOutOfBoundsException e) {
+			// expected
+		}
+		try {
+			context.createSubcontext(new CompositeName("test"), null);
+			fail("Should throw SchemaViolationException");
+		} catch (SchemaViolationException e) {
+			// expected
+		}
+		try {
+			context.createSubcontext(new CompositeName("test"),
+					new BasicAttributes());
+			fail("Should throw SchemaViolationException");
+		} catch (SchemaViolationException e) {
+			// expected
+		}
+
+		// Specify attributes for the schema object
+	}
+
+	public void test_modifyAttributes_LString_LModificationItem()
+			throws NamingException {
+		try {
+			context.modifyAttributes((String) null, new ModificationItem[] {});
+			fail("Should throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		try {
+			context.modifyAttributes("AttributeDefinition/cn", null);
+			fail("Should throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	public void test_search_LString_LAttributes_LString()
+			throws NamingException {
+		try {
+			context.search((String) null, new BasicAttributes(),
+					new String[] {});
+			fail("Should throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	public void testDestroySubcontextString() throws NamingException {
+		try {
+			context.destroySubcontext((String) null);
+			fail("Should throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+}

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

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java?rev=596127&r1=596126&r2=596127&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java Sun Nov 18 12:28:25 2007
@@ -31,13 +31,13 @@
         
         ASN1TestUtils.checkEncode(op, LdapASN1Constant.ModifyRequest);
         
-        LdapAttribute attr = new LdapAttribute("attr1");
+        LdapAttribute attr = new LdapAttribute("attr1", null);
         attr.add("value1");
         attr.add("value2");
         
         op.addModification(DirContext.ADD_ATTRIBUTE, attr);
         
-        attr = new LdapAttribute("attr2");
+        attr = new LdapAttribute("attr2", null);
         op.addModification(DirContext.REMOVE_ATTRIBUTE, attr);
         
         ASN1TestUtils.checkEncode(op, LdapASN1Constant.ModifyRequest);



Mime
View raw message