📄 javataskwrapper.java
字号:
/*
* Copyright (c) 2003-2004, Alexander Greif
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Flow4J-Eclipse project nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.orthanc.flow4j.designer.model;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.orthanc.flow4j.designer.core.Flow4JPlugin;
import net.orthanc.flow4j.runtime.ITaskFlowlet;
import net.orthanc.flow4j.runtime.descriptors.TaskPropertyDescriptor;
import net.orthanc.flow4j.runtime.descriptors.TaskPropertyDescriptors;
import org.eclipse.jdt.core.IJavaProject;
/**
* This class wraps a Task Flowlet instance with its properties.
* @author greifa
*/
public class JavaTaskWrapper implements ITaskWrapper {
private String taskClassName;
private ITaskFlowlet taskFlowletInstance;
private Map taskProperties;
/**
* Returns a Map that contains the tasks properties and their values.
* @return a Map that contains the tasks properties and their values.
*/
public Map getTaskProperties() {
return taskProperties;
}
/**
* Sets the tasks properties and their values.
* @param map Map containing the tasks properties and their values.
*/
public void setTaskProperties(Map map) {
taskProperties = map;
}
/**
* Sets a task property. Creates the properties Map if necessary.
* @param key the property key
* @param value the property value
*/
public void setTaskProperty(String key, String value) {
if (taskProperties == null)
taskProperties = new HashMap();
taskProperties.put(key, value);
}
/**
* Returns a task property or <code>null</code> if the property is
* not set or the task has no properties at all
* @param key the property key
* @return a task property or <code>null</code>
*/
public String getTaskProperty(String key) {
if (taskProperties == null)
return null;
return (String) taskProperties.get(key);
}
/**
* Returns the task flowlet instance, or throws a ClassNotFoundException.
* @param taskClassName the calssname of the task flowlet
* @return the task flowlet instance, or throws a ClassNotFoundException.
* @throws ClassNotFoundException
*/
public ITaskFlowlet getTaskFlowletInstance(String taskClassName)
throws ClassNotFoundException, Throwable {
this.taskClassName = taskClassName;
if (taskFlowletInstance != null
&& taskFlowletInstance.getClass().getName().equals(taskClassName))
return taskFlowletInstance;
return Flow4JPlugin.getTaskFlowletInstance(taskClassName);
}
/**
* Returns a task flowlet instance. That is searched in the project's classpath.
* @param taskClassName
* @param javaProject
* @return
* @throws ClassNotFoundException
* @throws Throwable
*/
public ITaskFlowlet getTaskFlowletInstance(
String taskClassName,
IJavaProject javaProject)
throws ClassNotFoundException, Throwable {
taskFlowletInstance =
Flow4JPlugin.getTaskFlowletInstance(taskClassName, javaProject);
checkTaskProperties(taskFlowletInstance.getPropertyDescriptors());
return taskFlowletInstance;
}
/**
* Returns a task flowlet instance. That is searched in the given classpath.
* @param taskClassName
* @param classpathURLs
* @return a task flowlet instance.
* @throws ClassNotFoundException
* @throws Throwable
*/
public ITaskFlowlet getTaskFlowletInstance(
String taskClassName,
List classpathURLs)
throws ClassNotFoundException, Throwable {
/* JavaTaskFlowletClassLoader taskFlowletClassLoader =
new JavaTaskFlowletClassLoader(
classpathEntries,
Flow4JPlugin
.getDefault()
.getDescriptor()
.getPluginClassLoader());
taskFlowletInstance =
taskFlowletClassLoader.getTaskInstance(taskClassName);
*/
taskFlowletInstance = Flow4JPlugin.getTaskFlowletInstance(taskClassName, classpathURLs);
checkTaskProperties(taskFlowletInstance.getPropertyDescriptors());
return taskFlowletInstance;
}
/**
* Checks the currently hold properties fit to the property
* descriptors of the task flowlet instance.
* Deleting the properties of some previous task flowlet happens when the label's content changes.
* Here we only set the defaults to empty string
* @param descs property descriptors of the task flowlet instance
*/
private void checkTaskProperties(TaskPropertyDescriptors descs) {
if (descs == null || descs.isEmpty())
return;
if (taskProperties == null)
taskProperties = new HashMap();
for (Iterator iter = descs.iterator(); iter.hasNext();) {
TaskPropertyDescriptor desc = (TaskPropertyDescriptor) iter.next();
if (taskProperties.get(desc.getName()) == null)
taskProperties.put(desc.getName(), "");
}
}
/**
* Returns the java task flowlet instance
* @return the java task flowlet instance
*/
public ITaskFlowlet getJavaTaskFlowletInstance() {
return taskFlowletInstance;
}
/**
* Returns the task's class name
* @return the task's class name
*/
public String getTaskClassName() {
return taskClassName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -