You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by qi...@apache.org on 2008/07/14 11:43:37 UTC

svn commit: r676530 [1/3] - in /harmony/enhanced/classlib/branches/java6: depends/build/platform/ depends/oss/ modules/awt/src/main/native/lcmm/shared/ modules/awt/src/main/native/oglwrapper/shared/ modules/beans/src/main/java/java/beans/ modules/beans...

Author: qiuxx
Date: Mon Jul 14 02:43:27 2008
New Revision: 676530

URL: http://svn.apache.org/viewvc?rev=676530&view=rev
Log:
Merge updates from classlib trunk@660000 since r651568

Added:
    harmony/enhanced/classlib/branches/java6/modules/beans/src/test/resources/xml/MockOwner.xml
      - copied unchanged from r660000, harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/xml/MockOwner.xml
    harmony/enhanced/classlib/branches/java6/modules/beans/src/test/resources/xml/MockOwner_Ambiguous.xml
      - copied unchanged from r660000, harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/xml/MockOwner_Ambiguous.xml
    harmony/enhanced/classlib/branches/java6/modules/beans/src/test/resources/xml/MockOwner_Null.xml
      - copied unchanged from r660000, harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/xml/MockOwner_Null.xml
    harmony/enhanced/classlib/branches/java6/modules/beans/src/test/resources/xml/MockOwner_Specific.xml
      - copied unchanged from r660000, harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/xml/MockOwner_Specific.xml
    harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/MockOwnerClass.java
      - copied unchanged from r660000, harmony/enhanced/classlib/trunk/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/MockOwnerClass.java
    harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaFilter.java
      - copied unchanged from r660000, harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaFilter.java
    harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ExtendedOpTest.java
      - copied unchanged from r660000, harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ExtendedOpTest.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java5/org/apache/harmony/unpack200/Pack200UnpackerAdapter.java
      - copied unchanged from r660000, harmony/enhanced/classlib/trunk/modules/pack200/src/main/java5/org/apache/harmony/unpack200/Pack200UnpackerAdapter.java
Removed:
    harmony/enhanced/classlib/branches/java6/depends/oss/icu4c-3.4-harmony-includes.zip
    harmony/enhanced/classlib/branches/java6/depends/oss/icu4c-3.4-harmony-windows.x86_64.zip
    harmony/enhanced/classlib/branches/java6/depends/oss/icu4c-3.4-harmony.zip
    harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaAttrDefContextImpl.java
    harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaClassDefContextImpl.java
Modified:
    harmony/enhanced/classlib/branches/java6/depends/build/platform/zos.s390.mk
    harmony/enhanced/classlib/branches/java6/depends/build/platform/zos.s390x.mk
    harmony/enhanced/classlib/branches/java6/depends/oss/README.txt
    harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/lcmm/shared/NativeCMM.c
    harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/oglwrapper/shared/nativelib_common.h
    harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLDecoder.java
    harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
    harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
    harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/native/pngencoder/unix/makefile
    harmony/enhanced/classlib/branches/java6/modules/imageio/src/test/java/javax/imageio/stream/ImageInputStreamImplTest.java
    harmony/enhanced/classlib/branches/java6/modules/jndi/META-INF/MANIFEST.MF
    harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
    harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapAttribute.java
    harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
    harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
    harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java
    harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java
    harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java
    harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ReferralExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/ObjectOutputStream.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/ArrayList.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/HashMap.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.c
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/procimpl.c
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TreeMapTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/AlreadyConnectedExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/AsynchronousCloseExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/CancelledKeyExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ClosedByInterruptExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ClosedChannelExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ClosedSelectorExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ConnectionPendingExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileLockInterruptionExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/IllegalBlockingModeExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/IllegalSelectorExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/NoConnectionPendingExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/NonReadableChannelExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/NonWritableChannelExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/NotYetBoundExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/NotYetConnectedExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/OverlappingFileLockExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/UnresolvedAddressExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/UnsupportedAddressTypeExceptionTest.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ByteCode.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassConstantPool.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassFileEntry.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/CodeAttribute.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ConstantPoolEntry.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/EnclosingMethodAttribute.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/LocalVariableTableAttribute.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/LocalVariableTypeTableAttribute.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/NewAttribute.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/SignatureAttribute.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/ByteCodeForm.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/NarrowClassRefForm.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/SingleByteReferenceForm.java
    harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/StringRefForm.java
    harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/unix/hyfile.c
    harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/unix/hyfiletext.c
    harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/unix/hymem.c
    harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/unix/hynlshelpers.c
    harmony/enhanced/classlib/branches/java6/modules/portlib/src/test/native/hyfile/shared/hyfile.c
    harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/org/apache/harmony/security/asn1/ASN1StringType.java

Modified: harmony/enhanced/classlib/branches/java6/depends/build/platform/zos.s390.mk
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/depends/build/platform/zos.s390.mk?rev=676530&r1=676529&r2=676530&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/depends/build/platform/zos.s390.mk (original)
+++ harmony/enhanced/classlib/branches/java6/depends/build/platform/zos.s390.mk Mon Jul 14 02:43:27 2008
@@ -20,7 +20,7 @@
 CXX = cxx
 
 DEFINES += -DZOS -DZOS_S390 -DHYS390 -DHY_ATOE
-OPT += -Wc,xplink,convlit\(ISO8859-1\),FLOAT\(IEEE,FOLD,AFP\) -Wc,"langlvl(commonc)" -Wa,goff -Wc,NOANSIALIAS -Wc,DLL,EXPORTALL
+OPT += -Wc,xplink,convlit\(ISO8859-1\),FLOAT\(IEEE,FOLD,AFP\) -Wa,goff -Wc,NOANSIALIAS -Wc,DLL,EXPORTALL
 
 CFLAGS += -Wc,"SSCOMM" -Wc,"langlvl(commonc)" -Wc,gonumber
 CXXFLAGS += -+ -Wc,"langlvl(extended)" -Wc,gonumber
@@ -32,6 +32,9 @@
 MDLLIBPREFIX =
 MDLLIBSUFFIX =
 
+# No need to specify STDC libs on z/OS
+STDCLIBS =
+
 # Don't use these flags on zOS
 DLL_LDFLAGS =
 

Modified: harmony/enhanced/classlib/branches/java6/depends/build/platform/zos.s390x.mk
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/depends/build/platform/zos.s390x.mk?rev=676530&r1=676529&r2=676530&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/depends/build/platform/zos.s390x.mk (original)
+++ harmony/enhanced/classlib/branches/java6/depends/build/platform/zos.s390x.mk Mon Jul 14 02:43:27 2008
@@ -20,7 +20,7 @@
 CXX = cxx
 
 DEFINES += -DZOS -DZOS_S390X -DHYS390X -DHY_ATOE
-OPT += -Wc,lp64,xplink,convlit\(ISO8859-1\),FLOAT\(IEEE,FOLD,AFP\) -Wc,"langlvl(commonc)" -Wa,goff -Wc,NOANSIALIAS -Wc,DLL,EXPORTALL
+OPT += -Wc,lp64,xplink,convlit\(ISO8859-1\),FLOAT\(IEEE,FOLD,AFP\) -Wa,goff -Wc,NOANSIALIAS -Wc,DLL,EXPORTALL
 
 CFLAGS += -Wc,"SSCOMM" -Wc,"langlvl(commonc)"
 CXXFLAGS += -+ -Wc,"langlvl(extended)"
