harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r687988 [3/11] - in /harmony/enhanced/classlib/branches/java6: ./ depends/build/ depends/build/platform/ depends/jars/ depends/jars/icu4jni_3.4/ depends/manifests/bcel-5.2/ depends/manifests/bcel-5.2/META-INF/ make/ modules/accessibility/ m...
Date Fri, 22 Aug 2008 07:15:27 GMT
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=687988&r1=687987&r2=687988&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 Fri Aug 22 00:15:00 2008
@@ -20,7 +20,9 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Vector;
 
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingEnumeration;
@@ -44,29 +46,24 @@
 
     private static final long serialVersionUID = -6492847268062616321L;
 
-    /**
-     * whether the value of attribute is binary
-     */
-    private boolean isBinary;
-
     private LdapContextImpl context = null;
 
     private static HashSet<String> BINARY_ATTRIBUTE = new HashSet<String>();
     static {
-        BINARY_ATTRIBUTE.add("photo");
-        BINARY_ATTRIBUTE.add("personalSignature");
-        BINARY_ATTRIBUTE.add("audio");
-        BINARY_ATTRIBUTE.add("jpegPhoto");
-        BINARY_ATTRIBUTE.add("javaSerializedData");
-        BINARY_ATTRIBUTE.add("thumbnailPhoto");
-        BINARY_ATTRIBUTE.add("thumbnailLogo");
-        BINARY_ATTRIBUTE.add("userPassword");
-        BINARY_ATTRIBUTE.add("userCertificate");
-        BINARY_ATTRIBUTE.add("cACertificate");
-        BINARY_ATTRIBUTE.add("authorityRevocationList");
-        BINARY_ATTRIBUTE.add("certificateRevocationList");
-        BINARY_ATTRIBUTE.add("crossCertificatePair");
-        BINARY_ATTRIBUTE.add("x500UniqueIdentifier");
+        BINARY_ATTRIBUTE.add("photo".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("personalSignature".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("audio".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("jpegPhoto".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("javaSerializedData".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("thumbnailPhoto".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("thumbnailLogo".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("userPassword".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("userCertificate".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("cACertificate".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("authorityRevocationList".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("certificateRevocationList".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("crossCertificatePair".toLowerCase()); //$NON-NLS-1$
+        BINARY_ATTRIBUTE.add("x500UniqueIdentifier".toLowerCase()); //$NON-NLS-1$
     }
 
     /**
@@ -79,7 +76,6 @@
 
     public LdapAttribute(String id, LdapContextImpl ctx) {
         super(id, false);
-        isBinary = isBinary(id);
         context = ctx;
     }
 
@@ -94,9 +90,9 @@
      *            may never be <code>null</code>
      * @throws NamingException
      */
-    public LdapAttribute(Attribute attr, LdapContextImpl ctx) throws NamingException {
+    public LdapAttribute(Attribute attr, LdapContextImpl ctx)
+            throws NamingException {
         super(attr.getID(), attr.isOrdered());
-        isBinary = isBinary(getID());
         NamingEnumeration<?> enu = attr.getAll();
         while (enu.hasMore()) {
             Object value = enu.next();
@@ -109,19 +105,10 @@
     public void decodeValues(Object[] vs) {
         byte[] type = (byte[]) vs[0];
         attrID = Utils.getString(type);
-        isBinary = isBinary(attrID);
         Collection<byte[]> list = (Collection<byte[]>) vs[1];
-        // FIXME: deal with java.naming.ldap.attributes.binary
-        if (!isBinary) {
-            for (byte[] bs : list) {
-                add(Utils.getString(bs));
-            }
-        } else {
-            for (byte[] bs : list) {
-                add(bs);
-            }
+        for (byte[] bs : list) {
+            add(bs);
         }
-
     }
 
     public void encodeValues(Object[] vs) {
@@ -130,7 +117,7 @@
         List<Object> list = new ArrayList<Object>(this.values.size());
 
         for (Object object : this.values) {
-            if (!isBinary && object instanceof String) {
+            if (object instanceof String) {
                 String str = (String) object;
                 object = Utils.getBytes(str);
             }
@@ -173,7 +160,35 @@
 
     }
 
-    private static boolean isBinary(String name) {
-        return BINARY_ATTRIBUTE.contains(name) || name.endsWith(";binary");
+    public void convertValueToString() {
+        // values can't be null
+        if (values.size() == 0) {
+            return;
+        }
+
+        Vector<Object> newValues = new Vector<Object>(values.size());
+        for (Iterator<Object> iter = values.iterator(); iter.hasNext();) {
+            Object value = iter.next();
+            newValues.add(Utils.getString(value));
+        }
+
+        values.clear();
+        values = newValues;
+    }
+
+    public static boolean isBinary(String name, String[] attrs) {
+        if (BINARY_ATTRIBUTE.contains(name.toLowerCase())
+                || name.endsWith(";binary")) { //$NON-NLS-1$
+            return true;
+        }
+
+        if (attrs != null) {
+            for (int i = 0; i < attrs.length; i++) {
+                if (name.equalsIgnoreCase(attrs[i])) {
+                    return true;
+                }
+            }
+        }
+        return false;
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapClient.java Fri Aug 22 00:15:00 2008
@@ -77,6 +77,8 @@
      */
     private Hashtable<Integer, Element> requests = new Hashtable<Integer, Element>();
 
+    private Hashtable<Integer, Element> batchedSearchRequests = new Hashtable<Integer, Element>();
+
     /**
      * the max time to wait server response in milli-second
      */
@@ -182,6 +184,11 @@
                             // get response operation according messageId
                             Element element = requests.get(Integer
                                     .valueOf(messageId));
+                            if (element == null) {
+                                element = batchedSearchRequests.get(Integer
+                                        .valueOf(messageId));
+                            }
+
                             if (element != null) {
                                 return element.response.getResponseOp();
                             }
@@ -229,20 +236,41 @@
 
             Element element = requests.get(Integer.valueOf(response
                     .getMessageId()));
+            if (element == null
+                    && batchedSearchRequests.contains(Integer.valueOf(response
+                            .getMessageId()))) {
+                element = batchedSearchRequests.get(Integer.valueOf(response
+                        .getMessageId()));
+                // error occurs when read response
+                if (ex != null) {
+                    ((SearchOp) response.getResponseOp()).getSearchResult()
+                            .setException(ex);
+                    batchedSearchRequests.remove(Integer.valueOf(response
+                            .getMessageId()));
+                    return;
+                }
+
+                // wait time out
+                if (element.response.getMessageId() != response.getMessageId()) {
+                    // ldap.31=Read LDAP response message time out
+                    ((SearchOp) response.getResponseOp()).getSearchResult()
+                            .setException(
+                                    new IOException(Messages
+                                            .getString("ldap.31"))); //$NON-NLS-1$);
+                    batchedSearchRequests.remove(Integer.valueOf(response
+                            .getMessageId()));
+                    return;
+                }
 
+            }
             if (element != null) {
                 element.response = response;
                 element.ex = ex;
-                // persistent search response
+                // persistent search response || search response
                 if (element.lock == null) {
-
                     notifyPersistenSearchListener(element);
 
                 } else {
-                    /*
-                     * notify the thread which send request and wait for
-                     * response
-                     */
                     if (element.response.getOperationIndex() == LdapASN1Constant.OP_EXTENDED_RESPONSE
                             && ((ExtendedOp) element.response.getResponseOp())
                                     .getExtendedRequest().getID().equals(
@@ -254,6 +282,10 @@
                         isStopped = true;
                     }
 
+                    /*
+                     * notify the thread which send request and wait for
+                     * response
+                     */
                     synchronized (element.lock) {
                         element.lock.notify();
                     }
@@ -366,7 +398,7 @@
                 }
             }
         }
-        
+
         element = requests.get(messageID);
 
         // wait time out
@@ -394,7 +426,10 @@
     }
 
     private LdapMessage doSearchOperation(ASN1Encodable request,
-            ASN1Decodable response, Control[] controls) throws IOException {
+            ASN1Decodable response, Control[] controls)
+            throws IOException {
+        int batchSize = ((SearchOp) request).getBatchSize();
+
         LdapMessage requestMsg = new LdapMessage(
                 LdapASN1Constant.OP_SEARCH_REQUEST, request, controls);
 
@@ -407,9 +442,15 @@
             out.write(requestMsg.encode());
             out.flush();
             LdapMessage responseMsg = waitResponse(messageID, lock);
-
+            int size = 1;
             while (responseMsg.getOperationIndex() != LdapASN1Constant.OP_SEARCH_RESULT_DONE) {
+                if (size == batchSize) {
+                    batchedSearchRequests.put(messageID, requests
+                            .get(messageID));
+                    break;
+                }
                 responseMsg = waitResponse(messageID, lock);
+                ++size;
             }
 
             return responseMsg;

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=687988&r1=687987&r2=687988&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 Fri Aug 22 00:15:00 2008
@@ -143,6 +143,10 @@
 
     private List<UnsolicitedNotificationListener> unls;
 
+    private String[] binaryAttributes;
+
+    private int batchSize = 0;
+
     private static final Control NON_CRITICAL_MANAGE_REF_CONTROL = new ManageReferralControl(
             Control.NONCRITICAL);
 
@@ -154,6 +158,8 @@
 
     private static final String LDAP_TYPES_ONLY = "java.naming.ldap.typesOnly"; //$NON-NLS-1$
 
+    private static final String LDAP_ATTRIBUTES_BINARY = "java.naming.ldap.attributes.binary"; //$NON-NLS-1$
+
     /**
      * Some properties, such as 'java.naming.security.authentication', changed
      * by <code>Context.addToEnvironment</code> or
@@ -205,6 +211,11 @@
         doBindOperation(connCtls);
     }
 
+    public LdapContextImpl(LdapContextImpl context, String dn)
+            throws NamingException {
+        this(context.client, context.env, dn);
+    }
+
     private void initial(LdapClient ldapClient,
             Hashtable<Object, Object> environment, String dn)
             throws InvalidNameException {
@@ -798,7 +809,7 @@
             searchControls.setReturningAttributes(new String[] {
                     "namingContexts", "subschemaSubentry", "altServer", });
             search = new SearchOp(name.toString(), searchControls, filter);
-
+            search.setBatchSize(0);
             try {
                 client.doOperation(search, requestControls);
             } catch (IOException e) {
@@ -849,7 +860,7 @@
             throw ex;
         }
         search = new SearchOp(subschemasubentry, searchControls, filter);
-
+        search.setBatchSize(0);
         try {
             client.doOperation(search, requestControls);
         } catch (IOException e) {
@@ -883,7 +894,6 @@
                 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++) {
@@ -894,8 +904,8 @@
             }
         }
 
-        ldapSchemaCtx = new LdapSchemaContextImpl(this, env, name,
-                schemaTable, LdapSchemaContextImpl.SCHEMA_ROOT_LEVEL);
+        ldapSchemaCtx = new LdapSchemaContextImpl(this, env, name, schemaTable,
+                LdapSchemaContextImpl.SCHEMA_ROOT_LEVEL);
         return ldapSchemaCtx;
     }
 
@@ -1079,7 +1089,8 @@
             filter.setValue("objectClass");
         } else {
             // only one attribute type and value pair
-            if (attributes.size() == 1 && attributes.getAll().next().size() == 1) {
+            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
@@ -1107,33 +1118,10 @@
         controls.setReturningAttributes(as);
         LdapSearchResult result = doSearch(targetDN, filter, controls);
 
-        List<SearchResult> list = new ArrayList<SearchResult>();
-        Map<String, Attributes> entries = result.getEntries();
-        Name tempName = new LdapName(contextDn.toString());
-        tempName.addAll(name);
-        String baseDN = tempName.toString();
-        for (String dn : entries.keySet()) {
-            SearchResult sr = null;
-            if (dn.startsWith("ldap://")) {
-                sr = new SearchResult(dn, null, entries.get(dn), false);
-                int index = dn.indexOf("/", 7);
-                sr.setNameInNamespace(dn.substring(index + 1, dn.length()));
-                list.add(sr);
-            } else {
-                String relativeName = LdapUtils.convertToRelativeName(dn,
-                        baseDN);
-                sr = new SearchResult(relativeName, null, entries.get(dn));
-                sr.setNameInNamespace(dn);
-            }
-            list.add(sr);
-        }
-
-        if (list.size() == 0 && result.getException() != null) {
+        if (result.isEmpty() && result.getException() != null) {
             throw result.getException();
         }
-
-        return new LdapNamingEnumeration<SearchResult>(list, result
-                .getException());
+        return result.toSearchResultEnumeration(targetDN);
     }
 
     public NamingEnumeration<SearchResult> search(Name name, String filter,
@@ -1166,33 +1154,10 @@
 
         LdapSearchResult result = doSearch(targetDN, f, searchControls);
 
-        List<SearchResult> list = new ArrayList<SearchResult>();
-        Map<String, Attributes> entries = result.getEntries();
-        Name tempName = new LdapName(contextDn.toString());
-        tempName.addAll(name);
-        String baseDN = tempName.toString();
-        for (String dn : entries.keySet()) {
-            SearchResult sr = null;
-            if (dn.startsWith("ldap://")) {
-                sr = new SearchResult(dn, null, entries.get(dn), false);
-                int index = dn.indexOf("/", 7);
-                sr.setNameInNamespace(dn.substring(index + 1, dn.length()));
-                list.add(sr);
-            } else {
-                String relativeName = LdapUtils.convertToRelativeName(dn,
-                        baseDN);
-                sr = new SearchResult(relativeName, null, entries.get(dn));
-                sr.setNameInNamespace(dn);
-            }
-            list.add(sr);
-        }
-
-        if (list.size() == 0 && result.getException() != null) {
+        if (result.isEmpty() && result.getException() != null) {
             throw result.getException();
         }
-
-        return new LdapNamingEnumeration<SearchResult>(list, result
-                .getException());
+        return result.toSearchResultEnumeration(targetDN);
     }
 
     public NamingEnumeration<SearchResult> search(Name name, String filter,
@@ -1225,6 +1190,7 @@
     LdapSearchResult doSearch(SearchOp op) throws NamingException {
         applyEnvChange();
 
+        op.setBatchSize(batchSize);
         if (env.get(LDAP_DEREF_ALIASES) != null) {
             String derefAliases = (String) env.get(LDAP_DEREF_ALIASES);
             if (derefAliases.equals("always")) {
@@ -1256,6 +1222,8 @@
             }
         }
 
+        op.getSearchResult().setBinaryAttributes(binaryAttributes);
+
         LdapMessage message = null;
         try {
             message = client.doOperation(op, requestControls);
@@ -1279,33 +1247,34 @@
 
         LdapResult result = op.getResult();
 
-        op.getSearchResult().setException(
-                LdapUtils.getExceptionFromResult(result));
-
-        // has error, not deal with referrals
-        if (result.getResultCode() != LdapResult.REFERRAL
-                && op.getSearchResult().getException() != null) {
-            return op.getSearchResult();
-        }
+        if (result != null) {
+            op.getSearchResult().setException(
+                    LdapUtils.getExceptionFromResult(result));
+
+            // has error, not deal with referrals
+            if (result.getResultCode() != LdapResult.REFERRAL
+                    && op.getSearchResult().getException() != null) {
+                return op.getSearchResult();
+            }
 
-        // baseObject is not located at the server
-        if (result.getResultCode() == LdapResult.REFERRAL) {
-            ReferralException ex = new ReferralExceptionImpl(contextDn
-                    .toString(), result.getReferrals(), env);
-            try {
-                if (isFollowReferral(ex)) {
-                    LdapContextImpl ctx = (LdapContextImpl) getReferralContext(ex);
-                    return ctx.doSearch(op);
-                } else {
-                    op.getSearchResult().setException(ex);
+            // baseObject is not located at the server
+            if (result.getResultCode() == LdapResult.REFERRAL) {
+                ReferralException ex = new ReferralExceptionImpl(contextDn
+                        .toString(), result.getReferrals(), env);
+                try {
+                    if (isFollowReferral(ex)) {
+                        LdapContextImpl ctx = (LdapContextImpl) getReferralContext(ex);
+                        return ctx.doSearch(op);
+                    } else {
+                        op.getSearchResult().setException(ex);
+                        return op.getSearchResult();
+                    }
+                } catch (PartialResultException e) {
+                    op.getSearchResult().setException(e);
                     return op.getSearchResult();
                 }
-            } catch (PartialResultException e) {
-                op.getSearchResult().setException(e);
-                return op.getSearchResult();
             }
         }
-
         // there are SearchResultReference in search result
         if (op.getSearchResult().getRefURLs() != null
                 && op.getSearchResult().getRefURLs().size() != 0) {
@@ -1399,6 +1368,13 @@
             throw new NullPointerException();
         }
 
+        if (s.equals(Context.BATCHSIZE)) {
+            batchSize = Integer.parseInt((String) o);
+        } else if (s.equals(LDAP_ATTRIBUTES_BINARY)) {
+            String value = (String) o;
+            binaryAttributes = value.trim().split(" ");
+        }
+
         Object preValue = env.put(s, o);
 
         // if preValue equals o, do nothing
@@ -1594,34 +1570,11 @@
 
         LdapSearchResult result = doSearch(targetDN, filter, controls);
 
-        List<NameClassPair> list = new ArrayList<NameClassPair>();
-        Map<String, Attributes> entries = result.getEntries();
-        Name tempName = new LdapName(contextDn.toString());
-        tempName.addAll(name);
-        String baseDN = tempName.toString();
-        for (String dn : entries.keySet()) {
-            String relativeName = LdapUtils.convertToRelativeName(dn, baseDN);
-            Attributes attrs = entries.get(dn);
-            Attribute attrClass = attrs.get("javaClassName");
-            String className = null;
-            if (attrClass != null) {
-                className = (String) attrClass.get(0);
-            } else {
-                className = DirContext.class.getName();
-            }
-            NameClassPair pair = new NameClassPair(relativeName, className,
-                    true);
-            pair.setNameInNamespace(dn);
-            list.add(pair);
-        }
-
-        // no entries return
-        if (list.size() == 0 && result.getException() != null) {
+        if (result.isEmpty() && result.getException() != null) {
             throw result.getException();
         }
 
-        return new LdapNamingEnumeration<NameClassPair>(list, result
-                .getException());
+        return result.toNameClassPairEnumeration(targetDN);
     }
 
     protected String getTargetDN(Name name, Name prefix)
@@ -1739,28 +1692,23 @@
          * there is only one ldap ns
          */
 
-        NamingEnumeration<NameClassPair> enu = list(name);
-
-        List<Binding> bindings = new ArrayList<Binding>();
+        // NamingEnumeration<NameClassPair> enu = list(name);
+        // absolute dn name to list
+        String targetDN = getTargetDN(name, contextDn);
 
-        while (enu.hasMore()) {
-            NameClassPair pair = enu.next();
-            Object bound = null;
-            if (!pair.getClassName().equals(DirContext.class.getName())) {
-                bound = lookup(pair.getName());
-            } else {
-                bound = new LdapContextImpl(this, env, contextDn.toString());
-            }
+        // construct one-level search using filter "(objectclass=*)"
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+        Filter filter = new Filter(Filter.PRESENT_FILTER);
+        filter.setValue("objectClass");
 
-            Binding binding = new Binding(pair.getName(), bound.getClass()
-                    .getName(), bound);
-            binding.setNameInNamespace(pair.getNameInNamespace());
-            bindings.add(binding);
+        LdapSearchResult result = doSearch(targetDN, filter, controls);
 
+        if (result.isEmpty() && result.getException() != null) {
+            throw result.getException();
         }
 
-        // FIXME: deal with exception
-        return new LdapNamingEnumeration<Binding>(bindings, null);
+        return result.toBindingEnumeration(this, name);
     }
 
     public NamingEnumeration<Binding> listBindings(String s)
@@ -1951,6 +1899,12 @@
             throw new NullPointerException();
         }
 
+        if (s.equals(Context.BATCHSIZE)) {
+            batchSize = 0;
+        } else if (s.equals(LDAP_ATTRIBUTES_BINARY)) {
+            binaryAttributes = null;
+        }
+
         Object preValue = env.remove(s);
 
         // if s doesn't exist in env

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapNamingEnumeration.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapNamingEnumeration.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapNamingEnumeration.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapNamingEnumeration.java Fri Aug 22 00:15:00 2008
@@ -17,66 +17,111 @@
 
 package org.apache.harmony.jndi.provider.ldap;
 
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.LinkedList;
 import java.util.NoSuchElementException;
 
+import javax.naming.CommunicationException;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 
+import org.apache.harmony.jndi.internal.nls.Messages;
+
 /**
  * TODO: dynamic load elements from server
  */
 public class LdapNamingEnumeration<T> implements NamingEnumeration<T> {
 
-    private ArrayList<T> values;
-
-    private int currentIndex;
+    private LinkedList<T> values;
 
     private NamingException exception;
 
     /**
+     * flag to indicate whether all element have been added
+     */
+    private boolean isFinished;
+
+    /**
+     * max time to wait next element in millisconds
+     */
+    private long timeout = DEFAULT_TIMEOUT;
+
+    private static final long DEFAULT_TIMEOUT = 30000;
+
+    /**
+     * This constructor equals to
+     * <code>LdapNamingEnumeration(Collection<T>, NamingException, true)</code>
+     */
+    public LdapNamingEnumeration(Collection<T> list, NamingException ex) {
+        this(list, ex, true);
+    }
+
+    /**
      * <code>list</code> and <code>ex</code> both can be <code>null</code>,
      * <code>null</code> of <code>list</code> will be treated as empty List.
      * 
      * @param list
-     *            All elements to be enumerate
+     *            elements added to the enumeration.
      * @param ex
-     *            exception would be thrown when over iterate
+     *            exception would be thrown when over iterate.
+     * @param isFinished
+     *            if all elements have been added.
      */
-    public LdapNamingEnumeration(Collection<T> list, NamingException ex) {
+    public LdapNamingEnumeration(Collection<T> list, NamingException ex,
+            boolean isFinished) {
         if (list == null) {
-            values = new ArrayList<T>();
+            values = new LinkedList<T>();
         } else {
-            values = new ArrayList<T>(list);
+            values = new LinkedList<T>(list);
         }
 
         exception = ex;
-        currentIndex = 0;
+        this.isFinished = isFinished;
     }
 
     /**
      * release all relative resources, current implementation just set
-     * enumeration values to <code>null</code>.
+     * enumeration values to <code>null</code> which indicate the enumeration
+     * is closed.
      */
-    public void close() throws NamingException {
+    public void close() {
         // no other resources need to release
-        values = null;
+        synchronized (values) {
+            values.clear();
+            values = null;
+        }
     }
 
     public boolean hasMore() throws NamingException {
+        // has been closed
         if (values == null) {
             return false;
         }
 
-        if (currentIndex < values.size()) {
+        if (!values.isEmpty()) {
             return true;
         }
-        // no elemnts to iterate, release resource first
+
+        synchronized (values) {
+            if (values.isEmpty() && !isFinished) {
+                waitMoreElement();
+                if (!values.isEmpty()) {
+                    return true;
+                }
+            }
+        }
+
         close();
+
         if (exception != null) {
             throw exception;
         }
+
+        if (!isFinished) {
+            // ldap.31=Read LDAP response message time out
+            throw new CommunicationException(Messages.getString("ldap.31")); //$NON-NLS-1$
+        }
+
         return false;
     }
 
@@ -86,11 +131,27 @@
      * invoked.
      */
     public T next() throws NamingException {
-        if (values == null || currentIndex >= values.size()) {
+        if (values == null || (values.isEmpty() && isFinished)) {
             throw new NoSuchElementException();
         }
 
-        return values.get(currentIndex++);
+        synchronized (values) {
+            if (values.isEmpty() && !isFinished) {
+                waitMoreElement();
+                // wait timeout
+                if (values.isEmpty() && !isFinished) {
+                    if (exception != null) {
+                        throw exception;
+                    }
+                    // ldap.31=Read LDAP response message time out
+                    throw new CommunicationException(Messages
+                            .getString("ldap.31")); //$NON-NLS-1$
+                } else if (values.isEmpty()) {
+                    throw new NoSuchElementException();
+                }
+            }
+            return values.poll();
+        }
     }
 
     public boolean hasMoreElements() {
@@ -98,26 +159,86 @@
             return false;
         }
 
-        if (currentIndex < values.size()) {
+        if (!values.isEmpty()) {
             return true;
         }
+
+        synchronized (values) {
+            if (values.isEmpty() && !isFinished) {
+                waitMoreElement();
+                if (!values.isEmpty()) {
+                    return true;
+                }
+            }
+        }
+
         return false;
     }
 
     public T nextElement() {
-        if (values == null || currentIndex >= values.size()) {
+        if (values == null || (values.isEmpty() && isFinished)) {
             throw new NoSuchElementException();
         }
 
-        return values.get(currentIndex++);
+        synchronized (values) {
+            if (values.isEmpty() && !isFinished) {
+                waitMoreElement();
+                if (values.isEmpty()) {
+                    throw new NoSuchElementException();
+                }
+            }
+            return values.poll();
+        }
+    }
+
+    private void waitMoreElement() {
+        try {
+            values.wait(timeout);
+        } catch (InterruptedException e) {
+            // ignore
+        }
     }
 
-    protected void setException(NamingException exception) {
+    void setException(NamingException exception) {
         this.exception = exception;
     }
-    
-    void add(T pair) {
-        values.add(pair);
+
+    void add(T pair, boolean isFinished) {
+        if (values == null) {
+            return;
+        }
+
+        synchronized (values) {
+            values.add(pair);
+            if (isFinished) {
+                this.isFinished = true;
+            }
+            values.notifyAll();
+        }
     }
 
+    void add(Collection<T> list, boolean isFinished) {
+        if (values == null) {
+            return;
+        }
+
+        synchronized (values) {
+            values.addAll(list);
+            if (isFinished) {
+                this.isFinished = true;
+            }
+            values.notifyAll();
+        }
+    }
+
+    boolean isFinished() {
+        return isFinished;
+    }
+
+    void setFinished() {
+        synchronized (values) {
+            isFinished = true;
+            values.notifyAll();
+        }
+    }
 }

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=687988&r1=687987&r2=687988&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 Fri Aug 22 00:15:00 2008
@@ -16,11 +16,13 @@
  */
 package org.apache.harmony.jndi.provider.ldap;
 
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.Map.Entry;
 
 import javax.naming.Binding;
 import javax.naming.CompositeName;
@@ -257,7 +259,7 @@
             // jndi.2E=The name is null
             throw new NullPointerException(Messages.getString("jndi.2E")); //$NON-NLS-1$
         }
-        
+
         if (attributes == null) {
             // jndi.13=Non-null attribute is required for modification
             throw new NullPointerException(Messages.getString("jndi.13")); //$NON-NLS-1$
@@ -283,7 +285,8 @@
         modifyAttributes(name, items);
     }
 
-    // Mapping from DirContext's attribute operation code to server's operation code. 
+    // Mapping from DirContext's attribute operation code to server's operation
+    // code.
     private static final int OperationJndi2Ldap[] = { -1, 0, 2, 1, };
 
     @Override
@@ -291,6 +294,12 @@
             throws NamingException {
         // First get the old schema.
         int size = name.size();
+
+        if (size < 1) {
+            // ldap.38=Can't modify schema root
+            throw new SchemaViolationException(Messages.getString("ldap.38")); //$NON-NLS-1$
+        }
+
         Hashtable<String, Object> subSchemaTree = doLookup(name
                 .getPrefix(size - 1), size - 1);
 
@@ -366,17 +375,41 @@
         ModifyOp op = new ModifyOp(ldapContext.subschemasubentry);
         Name modifySchemaName = name.getPrefix(size - 1).addAll(rdn);
         BasicAttribute schemaEntry = new LdapAttribute(new BasicAttribute(
-                jndi2ldap(modifySchemaName.toString()), schemaLine), ldapContext);
+                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), ldapContext);
+                jndi2ldap(modifySchemaName.toString()), newSchemaLine),
+                ldapContext);
         op.addModification(OperationJndi2Ldap[DirContext.ADD_ATTRIBUTE],
                 new LdapAttribute(addSchemaEntry, ldapContext));
 
         doBasicOperation(op);
-        subSchemaTree.remove(subSchemaType);
-        subSchemaTree.put(subSchemaType, newSchemaLine);
+
+        // Modify the hashtable to reflect the modification.
+        Object subSchema = subSchemaTree.get(subSchemaType);
+        if (subSchema instanceof String) {
+            subSchemaTree.remove(subSchemaType);
+            subSchemaTree.put(subSchemaType, newSchemaLine);
+        } else {
+            /*
+             * Here we can only change the content of subSchemaTable, instead of
+             * change the reference. Because in other ldapSchemaContext, there
+             * may be reference to this table. And they should also reflect the
+             * changes.
+             */
+            Hashtable<String, Object> subSchemaTable = (Hashtable<String, Object>) subSchema;
+            subSchemaTable.clear();
+            Hashtable<String, Object> parsedTable = SchemaParser
+                    .parseValue(newSchemaLine);
+            Iterator<Entry<String, Object>> it = parsedTable.entrySet()
+                    .iterator();
+            while (it.hasNext()) {
+                Entry<String, Object> entry = it.next();
+                subSchemaTable.put(entry.getKey(), entry.getValue());
+            }
+        }
     }
 
     @Override
@@ -458,21 +491,19 @@
 
         Hashtable<String, Object> tempSchema = doLookup(name, size);
 
-        LdapNamingEnumeration<NameClassPair> enumeration = new LdapNamingEnumeration<NameClassPair>(
-                null, null);
-
         if (size == level - 1) {
-            return enumeration;
+            return new LdapNamingEnumeration<NameClassPair>(null, null);
         }
 
         Iterator<String> keys = tempSchema.keySet().iterator();
 
+        List<NameClassPair> list = new ArrayList<NameClassPair>();
         while (keys.hasNext()) {
-            enumeration.add(new NameClassPair(ldap2jndi(keys.next()), this
-                    .getClass().getName()));
+            list.add(new NameClassPair(ldap2jndi(keys.next()), this.getClass()
+                    .getName()));
         }
 
-        return enumeration;
+        return new LdapNamingEnumeration<NameClassPair>(list, null);
     }
 
     @Override
@@ -495,21 +526,19 @@
 
         Hashtable<String, Object> tempSchema = doLookup(name, size);
 
-        LdapNamingEnumeration<Binding> enumeration = new LdapNamingEnumeration<Binding>(
-                null, null);
-
         if (size == level - 1) {
-            return enumeration;
+            return new LdapNamingEnumeration<Binding>(null, null);
         }
 
         Iterator<String> keys = tempSchema.keySet().iterator();
 
+        List<Binding> list = new ArrayList<Binding>();
         while (keys.hasNext()) {
-            enumeration.add(new Binding(ldap2jndi(keys.next()), this.getClass()
+            list.add(new Binding(ldap2jndi(keys.next()), this.getClass()
                     .getName()));
         }
 
-        return enumeration;
+        return new LdapNamingEnumeration<Binding>(list, null);
     }
 
     @Override
@@ -579,14 +608,26 @@
 
     @Override
     public void rename(Name nOld, Name nNew) throws NamingException {
+        if (nOld == null || nNew == null) {
+            throw new NullPointerException();
+        }
+
+        if (nOld.size() == 0 || nNew.size() == 0) {
+            // ldap.3A=Can't rename empty name
+            throw new InvalidNameException(Messages.getString("ldap.3A")); //$NON-NLS-1$
+        }
+
+        if (nOld.size() > 1 || nNew.size() > 1) {
+            // ldap.3B=Can't rename across contexts
+            throw new InvalidNameException(Messages.getString("ldap.3B")); //$NON-NLS-1$
+        }
         // 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 {
-        // ldap.39=Can't rename schema
-        throw new SchemaViolationException(Messages.getString("ldap.39")); //$NON-NLS-1$
+        rename(new CompositeName(sOld), new CompositeName(sNew));
     }
 
     @Override
@@ -603,8 +644,6 @@
 
         Hashtable<String, Object> subschemaTable = doLookup(name, size);
 
-        LdapNamingEnumeration<SearchResult> enumeration = new LdapNamingEnumeration<SearchResult>(
-                null, null);
         SearchResult searchResult;
         Attributes schemaAttributes;
         String schemaName;
@@ -612,6 +651,7 @@
 
         if (level - size > 1) {
             keyset = subschemaTable.keySet();
+            List<SearchResult> list = new ArrayList<SearchResult>();
             for (Iterator<String> i = keyset.iterator(); i.hasNext();) {
                 schemaName = ldap2jndi(i.next());
                 Name tempName = (Name) name.clone();
@@ -622,11 +662,12 @@
                             attributesToReturn);
                     searchResult = new SearchResult(ldap2jndi(schemaName), this
                             .getClass().getName(), null, schemaAttributes);
-                    enumeration.add(searchResult);
+                    list.add(searchResult);
                 }
             }
+            return new LdapNamingEnumeration<SearchResult>(list, null);
         }
-        return enumeration;
+        return new LdapNamingEnumeration<SearchResult>(null, null);
     }
 
     @Override
@@ -690,15 +731,13 @@
             }
         }
 
-        LdapNamingEnumeration<SearchResult> enumeration = new LdapNamingEnumeration<SearchResult>(
-                null, null);
-
         iterator = searchResults.iterator();
+        List<SearchResult> list = new ArrayList<SearchResult>();
         while (iterator.hasNext()) {
-            enumeration.add(iterator.next());
+            list.add(iterator.next());
         }
 
-        return enumeration;
+        return new LdapNamingEnumeration<SearchResult>(list, null);
     }
 
     @Override
@@ -720,7 +759,7 @@
     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 {
         Hashtable<String, Object> definitionTable = new Hashtable<String, Object>();

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSearchResult.java Fri Aug 22 00:15:00 2008
@@ -23,9 +23,17 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.naming.Binding;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.LdapName;
 
 import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
 import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
@@ -34,14 +42,14 @@
 public class LdapSearchResult {
 
     /**
-     * all search result entries
+     * All search result entries
      */
-    private Map<String, Attributes> entries = new HashMap<String, Attributes>();
+    protected HashMap<String, Attributes> entries = new HashMap<String, Attributes>();
 
     /**
      * SearchResultReference from server
      */
-    private List<String> refURLs;
+    protected List<String> refURLs;
 
     private LdapResult result;
 
@@ -49,13 +57,62 @@
 
     private String address;
 
+    private String[] binaryAttributes;
+
+    /**
+     * batch size for this search operation
+     */
+    private int batchSize;
+
+    /**
+     * NamingEnumeration for this LdapSearchResult. One LdapSearchResult
+     * instance can only has one corresponding NamingEnumeration instance.
+     */
+    private LdapNamingEnumeration<Object> enumeration;
+
+    /**
+     * Currently there are three different typs of LdapNamingEnumeration:
+     *
+     * <code>
+     * 1    NameClassPair
+     * 2    Binding
+     * 3    SearchResult
+     * </code>
+     */
+    private int enumerationType;
+
+    private String baseDN;
+
+    private LdapContextImpl context;
+
+    private Name name;
+
+    /**
+     * whether received all search result from server
+     */
+    private boolean isFinished;
+
+    private static int ENUMERATION_NAME_CLASS_PAIR = 1;
+
+    private static int ENUMERATION_BINDING = 2;
+
+    private static int ENUMERATION_SEARCH_RESULT = 3;
+
+    public int getBatchSize() {
+        return batchSize;
+    }
+
+    public void setBatchSize(int batchSize) {
+        this.batchSize = batchSize;
+    }
+
     public String getAddress() {
-		return address;
-	}
+        return address;
+    }
 
-	public void setAddress(String address) {
-		this.address = address;
-	}
+    public void setAddress(String address) {
+        this.address = address;
+    }
 
     public void decodeSearchResponse(Object[] values) {
         ChosenValue chosen = (ChosenValue) values[0];
@@ -75,6 +132,8 @@
     protected void decodeDone(Object value) {
         result = new LdapResult();
         result.decodeValues((Object[]) value);
+        isFinished = true;
+        addToEnumeration();
     }
 
     protected void decodeRef(Object value) {
@@ -90,27 +149,32 @@
 
     protected void decodeEntry(Object value) {
         Object[] values = (Object[]) value;
-        String name = Utils.getString((byte[]) values[0]);
+        String name = Utils.getString(values[0]);
 
         if (address != null) {
-        	name = address + name;
+            name = address + name;
         }
 
         Attributes attrs = null;
-
-        if (entries.containsKey(name)) {
-            attrs = entries.get(name);
-        } else {
-            attrs = new BasicAttributes(true);
-            entries.put(name, attrs);
+        synchronized (entries) {
+            if (entries.containsKey(name)) {
+                attrs = entries.get(name);
+            } else {
+                attrs = new BasicAttributes(true);
+                entries.put(name, attrs);
+            }
         }
 
         Collection<Object[]> list = (Collection<Object[]>) values[1];
         for (Object[] objects : list) {
             LdapAttribute attr = new LdapAttribute();
             attr.decodeValues(objects);
+            if (!LdapAttribute.isBinary(attr.getID(), binaryAttributes)) {
+                attr.convertValueToString();
+            }
             attrs.put(attr);
         }
+        addToEnumeration();
     }
 
     public Map<String, Attributes> getEntries() {
@@ -129,15 +193,140 @@
         return ex;
     }
 
-    public void setException(NamingException ex) {
-        this.ex = ex;
+    public void setException(Exception ex) {
+        if (ex == null) {
+            this.ex = null;
+            return;
+        }
+        if (!(ex instanceof NamingException)) {
+            this.ex = new NamingException(ex.getMessage());
+            this.ex.initCause(ex);
+        } else {
+            this.ex = (NamingException) ex;
+        }
     }
 
     public boolean isEmpty() {
-        return entries.size() == 0 && refURLs.size() == 0;
+        return entries.size() == 0 && (refURLs == null || refURLs.size() == 0);
     }
 
     public void setRefURLs(List<String> refURLs) {
         this.refURLs = refURLs;
     }
+
+    public String[] getBinaryAttributes() {
+        return binaryAttributes;
+    }
+
+    public void setBinaryAttributes(String[] binaryAttributes) {
+        this.binaryAttributes = binaryAttributes;
+    }
+
+    public NamingEnumeration<NameClassPair> toNameClassPairEnumeration(
+            String baseDN) {
+        enumerationType = ENUMERATION_NAME_CLASS_PAIR;
+        enumeration = new LdapNamingEnumeration<Object>(null, null);
+        this.baseDN = baseDN;
+        addToEnumeration();
+        return (NamingEnumeration) enumeration;
+    }
+
+    public NamingEnumeration<Binding> toBindingEnumeration(
+            LdapContextImpl context, Name name) throws NamingException {
+        enumerationType = ENUMERATION_BINDING;
+        enumeration = new LdapNamingEnumeration<Object>(null, null);
+        this.context = context;
+        this.name = name;
+
+        Name tempName = new LdapName(context.getNameInNamespace());
+        tempName.addAll(name);
+        baseDN = tempName.toString();
+
+        addToEnumeration();
+
+        return (NamingEnumeration) enumeration;
+    }
+
+    public NamingEnumeration<SearchResult> toSearchResultEnumeration(
+            String baseDN) {
+        enumerationType = ENUMERATION_SEARCH_RESULT;
+        enumeration = new LdapNamingEnumeration<Object>(null, null);
+        this.baseDN = baseDN;
+
+        addToEnumeration();
+
+        return (NamingEnumeration) enumeration;
+    }
+
+    private void addToEnumeration() {
+        if (enumeration == null || entries == null || entries.isEmpty()) {
+            return;
+        }
+
+        List<Object> list = new ArrayList<Object>();
+        HashMap<String, Attributes> tempEntries = null;
+
+        synchronized (entries) {
+            tempEntries = (HashMap<String, Attributes>) entries.clone();
+            entries.clear();
+        }
+
+        try {
+            for (String dn : tempEntries.keySet()) {
+                String relativeName = LdapUtils.convertToRelativeName(dn,
+                        baseDN);
+                Attributes attrs = tempEntries.get(dn);
+                Attribute attrClass = attrs.get("javaClassName"); //$NON-NLS-1$
+                String className = null;
+                switch (enumerationType) {
+                case 1:
+                    if (attrClass != null) {
+                        className = (String) attrClass.get(0);
+                    } else {
+                        className = DirContext.class.getName();
+                    }
+                    NameClassPair pair = new NameClassPair(relativeName,
+                            className, true);
+                    pair.setNameInNamespace(dn);
+                    list.add(pair);
+                    break;
+                case 2:
+                    Object bound = null;
+
+                    if (attrClass != null) {
+                        className = (String) attrClass.get(0);
+                        bound = context.lookup(name);
+                    } else {
+                        className = DirContext.class.getName();
+                        bound = new LdapContextImpl(context, baseDN);
+                    }
+
+                    Binding binding = new Binding(relativeName, className,
+                            bound);
+                    binding.setNameInNamespace(dn);
+                    list.add(binding);
+                    break;
+                case 3:
+                    SearchResult sr = null;
+                    if (dn.startsWith("ldap://")) {
+                        sr = new SearchResult(dn, null, attrs, false);
+                        int index = dn.indexOf("/", 7);
+                        sr.setNameInNamespace(dn.substring(index + 1, dn
+                                .length()));
+                    } else {
+                        sr = new SearchResult(relativeName, null, attrs);
+                        sr.setNameInNamespace(dn);
+                    }
+                    list.add(sr);
+                    break;
+                }
+            }
+        } catch (NamingException e) {
+            ex = e;
+            isFinished = true;
+        }
+
+        enumeration.setException(ex);
+        enumeration.add(list, isFinished);
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java Fri Aug 22 00:15:00 2008
@@ -43,7 +43,12 @@
 
     private LdapSearchResult result;
 
+    private int batchSize = 0;
+
     public LdapSearchResult getSearchResult() {
+        if (result == null) {
+            result = new LdapSearchResult();
+        }
         return result;
     }
 
@@ -146,4 +151,12 @@
         this.filter = filter;
     }
 
+    public int getBatchSize() {
+        return batchSize;
+    }
+
+    public void setBatchSize(int batchSize) {
+        this.batchSize = batchSize;
+    }
+
 }

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=687988&r1=687987&r2=687988&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 Fri Aug 22 00:15:00 2008
@@ -548,22 +548,11 @@
 
             LdapSearchResult result = context.doSearch(dn, filter, controls);
             
-            List<SearchResult> list = new ArrayList<SearchResult>();
-            Map<String, Attributes> entries = result.getEntries();
-            for (String name : entries.keySet()) {
-                String relativeName = convertToRelativeName(dn, name);
-                SearchResult sr = new SearchResult(relativeName, null, entries
-                        .get(name));
-                sr.setNameInNamespace(name);
-                list.add(sr);
-            }
-
-            if (list.size() == 0 && result.getException() != null) {
+            if (result.isEmpty() && result.getException() != null) {
                 throw result.getException();
             }
-
-            return new LdapNamingEnumeration<SearchResult>(list, result
-                    .getException());
+            
+            return result.toSearchResultEnumeration(dn);
         } finally {
             if (context != null) {
                 context.close();
@@ -609,22 +598,11 @@
             LdapSearchResult result = context.doSearch(dn, f,
                     searchControls);
             
-            List<SearchResult> list = new ArrayList<SearchResult>();
-            Map<String, Attributes> entries = result.getEntries();
-            for (String name : entries.keySet()) {
-                String relativeName = convertToRelativeName(dn, name);
-                SearchResult sr = new SearchResult(relativeName, null, entries
-                        .get(name));
-                sr.setNameInNamespace(name);
-                list.add(sr);
-            }
-
-            if (list.size() == 0 && result.getException() != null) {
+            if (result.isEmpty() && result.getException() != null) {
                 throw result.getException();
             }
-
-            return new LdapNamingEnumeration<SearchResult>(list, result
-                    .getException());
+            
+            return result.toSearchResultEnumeration(dn);
         } finally {
             if (context != null) {
                 context.close();

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java Fri Aug 22 00:15:00 2008
@@ -81,10 +81,19 @@
         id = "cn";
         values = new Object[] { Utils.getBytes(id), valueList };
         la = new LdapAttribute();
-        // 'cn' is not binary attribute, should return string value
+        /*
+         * 'cn' is not binary attribute, but LdapAttribute.decodeValues()
+         * doesn't convert values to string, must call convertValueToString() to
+         * do it.
+         */
         la.decodeValues(values);
 
         for (int i = 0; i < la.size(); ++i) {
+            assertTrue(la.get() instanceof byte[]);
+        }
+
+        la.convertValueToString();
+        for (int i = 0; i < la.size(); ++i) {
             assertTrue(la.get() instanceof String);
         }
 
@@ -98,4 +107,41 @@
             assertTrue(la.get() instanceof byte[]);
         }
     }
+
+    public void test_isBinary() {
+        assertTrue(LdapAttribute.isBinary("photo", null));
+        assertTrue(LdapAttribute.isBinary("Photo", null));
+        assertTrue(LdapAttribute.isBinary("photo", new String[0]));
+        assertTrue(LdapAttribute.isBinary("cn;binary", null));
+        assertTrue(LdapAttribute.isBinary("cn;binary", new String[0]));
+
+        assertFalse(LdapAttribute.isBinary("cn", null));
+        assertFalse(LdapAttribute.isBinary("cn",
+                new String[] { "ou", "person" }));
+        assertTrue(LdapAttribute.isBinary("cn", new String[] { "ou", "person",
+                "cn" }));
+        assertTrue(LdapAttribute.isBinary("cn", new String[] { "ou", "person",
+                "Cn" }));
+    }
+
+    public void test_convertValueToString() throws Exception {
+        LdapAttribute attr = new LdapAttribute();
+
+        // do nothing
+        attr.convertValueToString();
+
+        BasicAttribute basicAttribute = new BasicAttribute("cn");
+        attr = new LdapAttribute(basicAttribute, null);
+
+        // do nothing
+        attr.convertValueToString();
+        attr.add(Utils.getBytes("test"));
+        attr.add(Utils.getBytes("binary"));
+
+        attr.convertValueToString();
+
+        assertEquals(2, attr.size());
+        assertEquals("test", attr.get(0));
+        assertEquals("binary", attr.get(1));
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java Fri Aug 22 00:15:00 2008
@@ -363,7 +363,7 @@
                         new EncodableLdapResult(), null) });
 
         context.search("cn=test", null);
-        
+
     }
 
     public void testReferralFollow() throws Exception {
@@ -446,6 +446,80 @@
 
     }
 
+    public void testAddToEnvironment_binaryAttributeProp() throws Exception {
+        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
+                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
+
+        assertNull(env.get(Context.REFERRAL));
+
+        InitialDirContext initialDirContext = new InitialDirContext(env);
+
+        initialDirContext.addToEnvironment(
+                "java.naming.ldap.attributes.binary", "cn");
+        assertEquals("cn", initialDirContext.getEnvironment().get(
+                "java.naming.ldap.attributes.binary"));
+
+        initialDirContext.addToEnvironment(
+                "java.naming.ldap.attributes.binary", "cn ou");
+        assertEquals("cn ou", initialDirContext.getEnvironment().get(
+                "java.naming.ldap.attributes.binary"));
+
+        initialDirContext.addToEnvironment(
+                "java.naming.ldap.attributes.binary", " cn ");
+        assertEquals(" cn ", initialDirContext.getEnvironment().get(
+                "java.naming.ldap.attributes.binary"));
+
+        initialDirContext.addToEnvironment(
+                "java.naming.ldap.attributes.binary", " cn ou ");
+        assertEquals(" cn ou ", initialDirContext.getEnvironment().get(
+                "java.naming.ldap.attributes.binary"));
+
+        try {
+            initialDirContext.addToEnvironment(
+                    "java.naming.ldap.attributes.binary", new Object());
+            fail("Should throw ClassCastException");
+        } catch (ClassCastException e) {
+            // expected
+        }
+    }
+
+    public void testAddToEnvironment_batchSizeProp() throws Exception {
+        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
+                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
+
+        assertNull(env.get(Context.REFERRAL));
+        InitialDirContext initialDirContext = new InitialDirContext(env);
+
+        initialDirContext.addToEnvironment(Context.BATCHSIZE, "4");
+        assertEquals("4", initialDirContext.getEnvironment().get(
+                Context.BATCHSIZE));
+
+        try {
+            initialDirContext.addToEnvironment(Context.BATCHSIZE, "wrong");
+            fail("Should throw NumberFormatException");
+        } catch (NumberFormatException e) {
+            // expected
+        }
+        assertEquals("4", initialDirContext.getEnvironment().get(
+                Context.BATCHSIZE));
+
+        try {
+            initialDirContext.addToEnvironment(Context.BATCHSIZE, "3.3");
+            fail("Should throw NumberFormatException");
+        } catch (NumberFormatException e) {
+            // expected
+        }
+        assertEquals("4", initialDirContext.getEnvironment().get(
+                Context.BATCHSIZE));
+
+        try {
+            initialDirContext.addToEnvironment(Context.BATCHSIZE, new Object());
+            fail("Should throw ClassCastException");
+        } catch (ClassCastException e) {
+            // expected
+        }
+    }
+
     public void testReconnect() throws Exception {
         Control[] expected = new Control[] { new PagedResultsControl(10,
                 Control.NONCRITICAL) };
@@ -527,6 +601,12 @@
         another.reconnect(null);
     }
 
+    /*
+     * This test would block on RI, that because of difference of inner
+     * implementation between RI and Harmony, It's hard to emulate using
+     * MockServer. If run in real environment, the test will pass both on RI and
+     * Harmony.
+     */
     public void testFederation() throws Exception {
         server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                 LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
@@ -559,8 +639,8 @@
             assertEquals(1, e.getResolvedName().size());
             assertEquals("/", e.getResolvedName().toString());
             assertTrue(e.getAltNameCtx() instanceof LdapContext);
-            assertEquals(context.getNameInNamespace(), e
-                    .getAltNameCtx().getNameInNamespace());
+            assertEquals(context.getNameInNamespace(), e.getAltNameCtx()
+                    .getNameInNamespace());
             assertTrue(e.getResolvedObj() instanceof Reference);
 
             Reference ref = (Reference) e.getResolvedObj();
@@ -571,8 +651,8 @@
             assertEquals(1, ref.size());
             RefAddr addr = ref.get(0);
             assertTrue(addr.getContent() instanceof LdapContext);
-            assertEquals(context.getNameInNamespace(),
-                    ((LdapContext) addr.getContent()).getNameInNamespace());
+            assertEquals(context.getNameInNamespace(), ((LdapContext) addr
+                    .getContent()).getNameInNamespace());
             assertEquals("nns", addr.getType());
         }
 
@@ -607,8 +687,8 @@
             assertEquals(1, e.getResolvedName().size());
             assertEquals("/", e.getResolvedName().toString());
             assertTrue(e.getAltNameCtx() instanceof LdapContext);
-            assertEquals(context.getNameInNamespace(), e
-                    .getAltNameCtx().getNameInNamespace());
+            assertEquals(context.getNameInNamespace(), e.getAltNameCtx()
+                    .getNameInNamespace());
             assertTrue(e.getResolvedObj() instanceof Reference);
 
             Reference ref = (Reference) e.getResolvedObj();
@@ -619,11 +699,12 @@
             assertEquals(1, ref.size());
             RefAddr addr = ref.get(0);
             assertTrue(addr.getContent() instanceof LdapContext);
-            assertEquals(context.getNameInNamespace(),
-                    ((LdapContext) addr.getContent()).getNameInNamespace());
+            assertEquals(context.getNameInNamespace(), ((LdapContext) addr
+                    .getContent()).getNameInNamespace());
             assertEquals("nns", addr.getType());
         }
     }
+
     public void testUnsolicitedNotification() throws Exception {
         server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                 LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java Fri Aug 22 00:15:00 2008
@@ -1105,6 +1105,36 @@
         }
     }
 
+    public void testModifyAttributes_WatchSubSchema() throws NamingException {
+        // Creates the attributes.
+        Attributes attrs = new BasicAttributes(false); // Ignore case
+        attrs.put("NAME", "ListObjectClass");
+        attrs.put("SUP", "top");
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.77");
+        attrs.put("DESC", "for test");
+        attrs.put("STRUCTURAL", "fds");
+
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        DirContext dir = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/ListObjectClass"), attrs);
+
+        Attributes newAttrs = new BasicAttributes(false);
+        newAttrs.put("NAME", "Modified");
+        newAttrs.put("SUP", "top");
+        newAttrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.77");
+        newAttrs.put("DESC", "for test");
+        newAttrs.put("STRUCTURAL", "fds");
+
+        schema.modifyAttributes("ClassDefinition/ListObjectClass",
+                DirContext.REPLACE_ATTRIBUTE, newAttrs);
+
+        Attributes subSchemaAttrs = dir.getAttributes("");
+        assertEquals("Modified", subSchemaAttrs.get("NAME").get());
+    }
+
     public void testModifyAttributes_Exception() throws NamingException {
         Attributes attrs = new BasicAttributes(true); // Ignore case
         attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
@@ -1157,6 +1187,21 @@
         } catch (NameNotFoundException e) {
             // Expected.
         }
+
+        try {
+            schema.modifyAttributes("", new ModificationItem[] {});
+            fail("Should throw SchemaViolationException");
+        } catch (SchemaViolationException e) {
+            // expected
+        }
+
+        try {
+            schema.modifyAttributes(new CompositeName(""),
+                    new ModificationItem[] {});
+            fail("Should throw SchemaViolationException");
+        } catch (SchemaViolationException e) {
+            // expected
+        }
     }
 
     public void testCreateAndDeleteSubContext() throws NamingException {
@@ -2075,6 +2120,165 @@
         assertEquals(2, count);
     }
 
+    public void testRename() throws NamingException {
+        Name name1 = new CompositeName("test1");
+        Name name2 = new CompositeName("/");
+        Name invalidName1 = new CompositeName("");
+        try {
+            schema.rename(name1, name2);
+            fail("Should throw SchemaViolationException");
+        } catch (SchemaViolationException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(invalidName1, name2);
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(name2, invalidName1);
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("test1", "test2");
+            fail("Should throw SchemaViolationException");
+        } catch (SchemaViolationException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("", "test2");
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("test1", "");
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("classdefinition/javaClass", "test");
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("classdefinition\\javaClass", "test");
+            fail("Should throw SchemaViolationException");
+        } catch (SchemaViolationException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(new CompositeName("classdefinition/javaClass"),
+                    new CompositeName("test"));
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(new CompositeName("classdefinition\\javaClass"),
+                    new CompositeName("test"));
+            fail("Should throw SchemaViolationException");
+        } catch (SchemaViolationException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("classdefinition/javaClass", "");
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("", "classdefinition/javaClass");
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+    }
+
+    public void testRename_Exception() throws NamingException {
+        Name name = new CompositeName("test");
+        Name nullName = null;
+        String nullString = null;
+        try {
+            schema.rename(nullName, name);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(name, nullName);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(nullName, nullName);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(nullString, "test");
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("test", nullString);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(nullString, nullString);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("\\", nullString);
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("/", nullString);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(null, "");
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+    }
+
     public void testClassDefinition() throws NamingException {
         MockLdapSchemaContext mockSchema = new MockLdapSchemaContext(context,
                 null, name, schemaTable,

Modified: harmony/enhanced/classlib/branches/java6/modules/lang-management/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/lang-management/build.xml?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/lang-management/build.xml (original)
+++ harmony/enhanced/classlib/branches/java6/modules/lang-management/build.xml Fri Aug 22 00:15:00 2008
@@ -106,10 +106,8 @@
         </jar>
     </target>
 
-    <target name="compile-tests">
-        <antcall target="compile-tests-api" />
-        <antcall target="compile-tests-impl" />
-    </target>
+    <target name="compile-tests"
+            depends="compile-tests-api,compile-tests-impl" />
 
     <target name="compile-tests-api">
         <echo message="Compiling LANG-MANAGEMENT API tests" />
@@ -168,10 +166,7 @@
                              result="${lang-management.exclude.file}"/>
     </target>
 
-    <target name="run-tests">
-        <antcall target="run-tests-api" />
-        <antcall target="run-tests-impl" />
-    </target>
+    <target name="run-tests" depends="run-tests-api,run-tests-impl" />
 
     <target name="run-tests-api">
         <mkdir dir="${hy.tests.reports}" />
@@ -188,6 +183,10 @@
                dir="${basedir}"
                jvm="${test.jre.home}/bin/java">
 
+            <assertions enableSystemAssertions="true">
+                <enable />
+            </assertions>
+
             <jvmarg line="${hy.test.vmargs}" />
 
             <classpath>
@@ -226,6 +225,10 @@
                dir="${basedir}"
                jvm="${test.jre.home}/bin/java">
 
+            <assertions enableSystemAssertions="true">
+                <enable />
+            </assertions>
+
             <jvmarg line="${hy.test.vmargs}" />
 
             <classpath>

Modified: harmony/enhanced/classlib/branches/java6/modules/logging/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/logging/build.xml?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/logging/build.xml (original)
+++ harmony/enhanced/classlib/branches/java6/modules/logging/build.xml Fri Aug 22 00:15:00 2008
@@ -178,6 +178,10 @@
                dir="${basedir}"
                jvm="${test.jre.home}/bin/java">
 
+            <assertions enableSystemAssertions="true">
+                <enable />
+            </assertions>
+
             <jvmarg line="${hy.test.vmargs}" />
             <!-- Used by Support_Exec.execJava() -->
             <jvmarg value="-Dhy.test.vmargs=${hy.test.vmargs}" />

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/build.xml?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/build.xml (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/build.xml Fri Aug 22 00:15:00 2008
@@ -70,24 +70,12 @@
             </fileset>
         </copy>
 
-        <antcall target="copy-native-includes-windows" />
-        <antcall target="copy-native-includes-unix" />
-    </target>
-
-    <target name="copy-native-includes-windows" if="is.windows">
         <copy todir="${hy.hdk}/include" overwrite="yes">
-            <fileset dir="${hy.luni.src.main.native}/include/windows">
+            <fileset dir="${hy.luni.src.main.native}/include/${hy.os.family}">
                 <include name="jclprots.h" />
             </fileset>
         </copy>
-    </target>
 
-    <target name="copy-native-includes-unix" if="is.unix">
-        <copy todir="${hy.hdk}/include" overwrite="yes">
-            <fileset dir="${hy.luni.src.main.native}/include/unix">
-                <include name="jclprots.h" />
-            </fileset>
-        </copy>
     </target>
 
     <!-- Build native code -->
@@ -170,10 +158,11 @@
     </target>
 
     <!-- Overlay OSS packages into their required locations -->
-    <target name="overlay-oss" >
+    <target name="overlay-oss" depends="-unzip-oss,-ascii2ebcdic-conversion" />
+
+    <target name="-unzip-oss">
         <unzip src="${fdlibm.zip}" dest="${hy.luni.src.main.native}/fdlibm_dist" />
         <chmod dir="${hy.luni.src.main.native}/fdlibm_dist" perm="ugo+r" />
-        <antcall target="-ascii2ebcdic-conversion" />
     </target>
 
     <target name="-ascii2ebcdic-conversion" if="is.zos">
@@ -224,14 +213,13 @@
     <!-- internal target for local and global test run sequence -->
     <target name="-test-module" depends="build, compile-tests, prepare-exclude, run-tests" />
 
-    <target name="clean">
+    <target name="clean" depends="clean-native-includes" >
         <delete file="${hy.jdk}/jre/lib/boot/luni.jar" />
         <delete file="${hy.jdk}/jre/lib/boot/luni-src.jar" />
         <delete failonerror="false">
             <fileset refid="classes" />
         </delete>
         <delete failonerror="false" dir="bin"/>
-        <antcall target="clean-native-includes" />
     </target>
 
     <target name="clean-native-includes">
@@ -483,6 +471,10 @@
                    dir="${basedir}"
                    jvm="${test.jre.home}/bin/java">
 
+                <assertions enableSystemAssertions="true">
+                   <enable />
+                </assertions>
+
                 <jvmarg line="${hy.test.vmargs}" />
                 <!-- Used by Support_Exec.execJava() -->
                 <jvmarg value="-Dhy.test.vmargs=${hy.test.vmargs}" />

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/ObjectInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/ObjectInputStream.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/ObjectInputStream.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/ObjectInputStream.java Fri Aug 22 00:15:00 2008
@@ -702,8 +702,7 @@
                 ObjectStreamClass streamClass = ObjectStreamClass
                         .lookup(proxyClass);
                 streamClass.setLoadFields(new ObjectStreamField[0]);
-                registerObjectRead(streamClass, Integer.valueOf(nextHandle()),
-                        false);
+                registerObjectRead(streamClass, nextHandle(), false);
                 checkedSetSuperClassDesc(streamClass, readClassDesc());
                 return streamClass;
             case TC_REFERENCE:
@@ -1324,7 +1323,7 @@
                 int index = findStreamSuperclass(superclass, streamClassList,
                         lastIndex);
                 if (index == -1) {
-                    readObjectNoData(object, superclass);
+                    readObjectNoData(object, superclass, ObjectStreamClass.lookupStreamClass(superclass));
                 } else {
                     for (int j = lastIndex; j <= index; j++) {
                         readObjectForClass(object, streamClassList.get(j));
@@ -1358,12 +1357,11 @@
         return -1;
     }
 
-    private void readObjectNoData(Object object, Class<?> cl)
+    private void readObjectNoData(Object object, Class<?> cl, ObjectStreamClass classDesc)
             throws ObjectStreamException {
-        if (!ObjectStreamClass.isSerializable(cl)) {
+        if (!classDesc.isSerializable()) {
             return;
         }
-        ObjectStreamClass classDesc = ObjectStreamClass.lookupStreamClass(cl);
         if (classDesc.hasMethodReadObjectNoData()){
             final Method readMethod = classDesc.getMethodReadObjectNoData();
             try {
@@ -1501,7 +1499,7 @@
             throw new InvalidClassException(Msg.getString("K00d1")); //$NON-NLS-1$
         }
 
-        Integer newHandle = Integer.valueOf(nextHandle());
+        Integer newHandle = nextHandle();
 
         // Array size
         int size = input.readInt();
@@ -1562,6 +1560,10 @@
             // Array of Objects
             Object[] objectArray = (Object[]) result;
             for (int i = 0; i < size; i++) {
+                // TODO: This place is the opportunity for enhancement
+                //      We can implement writing elements through fast-path,
+                //      without setting up the context (see readObject()) for 
+                //      each element with public API
                 objectArray[i] = readObject();
             }
         }
@@ -1590,10 +1592,9 @@
         ObjectStreamClass classDesc = readClassDesc();
 
         if (classDesc != null) {
-            Integer newHandle = Integer.valueOf(nextHandle());
             Class<?> localClass = classDesc.forClass();
             if (localClass != null) {
-                registerObjectRead(localClass, newHandle, unshared);
+                registerObjectRead(localClass, nextHandle(), unshared);
             }
             return localClass;
         }
@@ -1659,7 +1660,7 @@
             ClassNotFoundException, IOException {
         // read classdesc for Enum first
         ObjectStreamClass classDesc = readEnumDesc();
-        Integer newHandle = Integer.valueOf(nextHandle());
+        int newHandle = nextHandle();
         // read name after class desc
         String name;
         byte tc = nextTC();
@@ -1705,7 +1706,7 @@
         // subclasses during readClassDescriptor()
         primitiveData = input;
         Integer oldHandle = descriptorHandle;
-        descriptorHandle = Integer.valueOf(nextHandle());
+        descriptorHandle = nextHandle();
         ObjectStreamClass newClassDesc = readClassDescriptor();
         registerObjectRead(newClassDesc, descriptorHandle, unshared);
         descriptorHandle = oldHandle;
@@ -1795,8 +1796,7 @@
          * descriptors. If called outside of readObject, the descriptorHandle
          * might be null.
          */
-        descriptorHandle = (null == descriptorHandle ? Integer
-                .valueOf(nextHandle()) : descriptorHandle);
+        descriptorHandle = (null == descriptorHandle ? nextHandle() : descriptorHandle);
         registerObjectRead(newClassDesc, descriptorHandle, false);
 
         readFieldDescriptors(newClassDesc);
@@ -1817,6 +1817,9 @@
      */
     protected Class<?> resolveProxyClass(String[] interfaceNames)
             throws IOException, ClassNotFoundException {
+            
+        // TODO: This method is opportunity for performance enhancement
+        //       We can cache the classloader and recently used interfaces.        
         ClassLoader loader = VM.getNonBootstrapClassLoader();
         Class<?>[] interfaces = new Class<?>[interfaceNames.length];
         for (int i = 0; i < interfaceNames.length; i++) {
@@ -1837,8 +1840,8 @@
      * @throws IOException
      *             If an IO exception happened when reading the handle
      */
-    private Integer readNewHandle() throws IOException {
-        return Integer.valueOf(input.readInt());
+    private int readNewHandle() throws IOException {
+        return input.readInt();
     }
 
     private Class<?> resolveConstructorClass(Class<?> objectClass, boolean wasSerializable, boolean wasExternalizable)
@@ -1936,7 +1939,7 @@
             throw new InvalidClassException(Msg.getString("K00d1")); //$NON-NLS-1$
         }
 
-        Integer newHandle = Integer.valueOf(nextHandle());
+        Integer newHandle = nextHandle();
 
         // Note that these values come from the Stream, and in fact it could be
         // that the classes have been changed so that the info below now
@@ -2009,9 +2012,8 @@
 
         if (objectClass != null) {
 
-            ObjectStreamClass desc = ObjectStreamClass.lookupStreamClass(objectClass);
-            if (desc.hasMethodReadResolve()){
-                Method methodReadResolve = desc.getMethodReadResolve();
+            if (classDesc.hasMethodReadResolve()){
+                Method methodReadResolve = classDesc.getMethodReadResolve();
                 try {
                     result = methodReadResolve.invoke(result, (Object[]) null);
                 } catch (IllegalAccessException iae) {
@@ -2059,8 +2061,7 @@
         if (enableResolve) {
             result = resolveObject(result);
         }
-        int newHandle = nextHandle();
-        registerObjectRead(result, Integer.valueOf(newHandle), unshared);
+		registerObjectRead(result, nextHandle(), unshared);
 
         return result;
     }
@@ -2082,8 +2083,7 @@
         if (enableResolve) {
             result = resolveObject(result);
         }
-        int newHandle = nextHandle();
-        registerObjectRead(result, Integer.valueOf(newHandle), unshared);
+        registerObjectRead(result, nextHandle(), unshared);
 
         return result;
     }
@@ -2427,8 +2427,6 @@
                 // Use the first non-null ClassLoader on the stack. If null, use
                 // the system class loader
                 cls = Class.forName(className, true, callerClassLoader);
-                // save the value
-                osClass.setClass(cls);
             }
         }
         return cls;



Mime
View raw message