harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r652421 [2/6] - in /harmony/enhanced/classlib/branches/java6/modules: beans/src/main/java/java/beans/ beans/src/main/java/org/apache/harmony/beans/editors/ beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ imageio/src/main/java...
Date Thu, 01 May 2008 03:14:38 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java Wed Apr 30 20:14:31 2008
@@ -223,6 +223,38 @@
         }
     }
 
+    // Regression test for HARMONY-5711
+    @SuppressWarnings("nls")
+    public void testBooleanEditor() {
+        PropertyEditor propertyEditor = PropertyEditorManager
+                .findEditor(boolean.class);
+        assertNotNull(propertyEditor);
+        String tags[] = propertyEditor.getTags();
+        assertEquals(2, tags.length);
+        assertEquals("True", tags[0]);
+        assertEquals("False", tags[1]);
+
+        propertyEditor.setValue(Boolean.FALSE);
+        assertEquals("False", propertyEditor.getAsText());
+        assertEquals("false", propertyEditor.getJavaInitializationString());
+        propertyEditor.setAsText("False");
+        assertEquals("False", propertyEditor.getAsText());
+        assertEquals("false", propertyEditor.getJavaInitializationString());
+        propertyEditor.setAsText("false");
+        assertEquals("False", propertyEditor.getAsText());
+        assertEquals("false", propertyEditor.getJavaInitializationString());
+
+        propertyEditor.setValue(Boolean.TRUE);
+        assertEquals("True", propertyEditor.getAsText());
+        assertEquals("true", propertyEditor.getJavaInitializationString());
+        propertyEditor.setAsText("True");
+        assertEquals("True", propertyEditor.getAsText());
+        assertEquals("true", propertyEditor.getJavaInitializationString());
+        propertyEditor.setAsText("true");
+        assertEquals("True", propertyEditor.getAsText());
+        assertEquals("true", propertyEditor.getJavaInitializationString());
+    }
+    
     public void testByteEditor() {
         PropertyEditor editor = PropertyEditorManager.findEditor(Byte.TYPE);
         byte b = (byte) 0x7F;

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java Wed Apr 30 20:14:31 2008
@@ -704,4 +704,43 @@
             e.close();
         }
     }
+
+    /**
+     * This is a regression test for HARMONY-5707.
+     */
+    public void test5707() {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        XMLEncoder encoder = new XMLEncoder(baos);
+        TstBean5707 bean1 = new TstBean5707();
+
+        encoder.writeObject(bean1);
+        encoder.close();        
+    }
+
+    public class TstBean5707 {
+        int val;
+
+        public TstBean5707() {
+            val = 0;
+        }
+
+        public TstBean5707(int n) {
+            val = n;
+        }
+
+        public TstBean5707 getProp1() {
+            return new TstBean5707(val);
+        }
+
+        public void setProp1(TstBean5707 val) {}
+
+        public boolean equals(Object obj) {
+            if (obj instanceof TstBean5707) {
+                return ((TstBean5707) obj).val == val;
+            }
+
+            return false;
+        }
+
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/java/javax/imageio/ImageIO.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/java/javax/imageio/ImageIO.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/java/javax/imageio/ImageIO.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/java/javax/imageio/ImageIO.java Wed Apr 30 20:14:31 2008
@@ -14,10 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Rustem V. Rafikov
- * @version $Revision: 1.3 $
- */
+
 package javax.imageio;
 
 import javax.imageio.stream.ImageInputStream;
@@ -146,9 +143,11 @@
         return new SpiIteratorToReadersIteratorWrapper(it);
     }
 
-    public static Iterator<ImageReader> getImageReadersByMIMEType(String MIMEType) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public static Iterator<ImageReader> getImageReadersByMIMEType(
+                    final String MIMEType) {
+        return new SpiIteratorToReadersIteratorWrapper(
+                registry.getServiceProviders(ImageReaderSpi.class,
+                new MIMETypeFilter(MIMEType), true));
     }
 
     public static String[] getWriterFormatNames() throws NotImplementedException {
@@ -181,9 +180,11 @@
         return new SpiIteratorToWritersIteratorWrapper(it);
     }
 