@@ -32,6 +32,9 @@
 MDLLIBPREFIX =
 MDLLIBSUFFIX =
 
+# No need to specify STDC libs on z/OS
+STDCLIBS =
+
 # Don't use these flags on z/OS
 DLL_LDFLAGS =
 

Modified: harmony/enhanced/classlib/branches/java6/depends/oss/README.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/depends/oss/README.txt?rev=676530&r1=676529&r2=676530&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/depends/oss/README.txt (original)
+++ harmony/enhanced/classlib/branches/java6/depends/oss/README.txt Mon Jul 14 02:43:27 2008
@@ -17,20 +17,6 @@
 
 
 
-ICU4C version 3.4
------------------
-ICU4C is a freely available set of libraries that provide Unicode support to
-C and C++ applications. The file icu4c-3.4-harmony.zip contains a set of C 
-header files (with .h extension) that come straight from the ICU download
-available on the ICU home page. These have been grouped into a directory 
-called "unicode". The icu4c-3.4-harmony.zip file also contains a compiled
-version of the ICU4C Windows .lib file.
-
-The official ICU page is located at
-http://www.ibm.com/software/globalization/icu
-
-
-
 FDLIBM version 5.2
 ------------------
 FDLIBM (Freely Distributable LIBM) is a C math library for supporting IEEE 754

Modified: harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/lcmm/shared/NativeCMM.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/lcmm/shared/NativeCMM.c?rev=676530&r1=676529&r2=676530&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/lcmm/shared/NativeCMM.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/lcmm/shared/NativeCMM.c Mon Jul 14 02:43:27 2008
@@ -27,7 +27,12 @@
 
 int gl_cmsErrorHandler(int errorCode, const char *msg) {
   if(errorCode == LCMS_ERRC_ABORTED) {
-    errMsg = _strdup(msg); // Throw exception later, after returning control from cmm
+    // Throw exception later, after returning control from cmm
+#ifndef ZOS
+    errMsg = _strdup(msg);
+#else
+    errMsg = strdup(msg);
+#endif
   }
 
   return 1;

Modified: harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/oglwrapper/shared/nativelib_common.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/oglwrapper/shared/nativelib_common.h?rev=676530&r1=676529&r2=676530&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/oglwrapper/shared/nativelib_common.h (original)
+++ harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/oglwrapper/shared/nativelib_common.h Mon Jul 14 02:43:27 2008
@@ -21,7 +21,7 @@
 #ifndef NATIVELIB_COMMON_H
 #define NATIVELIB_COMMON_H
 
-#if defined(LINUX) || defined(FREEBSD) || defined(AIX) || defined(MACOSX)
+#if defined(LINUX) || defined(FREEBSD) || defined(AIX) || defined(MACOSX) || defined(ZOS)
 // common linux section--------------------------------
 #include <dlfcn.h>
 #include <stdint.h>
@@ -35,7 +35,7 @@
 
 #define INIT_GL_GET_PROC_ADDRESS
 
-#if !defined(__INTEL_COMPILER) && !defined(AIX)
+#if !defined(__INTEL_COMPILER) && !defined(AIX) && !defined(ZOS)
     typedef long long __int64;
 #endif
 

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLDecoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLDecoder.java?rev=676530&r1=676529&r2=676530&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLDecoder.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLDecoder.java Mon Jul 14 02:43:27 2008
@@ -17,6 +17,7 @@
 
 package java.beans;
 
+import java.beans.Statement.MethodComparator;
 import java.io.InputStream;
 import java.lang.reflect.Array;
 import java.lang.reflect.Field;
@@ -27,6 +28,7 @@
 
 import javax.xml.parsers.SAXParserFactory;
 
+import org.apache.harmony.beans.internal.nls.Messages;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
@@ -331,10 +333,24 @@
                 }
                 Class[] c = new Class[args.size()];
                 for (int i = 0; i < args.size(); i++) {
-                    c[i] = args.get(i).getClass();
+                    Object arg = args.get(i);
+                    c[i] = (arg == null ? null: arg.getClass());
                 }
-                Method m = owner.getClass().getMethod(method, c);
-                return m.invoke(owner, args.toArray());
+
+                // Try actual match method
+                try {
+                    Method m = owner.getClass().getMethod(method, c);
+                    return m.invoke(owner, args.toArray());
+                } catch (NoSuchMethodException e) {
+                    // Do nothing
+                }
+
+                // Find the specific method matching the parameter
+                Method mostSpecificMethod = findMethod(
+                        owner instanceof Class ? (Class) owner : owner
+                                .getClass(), method, c);
+
+                return mostSpecificMethod.invoke(owner, args.toArray());
             }
 
             // execute
@@ -342,6 +358,75 @@
             return exp.getValue();
         }
 
+        private Method findMethod(Class clazz, String methodName,
+                Class[] clazzes) throws Exception {
+            Method[] methods = clazz.getMethods();
+            ArrayList<Method> matchMethods = new ArrayList<Method>();
+
+            // Add all matching methods into a ArrayList
+            for (Method method : methods) {
+                if (!methodName.equals(method.getName())) {
+                    continue;
+                }
+                Class[] parameterTypes = method.getParameterTypes();
+                if (parameterTypes.length != clazzes.length) {
+                    continue;
+                }
+                boolean match = true;
+                for (int i = 0; i < parameterTypes.length; i++) {
+                    boolean isNull = (clazzes[i] == null);
+                    boolean isPrimitive = isPrimitiveWrapper(clazzes[i], parameterTypes[i]);
+                    boolean isAssignable = isNull? false : parameterTypes[i].isAssignableFrom(clazzes[i]);
+                    if ( isNull || isPrimitive || isAssignable ) {
+                        continue;
+                    }
+                    match = false;
+                }
+                if (match) {
+                    matchMethods.add(method);
+                }
+            }
+
+            int size = matchMethods.size();
+            if (size == 1) {
+                // Only one method matches, just invoke it
+                return matchMethods.get(0);
+            } else if (size == 0) {
+                // Does not find any matching one, throw exception
+                throw new NoSuchMethodException(Messages.getString(
+                        "beans.41", methodName)); //$NON-NLS-1$
+            }
+
+            // There are more than one method matching the signature
+            // Find the most specific one to invoke
+            MethodComparator comparator = new MethodComparator(methodName,
+                    clazzes);
+            Method chosenOne = matchMethods.get(0);
+            matchMethods.remove(0);
+            for (Method method : matchMethods) {
+                int difference = comparator.compare(chosenOne, method);
+                if (difference > 0) {
+                    chosenOne = method;
+                } else if (difference == 0) {
+                    // if 2 methods have same relevance, throw exception
+                    throw new NoSuchMethodException(Messages.getString(
+                            "beans.62", methodName)); //$NON-NLS-1$
+                }
+            }
+            return chosenOne;
+        }
+
+        private boolean isPrimitiveWrapper(Class<?> wrapper, Class<?> base) {
+            return (base == boolean.class) && (wrapper == Boolean.class)
+                    || (base == byte.class) && (wrapper == Byte.class)
+                    || (base == char.class) && (wrapper == Character.class)
+                    || (base == short.class) && (wrapper == Short.class)
+                    || (base == int.class) && (wrapper == Integer.class)
+                    || (base == long.class) && (wrapper == Long.class)
+                    || (base == float.class) && (wrapper == Float.class)
+                    || (base == double.class) && (wrapper == Double.class);
+        }
+
         private String capitalize(String str) {
             StringBuffer buf = new StringBuffer(str);
             buf.setCharAt(0, Character.toUpperCase(buf.charAt(0)));

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties?rev=676530&r1=676529&r2=676530&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties Mon Jul 14 02:43:27 2008
@@ -113,3 +113,4 @@
 beans.5F=Indexed write method must take a two arguments
 beans.60=Indexed write method must take an int as its first argument
 beans.61=Indexed write method is not compatible with indexed read method
+beans.62=Cannot decide which method to call to match {0}

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java?rev=676530&r1=676529&r2=676530&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java Mon Jul 14 02:43:27 2008
@@ -24,6 +24,7 @@
 import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.util.HashMap;
 import java.util.Vector;
 import java.lang.reflect.Array;
 
@@ -33,6 +34,7 @@
 
 import org.apache.harmony.beans.tests.java.beans.EncoderTest.SampleBean;
 import org.apache.harmony.beans.tests.java.beans.XMLEncoderTest.DependencyBean;
+import org.apache.harmony.beans.tests.support.MockOwnerClass;
 import org.apache.harmony.beans.tests.support.mock.MockBean4Codec;
 import org.apache.harmony.beans.tests.support.mock.MockBean4Owner_Owner;
 import org.apache.harmony.beans.tests.support.mock.MockBean4Owner_Target;
@@ -254,6 +256,34 @@
         assertEquals(1, o1.getV());
         assertEquals(o1, t1.getV());
     }
