use of org.knime.core.node.DynamicNodeFactory in project knime-core by knime.
the class RepositoryFactory method createNode.
/**
* Creates a new node repository object. Throws an exception, if this fails
*
* @param element Configuration element from the contributing plugin
* @return NodeTemplate object to be used within the repository.
* @throws IllegalArgumentException If the element is not compatible (e.g.
* wrong attributes, or factory class not found)
*/
@SuppressWarnings("unchecked")
public static NodeTemplate createNode(final IConfigurationElement element) {
// Try to load the node factory class...
NodeFactory<? extends NodeModel> factory;
// this ensures that the class is loaded by the correct eclipse
// classloaders
GlobalClassCreator.lock.lock();
try {
factory = (NodeFactory<? extends NodeModel>) element.createExecutableExtension("factory-class");
} catch (Throwable e) {
throw new IllegalArgumentException("Can't load factory class for node: " + element.getAttribute("factory-class"), e);
} finally {
GlobalClassCreator.lock.unlock();
}
if (factory instanceof DynamicNodeFactory) {
throw new IllegalArgumentException("Dynamic node factory '" + element.getAttribute("factory-class") + "'" + " registered as normal node factory.");
}
String pluginID = element.getDeclaringExtension().getNamespaceIdentifier();
NodeTemplate node = new NodeTemplate((Class<NodeFactory<? extends NodeModel>>) factory.getClass(), factory.getNodeName(), pluginID);
node.setAfterID(str(element.getAttribute("after"), ""));
node.setType(factory.getType());
if (!Boolean.valueOf(System.getProperty("java.awt.headless", "false"))) {
// Load images from declaring plugin
Image icon = ImageRepository.getIconImage(factory);
node.setIcon(icon);
}
node.setCategoryPath(str(element.getAttribute("category-path"), "/"));
return node;
}
use of org.knime.core.node.DynamicNodeFactory in project knime-core by knime.
the class RepositoryFactory method createNodeSet.
/**
* Creates the set of dynamic node templates.
*
* @param root the root to add the missing categories in
* @param element from the extension points
* @return the created dynamic node templates
*/
public static Collection<DynamicNodeTemplate> createNodeSet(final Root root, final IConfigurationElement element) {
String iconPath = element.getAttribute("default-category-icon");
// Try to load the node set factory class...
NodeSetFactory nodeSet;
// this ensures that the class is loaded by the correct eclipse
// classloaders
GlobalClassCreator.lock.lock();
try {
nodeSet = (NodeSetFactory) element.createExecutableExtension("factory-class");
} catch (Throwable e) {
throw new IllegalArgumentException("Can't load factory class for node: " + element.getAttribute("factory-class"), e);
} finally {
GlobalClassCreator.lock.unlock();
}
Collection<DynamicNodeTemplate> dynamicNodeTemplates = new ArrayList<DynamicNodeTemplate>();
// for all nodes in the node set
for (String factoryId : nodeSet.getNodeFactoryIds()) {
@SuppressWarnings("unchecked") Class<NodeFactory<? extends NodeModel>> factoryClass = (Class<NodeFactory<? extends NodeModel>>) nodeSet.getNodeFactory(factoryId);
// Try to load the node factory class...
NodeFactory<? extends NodeModel> factory;
// this ensures that the class is loaded by the correct eclipse
// classloaders
GlobalClassCreator.lock.lock();
try {
factory = DynamicNodeTemplate.createFactoryInstance(factoryClass, nodeSet, factoryId);
} catch (Throwable e) {
throw new IllegalArgumentException("Can't load factory class for node: " + factoryClass.getName() + "-" + factoryId, e);
} finally {
GlobalClassCreator.lock.unlock();
}
// DynamicNodeFactory implementations can set deprecation independently from extension
if (factory.isDeprecated()) {
continue;
}
DynamicNodeTemplate node = new DynamicNodeTemplate(factoryClass, factoryId, nodeSet, factory.getNodeName());
node.setAfterID(nodeSet.getAfterID(factoryId));
if (!Boolean.getBoolean("java.awt.headless")) {
Image icon = ImageRepository.getIconImage(factory);
node.setIcon(icon);
}
node.setCategoryPath(nodeSet.getCategoryPath(factoryId));
dynamicNodeTemplates.add(node);
String pluginID = element.getDeclaringExtension().getNamespaceIdentifier();
//
// Insert in proper location, create all categories on
// the path
// if not already there
//
String path = node.getCategoryPath();
if (path.startsWith("/")) {
path = path.substring(1);
}
// split the path
String[] segments = path.split("/");
// start at root
IContainerObject container = root;
String currentPath = "";
for (int i = 0; i < segments.length; i++) {
IRepositoryObject obj = container.getChildByID(segments[i], false);
currentPath += segments[i];
if (obj == null) {
Category cat = createCategory(pluginID, segments[i], "", segments[i], "", iconPath, currentPath);
// append the newly created category to the container
container.addChild(cat);
obj = cat;
}
currentPath += "/";
// continue at this level
container = (IContainerObject) obj;
}
}
return dynamicNodeTemplates;
}
Aggregations