simplified component framework

This commit is contained in:
bancika
2011-01-05 00:09:11 +00:00
parent d1892cae70
commit 69acfcff2f
17 changed files with 145 additions and 149 deletions
@@ -23,8 +23,8 @@ public class ComparatorFactory {
@Override
public int compare(IDIYComponent o1, IDIYComponent o2) {
String name1 = ComponentProcessor.getInstance().extractComponentName(o1);
String name2 = ComponentProcessor.getInstance().extractComponentName(o2);
String name1 = o1.getName();
String name2 = o2.getName();
if (name1 == null || name2 == null) {
return 0;
}
@@ -11,8 +11,6 @@ import org.apache.log4j.Logger;
import org.diylc.common.ControlPointWrapper;
import org.diylc.common.PropertyWrapper;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentName;
import org.diylc.core.annotations.ComponentValue;
import org.diylc.core.annotations.ControlPoint;
import org.diylc.core.annotations.EditableProperty;
@@ -174,68 +172,4 @@ public class ComponentProcessor {
}
return properties;
}
/**
* Finds the method annotated with {@link ComponentName} annotations and
* calls it to retrieve component name.
*
* @param component
* @return
*/
public String extractComponentName(IDIYComponent component) {
String name = null;
for (Method method : component.getClass().getMethods()) {
if (method.isAnnotationPresent(ComponentName.class)) {
try {
name = method.invoke(component).toString();
} catch (Exception e) {
name = null;
}
}
}
return name;
}
/**
* Finds the method annotated with {@link ComponentName} and it's matching
* setter and calls the setter to update the component name.
*
* @param component
* @param newName
*/
public void writeComponentName(IDIYComponent component, String newName) {
for (Method method : component.getClass().getMethods()) {
if (method.isAnnotationPresent(ComponentName.class)) {
try {
Method setter = component.getClass().getMethod(
method.getName().replaceFirst("get", "set"), String.class);
setter.invoke(component, newName);
} catch (Exception e) {
LOG.warn("Could not update component name on a component of type "
+ component.getClass().getName());
}
}
}
}
/**
* Finds the method annotated with {@link ComponentValue} annotations and
* calls it to retrieve component value.
*
* @param component
* @return
*/
public String extractComponentValue(IDIYComponent component) {
String value = null;
for (Method method : component.getClass().getMethods()) {
if (method.isAnnotationPresent(ComponentValue.class)) {
try {
value = method.invoke(component).toString();
} catch (Exception e) {
value = null;
}
}
}
return value;
}
}
@@ -716,14 +716,13 @@ public class Presenter implements IPlugInPort {
String name = namePrefix + i;
exists = false;
for (IDIYComponent c : currentProject.getComponents()) {
String cName = ComponentProcessor.getInstance().extractComponentName(c);
if (cName.equals(name)) {
if (c.getName().equals(name)) {
exists = true;
break;
}
}
}
ComponentProcessor.getInstance().writeComponentName(component, namePrefix + i);
component.setName(namePrefix + i);
// Add it to the project.
currentProject.getComponents().add(component);