+    
+    public void testReadObject_Owner_Specific(){
+        String expectedValue = "expected value";
+        HashMap map = new HashMap();
+        map.put("key", expectedValue);
+        
+        XMLDecoder decoder = new XMLDecoder(this.getClass().getResourceAsStream(
+                "/xml/MockOwner.xml"), map);
+        String actualValue = (String) decoder.readObject();
+        assertEquals(expectedValue,actualValue);
+        
+        MockOwnerClass mock = new MockOwnerClass();
+        expectedValue = "I_Ljava.lang.String";
+        decoder = new XMLDecoder(this.getClass().getResourceAsStream(
+        "/xml/MockOwner_Specific.xml"), mock);
+        actualValue = (String) decoder.readObject();
+        assertEquals(expectedValue,actualValue);
+        
+        decoder = new XMLDecoder(this.getClass().getResourceAsStream(
+        "/xml/MockOwner_Ambiguous.xml"), mock);
+        actualValue = (String) decoder.readObject();
+        assertNull(actualValue);
+        
+        decoder = new XMLDecoder(this.getClass().getResourceAsStream(
+        "/xml/MockOwner_Null.xml"), mock);
+        actualValue = (String) decoder.readObject();
+        assertNull(actualValue);
+    }
 
     public void testReadObject_Owner_WithWriteStatement() {
         MockBean4Owner_Owner o2 = new MockBean4Owner_Owner();

Modified: harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/native/pngencoder/unix/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/native/pngencoder/unix/makefile?rev=676530&r1=676529&r2=676530&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/native/pngencoder/unix/makefile (original)
+++ harmony/enhanced/classlib/branches/java6/modules/imageio/src/main/native/pngencoder/unix/makefile Mon Jul 14 02:43:27 2008
@@ -32,6 +32,10 @@
 
 OSLIBS += $(STDCLIBS)
 
+ifeq ($(HY_OS),zos)
+MDLLIBFILES += $(MDLLIBZLIB)
+endif
+
 DLLNAME=../libpngencoder$(HY_SHLIB_SUFFIX)
 EXPNAME=HYPNGENCODER_0.1
 

Modified: harmony/enhanced/classlib/branches/java6/modules/imageio/src/test/java/javax/imageio/stream/ImageInputStreamImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/imageio/src/test/java/javax/imageio/stream/ImageInputStreamImplTest.java?rev=676530&r1=676529&r2=676530&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/imageio/src/test/java/javax/imageio/stream/ImageInputStreamImplTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/imageio/src/test/java/javax/imageio/stream/ImageInputStreamImplTest.java Mon Jul 14 02:43:27 2008
@@ -26,7 +26,7 @@
 
 	public void testReadLine() throws IOException {
 		final ImageInputStream in = new BasicImageInputStreamImpl(
-				"line1\nline2\rline3\r\nline4".getBytes());
+				"line1\nline2\rline3\r\nline4".getBytes("ISO8859_1"));
 
 		assertEquals("line1", in.readLine());
 		assertEquals("line2", in.readLine());

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/META-INF/MANIFEST.MF?rev=676530&r1=676529&r2=676530&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/META-INF/MANIFEST.MF (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/META-INF/MANIFEST.MF Mon Jul 14 02:43:27 2008
@@ -28,6 +28,7 @@
  java.text;resolution:=optional,
  java.util,
  java.util.jar,
+ java.util.regex,
  java.util.zip;resolution:=optional,
  javax.accessibility;resolution:=optional,
  javax.net,

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=676530&r1=676529&r2=676530&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 Mon Jul 14 02:43:27 2008
@@ -160,7 +160,6 @@
 jndi.8E=Cannot create new entry under schema root
 jndi.8F=Class definition doesn'thave a numeric OID
 jndi.90={0} does not have a syntax associated with it
-jndi.err.00=. The stack trace of the root exception is: 
 ldap.00=Should not be null
 ldap.01=is not an LdapName
 ldap.02=Posn must be in the range [0,size()]
@@ -219,3 +218,4 @@
 ldap.36=Must have numeric OID
 ldap.37=Can't delete schema root
 ldap.38=Can't modify schema root
+ldap.39=Can't rename schema

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapAttribute.java?rev=676530&r1=676529&r2=676530&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapAttribute.java Mon Jul 14 02:43:27 2008
@@ -1,4 +1,4 @@
-/* 
+/*
  *  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. 
@@ -45,20 +45,10 @@
     private static final long serialVersionUID = -6492847268062616321L;
 
     /**
-     * TODO: when to initialize it?
-     */
-    private DirContext attributeDefinition = null;
-
-    /**
-     * TODO: when to initialize it?
-     */
-    private DirContext attributeSyntaxDefinition = null;
-
-    /**
      * whether the value of attribute is binary
      */
     private boolean isBinary;
-    
+
     private LdapContextImpl context = null;
 
     private static HashSet<String> BINARY_ATTRIBUTE = new HashSet<String>();
@@ -92,7 +82,7 @@
         isBinary = isBinary(id);
         context = ctx;
     }
-    
+
     void setContext(LdapContextImpl ctx) {
         context = ctx;
     }
@@ -112,9 +102,6 @@
             Object value = enu.next();
             add(value);
         }