-    public static Iterator<ImageWriter> getImageWritersByMIMEType(String MIMEType) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public static Iterator<ImageWriter> getImageWritersByMIMEType(
+                    final String MIMEType) {
+        return new SpiIteratorToWritersIteratorWrapper(
+                registry.getServiceProviders(ImageWriterSpi.class,
+                new MIMETypeFilter(MIMEType), true));
     }
 
     public static ImageWriter getImageWriter(ImageReader reader) throws NotImplementedException {
@@ -386,6 +387,26 @@
     }
 
     /**
+     * Filter to match spi by MIMEType
+     */
+    static class MIMETypeFilter implements ServiceRegistry.Filter {
+        private final String mimeType;
+
+        public MIMETypeFilter(final String mimeType) {
+            if (mimeType == null) {
+                throw new NullPointerException("MIMEType cannot be NULL");
+            }
+            
+            this.mimeType = mimeType;
+        }
+
+        public boolean filter(final Object provider) {
+            final String[] types = ((ImageReaderWriterSpi) provider).getMIMETypes();
+            return (types != null) && Arrays.asList(types).contains(mimeType);
+        }
+    }
+
+    /**
      * Filter to match spi by decoding possibility
      */
     static class CanReadFilter implements ServiceRegistry.Filter {

Modified: harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/java/javax/imageio/ImageTypeSpecifier.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/java/javax/imageio/ImageTypeSpecifier.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/java/javax/imageio/ImageTypeSpecifier.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/java/javax/imageio/ImageTypeSpecifier.java Wed Apr 30 20:14:31 2008
@@ -21,6 +21,7 @@
 package javax.imageio;
 
 import java.awt.image.ColorModel;
+import java.awt.image.DirectColorModel;
 import java.awt.image.SampleModel;
 import java.awt.image.BufferedImage;
 import java.awt.image.RenderedImage;
@@ -28,9 +29,6 @@
 
 import org.apache.harmony.luni.util.NotImplementedException;
 
-/**
- * TODO implement all the methods
- */
 public class ImageTypeSpecifier {
     
     protected ColorModel colorModel;
@@ -59,15 +57,15 @@
         this.sampleModel = renderedImage.getSampleModel();
     }
 
-    public static ImageTypeSpecifier createPacked(ColorSpace colorSpace,
-                                                  int redMask,
-                                                  int greenMask,
-                                                  int blueMask,
-                                                  int alphaMask,
-                                                  int transferType,
-                                                  boolean isAlphaPremultiplied) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public static ImageTypeSpecifier createPacked(final ColorSpace colorSpace,
+                    final int redMask, final int greenMask, final int blueMask,
+                    final int alphaMask, final int transferType,
+                    final boolean isAlphaPremultiplied) {
+        final ColorModel model = new DirectColorModel(colorSpace, 32, redMask,
+                        greenMask, blueMask, alphaMask, isAlphaPremultiplied,
+                        transferType);
+        return new ImageTypeSpecifier(model, model.createCompatibleSampleModel(
+            1, 1));
     }
 
     public static ImageTypeSpecifier createInterleaved(ColorSpace colorSpace,

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties Wed Apr 30 20:14:31 2008
@@ -216,3 +216,6 @@
 ldap.33=Scope should be one of 'OBJECT_SCOPE', 'ONELEVEL_SCOPE' or 'SUBTREE_SCOPE'
 ldap.34=[LDAP: error code {0} - {1}]
 ldap.35=[LDAP: error code {0}]
+ldap.36=Must have numeric OID
+ldap.37=Can't delete schema root
+ldap.38=Can't modify schema root

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ExtendedOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ExtendedOp.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ExtendedOp.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ExtendedOp.java Wed Apr 30 20:14:31 2008
@@ -61,7 +61,7 @@
         return request;
     }
 
-    public ExtendedResponse getExtendedResponse() {
+    public ExtendedResponse getExtendedResponse() throws NamingException {
 
         if (result != null && result.getResultCode() == 0
                 && responseValues != null) {
@@ -74,13 +74,9 @@
             if (value != null) {
                 length = value.length;
             }
-            
-            try {
-                response = request.createExtendedResponse(id, value, 0, length);
-            } catch (NamingException e) {
-                // FIXME: how to deal with this exception
-                e.printStackTrace();
-            }
+
+            response = request.createExtendedResponse(id, value, 0, length);
+
         }
         return response;
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java Wed Apr 30 20:14:31 2008
@@ -95,6 +95,7 @@
 import org.apache.harmony.jndi.provider.ldap.parser.FilterParser;
 import org.apache.harmony.jndi.provider.ldap.parser.LdapUrlParser;
 import org.apache.harmony.jndi.provider.ldap.parser.ParseException;
+import org.apache.harmony.jndi.provider.ldap.parser.SchemaParser;
 import org.apache.harmony.jndi.provider.ldap.sasl.SaslBind;
 
 /**
@@ -113,7 +114,7 @@
     /**
      * name of the context
      */
-    protected Name contextDn;
+    protected LdapName contextDn;
 
     private Control[] requestControls;
 
@@ -201,7 +202,7 @@
             Hashtable<Object, Object> environment, String dn)
             throws NamingException {
         initial(client, environment, dn);
-            doBindOperation(connCtls);
+        doBindOperation(connCtls);
     }
 
     private void initial(LdapClient ldapClient,
@@ -245,19 +246,19 @@
 
         SaslBind.AuthMech authMech = saslBind.valueAuthMech(env);
         try {
-        if (authMech == SaslBind.AuthMech.None) {
-            BindOp bind = new BindOp("", "", null, null);
-            client.doOperation(bind, connCtsl);
-            result = bind.getResult();
-        } else if (authMech == SaslBind.AuthMech.Simple) {
-            String principal = (String) env.get(Context.SECURITY_PRINCIPAL);
-            String credential = Utils.getString(env
-                    .get(Context.SECURITY_CREDENTIALS));
-            BindOp bind = new BindOp(principal, credential, null, null);
-            client.doOperation(bind, connCtsl);
-            result = bind.getResult();
-        } else if (authMech == SaslBind.AuthMech.SASL) {
-            result = saslBind.doSaslBindOperation(env, client, connCtsl);
+            if (authMech == SaslBind.AuthMech.None) {
+                BindOp bind = new BindOp("", "", null, null);
+                client.doOperation(bind, connCtsl);
+                result = bind.getResult();
+            } else if (authMech == SaslBind.AuthMech.Simple) {
+                String principal = (String) env.get(Context.SECURITY_PRINCIPAL);
+                String credential = Utils.getString(env
+                        .get(Context.SECURITY_CREDENTIALS));
+                BindOp bind = new BindOp(principal, credential, null, null);
+                client.doOperation(bind, connCtsl);
+                result = bind.getResult();
+            } else if (authMech == SaslBind.AuthMech.SASL) {
+                result = saslBind.doSaslBindOperation(env, client, connCtsl);
             }
         } catch (IOException e) {
             CommunicationException ex = new CommunicationException();
@@ -363,7 +364,7 @@
             throws NamingException {
         checkName(name);
 
-        if (name instanceof CompositeName && name.size() > 1) {
+        if (hasMultiNamingSpace(name)) {
             /*
              * multi ns, find next ns context, delegate operation to the next
              * contex
@@ -524,7 +525,7 @@
             throws NamingException {
         checkName(name);
 
-        if (name instanceof CompositeName && name.size() > 1) {
+        if (hasMultiNamingSpace(name)) {
             /*
              * multi ns, find next ns context, delegate operation to the next
              * context
@@ -556,7 +557,10 @@
         List<LdapAttribute> la = new ArrayList<LdapAttribute>(attrs.size());
         NamingEnumeration<? extends Attribute> enu = attrs.getAll();
         while (enu.hasMore()) {
-            la.add(new LdapAttribute(enu.next(), this));
+            Attribute att = enu.next();
+            if (att.size() > 0) {
+                la.add(new LdapAttribute(att, this));
+            }
         }
 
         // do add operation
@@ -693,10 +697,7 @@
             throws NamingException {
         checkName(name);
 
-        if (name instanceof CompositeName && name.size() > 1) {
-            if (!(name.getPrefix(0) instanceof LdapName)) {
-                throw new InvalidNameException(Messages.getString("ldap.26")); //$NON-NLS-1$
-            }
+        if (hasMultiNamingSpace(name)) {
             /*
              * multi ns, find next ns context, delegate operation to the next
              * context
@@ -761,14 +762,17 @@
 
     public static Hashtable<String, Hashtable<String, Hashtable<String, Object>>> schemaTree = new Hashtable<String, Hashtable<String, Hashtable<String, Object>>>();
 
+    private Hashtable<String, Object> schemaTable = new Hashtable<String, Object>();
+
     private LdapSchemaContextImpl ldapSchemaCtx = null;
 
     protected String subschemasubentry = null;
 
     public DirContext getSchema(Name name) throws NamingException {
         checkName(name);
-        if (null != ldapSchemaCtx)
+        if (null != ldapSchemaCtx) {
             return ldapSchemaCtx;
+        }
 
         SearchControls searchControls = new SearchControls();
         SearchOp search = null;
@@ -778,9 +782,6 @@
         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 {
@@ -795,7 +796,7 @@
             searchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
             searchControls.setReturningAttributes(new String[] {
                     "namingContexts", "subschemaSubentry", "altServer", });
-            search = new SearchOp("", searchControls, filter);
+            search = new SearchOp(name.toString(), searchControls, filter);
 
             try {
                 client.doOperation(search, requestControls);
@@ -813,6 +814,7 @@
             names = sre.getEntries();
 
             keyset = names.keySet();
+
             schemaRoot: for (Iterator<String> iterator = keyset.iterator(); iterator
                     .hasNext();) {
                 String key = iterator.next();
@@ -828,6 +830,10 @@
             }
         }
 
+        if (null == subschemasubentry) {
+            return getSchema(name.getPrefix(name.size() - 1));
+        }
+
         searchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
         searchControls.setReturningAttributes(new String[] { "objectclasses",
                 "attributetypes", "matchingrules", "ldapsyntaxes" });
@@ -871,17 +877,32 @@
                 if (!schemaTree.contains(schemaType.toLowerCase())) {
                     schemaTree.put(schemaType.toLowerCase(),
                             new Hashtable<String, Hashtable<String, Object>>());
+
+                    schemaTable.put(schemaType.toLowerCase(),
+                            new Hashtable<String, String>());
                 }
                 Hashtable<String, Hashtable<String, Object>> schemaDefs = schemaTree
                         .get(schemaType.toLowerCase());
+
+                Hashtable<String, String> schemaDef = (Hashtable<String, String>) schemaTable
+                        .get(schemaType.toLowerCase());
                 LdapAttribute attribute = (LdapAttribute) as.get(schemaType);
+               
+                String value;
+                String attrName;
                 for (int i = 0; i < attribute.size(); i++) {
-                    String value = (String) attribute.get(i);
+                    value = (String) attribute.get(i);
+                    attrName = SchemaParser.getName(value);
+                    schemaDef.put(attrName.toLowerCase(), value);
+
                     parseValue(schemaType, value.toLowerCase(), schemaDefs);
                 }
+
             }
         }
-        ldapSchemaCtx = new LdapSchemaContextImpl(this, env, name);
+
+        ldapSchemaCtx = new LdapSchemaContextImpl(this, env, name,
+                schemaTable, LdapSchemaContextImpl.SCHEMA_ROOT_LEVEL);
         return ldapSchemaCtx;
     }
 
@@ -895,12 +916,14 @@
 
     /*
      * 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
+     * '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 schemaType, String value,
             Hashtable<String, Hashtable<String, Object>> schemaDefs) {
-        StringTokenizer st = new StringTokenizer(value);
+        StringTokenizer st = new StringTokenizer(value.toLowerCase());
         // Skip (
         st.nextToken();
 
@@ -917,9 +940,15 @@
             if (attrName.startsWith("x-")) {
                 token = st.nextToken();
                 // remove the ending ' symbol
-                token = token.substring(0, token.length() - 1);
+                token = token.substring(1, token.length() - 1);
                 schemaDef.put(attrName, token);
             }
+            if (attrName.startsWith("auxiliary")) {
+                schemaDef.put(attrName, "true");
+            }
+            if (attrName.startsWith("structural")) {
+                schemaDef.put(attrName, "true");
+            }
             if (attrName.equals("usage") || attrName.equals("equality")
                     || attrName.equals("syntax") || attrName.equals("ordering")
                     || attrName.equals("substr")) {
@@ -1032,6 +1061,8 @@
 
     public DirContext getSchemaClassDefinition(Name name)
             throws NamingException {
+        checkName(name);
+
         if (null == ldapSchemaCtx) {
             getSchema("");
         }
@@ -1132,7 +1163,7 @@
             throw new NullPointerException(Messages.getString("ldap.27")); //$NON-NLS-1$
         }
 
-        if (name instanceof CompositeName && name.size() > 1) {
+        if (hasMultiNamingSpace(name)) {
             /*
              * multi ns, find next ns context, delegate operation to the next
              * context
@@ -1143,6 +1174,10 @@
             return;
         }
 
+        if (modificationItems.length == 0) {
+            return;
+        }
+
         /*
          * there is only one ldap ns
          */
@@ -1228,7 +1263,7 @@
             Attributes attributes, String[] as) throws NamingException {
         checkName(name);
 
-        if (name instanceof CompositeName && name.size() > 1) {
+        if (hasMultiNamingSpace(name)) {
             /*
              * multi ns, find next ns context, delegate operation to the next
              * context
@@ -1250,17 +1285,27 @@
             filter = new Filter(Filter.PRESENT_FILTER);
             filter.setValue("objectClass");
         } else {
-            NamingEnumeration<? extends Attribute> attrs = attributes.getAll();
-            filter = new Filter(Filter.AND_FILTER);
-            while (attrs.hasMore()) {
-                Attribute attr = attrs.next();
-                String type = attr.getID();
-                NamingEnumeration<?> enuValues = attr.getAll();
-                while (enuValues.hasMore()) {
-                    Object value = enuValues.next();
-                    Filter child = new Filter(Filter.EQUALITY_MATCH_FILTER);
-                    child.setValue(new AttributeTypeAndValuePair(type, value));
-                    filter.addChild(child);
+            // only one attribute type and value pair
+            if (attributes.size() == 1 && attributes.getAll().next().size() == 1) {
+                filter = new Filter(Filter.EQUALITY_MATCH_FILTER);
+                Attribute att = attributes.getAll().next();
+                filter.setValue(new AttributeTypeAndValuePair(att.getID(), att
+                        .get()));
+            } else {
+                NamingEnumeration<? extends Attribute> attrs = attributes
+                        .getAll();
+                filter = new Filter(Filter.AND_FILTER);
+                while (attrs.hasMore()) {
+                    Attribute attr = attrs.next();
+                    String type = attr.getID();
+                    NamingEnumeration<?> enuValues = attr.getAll();
+                    while (enuValues.hasMore()) {
+                        Object value = enuValues.next();
+                        Filter child = new Filter(Filter.EQUALITY_MATCH_FILTER);
+                        child.setValue(new AttributeTypeAndValuePair(type,
+                                value));
+                        filter.addChild(child);
+                    }
                 }
             }
         }
@@ -1282,7 +1327,8 @@
                 sr.setNameInNamespace(dn.substring(index + 1, dn.length()));
                 list.add(sr);
             } else {
-                String relativeName = LdapUtils.convertToRelativeName(dn, baseDN);
+                String relativeName = LdapUtils.convertToRelativeName(dn,
+                        baseDN);
                 sr = new SearchResult(relativeName, null, entries.get(dn));
                 sr.setNameInNamespace(dn);
             }
@@ -1302,7 +1348,7 @@
             throws NamingException {
         checkName(name);
 
-        if (name instanceof CompositeName && name.size() > 1) {
+        if (hasMultiNamingSpace(name)) {
             /*
              * multi ns, find next ns context, delegate operation to the next
              * context
@@ -1340,7 +1386,8 @@
                 sr.setNameInNamespace(dn.substring(index + 1, dn.length()));
                 list.add(sr);
             } else {
-                String relativeName = LdapUtils.convertToRelativeName(dn, baseDN);
+                String relativeName = LdapUtils.convertToRelativeName(dn,
+                        baseDN);
                 sr = new SearchResult(relativeName, null, entries.get(dn));
                 sr.setNameInNamespace(dn);
             }
@@ -1646,6 +1693,10 @@
         }
 
         if (name instanceof CompositeName) {
+            if (name.size() == 0) {
+                return new BasicAttributes(true);
+            }
+
             LdapName lname = new LdapName(name.get(0));
             Rdn rdn = lname.getRdn(lname.size() - 1);
             return rdn.toAttributes();
@@ -1661,10 +1712,7 @@
     public void destroySubcontext(Name name) throws NamingException {
         checkName(name);
 
-        if (name instanceof CompositeName && name.size() > 1) {
-            if (!(name.getPrefix(0) instanceof LdapName)) {
-                throw new InvalidNameException(Messages.getString("ldap.26")); //$NON-NLS-1$
-            }
+        if (hasMultiNamingSpace(name)) {
             /*
              * multi ns, find next ns context, delegate operation to the next
              * context
@@ -1708,10 +1756,7 @@
     }
 
     public NameParser getNameParser(Name name) throws NamingException {
-        if (name instanceof CompositeName && name.size() > 1) {
-            if (!(name.getPrefix(0) instanceof LdapName)) {
-                throw new InvalidNameException(Messages.getString("ldap.26")); //$NON-NLS-1$
-            }
+        if (hasMultiNamingSpace(name)) {
             /*
              * multi ns, find next ns context, delegate operation to the next
              * context
@@ -1732,10 +1777,7 @@
             throws NamingException {
         checkName(name);
 
-        if (name instanceof CompositeName && name.size() > 1) {
-            if (!(name.getPrefix(0) instanceof LdapName)) {
-                throw new InvalidNameException(Messages.getString("ldap.26")); //$NON-NLS-1$
-            }
+        if (hasMultiNamingSpace(name)) {
             /*
              * multi ns, find next ns context, delegate operation to the next
              * context
@@ -1789,7 +1831,6 @@
                 .getException());
     }
 
-
     protected String getTargetDN(Name name, Name prefix)
             throws NamingException, InvalidNameException {
         Name target = null;
@@ -1806,6 +1847,21 @@
         return target.toString();
     }
 
+    protected boolean hasMultiNamingSpace(Name name) {
+        if (name instanceof CompositeName) {
+            // name '/'
+            if (name.size() == 1 && "".equals(name.get(0))) {
+                return true;
+            }
+
+            if (name.size() > 1) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     protected Context findNnsContext(Name name) throws NamingException {
         CannotProceedException cpe = null;
         if (env.containsKey(NamingManager.CPE)) {
@@ -1814,35 +1870,40 @@
             cpe = new CannotProceedException();
         }
 
-        Name remainingName = name.getSuffix(1);
-        Name altName = name.getPrefix(0);
-        Name targetName = composeName(altName, contextDn);
+        String dn = name.get(0);
+
+        // seems altName always is "/"
+        Name altName = new CompositeName();
+        altName.add("");
+
+        // if the dn doesn't exist, throw NameNotFoundException
+        lookup(dn);
 
         Name resolvedName = cpe.getResolvedName();
         if (resolvedName == null) {
             resolvedName = new CompositeName();
 
-        } else if (resolvedName.size() >= 2
-                && resolvedName.get(resolvedName.size() - 1).equals("")) {
-            // remove the last component if it is ""
-            // (the sign of the next naming system), so there must be at least
-            // one name before "".
-            resolvedName.remove(resolvedName.size() - 1);
         }
 
-        resolvedName.add(targetName.toString());
-        // add empty component name to indicate nns pointer
-        resolvedName.add("");
+        resolvedName.add(dn);
+
+        Name remainingName = name.getSuffix(1);
+        if (remainingName.size() == 1 && remainingName.get(0).equals("")) {
+            remainingName = new CompositeName();
+            if (!resolvedName.get(resolvedName.size() - 1).equals("")) {
+                resolvedName.add("");
+            }
+        }
+
+        final LdapContextImpl context = new LdapContextImpl(this, env,
+                composeName(new LdapName(dn), contextDn).toString());
 
         cpe.setAltName(altName);
-        cpe.setAltNameCtx(this);
+        cpe.setAltNameCtx(context);
         cpe.setEnvironment((Hashtable<Object, Object>) env.clone());
         cpe.setRemainingName(remainingName);
         cpe.setResolvedName(resolvedName);
 
-        final LdapContextImpl context = new LdapContextImpl(this, env,
-                composeName(altName, contextDn).toString());
-
         RefAddr addr = new RefAddr("nns") { //$NON-NLS-1$
 
             private static final long serialVersionUID = -5428706819217461955L;
@@ -1854,7 +1915,9 @@
 
         };
 
-        Reference ref = new Reference(context.getClass().getName(), addr);
+        // class name is always java.lang.Object in RI
+        Reference ref = new Reference(Object.class.getName(), addr);
+
         cpe.setResolvedObj(ref);
 
         return DirectoryManager.getContinuationDirContext(cpe);
@@ -1869,7 +1932,7 @@
             throws NamingException {
         checkName(name);
 
-        if (name instanceof CompositeName && name.size() > 1) {
+        if (hasMultiNamingSpace(name)) {
             /*
              * multi ns, find next ns context, delegate operation to the next
              * contex
@@ -1915,7 +1978,7 @@
     public Object lookup(Name name) throws NamingException {
         checkName(name);
 
-        if (name instanceof CompositeName && name.size() > 1) {
+        if (hasMultiNamingSpace(name)) {
             /*
              * multi ns, find next ns context, delegate operation to the next
              * context
@@ -2026,7 +2089,7 @@
     }
 
     private boolean hasAttribute(Attributes attributes, String type,
-            Object value) throws NamingException {
+            String value) throws NamingException {
         Attribute attr = attributes.get(type);
         if (attr == null) {
             return false;
@@ -2035,7 +2098,7 @@
         NamingEnumeration<?> enu = attr.getAll();
         while (enu.hasMore()) {
             Object o = enu.next();
-            if (value.equals(o)) {
+            if (value.equalsIgnoreCase(Utils.getString(o))) {
                 return true;
             }
         }
@@ -2131,8 +2194,7 @@
             throw new InvalidNameException(Messages.getString("ldap.2A")); //$NON-NLS-1$
         }
 
-        if (nOld instanceof CompositeName && nOld.size() > 1
-                && nNew instanceof CompositeName && nNew.size() > 1) {
+        if (hasMultiNamingSpace(nOld) && hasMultiNamingSpace(nNew)) {
             Context context = findNnsContext(nOld);
             context.rename(nOld.getSuffix(1), nNew.getSuffix(1));
             return;
@@ -2278,11 +2340,20 @@
         return controls;
     }
 
-    private void checkName(Name name) {
+    private void checkName(Name name) throws InvalidNameException {
         if (name == null) {
             // jndi.2E=The name is null
             throw new NullPointerException(Messages.getString("jndi.2E")); //$NON-NLS-1$
         }
+
+        if (!(name instanceof LdapName) && !(name instanceof CompositeName)) {
+            throw new InvalidNameException(Messages.getString("ldap.26")); //$NON-NLS-1$
+        }
+
+        // the first part of CompositeName must be ldap name
+        if (name instanceof CompositeName && name.size() > 0) {
+            new LdapName(name.get(0));
+        }
     }
 
     @Override
@@ -2460,7 +2531,8 @@
                 EventObject event = null;
                 try {
                     un.setControls(narrowingControls(cs));
-                    event = new UnsolicitedNotificationEvent(this, un);
+                    event = new UnsolicitedNotificationEvent(
+                            LdapContextImpl.this, un);
                 } catch (NamingException e) {
                     event = new NamingExceptionEvent(LdapContextImpl.this, e);
                 }
@@ -2583,41 +2655,44 @@
     }
 
     public boolean targetMustExist() throws NamingException {
-        // FIXME
-        return false;
+        return true;
     }
 
     private NamingEvent constructNamingEvent(PersistentSearchResult result,
-            ECNotificationControl control, String baseDN) throws InvalidNameException, NamingException {
+            ECNotificationControl control, String baseDN)
+            throws InvalidNameException, NamingException {
         Binding newBinding = null;
         Binding oldBinding = null;
 
         switch (control.getChangeType()) {
         case ECNotificationControl.ADD:
-            String newName = LdapUtils.convertToRelativeName(result.getDn(), baseDN);
+            String newName = LdapUtils.convertToRelativeName(result.getDn(),
+                    baseDN);
             newBinding = new Binding(newName, null);
             newBinding.setNameInNamespace(result.getDn());
             break;
         case ECNotificationControl.DELETE:
-            String deleteName = LdapUtils.convertToRelativeName(result.getDn(), baseDN);
+            String deleteName = LdapUtils.convertToRelativeName(result.getDn(),
+                    baseDN);
             oldBinding = new Binding(deleteName, null);
             oldBinding.setNameInNamespace(result.getDn());
             break;
         case ECNotificationControl.MODIFY_DN:
             if (result.getDn() != null) {
-                newBinding = new Binding(LdapUtils.convertToRelativeName(result.getDn(),
-                        baseDN), null);
+                newBinding = new Binding(LdapUtils.convertToRelativeName(result
+                        .getDn(), baseDN), null);
                 newBinding.setNameInNamespace(result.getDn());
             }
 
             if (control.getPreviousDN() != null) {
-                oldBinding = new Binding(LdapUtils.convertToRelativeName(control
-                        .getPreviousDN(), baseDN), null);
+                oldBinding = new Binding(LdapUtils.convertToRelativeName(
+                        control.getPreviousDN(), baseDN), null);
                 oldBinding.setNameInNamespace(control.getPreviousDN());
             }
             break;
         case ECNotificationControl.MODIFY:
-            String relativeName = LdapUtils.convertToRelativeName(result.getDn(), baseDN);
+            String relativeName = LdapUtils.convertToRelativeName(result
+                    .getDn(), baseDN);
             newBinding = new Binding(relativeName, null);
             newBinding.setNameInNamespace(result.getDn());
             // FIXME: how to get old binding?

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapMessage.java Wed Apr 30 20:14:31 2008
@@ -196,7 +196,8 @@
         // ABANDON, UNBIND and DELETE request are ASN.1 primitive
         if (opIndex == LdapASN1Constant.OP_ABANDON_REQUEST
                 || opIndex == LdapASN1Constant.OP_DEL_REQUEST
-                || opIndex == LdapASN1Constant.OP_UNBIND_REQUEST) {
+                || opIndex == LdapASN1Constant.OP_UNBIND_REQUEST
+                || opIndex == LdapASN1Constant.OP_SEARCH_RESULT_REF) {
             Object[] objs = new Object[1];
             requestOp.encodeValues(objs);
             values[1] = new ChosenValue(opIndex, objs[0]);

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java Wed Apr 30 20:14:31 2008
@@ -27,10 +27,10 @@
 
 import javax.naming.Binding;
 import javax.naming.CompositeName;
-import javax.naming.ConfigurationException;
 import javax.naming.Context;
 import javax.naming.InvalidNameException;
 import javax.naming.Name;
+import javax.naming.NameAlreadyBoundException;
 import javax.naming.NameClassPair;
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingEnumeration;
@@ -52,16 +52,17 @@
 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;
+import org.apache.harmony.jndi.provider.ldap.parser.SchemaParser;
 
 public class LdapSchemaContextImpl extends LdapContextImpl {
 
-    public static final String CLASS_DEFINITION = "classdefinition";
+    public static final String CLASS_DEFINITION = "ClassDefinition";
 
-    public static final String ATTRIBUTE_DEFINITION = "attributedefinition";
+    public static final String ATTRIBUTE_DEFINITION = "AttributeDefinition";
 
-    public static final String SYNTAX_DEFINITION = "syntaxdefinition";
+    public static final String SYNTAX_DEFINITION = "SyntaxDefinition";
 
-    public static final String MATCHING_RULE = "matchingrule";
+    public static final String MATCHING_RULE = "MatchingRule";
 
     public static final String OBJECT_CLASSES = "objectclasses";
 
@@ -71,14 +72,17 @@
 
     public static final String MATCHING_RULES = "matchingrules";
 
+    public static final int SCHEMA_ROOT_LEVEL = 3;
+
     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);
+        schemaJndi2Ldap.put(CLASS_DEFINITION.toLowerCase(), OBJECT_CLASSES);
+        schemaJndi2Ldap
+                .put(ATTRIBUTE_DEFINITION.toLowerCase(), ATTRIBUTE_TYPES);
+        schemaJndi2Ldap.put(SYNTAX_DEFINITION.toLowerCase(), LDAP_SYNTAXES);
+        schemaJndi2Ldap.put(MATCHING_RULE.toLowerCase(), MATCHING_RULES);
     }
 
     final private static Hashtable<String, String> schemaLdap2Jndi = new Hashtable<String, String>();
@@ -91,139 +95,152 @@
 
     private LdapContextImpl parent;
 
+    private Hashtable<String, Object> schemaTable;
+
     private Name rdn = null;
 
-    public LdapSchemaContextImpl(LdapContextImpl ctx, Hashtable<Object, Object> env,
-            Name dn) throws InvalidNameException {
+    private int level;
+
+    public LdapSchemaContextImpl(LdapContextImpl ctx,
+            Hashtable<Object, Object> env, Name dn) throws InvalidNameException {
+        super(ctx, env, dn.getPrefix(0).toString());
+        parent = ctx;
+        rdn = dn;
+    }
+
+    public LdapSchemaContextImpl(LdapContextImpl ctx,
+            Hashtable<Object, Object> env, Name dn,
+            Hashtable<String, Object> schemaTable, int level)
+            throws InvalidNameException {
         super(ctx, env, dn.getPrefix(0).toString());
         parent = ctx;
         rdn = dn;
+        this.schemaTable = schemaTable;
+        this.level = level;
     }
 
+    @Override
     public DirContext getSchema(Name name) throws NamingException {
         throw new OperationNotSupportedException();
     }
 
+    @Override
     public DirContext getSchema(String name) throws NamingException {
         throw new OperationNotSupportedException();
     }
 
+    @Override
     public DirContext getSchemaClassDefinition(Name name)
             throws NamingException {
         throw new OperationNotSupportedException();
     }
 
+    @Override
     public DirContext getSchemaClassDefinition(String name)
             throws NamingException {
         throw new OperationNotSupportedException();
     }
 
+    @Override
     public String getNameInNamespace() throws NamingException {
         throw new OperationNotSupportedException();
     }
 
+    @Override
     public DirContext createSubcontext(Name name, Attributes attributes)
             throws NamingException {
-        checkName(name);
-
-        Name schemaType = name.getPrefix(name.size() - 1);
+        int size = name.size();
+        Hashtable<String, Object> subSchemaTree = doLookup(name
+                .getPrefix(size - 1), size - 1);
 
         if (null == attributes || attributes.size() == 0) {
-            throw new SchemaViolationException(Messages.getString("jndi.8D"));
+            // jndi.8D=Must supply attributes describing schema
+            throw new SchemaViolationException(Messages.getString("jndi.8D")); //$NON-NLS-1$
         }
 
-        String schema = schemaJndi2Ldap.get(schemaType.toString().toLowerCase());
-        if (null == schema) {
-            throw new SchemaViolationException(Messages.getString("jndi.8D"));
-        }
-        if (!LdapContextImpl.schemaTree.keySet().contains(schema)) {
-            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(" ");
-            }
+        if (level - size == 2) {
+            // jndi.8E=Cannot create new entry under schema root
+            throw new SchemaViolationException(Messages.getString("jndi.8E")); //$NON-NLS-1$
         }
-        builder.append(")");
-        if (!hasNOID) {
-            throw new ConfigurationException(Messages.getString("jndi.8F"));
+
+        String subSchemaType = name.getSuffix(size - 1).toString();
+
+        if (subSchemaTree.get(subSchemaType.toLowerCase()) != null) {
+            throw new NameAlreadyBoundException(subSchemaType);
         }
 
-        ModifyOp op = new ModifyOp(targetDN);
+        String schemaLine = SchemaParser.format(attributes);
+
+        ModifyOp op = new ModifyOp(parent.subschemasubentry);
+        Name modifySchemaName = name.getPrefix(size - 1).addAll(rdn);
         BasicAttribute schemaEntry = new LdapAttribute(new BasicAttribute(
-                schema, builder.toString()), parent);
+                jndi2ldap(modifySchemaName.toString()), schemaLine), parent);
         op.addModification(jndi2ldap[DirContext.ADD_ATTRIBUTE],
                 new LdapAttribute(schemaEntry, parent));
-
         try {
             doBasicOperation(op);
+            subSchemaTree.put(subSchemaType.toLowerCase(), schemaLine);
         } catch (ReferralException e) {
             // TODO
         }
-        return new LdapSchemaContextImpl(parent, parent.env, name);
+
+        return (DirContext) lookup(name);
+
     }
 
+    @Override
     public DirContext createSubcontext(String name, Attributes attributes)
             throws NamingException {
         Name n = convertFromStringToName(name);
         return createSubcontext(n, attributes);
     }
 
+    @Override
     public Attributes getAttributes(Name name) throws NamingException {
-        Name targetDN = (rdn.size() != 0) ? name.addAll(rdn) : name;
+        int size = name.size();
+
+        Hashtable<String, Object> attributesTable = doLookup(name, size);
 
         BasicAttributes schemaAttributes = new BasicAttributes(true);
 
-        Set<String> keyset = null;
-        int size = targetDN.size();
-        switch (size) {
-        case 0:
-            break;
+        switch (level - size) {
         case 1:
-            String schemaType = schemaJndi2Ldap.get(name.get(0).toLowerCase());
-            if (null == schemaType) {
-                throw new NameNotFoundException(name.toString());
-            }
-            schemaAttributes.put(new BasicAttribute("objectclass", name.get(0)
-                    .toLowerCase()));
-            break;
-        default:
-            Hashtable<String, Object> classDef = parent.findSchemaDefInfo(
-                    schemaJndi2Ldap.get(name.get(0).toLowerCase()), name.get(1));
-            if (null == classDef) {
-                throw new NameNotFoundException(name.toString());
-            }
-            schemaAttributes = new BasicAttributes(true);
-            keyset = classDef.keySet();
+            Set<String> keyset = attributesTable.keySet();
             for (Iterator<String> i = keyset.iterator(); i.hasNext();) {
                 String id = i.next();
-                if (id.equals("orig")) {
+                if (id.equals("orig")) { //$NON-NLS-1$
                     continue;
                 }
-                Object value = classDef.get(id);
-                schemaAttributes
-                        .put(new BasicAttribute(id.toLowerCase(), value));
+                Object value = attributesTable.get(id);
+                BasicAttribute basicAttr = new BasicAttribute(id);
+
+                if (value instanceof List) {
+                    List<Object> list = (List<Object>) value;
+                    for (int j = 0; j < list.size(); j++) {
+                        basicAttr.add(list.get(j));
+                    }
+                } else {
+                    basicAttr.add(value);
+                }
+                schemaAttributes.put(basicAttr);
             }
+            break;
+
+        case 2:
+            BasicAttribute basicAttr = new BasicAttribute("objectclass"); //$NON-NLS-1$
+            Name allName = name.addAll(rdn);
+            basicAttr.add(allName.toString());
+            schemaAttributes.put(basicAttr);
+            break;
+
+        default:
+            // Do nothing.
         }
+
         return schemaAttributes;
     }
 
+    @Override
     public Attributes getAttributes(Name name, String[] as)
             throws NamingException {
         Attributes attrs = getAttributes(name);
@@ -238,12 +255,14 @@
         return filteredAttrs;
     }
 
+    @Override
     public Attributes getAttributes(String attributeName)
             throws NamingException {
         Name name = new CompositeName(attributeName);
         return getAttributes(name);
     }
 
+    @Override
     public Attributes getAttributes(String name, String[] as)
             throws NamingException {
         return getAttributes(new CompositeName(name), as);
@@ -256,6 +275,7 @@
         }
     }
 
+    @Override
     public void modifyAttributes(Name name, int i, Attributes attributes)
             throws NamingException {
         checkName(name);
@@ -282,231 +302,324 @@
         }
 
         modifyAttributes(name, items);
-
     }
 
     private static final int jndi2ldap[] = { -1, 0, 2, 1, };
 
+    @Override
     public void modifyAttributes(Name name, ModificationItem[] modificationItems)
             throws NamingException {
-        checkName(name);
+        // First get the old schema.
+        int size = name.size();
+        Hashtable<String, Object> subSchemaTree = doLookup(name
+                .getPrefix(size - 1), size - 1);
 
-        Name targetDN = (rdn.size() != 0) ? name.addAll(rdn) : name;
-        int size = targetDN.size();
-        ModifyOp op = new ModifyOp(targetDN.toString());
-        String oldValue = "(objectclass)";
-        switch (size) {
-        case 0:
-            break;
-        case 1:
-            String schemaType = schemaJndi2Ldap.get(name.get(0).toLowerCase());
-            if (null == schemaType) {
-                throw new NameNotFoundException(name.toString());
-            }
-            if (modificationItems == null) {
-                throw new NullPointerException(Messages.getString("ldap.27")); //$NON-NLS-1$
-            }
-            break;
-        default:
-            Hashtable<String, Object> classDef = parent
-                    .findSchemaDefInfo(schemaJndi2Ldap.get(name.get(0)
-                            .toLowerCase()), name.get(1));
-            if (modificationItems == null) {
-                throw new NullPointerException(Messages.getString("ldap.27")); //$NON-NLS-1$
-            }
-            if (null == classDef) {
-                throw new NameNotFoundException(name.toString());
-            }
+        String subSchemaType = name.getSuffix(size - 1).toString()
+                .toLowerCase();
+
+        Object schema = subSchemaTree.get(jndi2ldap(subSchemaType));
+        if (schema == null) {
+            throw new NameNotFoundException(name.toString());
+        }
+
+        if (level - size == 2) {
+            // ldap.38=Can't modify schema root
+            throw new SchemaViolationException(Messages.getString("ldap.38")); //$NON-NLS-1$
+        }
+
+        if (modificationItems.length == 0) {
+            return;
+        }
+
+        String schemaLine = schema.toString();
+        if (schema instanceof Hashtable) {
+            Hashtable table = (Hashtable) schema;
+            schemaLine = table.get(SchemaParser.ORIG).toString();
+        }
+
+        // Construct the new schema.
+        Attributes attributes = getAttributes(name);
+        int modifyOperation;
+        Attribute modifyAttribute;
+        Attribute attribute;
+        NamingEnumeration<?> enu;
+        for (int i = 0; i < modificationItems.length; i++) {
+            modifyOperation = modificationItems[i].getModificationOp();
+            modifyAttribute = modificationItems[i].getAttribute();
+
+            switch (modifyOperation) {
+            case DirContext.ADD_ATTRIBUTE:
+                attribute = attributes.get(modifyAttribute.getID());
+                if (attribute == null) {
+                    attributes.put(modifyAttribute);
+                } else {
+                    enu = modifyAttribute.getAll();
+                    while (enu.hasMoreElements()) {
+                        attribute.add(enu.nextElement());
+                    }
+                    attributes.put(attribute);
+                }
+                break;
+
+            case DirContext.REMOVE_ATTRIBUTE:
+                attribute = attributes.get(modifyAttribute.getID());
+                enu = modifyAttribute.getAll();
+                while (enu.hasMoreElements()) {
+                    attribute.remove(enu.nextElement());
+                }
+                if (attribute.size() == 0) {
+                    attributes.remove(modifyAttribute.getID());
+                }
+                break;
 
-            oldValue = (String) classDef.get("orig");
+            case DirContext.REPLACE_ATTRIBUTE:
+                attributes.remove(modifyAttribute.getID());
+                attributes.put(modifyAttribute);
+                break;
+            default:
+                // Never reach here.
+            }
         }
-        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);
+        String newSchemaLine = SchemaParser.format(attributes);
+
+        // Remove old schema, then add new schema.
+        ModifyOp op = new ModifyOp(parent.subschemasubentry);
+        Name modifySchemaName = name.getPrefix(size - 1).addAll(rdn);
+        BasicAttribute schemaEntry = new LdapAttribute(new BasicAttribute(
+                jndi2ldap(modifySchemaName.toString()), schemaLine), parent);
         op.addModification(jndi2ldap[DirContext.REMOVE_ATTRIBUTE],
-                new LdapAttribute(oldAttr, parent));
+                new LdapAttribute(schemaEntry, parent));
+        BasicAttribute addSchemaEntry = new LdapAttribute(new BasicAttribute(
+                jndi2ldap(modifySchemaName.toString()), newSchemaLine), parent);
         op.addModification(jndi2ldap[DirContext.ADD_ATTRIBUTE],
-                new LdapAttribute(newAttr, parent));
-        
-        try {
-            doBasicOperation(op);
-        } catch (Exception e) {
-            throw new SchemaViolationException("Cannot modify schema root");
-        }
+                new LdapAttribute(addSchemaEntry, parent));
 
+        doBasicOperation(op);
+        subSchemaTree.remove(subSchemaType);
+        subSchemaTree.put(subSchemaType, newSchemaLine);
     }
 
+    @Override
     public void modifyAttributes(String s, int i, Attributes attributes)
             throws NamingException {
         Name name = convertFromStringToName(s);
         modifyAttributes(name, i, attributes);
     }
 
+    @Override
     public void modifyAttributes(String s, ModificationItem[] modificationItems)
             throws NamingException {
         Name name = convertFromStringToName(s);
         modifyAttributes(name, modificationItems);
-
     }
 
+    @Override
     public Context createSubcontext(Name name) throws NamingException {
         DirContext subContext = createSubcontext(name, null);
         return subContext;
     }
 
+    @Override
     public Context createSubcontext(String name) throws NamingException {
         Name n = convertFromStringToName(name);
         return createSubcontext(n);
     }
 
+    @Override
     public void destroySubcontext(Name name) throws NamingException {
-        checkName(name);
+        int size = name.size();
+        Hashtable<String, Object> subSchemaTree = doLookup(name
+                .getPrefix(size - 1), size - 1);
+
+        String subSchemaType = name.getSuffix(size - 1).toString()
+                .toLowerCase();
+
+        Object schema = subSchemaTree.get(jndi2ldap(subSchemaType));
+        if (schema == null) {
+            // Return silently.
+            return;
+        }
 
-        // 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();
+        if (level - size == 2) {
+            // ldap.37=Can't delete schema root
+            throw new SchemaViolationException(Messages.getString("ldap.37")); //$NON-NLS-1$
         }
 
-        Hashtable<String, Object> classDef = parent.findSchemaDefInfo(
-                schemaType, name.get(1));
-        if (null == classDef) {
+        if (level == size) {
+            // Return silently.
             return;
         }
-        String oldValue = (String) classDef.get("orig");
-        LdapAttribute oldAttr = new LdapAttribute(new BasicAttribute(
-                schemaType, oldValue), parent);
-        op.addModification(jndi2ldap[DirContext.REMOVE_ATTRIBUTE], oldAttr);
 
+        String schemaLine = schema.toString();
+        if (schema instanceof Hashtable) {
+            Hashtable table = (Hashtable) schema;
+            schemaLine = table.get(SchemaParser.ORIG).toString();
+        }
+
+        ModifyOp op = new ModifyOp(parent.subschemasubentry);
+        Name modifySchemaName = name.getPrefix(size - 1).addAll(rdn);
+        BasicAttribute schemaEntry = new LdapAttribute(new BasicAttribute(
+                jndi2ldap(modifySchemaName.toString()), schemaLine), parent);
+        op.addModification(jndi2ldap[DirContext.REMOVE_ATTRIBUTE],
+                new LdapAttribute(schemaEntry, parent));
         try {
             doBasicOperation(op);
-        } catch (Exception e) {
-            // TODO need to handle referal exception in the future
+            subSchemaTree.remove(subSchemaType);
+        } catch (ReferralException e) {
+            // TODO
         }
     }
 
+    @Override
     public void destroySubcontext(String name) throws NamingException {
         destroySubcontext(convertFromStringToName(name));
     }
 
+    private String ldap2jndi(String jndiName) {
+        String ldapName = schemaLdap2Jndi.get(jndiName);
+        if (null == ldapName) {
+            ldapName = jndiName;
+        }
+
+        return ldapName;
+    }
+
+    private String jndi2ldap(String ldapName) {
+        String jndiName = schemaJndi2Ldap.get(ldapName.toLowerCase());
+        if (null == jndiName) {
+            jndiName = ldapName;
+        }
+
+        return jndiName.toLowerCase();
+    }
+
+    @Override
     public NamingEnumeration<NameClassPair> list(Name name)
             throws NamingException {
-        Name targetDN = name.addAll(rdn);
+        int size = name.size();
+
+        Hashtable<String, Object> tempSchema = doLookup(name, size);
 
         LdapNamingEnumeration<NameClassPair> enumeration = new LdapNamingEnumeration<NameClassPair>(
                 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();
-                NameClassPair pair = new NameClassPair(schemaLdap2Jndi
-                        .get(schemaType.toLowerCase()), this.getClass()
-                        .getName());
-                enumeration.add(pair);
-            }
-            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();
-                NameClassPair pair = new NameClassPair(
-                        schemaType.toLowerCase(), this.getClass().getName());
-                enumeration.add(pair);
-            }
-            break;
-        default:
-            schemaType = schemaJndi2Ldap.get(name.getPrefix(1).toString()
-                    .toLowerCase());
-            if (null == schemaType) {
-                throw new NameNotFoundException(name.toString());
-            }
-            list(name.getSuffix(1));
+
+        if (size == level - 1) {
+            return enumeration;
+        }
+
+        Iterator<String> keys = tempSchema.keySet().iterator();
+
+        while (keys.hasNext()) {
+            enumeration.add(new NameClassPair(ldap2jndi(keys.next()), this
+                    .getClass().getName()));
         }
+
         return enumeration;
     }
 
+    @Override
+    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$
+        }
+
+        CompositeName name = new CompositeName(s);
+        return name;
+    }
+
+    @Override
     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));
     }
 
+    @Override
     public NamingEnumeration<Binding> listBindings(Name name)
             throws NamingException {
-        Name targetDN = name.addAll(rdn);
+        int size = name.size();
+
+        Hashtable<String, Object> tempSchema = doLookup(name, size);
 
         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));
+
+        if (size == level - 1) {
+            return enumeration;
+        }
+
+        Iterator<String> keys = tempSchema.keySet().iterator();
+
+        while (keys.hasNext()) {
+            enumeration.add(new Binding(ldap2jndi(keys.next()), this.getClass()
+                    .getName()));
         }
+
         return enumeration;
     }
 
+    @Override
     public NamingEnumeration<Binding> listBindings(String name)
             throws NamingException {
         return listBindings(convertFromStringToName(name));
     }
 
-    public Object lookup(Name n) throws NamingException {
-        return new LdapSchemaContextImpl(parent, env, n.addAll(rdn));
+    private Hashtable<Name, LdapSchemaContextImpl> cachedSubSchemas = new Hashtable<Name, LdapSchemaContextImpl>();
+
+    @Override
+    public Object lookup(Name name) throws NamingException {
+        // If cached, directly return cached one.
+        Name targetDN = name;
+        LdapSchemaContextImpl cachedSchema = cachedSubSchemas.get(targetDN);
+        if (cachedSchema != null) {
+            return cachedSchema;
+        }
+        int size = targetDN.size();
+        if (size == 0) {
+            return this;
+        }
+
+        Hashtable<String, Object> newSchemaTable = doLookup(name, size);
+
+        cachedSchema = new LdapSchemaContextImpl(parent, env, targetDN,
+                newSchemaTable, level - size);
+        cachedSubSchemas.put(targetDN, cachedSchema);
+
+        return cachedSchema;
+    }
+
+    // Find the subtree of schematree corresponding to the name.
+    private Hashtable<String, Object> doLookup(Name name, int size)
+            throws NamingException {
+        Name targetDN = name;
+        if (size >= level) {
+            throw new NameNotFoundException(name.toString());
+        }
+
+        Hashtable<String, Object> tempSchema = schemaTable;
+        Object tempValue;
+        for (int i = 0; i < size; i++) {
+            String key = targetDN.get(i);
+            tempValue = tempSchema.get(jndi2ldap(key));
+            if (tempValue == null) {
+                throw new NameNotFoundException(name.toString());
+            }
+
+            if (tempValue instanceof String) {
+                Hashtable<String, Object> attributesTable = SchemaParser
+                        .parseValue(tempValue.toString());
+                tempSchema.put(jndi2ldap(key).toLowerCase(), attributesTable);
+                tempSchema = attributesTable;
+            } else {
+                tempSchema = (Hashtable<String, Object>) tempValue;
+            }
+        }
+
+        return tempSchema;
     }
 
+    @Override
     public Object lookup(String name) throws NamingException {
         return lookup(convertFromStringToName(name));
     }
@@ -611,7 +724,8 @@
                      * encountered attribute value,
                      */
                     if (attribute.contains(schemaType)) {
-                        BasicAttributes basicAttributes = new BasicAttributes(true);
+                        BasicAttributes basicAttributes = new BasicAttributes(
+                                true);
                         /*
                          * if(objectclassIndex == -1), then No name was choose,
                          * which means SearchResult will have empty
@@ -729,11 +843,11 @@
     private boolean match(Attribute filter, Object values)
             throws NamingException {
         NamingEnumeration<?> attrValues = filter.getAll();
-        ArrayList v = null;
+        ArrayList<Object> v = null;
         if (values instanceof ArrayList) {
-            v = (ArrayList) values;
+            v = (ArrayList<Object>) values;
         } else {
-            v = new ArrayList();
+            v = new ArrayList<Object>();
             v.add(values);
         }
 
@@ -793,8 +907,8 @@
             BasicAttributes matchingAttrs) {
         if (!f.isLeaf()) {
             List<Filter> children = f.getChildren();
-            for (Iterator iter = children.iterator(); iter.hasNext();) {
-                extractMatchingAttributes((Filter) iter.next(), matchingAttrs);
+            for (Iterator<Filter> iter = children.iterator(); iter.hasNext();) {
+                extractMatchingAttributes(iter.next(), matchingAttrs);
             }
         } else {
             Object value = f.getValue();

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java Wed Apr 30 20:14:31 2008
@@ -40,7 +40,9 @@
     public void decodeValues(Object[] values) {
         result = new LdapResult();
         result.decodeValues(values);
-        oid = Utils.getString(values[4]);
+        if (values[4] != null) {
+            oid = Utils.getString(values[4]);
+        }
         if (values[5] != null) {
             encodedValue = (byte[]) values[5];
         }

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java Wed Apr 30 20:14:31 2008
@@ -61,8 +61,8 @@
             out.content = bytes;
             out.length = bytes.length;
         }
-        // TODO: Any way better to do this(append out.content to out.encoded)?
-        out.encodeString();
+
+        out.encodeANY();
     }
 
     @Override
@@ -93,4 +93,8 @@
         out.length = bytes.length;
     }
 
+    @Override
+    public int getEncodedLength(BerOutputStream out) {
+        return out.length;
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java Wed Apr 30 20:14:31 2008
@@ -102,6 +102,7 @@
 
         if (name.size() == 1) {
             bind(name.get(0), obj, attributes);
+            return;
         }
 
         DirContext context = getContinuationContext(name);
@@ -359,6 +360,7 @@
 
         if (name.size() == 1) {
             rebind(name.get(0), obj, attributes);
+            return;
         }
 
         DirContext context = getContinuationContext(name);
@@ -518,20 +520,27 @@
                     filter = new Filter(Filter.PRESENT_FILTER);
                     filter.setValue("objectClass");
                 } else {
-                    NamingEnumeration<? extends Attribute> attrs = attributes
-                            .getAll();
-                    filter = new Filter(Filter.AND_FILTER);
-                    while (attrs.hasMore()) {
-                        Attribute attr = attrs.next();
-                        String type = attr.getID();
-                        NamingEnumeration<?> enuValues = attr.getAll();
-                        while (enuValues.hasMore()) {
-                            Object value = enuValues.next();
-                            Filter child = new Filter(
-                                    Filter.EQUALITY_MATCH_FILTER);
-                            child.setValue(new AttributeTypeAndValuePair(type,
-                                    value));
-                            filter.addChild(child);
+                    if (attributes.size() == 1) {
+                        filter = new Filter(Filter.EQUALITY_MATCH_FILTER);
+                        Attribute att = attributes.getAll().next();
+                        filter.setValue(new AttributeTypeAndValuePair(att
+                                .getID(), att.get()));
+                    } else {
+                        NamingEnumeration<? extends Attribute> attrs = attributes
+                                .getAll();
+                        filter = new Filter(Filter.AND_FILTER);
+                        while (attrs.hasMore()) {
+                            Attribute attr = attrs.next();
+                            String type = attr.getID();
+                            NamingEnumeration<?> enuValues = attr.getAll();
+                            while (enuValues.hasMore()) {
+                                Object value = enuValues.next();
+                                Filter child = new Filter(
+                                        Filter.EQUALITY_MATCH_FILTER);
+                                child.setValue(new AttributeTypeAndValuePair(
+                                        type, value));
+                                filter.addChild(child);
+                            }
                         }
                     }
                 }
@@ -549,6 +558,10 @@
                 list.add(sr);
             }
 
+            if (list.size() == 0 && result.getException() != null) {
+                throw result.getException();
+            }
+
             return new LdapNamingEnumeration<SearchResult>(list, result
                     .getException());
         } finally {
@@ -606,6 +619,10 @@
                 list.add(sr);
             }
 
+            if (list.size() == 0 && result.getException() != null) {
+                throw result.getException();
+            }
+
             return new LdapNamingEnumeration<SearchResult>(list, result
                     .getException());
         } finally {

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java Wed Apr 30 20:14:31 2008
@@ -17,9 +17,8 @@
 
 package org.apache.harmony.jndi.provider.ldap;
 
-import java.util.ArrayList;
-
 import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
+import org.apache.harmony.jndi.provider.ldap.Filter.MatchingRuleAssertion;
 import org.apache.harmony.jndi.provider.ldap.Filter.SubstringFilter;
 import org.apache.harmony.jndi.provider.ldap.asn1.ASN1TestUtils;
 import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
@@ -73,7 +72,21 @@
         filter = new Filter(Filter.APPROX_MATCH_FILTER);
         filter.setValue(new AttributeTypeAndValuePair("cn", "test"));
         ASN1TestUtils.checkEncode(filter, LdapASN1Constant.Filter);
+        
+        filter = new Filter(Filter.EXTENSIBLE_MATCH_FILTER);
+        MatchingRuleAssertion value = new MatchingRuleAssertion();
+        value.setDnAttributes(true);
+        assertTrue(value.isDnAttributes());
+        value.setMatchingRule("equal");
+        assertEquals("equal", value.getMatchingRule());
+        value.setMatchValue("cn");
+        assertEquals("cn", value.getMatchValue());
+        value.setType("type");
+        assertEquals("type", value.getType());
+        filter.setValue(value);
 
+        ASN1TestUtils.checkEncode(filter, LdapASN1Constant.Filter);
+        
         // composite filter
         filter = new Filter(Filter.AND_FILTER);
         Filter equal = new Filter(Filter.EQUALITY_MATCH_FILTER);

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java?rev=652421&r1=652420&r2=652421&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java Wed Apr 30 20:14:31 2008
@@ -306,7 +306,7 @@
         assertEquals("cn=what,cn=test", op.getEntry());
         assertEquals("cn=how", op.getNewrdn());
         assertEquals("cn=test", op.getNewSuperior());
-        assertEquals(true, op.isDeleteoldrdn());
+        assertTrue(op.isDeleteoldrdn());
 
         Hashtable<Object, Object> env = new Hashtable<Object, Object>();
         env.put("java.naming.ldap.deleteRDN", "false");
@@ -318,7 +318,7 @@
         assertEquals("cn=what,o=harmony,cn=test", op.getEntry());
         assertEquals("o=apache", op.getNewrdn());
         assertEquals("cn=test", op.getNewSuperior());
-        assertEquals(false, op.isDeleteoldrdn());
+        assertFalse(op.isDeleteoldrdn());
 
         try {
             context.rename(null, "cn=hello");
@@ -402,7 +402,7 @@
         assertEquals(controls.length + 1, actual.length);
     }
 
-    public void test_search_LAttribute() throws Exception {
+    public void test_search_LAttributes() throws Exception {
         MockLdapClient client = new MockLdapClient();
         context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
                 "cn=test");
@@ -421,9 +421,9 @@
         SearchControls controls = op.getControls();
         assertEquals(SearchControls.ONELEVEL_SCOPE, controls.getSearchScope());
         assertEquals(0, controls.getCountLimit());
-        assertEquals(false, controls.getDerefLinkFlag());
-        assertEquals(false, controls.getReturningObjFlag());
-        assertEquals(null, controls.getReturningAttributes());
+        assertFalse(controls.getDerefLinkFlag());
+        assertFalse(controls.getReturningObjFlag());
+        assertNull(controls.getReturningAttributes());
 
         Filter filter = op.getFilter();
         assertEquals(Filter.AND_FILTER, filter.getType());
@@ -463,6 +463,35 @@
         }
     }
 
+    public void test_search_LAttributes_single() throws Exception {
+        MockLdapClient client = new MockLdapClient();
+        context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
+                "cn=test");
+
+        Attributes attrs = new BasicAttributes();
+        attrs.put("cn", "hello");
+
+        context.search("cn=hello", attrs);
+
+        SearchOp op = (SearchOp) client.getRequest();
+        assertEquals("cn=hello,cn=test", op.getBaseObject());
+        SearchControls controls = op.getControls();
+        assertEquals(SearchControls.ONELEVEL_SCOPE, controls.getSearchScope());
+        assertEquals(0, controls.getCountLimit());
+        assertFalse(controls.getDerefLinkFlag());
+        assertFalse(controls.getReturningObjFlag());
+        assertNull(controls.getReturningAttributes());
+
+        Filter filter = op.getFilter();
+        assertNull(filter.getChildren());
+        assertEquals(Filter.EQUALITY_MATCH_FILTER, filter.getType());
+        AttributeTypeAndValuePair pair = (AttributeTypeAndValuePair) filter
+                .getValue();
+        assertEquals("cn", pair.getType());
+        assertEquals("hello", pair.getValue());
+    }
+        
+
     public void test_search_with_filter() throws Exception {
         MockLdapClient client = new MockLdapClient();
         context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
@@ -499,8 +528,8 @@
         context.search("test=search", "(objectClass=*)", null);
         op = (SearchOp) client.getRequest();
         assertEquals(0, op.getControls().getCountLimit());
-        assertEquals(false, op.getControls().getDerefLinkFlag());
-        assertEquals(false, op.getControls().getReturningObjFlag());
+        assertFalse(op.getControls().getDerefLinkFlag());
+        assertFalse(op.getControls().getReturningObjFlag());
         assertEquals(SearchControls.ONELEVEL_SCOPE, op.getControls()
                 .getSearchScope());
         assertEquals(0, op.getControls().getTimeLimit());
@@ -578,6 +607,14 @@
         Hashtable<Object, Object> env = new Hashtable<Object, Object>();
 
         context = new LdapContextImpl(client, env, "cn=test");
+
+        try {
+            context.bind("cn=bind", new Object());
+            fail("Should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // exptected
+        }
+
         context.bind("cn=bind", "it's bind");
 
         AddOp op = (AddOp) client.getRequest();
@@ -694,9 +731,9 @@
         SearchControls controls = op.getControls();
         assertEquals(SearchControls.OBJECT_SCOPE, controls.getSearchScope());
         assertEquals(0, controls.getCountLimit());
-        assertEquals(false, controls.getDerefLinkFlag());
-        assertEquals(false, controls.getReturningObjFlag());
-        assertEquals(null, controls.getReturningAttributes());
+        assertFalse(controls.getDerefLinkFlag());
+        assertFalse(controls.getReturningObjFlag());
+        assertNull(controls.getReturningAttributes());
 
         Filter filter = op.getFilter();
         assertEquals(Filter.PRESENT_FILTER, filter.getType());
@@ -766,8 +803,8 @@
 
         op = (SearchOp) client.getRequest();
         assertEquals(0, op.getControls().getCountLimit());
-        assertEquals(false, op.getControls().getDerefLinkFlag());
-        assertEquals(false, op.getControls().getReturningObjFlag());
+        assertFalse(op.getControls().getDerefLinkFlag());
+        assertFalse(op.getControls().getReturningObjFlag());
         assertEquals(SearchControls.ONELEVEL_SCOPE, op.getControls()
                 .getSearchScope());
         assertEquals(0, op.getControls().getTimeLimit());



Mime
View raw message