diff options
author | Mark Spruiell <mes@zeroc.com> | 2002-09-18 21:04:11 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2002-09-18 21:04:11 +0000 |
commit | dd17ae418ee1cdf7b1be1062faa47103808ed73c (patch) | |
tree | 5d58fab908d95b0f731562058105c252e40d9dbb /java/src/Ice/ObjectImpl.java | |
parent | simplified cloning; clone is no longer optional (diff) | |
download | ice-dd17ae418ee1cdf7b1be1062faa47103808ed73c.tar.bz2 ice-dd17ae418ee1cdf7b1be1062faa47103808ed73c.tar.xz ice-dd17ae418ee1cdf7b1be1062faa47103808ed73c.zip |
simplifying clone()
Diffstat (limited to 'java/src/Ice/ObjectImpl.java')
-rw-r--r-- | java/src/Ice/ObjectImpl.java | 51 |
1 files changed, 11 insertions, 40 deletions
diff --git a/java/src/Ice/ObjectImpl.java b/java/src/Ice/ObjectImpl.java index 724f13c161e..4ee185b34f7 100644 --- a/java/src/Ice/ObjectImpl.java +++ b/java/src/Ice/ObjectImpl.java @@ -10,7 +10,7 @@ package Ice; -public class ObjectImpl implements Object +public class ObjectImpl implements Object, java.lang.Cloneable { public ObjectImpl() @@ -35,57 +35,28 @@ public class ObjectImpl implements Object clone() throws java.lang.CloneNotSupportedException { - Object result = null; - - try - { - result = (Object)getClass().newInstance(); - ((ObjectImpl)result).ice_copyStateFrom(this); - } - catch(InstantiationException ex) - { - CloneNotSupportedException e = new CloneNotSupportedException(); - e.initCause(ex); - throw e; - } - catch(IllegalAccessException ex) - { - CloneNotSupportedException e = new CloneNotSupportedException(); - e.initCause(ex); - throw e; - } - - return result; - } - - protected final void - ice_cloneFacets(Object obj) - throws java.lang.CloneNotSupportedException - { // - // Clone facets. + // Use super.clone() to perform a shallow copy of all members, + // and then clone the facets manually. // - ObjectImpl impl = (ObjectImpl)obj; - synchronized(impl._activeFacetMap) + ObjectImpl result = (ObjectImpl)super.clone(); + + result._activeFacetMap = new java.util.HashMap(); + synchronized(_activeFacetMap) { - if(!impl._activeFacetMap.isEmpty()) + if(!_activeFacetMap.isEmpty()) { - java.util.Iterator p = impl._activeFacetMap.entrySet().iterator(); + java.util.Iterator p = _activeFacetMap.entrySet().iterator(); while(p.hasNext()) { java.util.Map.Entry e = (java.util.Map.Entry)p.next(); Object facet = (Object)e.getValue(); - _activeFacetMap.put(e.getKey(), facet.clone()); + result._activeFacetMap.put(e.getKey(), facet.clone()); } } } - } - protected void - ice_copyStateFrom(Object obj) - throws java.lang.CloneNotSupportedException - { - ice_cloneFacets(obj); + return result; } public int |