-
-        attributeDefinition = null;
-        attributeSyntaxDefinition = null;
         context = ctx;
     }
 
@@ -155,37 +142,35 @@
 
     @Override
     public DirContext getAttributeDefinition() throws NamingException {
-        if (attributeDefinition != null) {
-            return attributeDefinition;
-        }
-        attributeDefinition = context
-                .getSchemaAttributeDefinition(getID());
-        return attributeDefinition;
+        DirContext schema = context.getSchema(""); //$NON-NLS-1$
+
+        return (DirContext) schema
+                .lookup(LdapSchemaContextImpl.ATTRIBUTE_DEFINITION
+                        + "/" + getID()); //$NON-NLS-1$
     }
 
     @Override
     public DirContext getAttributeSyntaxDefinition() throws NamingException {
-        if (attributeSyntaxDefinition != null) {
-            return attributeSyntaxDefinition;
-        }
-        //      get the syntax id from the attribute def
-        DirContext schema = context.getSchema("");
-        DirContext attrDef = (DirContext)schema.lookup(
-                LdapSchemaContextImpl.ATTRIBUTE_DEFINITION + "/" + getID());
+        DirContext schema = context.getSchema(""); //$NON-NLS-1$
+        DirContext attrDef = (DirContext) schema
+                .lookup(LdapSchemaContextImpl.ATTRIBUTE_DEFINITION + "/" //$NON-NLS-1$
+                        + getID());
 
-        Attribute syntaxAttr = attrDef.getAttributes("").get("syntax");
+        Attribute syntaxAttr = attrDef.getAttributes("").get("syntax"); //$NON-NLS-1$ //$NON-NLS-2$
 
         if (syntaxAttr == null || syntaxAttr.size() == 0) {
-            throw new NameNotFoundException(Messages.getString("jndi.90",
+            // jndi.90={0} does not have a syntax associated with it
+            throw new NameNotFoundException(Messages.getString("jndi.90", //$NON-NLS-1$
                     getID()));
         }
 
-        String syntaxName = (String)syntaxAttr.get();
+        String syntaxName = (String) syntaxAttr.get();
 
         // look in the schema tree for the syntax definition
-        return (DirContext)schema.lookup(
-                LdapSchemaContextImpl.SYNTAX_DEFINITION + "/" + syntaxName);
-        
+        return (DirContext) schema
+                .lookup(LdapSchemaContextImpl.SYNTAX_DEFINITION + "/" //$NON-NLS-1$
+                        + syntaxName);
+
     }
 
     private static boolean isBinary(String name) {

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=676530&r1=676529&r2=676530&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 Mon Jul 14 02:43:27 2008
@@ -416,8 +416,11 @@
                 if (element.getID().equalsIgnoreCase("objectClass")) {
                     element = mergeAttribute(resultAttributes
                             .get("objectClass"), element);
-                    if (resultAttributes.get("objectClass") != null) {
-                        element.remove("javaContainer");
+                    Attribute oc = resultAttributes.get("objectClass");
+                    if (oc != null) {
+                        if (!oc.contains("javaContainer") && oc.size() > 0) {
+                            element.remove("javaContainer");
+                        }
                     }
                     resultAttributes.put(element);
                 } else if (resultAttributes.get(element.getID()) == null) {
@@ -760,8 +763,6 @@
         return getAttributes(convertFromStringToName(s), as);
     }
 
-    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;
@@ -874,15 +875,10 @@
 
             while (ids.hasMoreElements()) {
                 String schemaType = ids.nextElement();
-                if (!schemaTree.contains(schemaType.toLowerCase())) {
-                    schemaTree.put(schemaType.toLowerCase(),
-                            new Hashtable<String, Hashtable<String, Object>>());
-
+                if (!schemaTable.contains(schemaType.toLowerCase())) {
                     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());
@@ -894,10 +890,7 @@
                     value = (String) attribute.get(i);
                     attrName = SchemaParser.getName(value);
                     schemaDef.put(attrName.toLowerCase(), value);
-
-                    parseValue(schemaType, value.toLowerCase(), schemaDefs);
                 }
-
             }
         }
 
@@ -906,219 +899,19 @@
         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 schemaType, String value,
-            Hashtable<String, Hashtable<String, Object>> schemaDefs) {
-        StringTokenizer st = new StringTokenizer(value.toLowerCase());
-        // 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(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")) {
-                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 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));
-                        values.add(desc.toString());
-                        desc.delete(0, desc.length());
-
-                        token = st.nextToken();
-                    }
-                } else {
-                    // 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));
-                    values.add(desc.toString());
-                    desc.delete(0, desc.length());
-                }
-                schemaDef.put(attrName, values);
-                if (schemaType
-                        .equalsIgnoreCase(LdapSchemaContextImpl.LDAP_SYNTAXES)) {
-                    schemaDefs.put(oid, schemaDef);
-                } else {
-                    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(new CompositeName(s));
     }
 
