simplified auto-create logic

cloud management work
This commit is contained in:
bancika
2016-10-31 13:11:53 +01:00
parent a74f00a5fd
commit f9a32ebce3
13 changed files with 77 additions and 83 deletions
@@ -31,14 +31,13 @@ public class ComponentType {
private BomPolicy bomPolicy;
private boolean autoEdit;
private boolean rotatable;
private IAutoCreator autoCreator;
private KeywordPolicy keywordPolicy;
private String keywordTag;
public ComponentType(String name, String description, CreationMethod creationMethod, String category,
String namePrefix, String author, Icon icon, Class<? extends IDIYComponent<?>> instanceClass, double zOrder,
boolean flexibleZOrder, boolean stretchable, BomPolicy bomPolicy, boolean autoEdit, boolean rotatable,
IAutoCreator autoCreator, KeywordPolicy keywordPolicy, String keywordTag) {
KeywordPolicy keywordPolicy, String keywordTag) {
super();
this.name = name;
this.description = description;
@@ -54,7 +53,6 @@ public class ComponentType {
this.bomPolicy = bomPolicy;
this.autoEdit = autoEdit;
this.rotatable = rotatable;
this.autoCreator = autoCreator;
this.keywordPolicy = keywordPolicy;
this.keywordTag = keywordTag;
}
@@ -115,14 +113,10 @@ public class ComponentType {
return rotatable;
}
public IAutoCreator getAutoCreateor() {
return autoCreator;
}
public KeywordPolicy getKeywordPolicy() {
return keywordPolicy;
}
public String getKeywordTag() {
return keywordTag;
}
@@ -1,9 +0,0 @@
package org.diylc.core.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface AutoCreator {
public Class<? extends IAutoCreator> creatorClass();
}
@@ -20,11 +20,9 @@ import org.diylc.common.PropertyWrapper;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IPropertyValidator;
import org.diylc.core.annotations.AutoCreator;
import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.IAutoCreator;
import org.diylc.core.annotations.KeywordPolicy;
/**
@@ -73,7 +71,6 @@ public class ComponentProcessor {
BomPolicy bomPolicy;
boolean autoEdit;
boolean rotatable;
IAutoCreator autoCreator = null;
KeywordPolicy keywordPolicy;
String keywordTag;
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
@@ -108,14 +105,6 @@ public class ComponentProcessor {
keywordPolicy = KeywordPolicy.NEVER_SHOW;
keywordTag = null;
}
if (clazz.isAnnotationPresent(AutoCreator.class)) {
AutoCreator annotation = clazz.getAnnotation(AutoCreator.class);
try {
autoCreator = annotation.creatorClass().newInstance();
} catch (Exception e) {
LOG.error("Could not instantiate auto-creator for " + name, e);
}
}
icon = null;
// Draw component icon.
try {
@@ -134,7 +123,7 @@ public class ComponentProcessor {
}
ComponentType componentType =
new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, autoCreator, keywordPolicy, keywordTag);
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, keywordPolicy, keywordTag);
componentTypeMap.put(clazz.getName(), componentType);
return componentType;
}
@@ -41,7 +41,7 @@ public class InstantiationManager {
private static final ComponentType clipboardType = new ComponentType("Clipboard contents",
"Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
false, true, null, KeywordPolicy.NEVER_SHOW, null);
false, true, KeywordPolicy.NEVER_SHOW, null);
public InstantiationManager() {}
@@ -312,42 +312,27 @@ public class Presenter implements IPlugInPort {
Set<Class<?>> componentTypeClasses = null;
try {
componentTypeClasses = Utils.getClasses("org.diylc.components");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// for (String path : classPath) {
// path = path.replace('\\', '/');
// File f = new File(path);
// try {
// if (f.isDirectory()) {
// LOG.info("Scanning folder for components: "
// + f.getAbsolutePath());
// componentTypeClasses.addAll(JarScanner.getInstance()
// .scanFolder(path, IDIYComponent.class));
// } else {
// LOG.info("Scanning JAR for components: "
// + f.getAbsolutePath());
// componentTypeClasses.addAll(JarScanner.getInstance()
// .scanJar(f, IDIYComponent.class));
// }
// } catch (Exception e) {
// LOG.warn("Could not scan path " + path, e);
// }
// }
for (Class<?> clazz : componentTypeClasses) {
if (!Modifier.isAbstract(clazz.getModifiers()) && IDIYComponent.class.isAssignableFrom(clazz)) {
ComponentType componentType =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) clazz);
List<ComponentType> nestedList;
if (componentTypes.containsKey(componentType.getCategory())) {
nestedList = componentTypes.get(componentType.getCategory());
} else {
nestedList = new ArrayList<ComponentType>();
componentTypes.put(componentType.getCategory(), nestedList);
for (Class<?> clazz : componentTypeClasses) {
if (!Modifier.isAbstract(clazz.getModifiers()) && IDIYComponent.class.isAssignableFrom(clazz)) {
ComponentType componentType =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) clazz);
List<ComponentType> nestedList;
if (componentTypes.containsKey(componentType.getCategory())) {
nestedList = componentTypes.get(componentType.getCategory());
} else {
nestedList = new ArrayList<ComponentType>();
componentTypes.put(componentType.getCategory(), nestedList);
}
nestedList.add(componentType);
}
nestedList.add(componentType);
}
for (Map.Entry<String, List<ComponentType>> e : componentTypes.entrySet()) {
LOG.debug(e.getKey() + ": " + e.getValue());
}
} catch (Exception e) {
LOG.error("Error loading component types", e);
}
}
return componentTypes;
@@ -356,11 +341,17 @@ public class Presenter implements IPlugInPort {
public List<IAutoCreator> getAutoCreators() {
if (autoCreators == null) {
autoCreators = new ArrayList<IAutoCreator>();
for (Map.Entry<String, List<ComponentType>> entry : getComponentTypes().entrySet()) {
for (ComponentType t : entry.getValue()) {
if (t.getAutoCreateor() != null)
autoCreators.add(t.getAutoCreateor());
Set<Class<?>> classes = null;
try {
classes = Utils.getClasses("org.diylc.components.autocreate");
for (Class<?> clazz : classes) {
if (IAutoCreator.class.isAssignableFrom(clazz)) {
autoCreators.add((IAutoCreator) clazz.newInstance());
LOG.debug("Loaded auto-cretor: " + clazz.getName());
}
}
} catch (Exception e) {
LOG.error("Error loading auto-creator types", e);
}
}
return autoCreators;