mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Replaced deep cloning library with manual implementation
This commit is contained in:
@@ -6,12 +6,8 @@
|
||||
<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/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 combineaccessrules="false" kind="src" path="/app-framework"/>
|
||||
<classpathentry kind="lib" path="lib/cloning-1.8.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/objenesis-1.2.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+21
-10
@@ -22,8 +22,8 @@ public class PropertyWrapper implements Cloneable {
|
||||
private boolean unique = true;
|
||||
private boolean changed = false;
|
||||
|
||||
public PropertyWrapper(String name, Class<?> type, String getter, String setter,
|
||||
boolean defaultable, IPropertyValidator validator) {
|
||||
public PropertyWrapper(String name, Class<?> type, String getter,
|
||||
String setter, boolean defaultable, IPropertyValidator validator) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
@@ -33,8 +33,9 @@ public class PropertyWrapper implements Cloneable {
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
public void readFrom(Object object) throws IllegalArgumentException, IllegalAccessException,
|
||||
InvocationTargetException, SecurityException, NoSuchMethodException {
|
||||
public void readFrom(Object object) throws IllegalArgumentException,
|
||||
IllegalAccessException, InvocationTargetException,
|
||||
SecurityException, NoSuchMethodException {
|
||||
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,
|
||||
InvocationTargetException, SecurityException, NoSuchMethodException {
|
||||
public void writeTo(Object object) throws IllegalArgumentException,
|
||||
IllegalAccessException, InvocationTargetException,
|
||||
SecurityException, NoSuchMethodException {
|
||||
object.getClass().getMethod(setter, type).invoke(object, this.value);
|
||||
}
|
||||
|
||||
@@ -75,19 +77,19 @@ public class PropertyWrapper implements Cloneable {
|
||||
public IPropertyValidator getValidator() {
|
||||
return validator;
|
||||
}
|
||||
|
||||
|
||||
public boolean isUnique() {
|
||||
return unique;
|
||||
}
|
||||
|
||||
|
||||
public void setUnique(boolean unique) {
|
||||
this.unique = unique;
|
||||
}
|
||||
|
||||
|
||||
public boolean isChanged() {
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
||||
public void setChanged(boolean changed) {
|
||||
this.changed = changed;
|
||||
}
|
||||
@@ -102,6 +104,15 @@ public class PropertyWrapper implements Cloneable {
|
||||
// }
|
||||
// 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
|
||||
public int hashCode() {
|
||||
|
||||
+1
-3
@@ -18,8 +18,6 @@ import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
import com.rits.cloning.CloningException;
|
||||
|
||||
/**
|
||||
* Abstract implementation of {@link IDIYComponent} that contains component name
|
||||
* and toString.
|
||||
@@ -177,7 +175,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
}
|
||||
return newInstance;
|
||||
} catch (Exception e) {
|
||||
throw new CloningException("Could not clone the component", e);
|
||||
throw new CloneNotSupportedException("Could not clone the component. Reason: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-7
@@ -24,8 +24,6 @@ import org.diylc.core.annotations.BomPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
/**
|
||||
* Utility class with component processing methods.
|
||||
*
|
||||
@@ -42,8 +40,6 @@ public class ComponentProcessor {
|
||||
private Map<String, IPropertyValidator> propertyValidatorCache;
|
||||
private Map<String, ComponentType> componentTypeMap;
|
||||
|
||||
private Cloner cloner;
|
||||
|
||||
public static ComponentProcessor getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ComponentProcessor();
|
||||
@@ -53,7 +49,6 @@ public class ComponentProcessor {
|
||||
|
||||
private ComponentProcessor() {
|
||||
super();
|
||||
this.cloner = new Cloner();
|
||||
this.propertyCache = new HashMap<String, List<PropertyWrapper>>();
|
||||
this.componentTypeMap = new HashMap<String, ComponentType>();
|
||||
this.propertyValidatorCache = new HashMap<String, IPropertyValidator>();
|
||||
@@ -132,7 +127,7 @@ public class ComponentProcessor {
|
||||
*/
|
||||
public List<PropertyWrapper> extractProperties(Class<?> clazz) {
|
||||
if (propertyCache.containsKey(clazz.getName())) {
|
||||
return cloner.deepClone(propertyCache.get(clazz.getName()));
|
||||
return cloneProperties(propertyCache.get(clazz.getName()));
|
||||
}
|
||||
List<PropertyWrapper> properties = new ArrayList<PropertyWrapper>();
|
||||
for (Method method : clazz.getMethods()) {
|
||||
@@ -167,7 +162,19 @@ public class ComponentProcessor {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-6
@@ -16,8 +16,6 @@ import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.measures.Size;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
/**
|
||||
* Manages component instantiation.
|
||||
*
|
||||
@@ -30,15 +28,12 @@ public class InstantiationManager {
|
||||
|
||||
public static int MAX_RECENT_COMPONENTS = 16;
|
||||
|
||||
private Cloner cloner;
|
||||
|
||||
private ComponentType componentTypeSlot;
|
||||
private IDIYComponent<?> componentSlot;
|
||||
private Point firstControlPoint;
|
||||
private Point potentialControlPoint;
|
||||
|
||||
public InstantiationManager() {
|
||||
cloner = new Cloner();
|
||||
}
|
||||
|
||||
public ComponentType getComponentTypeSlot() {
|
||||
@@ -227,7 +222,7 @@ public class InstantiationManager {
|
||||
+ object.getClass().getName() + ":"
|
||||
+ property.getName(), null);
|
||||
if (defaultValue != null) {
|
||||
property.setValue(cloner.deepClone(defaultValue));
|
||||
property.setValue(defaultValue);
|
||||
property.writeTo(object);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user