-    DirContext getSchemaAttributeDefinition(String name) throws NamingException {
-        if (null == ldapSchemaCtx) {
-            getSchema("");
-        }
-        Hashtable<String, Object> attrDef = findSchemaDefInfo(
-                LdapSchemaContextImpl.ATTRIBUTE_TYPES, name);
-
-        return new LdapSchemaAttrDefContextImpl(new CompositeName(name), env,
-                attrDef, this);
-    }
-
     public DirContext getSchemaClassDefinition(Name name)
             throws NamingException {
-        checkName(name);
+        Attributes attrs = getAttributes(name, new String[] { "objectClass" }); //$NON-NLS-1$
+        Attribute attr = attrs.get("objectClass"); //$NON-NLS-1$
 
         if (null == ldapSchemaCtx) {
-            getSchema("");
-        }
-
-        Hashtable<String, ArrayList<String>> classTree = new Hashtable<String, ArrayList<String>>();
-
-        SearchControls searchControls = new SearchControls();
-        searchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
-        searchControls.setReturningAttributes(new String[] { "objectClass", });
-        searchControls.setReturningObjFlag(false);
-        FilterParser parser = new FilterParser("(objectClass=*)");
-        Filter filter = null;
-        try {
-            filter = parser.parse();
-        } catch (ParseException e1) {
-            // Should not throw this excption
-        }
-        String targetDN = getTargetDN(name, contextDn);
-        SearchOp search = new SearchOp(targetDN, searchControls, filter);
-
-        try {
-            client.doOperation(search, requestControls);
-        } catch (IOException e) {
-            CommunicationException ex = new CommunicationException(e
-                    .getMessage());
-            ex.setRootCause(e);
-            if (search.getSearchResult().isEmpty()) {
-                throw ex;
-            }
-            search.getSearchResult().setException(ex);
-        }
-        LdapSearchResult sre = search.getSearchResult();
-        Map<String, Attributes> names = sre.getEntries();
-
-        Set<String> keyset = names.keySet();
-        for (Iterator<String> iterator = keyset.iterator(); iterator.hasNext();) {
-            String key = iterator.next();
-            Attributes as = names.get(key);
-            NamingEnumeration<String> ids = as.getIDs();
-
-            while (ids.hasMoreElements()) {
-                String schemaType = ids.nextElement();
-                if (!classTree.contains(schemaType)) {
-                    classTree.put(schemaType, new ArrayList());
-                }
-                ArrayList<String> classDefs = classTree.get(schemaType);
-                LdapAttribute attribute = (LdapAttribute) as.get(schemaType);
-                for (int i = 0; i < attribute.size(); i++) {
-                    String value = (String) attribute.get(i);
-                    classDefs.add(value);
-                }
-            }
+            getSchema(""); //$NON-NLS-1$
         }
-
-        return new LdapSchemaClassDefContextImpl(new CompositeName(targetDN),
-                env, classTree, this);
+        return ldapSchemaCtx.getClassDefinition(attr);
     }
 
     public DirContext getSchemaClassDefinition(String s) throws NamingException {

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=676530&r1=676529&r2=676530&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 Mon Jul 14 02:43:27 2008
@@ -16,14 +16,11 @@
  */
 package org.apache.harmony.jndi.provider.ldap;
 
-import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
-import java.util.TreeSet;
 
 import javax.naming.Binding;
 import javax.naming.CompositeName;
@@ -42,39 +39,35 @@
 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.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"; //$NON-NLS-1$
 
-    public static final String ATTRIBUTE_DEFINITION = "AttributeDefinition";
+    public static final String ATTRIBUTE_DEFINITION = "AttributeDefinition"; //$NON-NLS-1$
 
-    public static final String SYNTAX_DEFINITION = "SyntaxDefinition";
+    public static final String SYNTAX_DEFINITION = "SyntaxDefinition"; //$NON-NLS-1$
 
-    public static final String MATCHING_RULE = "MatchingRule";
+    public static final String MATCHING_RULE = "MatchingRule"; //$NON-NLS-1$
 
-    public static final String OBJECT_CLASSES = "objectclasses";
+    public static final String OBJECT_CLASSES = "objectclasses"; //$NON-NLS-1$
 
-    public static final String ATTRIBUTE_TYPES = "attributetypes";
+    public static final String ATTRIBUTE_TYPES = "attributetypes"; //$NON-NLS-1$
 
-    public static final String LDAP_SYNTAXES = "ldapsyntaxes";
+    public static final String LDAP_SYNTAXES = "ldapsyntaxes"; //$NON-NLS-1$
 
-    public static final String MATCHING_RULES = "matchingrules";
+    public static final String MATCHING_RULES = "matchingrules"; //$NON-NLS-1$
 
     public static final int SCHEMA_ROOT_LEVEL = 3;
 
-    protected String subschemasubentry = null;
+    public static final int DEFINITION_LEVEL = 2;
 
     final private static Hashtable<String, String> schemaJndi2Ldap = new Hashtable<String, String>();
     static {
@@ -93,7 +86,7 @@
         schemaLdap2Jndi.put(MATCHING_RULES, MATCHING_RULE);
     }
 
-    private LdapContextImpl parent;
+    private LdapContextImpl ldapContext;
 
     private Hashtable<String, Object> schemaTable;
 
@@ -102,18 +95,11 @@
     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;
+        ldapContext = ctx;
         rdn = dn;
         this.schemaTable = schemaTable;
         this.level = level;
@@ -171,12 +157,12 @@
 
         String schemaLine = SchemaParser.format(attributes);
 
-        ModifyOp op = new ModifyOp(parent.subschemasubentry);
+        ModifyOp op = new ModifyOp(ldapContext.subschemasubentry);
         Name modifySchemaName = name.getPrefix(size - 1).addAll(rdn);
         BasicAttribute schemaEntry = new LdapAttribute(new BasicAttribute(
-                jndi2ldap(modifySchemaName.toString()), schemaLine), parent);
-        op.addModification(jndi2ldap[DirContext.ADD_ATTRIBUTE],
-                new LdapAttribute(schemaEntry, parent));
+                jndi2ldap(modifySchemaName.toString()), schemaLine), ldapContext);
+        op.addModification(OperationJndi2Ldap[DirContext.ADD_ATTRIBUTE],
+                new LdapAttribute(schemaEntry, ldapContext));
         try {
             doBasicOperation(op);
             subSchemaTree.put(subSchemaType.toLowerCase(), schemaLine);
@@ -185,14 +171,12 @@
         }
 
         return (DirContext) lookup(name);
-
     }
 
     @Override
     public DirContext createSubcontext(String name, Attributes attributes)
             throws NamingException {
-        Name n = convertFromStringToName(name);
-        return createSubcontext(n, attributes);
+        return createSubcontext(new CompositeName(name), attributes);
     }
 
     @Override
@@ -256,10 +240,8 @@
     }
 
     @Override
-    public Attributes getAttributes(String attributeName)
-            throws NamingException {
-        Name name = new CompositeName(attributeName);
-        return getAttributes(name);
+    public Attributes getAttributes(String name) throws NamingException {
+        return getAttributes(new CompositeName(name));
     }
 
     @Override
@@ -268,17 +250,14 @@
         return getAttributes(new CompositeName(name), as);
     }
 
-    private void checkName(Name name) {
+    @Override
+    public void modifyAttributes(Name name, int i, Attributes attributes)
+            throws NamingException {
         if (name == null) {
             // jndi.2E=The name is null
             throw new NullPointerException(Messages.getString("jndi.2E")); //$NON-NLS-1$
         }
-    }
-
-    @Override
-    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$
@@ -304,7 +283,8 @@
         modifyAttributes(name, items);
     }
 
-    private static final int jndi2ldap[] = { -1, 0, 2, 1, };
+    // Mapping from DirContext's attribute operation code to server's operation code. 
+    private static final int OperationJndi2Ldap[] = { -1, 0, 2, 1, };
 
     @Override
     public void modifyAttributes(Name name, ModificationItem[] modificationItems)
@@ -333,7 +313,7 @@
 
         String schemaLine = schema.toString();
         if (schema instanceof Hashtable) {
-            Hashtable table = (Hashtable) schema;
+            Hashtable<String, Object> table = (Hashtable<String, Object>) schema;
             schemaLine = table.get(SchemaParser.ORIG).toString();
         }
 
@@ -383,16 +363,16 @@
         String newSchemaLine = SchemaParser.format(attributes);
 
         // Remove old schema, then add new schema.
-        ModifyOp op = new ModifyOp(parent.subschemasubentry);
+        ModifyOp op = new ModifyOp(ldapContext.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));
+                jndi2ldap(modifySchemaName.toString()), schemaLine), ldapContext);
+        op.addModification(OperationJndi2Ldap[DirContext.REMOVE_ATTRIBUTE],
+                new LdapAttribute(schemaEntry, ldapContext));
         BasicAttribute addSchemaEntry = new LdapAttribute(new BasicAttribute(
-                jndi2ldap(modifySchemaName.toString()), newSchemaLine), parent);
-        op.addModification(jndi2ldap[DirContext.ADD_ATTRIBUTE],
-                new LdapAttribute(addSchemaEntry, parent));
+                jndi2ldap(modifySchemaName.toString()), newSchemaLine), ldapContext);
+        op.addModification(OperationJndi2Ldap[DirContext.ADD_ATTRIBUTE],
+                new LdapAttribute(addSchemaEntry, ldapContext));
 
         doBasicOperation(op);
         subSchemaTree.remove(subSchemaType);
