harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r833382 - /harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSContext.java
Date Fri, 06 Nov 2009 13:03:19 GMT
Author: tellison
Date: Fri Nov  6 13:03:19 2009
New Revision: 833382

URL: http://svn.apache.org/viewvc?rev=833382&view=rev
Log:
Reimplement clone() to call super clone, so subclasses get the right type.

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSContext.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSContext.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSContext.java?rev=833382&r1=833381&r2=833382&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSContext.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSContext.java
Fri Nov  6 13:03:19 2009
@@ -312,20 +312,32 @@
      * @param name
      *            name of newly created context in the ancestor context
      */
-    @SuppressWarnings("unchecked")
     DNSContext(DNSContext ancestorCtx, DNSName name) {
-        this.contextName = (DNSName) name.clone();
-        this.nameParser = ancestorCtx.nameParser;
-        this.environment = (Hashtable<Object, Object>) ancestorCtx.environment
-                .clone();
-        this.resolver = ancestorCtx.resolver;
-        this.authoritative = ancestorCtx.authoritative;
-        this.lookupAttrType = ancestorCtx.lookupAttrType;
-        this.lookupAttrClass = ancestorCtx.lookupAttrClass;
-        this.recursion = ancestorCtx.recursion;
-        this.timeoutInitial = ancestorCtx.timeoutInitial;
-        this.timeoutRetries = ancestorCtx.timeoutRetries;
-        this.maxThreads = ancestorCtx.maxThreads;
+        super();
+        initialize(ancestorCtx, name);
+    }
+
+    /**
+     * Initialize all private properties from the given context.
+     * 
+     * @param ancestorCtx
+     *            an ancestor context to read all internal properties from
+     * @param name
+     *            name of newly created context in the ancestor context
+     */
+    @SuppressWarnings("unchecked")
+    private void initialize(DNSContext ancestorCtx, DNSName name) {
+        contextName = (DNSName) name.clone();
+        nameParser = ancestorCtx.nameParser;
+        environment = (Hashtable<Object, Object>) ancestorCtx.environment.clone();
+        resolver = ancestorCtx.resolver;
+        authoritative = ancestorCtx.authoritative;
+        lookupAttrType = ancestorCtx.lookupAttrType;
+        lookupAttrClass = ancestorCtx.lookupAttrClass;
+        recursion = ancestorCtx.recursion;
+        timeoutInitial = ancestorCtx.timeoutInitial;
+        timeoutRetries = ancestorCtx.timeoutRetries;
+        maxThreads = ancestorCtx.maxThreads;
     }
 
     /**
@@ -2037,7 +2049,15 @@
      */
     @Override
     public Object clone() {
-        return new DNSContext(this, contextName);
+        DNSContext clone;
+        try {
+            clone = (DNSContext)super.clone();
+        } catch (CloneNotSupportedException e) {
+            // impossible
+            return null;
+        }
+        clone.initialize(this, contextName);
+        return clone;
     }
 
     /**



Mime
View raw message