StartTask.java :  » Workflow-Engines » bexee » bexee » ant » Java Open Source

Java Open Source » Workflow Engines » bexee 
bexee » bexee » ant » StartTask.java
/*
 * $Id: StartTask.java,v 1.1 2004/12/06 07:53:37 fornp1 Exp $
 *
 * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
 * Berne University of Applied Sciences
 * School of Engineering and Information Technology
 * All rights reserved.
 */
package bexee.ant;

import java.rmi.RemoteException;

import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

/**
 * Starts a BPEL process on bexee.
 * <p>
 * Note that this Task is very primitive and supports only service operations
 * that take a string parameter as input and return a string. It is only used
 * for simple demonstration purposes.
 * 
 * @version $Revision: 1.1 $, $Date: 2004/12/06 07:53:37 $
 * @author Patric Fornasier
 * @author Pawel Kowalski
 */
public class StartTask extends Task {

    private String url;

    private String operation;

    private String input;

    /**
     * Location of the BPEL process Web Service.
     * 
     * @param url
     *            a <code>URL</code>
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * Name of the operation to perform
     * 
     * @param operation
     *            a <code>String</code>
     */
    public void setOperation(String operation) {
        this.operation = operation;
    }

    /**
     * The input value to pass to the process.
     * 
     * @param input
     *            a <code>String</code>
     */
    public void setInput(String input) {
        this.input = input;
    }

    /**
     * Starts the process on bexee.
     */
    public void execute() throws BuildException {

        // check if the required parameter have been set
        if (url == null || operation == null || input == null) {
            throw new BuildException("All of url, operation and value required");
        }

        Service service = new Service();
        Call call = null;
        try {
            call = (Call) service.createCall();
            call.setTargetEndpointAddress(url);
            call.setOperation(operation);
            call.addParameter("x", XMLType.XSD_STRING, ParameterMode.IN);
            call.setReturnType(XMLType.XSD_STRING);
        } catch (ServiceException e) {
            throw new BuildException("Unable to create call", e);
        }

        try {
            String result = (String) call.invoke(new Object[] { input });
            log(result);
        } catch (RemoteException e) {
            throw new BuildException("Unable to invoke service", e);
        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.