mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
show mutual properties across different component types
This commit is contained in:
+16
-8
@@ -1,7 +1,6 @@
|
||||
package org.diylc.common;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.diylc.core.IPropertyValidator;
|
||||
|
||||
@@ -16,12 +15,13 @@ public class PropertyWrapper implements Cloneable {
|
||||
private String name;
|
||||
private Class<?> type;
|
||||
private Object value;
|
||||
private Method setter;
|
||||
private Method getter;
|
||||
private String setter;
|
||||
private String getter;
|
||||
private boolean defaultable;
|
||||
private IPropertyValidator validator;
|
||||
private boolean unique = true;
|
||||
|
||||
public PropertyWrapper(String name, Class<?> type, Method getter, Method setter,
|
||||
public PropertyWrapper(String name, Class<?> type, String getter, String setter,
|
||||
boolean defaultable, IPropertyValidator validator) {
|
||||
super();
|
||||
this.name = name;
|
||||
@@ -33,8 +33,8 @@ public class PropertyWrapper implements Cloneable {
|
||||
}
|
||||
|
||||
public void readFrom(Object object) throws IllegalArgumentException, IllegalAccessException,
|
||||
InvocationTargetException {
|
||||
this.value = getter.invoke(object);
|
||||
InvocationTargetException, SecurityException, NoSuchMethodException {
|
||||
this.value = object.getClass().getMethod(getter).invoke(object);
|
||||
}
|
||||
|
||||
// public void readUniqueFrom(IDIYComponent component)
|
||||
@@ -47,8 +47,8 @@ public class PropertyWrapper implements Cloneable {
|
||||
// }
|
||||
|
||||
public void writeTo(Object object) throws IllegalArgumentException, IllegalAccessException,
|
||||
InvocationTargetException {
|
||||
setter.invoke(object, value);
|
||||
InvocationTargetException, SecurityException, NoSuchMethodException {
|
||||
object.getClass().getMethod(setter, this.value.getClass()).invoke(object, this.value);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -74,6 +74,14 @@ public class PropertyWrapper implements Cloneable {
|
||||
public IPropertyValidator getValidator() {
|
||||
return validator;
|
||||
}
|
||||
|
||||
public boolean isUnique() {
|
||||
return unique;
|
||||
}
|
||||
|
||||
public void setUnique(boolean unique) {
|
||||
this.unique = unique;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Object clone() throws CloneNotSupportedException {
|
||||
|
||||
+2
-2
@@ -141,8 +141,8 @@ public class ComponentProcessor {
|
||||
Method setter = clazz.getMethod("set" + method.getName().substring(3),
|
||||
method.getReturnType());
|
||||
PropertyWrapper property = new PropertyWrapper(name,
|
||||
method.getReturnType(), method, setter, annotation.defaultable(),
|
||||
validator);
|
||||
method.getReturnType(), method.getName(), setter.getName(),
|
||||
annotation.defaultable(), validator);
|
||||
properties.add(property);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
||||
+3
-1
@@ -173,9 +173,11 @@ public class InstantiationManager {
|
||||
* @throws IllegalArgumentException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InvocationTargetException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws SecurityException
|
||||
*/
|
||||
public void fillWithDefaultProperties(Object object) throws IllegalArgumentException,
|
||||
IllegalAccessException, InvocationTargetException {
|
||||
IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
|
||||
// Extract properties.
|
||||
List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(
|
||||
object.getClass());
|
||||
|
||||
Reference in New Issue
Block a user