@@ -400,29 +380,25 @@
     }
 
     @Override
-    public void modifyAttributes(String s, int i, Attributes attributes)
+    public void modifyAttributes(String name, int i, Attributes attributes)
             throws NamingException {
-        Name name = convertFromStringToName(s);
-        modifyAttributes(name, i, attributes);
+        modifyAttributes(new CompositeName(name), i, attributes);
     }
 
     @Override
-    public void modifyAttributes(String s, ModificationItem[] modificationItems)
-            throws NamingException {
-        Name name = convertFromStringToName(s);
-        modifyAttributes(name, modificationItems);
+    public void modifyAttributes(String name,
+            ModificationItem[] modificationItems) throws NamingException {
+        modifyAttributes(new CompositeName(name), modificationItems);
     }
 
     @Override
     public Context createSubcontext(Name name) throws NamingException {
-        DirContext subContext = createSubcontext(name, null);
-        return subContext;
+        return createSubcontext(name, null);
     }
 
     @Override
     public Context createSubcontext(String name) throws NamingException {
-        Name n = convertFromStringToName(name);
-        return createSubcontext(n);
+        return createSubcontext(new CompositeName(name));
     }
 
     @Override
@@ -452,16 +428,16 @@
 
         String schemaLine = schema.toString();
         if (schema instanceof Hashtable) {
-            Hashtable table = (Hashtable) schema;
+            Hashtable<String, Object> table = (Hashtable<String, Object>) schema;
             schemaLine = table.get(SchemaParser.ORIG).toString();
         }
 
-        ModifyOp op = new ModifyOp(parent.subschemasubentry);
+        ModifyOp op = new ModifyOp(ldapContext.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));
+                jndi2ldap(modifySchemaName.toString()), schemaLine), ldapContext);
+        op.addModification(OperationJndi2Ldap[DirContext.REMOVE_ATTRIBUTE],
+                new LdapAttribute(schemaEntry, ldapContext));
         try {
             doBasicOperation(op);
             subSchemaTree.remove(subSchemaType);
@@ -472,25 +448,7 @@
 
     @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();
+        destroySubcontext(new CompositeName(name));
     }
 
     @Override
@@ -520,11 +478,6 @@
     @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;
     }
@@ -532,7 +485,7 @@
     @Override
     public NamingEnumeration<NameClassPair> list(String name)
             throws NamingException {
-        return list(convertFromStringToName(name));
+        return list(new CompositeName(name));
     }
 
     @Override
@@ -562,7 +515,7 @@
     @Override
     public NamingEnumeration<Binding> listBindings(String name)
             throws NamingException {
-        return listBindings(convertFromStringToName(name));
+        return listBindings(new CompositeName(name));
     }
 
     private Hashtable<Name, LdapSchemaContextImpl> cachedSubSchemas = new Hashtable<Name, LdapSchemaContextImpl>();
@@ -582,7 +535,7 @@
 
         Hashtable<String, Object> newSchemaTable = doLookup(name, size);
 
-        cachedSchema = new LdapSchemaContextImpl(parent, env, targetDN,
+        cachedSchema = new LdapSchemaContextImpl(ldapContext, env, targetDN,
                 newSchemaTable, level - size);
         cachedSubSchemas.put(targetDN, cachedSchema);
 
@@ -621,303 +574,280 @@
 
     @Override
     public Object lookup(String name) throws NamingException {
-        return lookup(convertFromStringToName(name));
+        return lookup(new CompositeName(name));
     }
 
+    @Override
     public void rename(Name nOld, Name nNew) throws NamingException {
-        throw new SchemaViolationException(Messages.getString("jndi.err.01"));
+        // ldap.39=Can't rename schema
+        throw new SchemaViolationException(Messages.getString("ldap.39")); //$NON-NLS-1$
     }
 
+    @Override
     public void rename(String sOld, String sNew) throws NamingException {
-        throw new SchemaViolationException(Messages.getString("jndi.err.01"));
+        // ldap.39=Can't rename schema
+        throw new SchemaViolationException(Messages.getString("ldap.39")); //$NON-NLS-1$
     }
 
+    @Override
     public NamingEnumeration<SearchResult> search(Name name,
             Attributes attributes) throws NamingException {
         return search(name, attributes, null);
     }
 
+    @Override
     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(true);
-        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);
-            }
-        }
+            Attributes matchingAttributes, String[] attributesToReturn)
+            throws NamingException {
+        int size = name.size();
 
-        // Attribute selector
-        TreeSet<String> attrSel = new TreeSet<String>();
+        Hashtable<String, Object> subschemaTable = doLookup(name, size);
 
-        // Construct result NamingEnumeration
         LdapNamingEnumeration<SearchResult> enumeration = new LdapNamingEnumeration<SearchResult>(
                 null, null);
-        String schemaType = null;
+        SearchResult searchResult;
+        Attributes schemaAttributes;
+        String schemaName;
+        Set<String> keyset;
 
-        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;
-                    }
+        if (level - size > 1) {
+            keyset = subschemaTable.keySet();
+            for (Iterator<String> i = keyset.iterator(); i.hasNext();) {
+                schemaName = ldap2jndi(i.next());
+                Name tempName = (Name) name.clone();
+                schemaAttributes = getAttributes(tempName.add(schemaName));
+
+                if (isMatch(schemaAttributes, matchingAttributes)) {
+                    schemaAttributes = filterAttributes(schemaAttributes,
+                            attributesToReturn);
+                    searchResult = new SearchResult(ldap2jndi(schemaName), this
+                            .getClass().getName(), null, schemaAttributes);
+                    enumeration.add(searchResult);
                 }
             }
-            attrSel.add("objectclass");
+        }
+        return enumeration;
+    }
 
