Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2010 JBoss Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package org.jbpm.process.workitem.transform;
public class TransformWorkItemHandler implements WorkItemHandler {
	private static String INPUT_KEY = "InputObject";
	private static String OUTPUT_TYPE_KEY = "OutputType";
	private static String VARIABLE_OUTPUT_NAME = "OutputObject";
	// Keyed on the return type of the transformer with a second key of the parameter type
	private Map<Class<?>, Map<Class<?>, Method>> transforms =
		new HashMap<Class<?>, Map<Class<?>, Method>>();
	public void executeWorkItem(WorkItem inputItemWorkItemManager itemMgr) {
		try {
			Object in = inputItem.getParameter();
			String outputType = (StringinputItem.getParameter();
			Object output = Class.forName(outputType).newInstance();
			Method txMethod = this.findTransform(output.getClass(), in.getClass());
			if (txMethod != null) {
				Object out = txMethod.invoke(nullin);
				Map<StringObjectresult = new HashMap<StringObject>();
				itemMgr.completeWorkItem(inputItem.getId(), result);
else {
				..println("Failed to find a transform ");
catch (Exception e) {
	public void registerTransformer(Class<?> transformer) {
		Method[] methods = transformer.getMethods();
		if (methods == null) {
		for (Method meth : methods) {
			// Only consider methods that have the @Transformer annotation
			if (meth.getAnnotation(Transformer.class) == null) {
			Class<?> returnType = meth.getReturnType();
			Class<?> paramType = meth.getParameterTypes()[0];
			Map<Class<?>, Methodindex = .get(returnType);
			if (index == null) {
				index = new HashMap<Class<?>, Method>();
	private Method findTransform(Class<?> returnClassClass<?> paramClass) {
		Map<Class<?>, MethodindexedTxForm = .get(returnClass);
		if (indexedTxForm == null) {
			return null;
		return indexedTxForm.get(paramClass);
	public void abortWorkItem(WorkItem arg0WorkItemManager arg1) {
		// Do nothing
New to GrepCode? Check out our FAQ X