package ru.runa.specific.alf;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.eclipse.jface.resource.ImageDescriptor;
import org.jbpm.ui.common.model.Delegable;
import org.jbpm.ui.custom.ParamBasedProvider;
import org.jbpm.ui.custom.ParamDef;
import org.jbpm.ui.util.IOUtils;
import ru.runa.specific.Activator;
public class AlfHandlerProvider extends ParamBasedProvider {
@Override
protected ImageDescriptor getLogo() {
return Activator.getImageDescriptor("/icons/logo.gif");
}
@Override
protected List<ParamDef> getParamDefinitions(Delegable delegable) {
List<ParamDef> paramDefs = new ArrayList<ParamDef>();
String path = "/conf/" + getSimpleClassName(delegable.getDelegationClassName()) + ".xml";
InputStream is = getClass().getResourceAsStream(path);
if (is == null) {
throw new NullPointerException("No conf file found at " + path);
}
try {
Document doc = DocumentHelper.parseText(IOUtils.readStream(is));
Element inputElement = doc.getRootElement().element("input");
if (inputElement != null) {
List<Element> inputParamElements = inputElement.elements("param");
for (Element element : inputParamElements) {
paramDefs.add(new ParamDef(element, true));
}
}
Element outputElement = doc.getRootElement().element("output");
if (outputElement != null) {
List<Element> outputParamElements = outputElement.elements("param");
for (Element element : outputParamElements) {
paramDefs.add(new ParamDef(element, false));
}
}
return paramDefs;
} catch (Exception e) {
throw new RuntimeException("Unable parse config at " + path, e);
}
}
private String getSimpleClassName(String className) {
int dotIndex = className.lastIndexOf(".");
return className.substring(dotIndex+1);
}
}