Author: dkuleshov
Date: 2011-11-22 05:37:35 -0500 (Tue, 22 Nov 2011)
New Revision: 5230
Added:
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/ExtendedCloneable.java
Modified:
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/CacheHandler.java
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/GroupImpl.java
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipImpl.java
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipTypeImpl.java
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/UserImpl.java
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/UserProfileImpl.java
Log:
EXOJCR-1545: fixed ugly cloning
Modified:
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/CacheHandler.java
===================================================================
---
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/CacheHandler.java 2011-11-21
15:03:07 UTC (rev 5229)
+++
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/CacheHandler.java 2011-11-22
10:37:35 UTC (rev 5230)
@@ -125,17 +125,9 @@
obj = userProfileCache.get(key);
}
- if (obj != null && obj instanceof Cloneable)
+ if (obj instanceof ExtendedCloneable)
{
- try
- {
- // need to return the clone of the object since object is mutable
- return obj.getClass().getMethod("clone").invoke(obj);
- }
- catch (Exception e)
- {
- return obj;
- }
+ return ((ExtendedCloneable)obj).clone();
}
return obj;
}
Added:
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/ExtendedCloneable.java
===================================================================
---
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/ExtendedCloneable.java
(rev 0)
+++
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/ExtendedCloneable.java 2011-11-22
10:37:35 UTC (rev 5230)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.organization;
+
+/**
+ * Used to allow to use clone method without involvement of reflection.
+ *
+ * Created by The eXo Platform SAS.
+ *
+ * Date: 21.11.2011
+ *
+ * @author <a href="mailto:dmitry.kuleshov@exoplatform.com">Dmitry
Kuleshov</a>
+ * @version $Id:
+ */
+public interface ExtendedCloneable extends Cloneable
+{
+ public Object clone();
+
+}
Modified:
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/GroupImpl.java
===================================================================
---
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/GroupImpl.java 2011-11-21
15:03:07 UTC (rev 5229)
+++
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/GroupImpl.java 2011-11-22
10:37:35 UTC (rev 5230)
@@ -25,12 +25,13 @@
*/
package org.exoplatform.services.organization.impl;
+import org.exoplatform.services.organization.ExtendedCloneable;
import org.exoplatform.services.organization.Group;
/**
* @hibernate.class table="EXO_GROUP"
*/
-public class GroupImpl implements Group, Cloneable
+public class GroupImpl implements Group, ExtendedCloneable
{
private String id;
@@ -148,16 +149,15 @@
/**
* {@inheritDoc}
**/
- public Object clone()
+ public GroupImpl clone()
{
- GroupImpl gi = new GroupImpl();
-
- gi.setId(this.id);
- gi.setParentId(this.parentId);
- gi.setGroupName(this.groupName);
- gi.setLabel(this.label);
- gi.setDescription(this.desc);
-
- return gi;
+ try
+ {
+ return (GroupImpl)super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ return this;
+ }
}
}
Modified:
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipImpl.java
===================================================================
---
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipImpl.java 2011-11-21
15:03:07 UTC (rev 5229)
+++
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipImpl.java 2011-11-22
10:37:35 UTC (rev 5230)
@@ -18,12 +18,13 @@
*/
package org.exoplatform.services.organization.impl;
+import org.exoplatform.services.organization.ExtendedCloneable;
import org.exoplatform.services.organization.Membership;
/**
* @hibernate.class table="EXO_MEMBERSHIP"
*/
-public class MembershipImpl implements Membership, Cloneable
+public class MembershipImpl implements Membership, ExtendedCloneable
{
private String id = null;
@@ -101,15 +102,15 @@
/**
* {@inheritDoc}
**/
- public Object clone()
+ public MembershipImpl clone()
{
- MembershipImpl mi = new MembershipImpl();
-
- mi.setGroupId(this.groupId);
- mi.setMembershipType(this.membershipType);
- mi.setId(this.id);
- mi.setUserName(this.userName);
-
- return mi;
+ try
+ {
+ return (MembershipImpl)super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ return this;
+ }
}
}
Modified:
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipTypeImpl.java
===================================================================
---
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipTypeImpl.java 2011-11-21
15:03:07 UTC (rev 5229)
+++
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipTypeImpl.java 2011-11-22
10:37:35 UTC (rev 5230)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.organization.impl;
+import org.exoplatform.services.organization.ExtendedCloneable;
import org.exoplatform.services.organization.MembershipType;
import java.util.Date;
@@ -28,7 +29,7 @@
*
* @hibernate.class table="EXO_MEMBERSHIP_TYPE"
*/
-public class MembershipTypeImpl implements MembershipType, Cloneable
+public class MembershipTypeImpl implements MembershipType, ExtendedCloneable
{
private String name;
@@ -120,14 +121,25 @@
/**
* {@inheritDoc}
**/
- public Object clone()
+ public MembershipTypeImpl clone()
{
- MembershipTypeImpl mti = new MembershipTypeImpl();
- mti.setName(this.name);
- mti.setDescription(this.description);
- mti.setOwner(this.owner);
- mti.setCreatedDate((Date)this.createdDate.clone());
- mti.setModifiedDate((Date)this.modifiedDate.clone());
+ MembershipTypeImpl mti;
+ try
+ {
+ mti = (MembershipTypeImpl)super.clone();
+ if (createdDate != null)
+ {
+ mti.createdDate = (Date)createdDate.clone();
+ }
+ if (modifiedDate != null)
+ {
+ mti.modifiedDate = (Date)modifiedDate.clone();
+ }
+ }
+ catch (CloneNotSupportedException e)
+ {
+ return this;
+ }
return mti;
}
Modified:
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/UserImpl.java
===================================================================
---
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/UserImpl.java 2011-11-21
15:03:07 UTC (rev 5229)
+++
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/UserImpl.java 2011-11-22
10:37:35 UTC (rev 5230)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.organization.impl;
+import org.exoplatform.services.organization.ExtendedCloneable;
import org.exoplatform.services.organization.User;
import java.util.Date;
@@ -25,7 +26,7 @@
/**
* @hibernate.class table="EXO_USER"
*/
-public class UserImpl implements User, Cloneable
+public class UserImpl implements User, ExtendedCloneable
{
private String id = null;
@@ -189,20 +190,26 @@
/**
* {@inheritDoc}
**/
- public Object clone()
+ public UserImpl clone()
{
- UserImpl ui = new UserImpl();
+ UserImpl ui;
+ try
+ {
+ ui = (UserImpl)super.clone();
+ if (createdDate != null)
+ {
+ ui.createdDate = (Date)createdDate.clone();
+ }
+ if (lastLoginTime != null)
+ {
+ ui.lastLoginTime = (Date)lastLoginTime.clone();
+ }
+ }
+ catch (CloneNotSupportedException e)
+ {
+ return this;
+ }
- ui.setId(this.id);
- ui.setUserName(this.userName);
- ui.setPassword(this.password);
- ui.setFirstName(this.firstName);
- ui.setLastName(this.lastName);
- ui.setEmail(this.email);
- ui.setCreatedDate((Date)this.createdDate.clone());
- ui.setLastLoginTime((Date)this.lastLoginTime.clone());
- ui.setOrganizationId(this.organizationId);
-
return ui;
}
}
Modified:
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/UserProfileImpl.java
===================================================================
---
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/UserProfileImpl.java 2011-11-21
15:03:07 UTC (rev 5229)
+++
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/UserProfileImpl.java 2011-11-22
10:37:35 UTC (rev 5230)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.organization.impl;
+import org.exoplatform.services.organization.ExtendedCloneable;
import org.exoplatform.services.organization.UserProfile;
import java.util.HashMap;
@@ -27,7 +28,7 @@
* Created by The eXo Platform SAS Author : Mestrallet Benjamin
* benjmestrallet(a)users.sourceforge.net Date: Aug 21, 2003 Time: 3:22:54 PM
*/
-public class UserProfileImpl implements UserProfile, Cloneable
+public class UserProfileImpl implements UserProfile, ExtendedCloneable
{
private String userName;
@@ -90,8 +91,19 @@
/**
* {@inheritDoc}
**/
- public Object clone()
+ public UserProfileImpl clone()
{
- return new UserProfileImpl(this.userName, new HashMap<String,
String>(this.attributes));
+ UserProfileImpl upi;
+ try
+ {
+ upi = (UserProfileImpl)super.clone();
+ upi.attributes = new HashMap<String, String>(attributes);
+ }
+ catch (CloneNotSupportedException e)
+ {
+ return this;
+ }
+
+ return upi;
}
}