-            /*
-             * 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(
-                                true);
-                        /*
-                         * 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(true);
-                    /*
-                     * 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:
-            if (hasAttributes2Return) {
-                attrSel.addAll(Arrays.asList(as));
-            }
-            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);
-                    boolean matched = true;
-                    while (filters.hasMore()) {
-                        Attribute filter = filters.next();
-                        Object values = schemaDef.get(filter.getID());
-                        /*
-                         * Attribute definition will only be retrieved when it
-                         * is designated in attrFilter
-                         */
-                        if (values == null || !match(filter, values)) {
-                            matched = false;
-                            break;
-                        }
-                    }
-                    if (matched) {
-                        basicAttributes = new BasicAttributes(true);
-                        for (Iterator<String> iterator = schemaDef.keySet()
-                                .iterator(); iterator.hasNext();) {
-                            String key = iterator.next();
-                            if (key.equals("orig")) {
-                                continue;
-                            }
-                            if (hasAttributes2Return && attrSel.contains(key)
-                                    || !hasAttributes2Return) {
-                                basicAttributes.put(key, schemaDef.get(key));
-                            }
-                        }
-                        SearchResult pair = new SearchResult(id, null,
-                                basicAttributes);
-                        enumeration.add(pair);
-                    }
+    @Override
+    public NamingEnumeration<SearchResult> search(Name name, String filter,
+            SearchControls searchControls) throws NamingException {
+        return search(name, filter, null, searchControls);
+    }
+
+    @Override
+    public NamingEnumeration<SearchResult> search(Name name, String filter,
+            Object[] filterArgs, SearchControls searchControls)
+            throws NamingException {
+
+        HashSet<SearchResult> searchResults = new HashSet<SearchResult>();
+        Iterator<SearchResult> iterator;
+        SearchResult searchResult;
+
+        Attributes schemaAttributes;
+
+        // Default search scope is ONELEVEL_SCOPE.
+        if (searchControls == null
+                || searchControls.getSearchScope() == SearchControls.ONELEVEL_SCOPE) {
+            searchResults = doSimpleSearch(name, false);
+
+        }
+        // SearchControls.SUBTREE_SCOPE
+        else if (searchControls.getSearchScope() == SearchControls.SUBTREE_SCOPE) {
+            searchResults = doSimpleSearch(name, true);
+        }
+
+        // SearchControls.OBJECT_SCOPE.
+        else {
+            schemaAttributes = getAttributes(name);
+            searchResult = new SearchResult(ldap2jndi(name.toString()), this
+                    .getClass().getName(), null, schemaAttributes);
+            searchResults.add(searchResult);
+        }
+
+        LdapSchemaFilter schemaFilter = new LdapSchemaFilter(filter, filterArgs);
+        searchResults = schemaFilter.filter(searchResults);
+
+        if (searchControls != null
+                && searchControls.getReturningAttributes() != null) {
+            String[] attributesToReturn = searchControls
+                    .getReturningAttributes();
+            // Take the 0 as special case to improve perfomance.
+            if (attributesToReturn.length > 0) {
+                iterator = searchResults.iterator();
+                while (iterator.hasNext()) {
+                    searchResult = iterator.next();
+                    schemaAttributes = filterAttributes(searchResult
+                            .getAttributes(), attributesToReturn);
+                    searchResult.setAttributes(schemaAttributes);
                 }
             } else {
-                for (int i = 0; i < attrValues.size(); i++) {
-                    Hashtable<String, Object> schemaDef = schemas
-                            .get(attrValues.get(i));
-                    basicAttributes = new BasicAttributes(true);
-                    for (Iterator<String> iterator = schemaDef.keySet()
-                            .iterator(); iterator.hasNext();) {
-                        String key = iterator.next();
-                        if (key.equals("orig")) {
-                            continue;
-                        }
-                        if (hasAttributes2Return && attrSel.contains(key)
-                                || !hasAttributes2Return) {
-                            basicAttributes.put(key, schemaDef.get(key));
-                        }
-                    }
-                    SearchResult pair = new SearchResult(attrValues.get(i),
-                            null, basicAttributes);
-                    enumeration.add(pair);
+                iterator = searchResults.iterator();
+                while (iterator.hasNext()) {
+                    searchResult = iterator.next();
+                    searchResult.setAttributes(new BasicAttributes(true));
                 }
             }
-            break;
+        }
 
-        default:
-            schemaType = schemaJndi2Ldap.get(name.getPrefix(1).toString()
-                    .toLowerCase());
-            if (null == schemaType) {
-                throw new NameNotFoundException(name.toString());
-            }
-            search(name.getSuffix(1), attributes, as);
+        LdapNamingEnumeration<SearchResult> enumeration = new LdapNamingEnumeration<SearchResult>(
+                null, null);
+
+        iterator = searchResults.iterator();
+        while (iterator.hasNext()) {
+            enumeration.add(iterator.next());
         }
+
         return enumeration;
+    }
+
+    @Override
+    public NamingEnumeration<SearchResult> search(String name, Attributes attributes, String[] as) throws NamingException {
+        return search(new CompositeName(name), attributes, as);
+    }
 
+    @Override
+    public NamingEnumeration<SearchResult> search(String name, Attributes attributes) throws NamingException {
+        return search(new CompositeName(name), attributes);
     }
 
-    private boolean match(Attribute filter, Object values)
+    @Override
+    public NamingEnumeration<SearchResult> search(String name, String filter, Object[] objs, SearchControls searchControls) throws NamingException {
+        return search(new CompositeName(name), filter, objs, searchControls);
+    }
+
+    @Override
+    public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls searchControls) throws NamingException {
+        return search(new CompositeName(name), filter, searchControls);
+    }
+    
+    protected DirContext getClassDefinition(Attribute objectclassAttr)
             throws NamingException {
-        NamingEnumeration<?> attrValues = filter.getAll();
-        ArrayList<Object> v = null;
-        if (values instanceof ArrayList) {
-            v = (ArrayList<Object>) values;
-        } else {
-            v = new ArrayList<Object>();
-            v.add(values);
+        Hashtable<String, Object> definitionTable = new Hashtable<String, Object>();
+        Hashtable<String, Object> allDefinitionTable = (Hashtable<String, Object>) schemaTable
+                .get(OBJECT_CLASSES);
+
+        if (objectclassAttr != null) {
+            NamingEnumeration<?> ne = objectclassAttr.getAll();
+            String attributeType;
+            while (ne.hasMore()) {
+                attributeType = ne.next().toString().toLowerCase();
+                definitionTable.put(attributeType, allDefinitionTable
+                        .get(attributeType));
+            }
+        }
+
+        return new LdapSchemaContextImpl(this, env, new CompositeName(
+                OBJECT_CLASSES), definitionTable,
+                LdapSchemaContextImpl.DEFINITION_LEVEL);
+    }
+
+    private HashSet<SearchResult> doSimpleSearch(Name name,
+            boolean searchSubTree) throws NamingException {
+        int size = name.size();
+        Hashtable<String, Object> subschemaTable = doLookup(name, size);
+
+        HashSet<SearchResult> searchResults = new HashSet<SearchResult>();
+        HashSet<SearchResult> tempResults;
+        SearchResult searchResult;
+        Attributes schemaAttributes;
+        String schemaName;
+        Set<String> keyset;
+
+        keyset = subschemaTable.keySet();
+        for (Iterator<String> i = keyset.iterator(); i.hasNext();) {
+            schemaName = ldap2jndi(i.next());
+            Name tempName = (Name) name.clone();
+            tempName = tempName.add(schemaName);
+            if (tempName.size() < level) {
+                schemaAttributes = getAttributes(tempName);
+                searchResult = new SearchResult(tempName.toString(), this
+                        .getClass().getName(), null, schemaAttributes);
+                searchResults.add(searchResult);
+
+                if (searchSubTree) {
+                    tempResults = doSimpleSearch(tempName, searchSubTree);
+                    searchResults.addAll(tempResults);
+                }
+            }
+        }
+        return searchResults;
+    }
+
+    private Attributes filterAttributes(Attributes attributes,
+            String[] attributesToReturn) {
+        if (attributesToReturn == null) {
+            return attributes;
         }
 
-        while (attrValues.hasMore()) {
-            Object attrValue = attrValues.next();
-            for (int i = 0; i < v.size(); i++) {
-                if (attrValue.equals("*") || attrValue.equals(v.get(i))) {
-                    return true;
+        Attribute attribute;
+        Attributes filteredAttrs = new BasicAttributes(true);
+        for (int i = 0; i < attributesToReturn.length; i++) {
+            if (attributesToReturn[i] != null) {
+                attribute = attributes.get(attributesToReturn[i]);
+                if (attribute != null) {
+                    filteredAttrs.put(attribute);
                 }
             }
         }
-        return false;
+
+        return filteredAttrs;
     }
 
-    public NamingEnumeration<SearchResult> search(Name name, String filter,
-            Object[] objs, SearchControls searchControls)
-            throws NamingException {
+    private boolean isMatch(Attributes schemaAttributes,
+            Attributes matchingAttributes) throws NamingException {
+        if (matchingAttributes == null) {
+            return true;
+        }
 
-        checkName(name);
+        NamingEnumeration<? extends Attribute> enumeration = matchingAttributes
+                .getAll();
+        Attribute matchAttribute;
+        Attribute schemaAttribute;
+        String id;
+        while (enumeration.hasMore()) {
+            matchAttribute = enumeration.next();
+            id = matchAttribute.getID();
+            schemaAttribute = schemaAttributes.get(id);
+            if (schemaAttribute == null) {
+                return false;
+            }
 
-        if (filter == null) {
-            throw new NullPointerException(Messages.getString("ldap.28")); //$NON-NLS-1$
-        }
-        if (filter.length() == 0) {
-            throw new StringIndexOutOfBoundsException();
+            NamingEnumeration<?> singleEnu = matchAttribute.getAll();
+            while (singleEnu.hasMore()) {
+                if (!schemaAttribute.contains(singleEnu.next())) {
+                    return false;
+                }
+            }
         }
-        if (!filter.startsWith("(")) {
-            StringBuilder filterWrapper = new StringBuilder("(");
-            filterWrapper.append(filter).append(")");
-            filter = filterWrapper.toString();
+
+        return true;
+    }
+
+    // Convert ldap name to jndi name.
+    private String ldap2jndi(String jndiName) {
+        String ldapName = schemaLdap2Jndi.get(jndiName);
+        if (null == ldapName) {
+            ldapName = jndiName;
         }
 
-        if (null == searchControls) {
-            searchControls = new SearchControls();
+        return ldapName;
+    }
+
+    // Convert jndi name to ldap name.
+    private String jndi2ldap(String jndiName) {
+        // If the parameter indeed is ldapName, convert it to jndiName to avoid
+        // confusion.
+        String ldapName = schemaLdap2Jndi.get(jndiName);
+        if (null != ldapName) {
+            return ldapName;
         }
 
-        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;
-        }
-
-        BasicAttributes matchingAttrs = new BasicAttributes(true);
-        extractMatchingAttributes(f, matchingAttrs);
-
-        return search(name, matchingAttrs, searchControls
-                .getReturningAttributes());
-    }
-
-    private void extractMatchingAttributes(Filter f,
-            BasicAttributes matchingAttrs) {
-        if (!f.isLeaf()) {
-            List<Filter> children = f.getChildren();
-            for (Iterator<Filter> iter = children.iterator(); iter.hasNext();) {
-                extractMatchingAttributes(iter.next(), matchingAttrs);
-            }
-        } else {
-            Object value = f.getValue();
-            if (value instanceof AttributeTypeAndValuePair) {
-                AttributeTypeAndValuePair pair = (AttributeTypeAndValuePair) value;
-                matchingAttrs.put(pair.getType(), pair.getValue());
-            } else {
-                matchingAttrs.put((String) value, "*");
-            }
+        ldapName = schemaJndi2Ldap.get(jndiName.toLowerCase());
+        if (null == ldapName) {
+            ldapName = jndiName;
         }
+
+        return ldapName.toLowerCase();
     }
 }

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=676530&r1=676529&r2=676530&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 Mon Jul 14 02:43:27 2008
@@ -674,6 +674,74 @@
         assertEquals("bind", attribute.get(0));
     }
 
+    public void test_bind_LAttributes() throws Exception {
+        MockLdapClient client = new MockLdapClient();
+        Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+
+        context = new LdapContextImpl(client, env, "cn=test");
+        
+        Attributes attrs = new BasicAttributes();
+        attrs.put("objectClass", "cn");
+        attrs.put("cn", "testBind");
+        context.bind("cn=testBind", "object", attrs);
+        
+        AddOp op = (AddOp) client.getRequest();
+        assertEquals("cn=testBind,cn=test", op.getEntry());
+        List<LdapAttribute> attrList = op.getAttributeList();
+        // has attribute: objectClass, javaClassNames, javaClassName,
+        // javaSerializedData, cn
+        assertEquals(5, attrList.size());
+        Map<String, LdapAttribute> map = new HashMap<String, LdapAttribute>();
+        for (Iterator iter = attrList.iterator(); iter.hasNext();) {
+            LdapAttribute attr = (LdapAttribute) iter.next();
+            map.put(attr.getID(), attr);
+        }
+
+        assertTrue(map.containsKey("objectClass"));
+        Attribute attribute = map.get("objectClass");
+        NamingEnumeration<?> enu = attribute.getAll();
+        HashSet<Object> valueSet = new HashSet<Object>();
+        while (enu.hasMore()) {
+            valueSet.add(enu.next());
+        }
+        // objectClass has values: top, cn, javaObject, 
+        // javaSerializedObject
+        assertEquals(4, valueSet.size());
+        assertTrue(valueSet.contains("top"));
+        assertTrue(valueSet.contains("cn"));
+        assertTrue(valueSet.contains("javaObject"));
+        assertTrue(valueSet.contains("javaSerializedObject"));
+
+        assertTrue(map.containsKey("javaClassNames"));
+        attribute = map.get("javaClassNames");
+        enu = attribute.getAll();
+        valueSet = new HashSet<Object>();
+        while (enu.hasMore()) {
+            valueSet.add(enu.next());
+        }
+
+        assertEquals(5, valueSet.size());
+        assertTrue(valueSet.contains("java.io.Serializable"));
+        assertTrue(valueSet.contains("java.lang.CharSequence"));
+        assertTrue(valueSet.contains("java.lang.Comparable"));
+        assertTrue(valueSet.contains("java.lang.Object"));
+        assertTrue(valueSet.contains("java.lang.String"));
+
+        assertTrue(map.containsKey("javaClassName"));
+        attribute = map.get("javaClassName");
+        assertEquals(1, attribute.size());
+        assertEquals(String.class.getName(), attribute.get(0));
+
+        assertTrue(map.containsKey("javaSerializedData"));
+        assertEquals(1, attribute.size());
+        attribute = map.get("javaSerializedData");
+
+        assertTrue(map.containsKey("cn"));
+        attribute = map.get("cn");
+        assertEquals(1, attribute.size());
+        assertEquals("testBind", attribute.get(0));
+    }
+    
     public void test_lookup() throws Exception {
         MockLdapClient client = new MockLdapClient();
         Hashtable<Object, Object> env = new Hashtable<Object, Object>();