Replaced deep cloning library with manual implementation

This commit is contained in:
bancika
2012-08-21 14:16:19 +00:00
parent 1645eae18d
commit 6c698e935e
7 changed files with 38 additions and 31 deletions
@@ -6,12 +6,8 @@
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/> <classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/> <classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/>
<classpathentry kind="lib" path="lib/junit-4.7.jar"/> <classpathentry kind="lib" path="lib/junit-4.7.jar"/>
<classpathentry kind="lib" path="lib/iText-2.1.7.jar"/>
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/poi-3.5-FINAL-20090928.jar"/>
<classpathentry kind="lib" path="library/main.jar"/> <classpathentry kind="lib" path="library/main.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/app-framework"/> <classpathentry combineaccessrules="false" kind="src" path="/app-framework"/>
<classpathentry kind="lib" path="lib/cloning-1.8.1.jar"/> <classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/objenesis-1.2.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
@@ -22,8 +22,8 @@ public class PropertyWrapper implements Cloneable {
private boolean unique = true; private boolean unique = true;
private boolean changed = false; private boolean changed = false;
public PropertyWrapper(String name, Class<?> type, String getter, String setter, public PropertyWrapper(String name, Class<?> type, String getter,
boolean defaultable, IPropertyValidator validator) { String setter, boolean defaultable, IPropertyValidator validator) {
super(); super();
this.name = name; this.name = name;
this.type = type; this.type = type;
@@ -33,8 +33,9 @@ public class PropertyWrapper implements Cloneable {
this.validator = validator; this.validator = validator;
} }
public void readFrom(Object object) throws IllegalArgumentException, IllegalAccessException, public void readFrom(Object object) throws IllegalArgumentException,
InvocationTargetException, SecurityException, NoSuchMethodException { IllegalAccessException, InvocationTargetException,
SecurityException, NoSuchMethodException {
this.value = object.getClass().getMethod(getter).invoke(object); this.value = object.getClass().getMethod(getter).invoke(object);
} }
@@ -47,8 +48,9 @@ public class PropertyWrapper implements Cloneable {
// } // }
// } // }
public void writeTo(Object object) throws IllegalArgumentException, IllegalAccessException, public void writeTo(Object object) throws IllegalArgumentException,
InvocationTargetException, SecurityException, NoSuchMethodException { IllegalAccessException, InvocationTargetException,
SecurityException, NoSuchMethodException {
object.getClass().getMethod(setter, type).invoke(object, this.value); object.getClass().getMethod(setter, type).invoke(object, this.value);
} }
@@ -75,19 +77,19 @@ public class PropertyWrapper implements Cloneable {
public IPropertyValidator getValidator() { public IPropertyValidator getValidator() {
return validator; return validator;
} }
public boolean isUnique() { public boolean isUnique() {
return unique; return unique;
} }
public void setUnique(boolean unique) { public void setUnique(boolean unique) {
this.unique = unique; this.unique = unique;
} }
public boolean isChanged() { public boolean isChanged() {
return changed; return changed;
} }
public void setChanged(boolean changed) { public void setChanged(boolean changed) {
this.changed = changed; this.changed = changed;
} }
@@ -102,6 +104,15 @@ public class PropertyWrapper implements Cloneable {
// } // }
// return new Property(name, type, value); // return new Property(name, type, value);
// } // }
@Override
public Object clone() throws CloneNotSupportedException {
PropertyWrapper clone = new PropertyWrapper(this.name, this.type, this.getter,
this.setter, this.defaultable, this.validator);
clone.value = this.value;
clone.changed = this.changed;
clone.unique = this.unique;
return clone;
}
@Override @Override
public int hashCode() { public int hashCode() {
@@ -18,8 +18,6 @@ import org.diylc.common.VerticalAlignment;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
import com.rits.cloning.CloningException;
/** /**
* Abstract implementation of {@link IDIYComponent} that contains component name * Abstract implementation of {@link IDIYComponent} that contains component name
* and toString. * and toString.
@@ -177,7 +175,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
} }
return newInstance; return newInstance;
} catch (Exception e) { } catch (Exception e) {
throw new CloningException("Could not clone the component", e); throw new CloneNotSupportedException("Could not clone the component. Reason: " + e.getMessage());
} }
} }
} }
@@ -24,8 +24,6 @@ import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
import com.rits.cloning.Cloner;
/** /**
* Utility class with component processing methods. * Utility class with component processing methods.
* *
@@ -42,8 +40,6 @@ public class ComponentProcessor {
private Map<String, IPropertyValidator> propertyValidatorCache; private Map<String, IPropertyValidator> propertyValidatorCache;
private Map<String, ComponentType> componentTypeMap; private Map<String, ComponentType> componentTypeMap;
private Cloner cloner;
public static ComponentProcessor getInstance() { public static ComponentProcessor getInstance() {
if (instance == null) { if (instance == null) {
instance = new ComponentProcessor(); instance = new ComponentProcessor();
@@ -53,7 +49,6 @@ public class ComponentProcessor {
private ComponentProcessor() { private ComponentProcessor() {
super(); super();
this.cloner = new Cloner();
this.propertyCache = new HashMap<String, List<PropertyWrapper>>(); this.propertyCache = new HashMap<String, List<PropertyWrapper>>();
this.componentTypeMap = new HashMap<String, ComponentType>(); this.componentTypeMap = new HashMap<String, ComponentType>();
this.propertyValidatorCache = new HashMap<String, IPropertyValidator>(); this.propertyValidatorCache = new HashMap<String, IPropertyValidator>();
@@ -132,7 +127,7 @@ public class ComponentProcessor {
*/ */
public List<PropertyWrapper> extractProperties(Class<?> clazz) { public List<PropertyWrapper> extractProperties(Class<?> clazz) {
if (propertyCache.containsKey(clazz.getName())) { if (propertyCache.containsKey(clazz.getName())) {
return cloner.deepClone(propertyCache.get(clazz.getName())); return cloneProperties(propertyCache.get(clazz.getName()));
} }
List<PropertyWrapper> properties = new ArrayList<PropertyWrapper>(); List<PropertyWrapper> properties = new ArrayList<PropertyWrapper>();
for (Method method : clazz.getMethods()) { for (Method method : clazz.getMethods()) {
@@ -167,7 +162,19 @@ public class ComponentProcessor {
} }
propertyCache.put(clazz.getName(), properties); propertyCache.put(clazz.getName(), properties);
return cloner.deepClone(properties); return cloneProperties(properties);
}
private List<PropertyWrapper> cloneProperties(List<PropertyWrapper> properties) {
List<PropertyWrapper> result = new ArrayList<PropertyWrapper>(properties.size());
for (PropertyWrapper propertyWrapper : properties) {
try {
result.add((PropertyWrapper) propertyWrapper.clone());
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
return result;
} }
/** /**
@@ -16,8 +16,6 @@ import org.diylc.core.IDIYComponent;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import com.rits.cloning.Cloner;
/** /**
* Manages component instantiation. * Manages component instantiation.
* *
@@ -30,15 +28,12 @@ public class InstantiationManager {
public static int MAX_RECENT_COMPONENTS = 16; public static int MAX_RECENT_COMPONENTS = 16;
private Cloner cloner;
private ComponentType componentTypeSlot; private ComponentType componentTypeSlot;
private IDIYComponent<?> componentSlot; private IDIYComponent<?> componentSlot;
private Point firstControlPoint; private Point firstControlPoint;
private Point potentialControlPoint; private Point potentialControlPoint;
public InstantiationManager() { public InstantiationManager() {
cloner = new Cloner();
} }
public ComponentType getComponentTypeSlot() { public ComponentType getComponentTypeSlot() {
@@ -227,7 +222,7 @@ public class InstantiationManager {
+ object.getClass().getName() + ":" + object.getClass().getName() + ":"
+ property.getName(), null); + property.getName(), null);
if (defaultValue != null) { if (defaultValue != null) {
property.setValue(cloner.deepClone(defaultValue)); property.setValue(defaultValue);
property.writeTo(object); property.writeTo(object);
} }
} }