/*
* Copyright 2004 The Apache Software Foundation.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.apache.agila.example;
import org.apache.agila.model.Connection;
import org.apache.agila.model.node.BaseNodeImpl;
import org.apache.agila.model.NodeContext;
import org.apache.agila.services.task.Renderer;
import org.apache.agila.services.task.ResponseHandler;
import org.apache.agila.services.task.TaskActivity;
import org.apache.agila.services.task.TaskService;
import org.apache.agila.services.user.UserID;
import java.util.Date;
/**
* Task to get data from user about their leave. It needs no input, but
* will put two values out to the app data, 'numdays', and 'reason'
*/
public class LeaveApplicationTask extends BaseNodeImpl implements TaskActivity {
protected final static String NUMDAYS = "numdays";
protected final static String REASON = "reason";
// mock properties to test XML serialization
private String foo;
private int bar;
public int getBar() {
return bar;
}
public void setBar(int bar) {
this.bar = bar;
}
public String getFoo() {
return foo;
}
public void setFoo(String foo) {
this.foo = foo;
}
/**
* Start method for the activity. Sets up a tast for the user
*
* @param ctx
* @return
*/
public boolean doStart(NodeContext ctx) {
TaskService ts = ctx.getTaskService();
ts.assignTask(ctx.getNextExecutionToken().getTokenID(), "Enter leave details",
new UserID(1), new Date());
return false;
}
/**
* End method. Gets the data from the context's app data, and writes to
* instance variables through the bindings
*
* @param ctx
* @return
*/
public Connection[] doEnd(NodeContext ctx) {
/*
* get the data from the user from the app data
*
*/
LeaveApplicationHandler.DataCarrier taskData =
(LeaveApplicationHandler.DataCarrier)
ctx.getAppData().get(LeaveApplicationHandler.APP_DATA_NAME);
/*
* now write these values out to the instance variable space through
* the bindings
*/
ctx.setBoundValue(NUMDAYS, taskData.numDays);
ctx.setBoundValue(REASON, taskData.reason);
return getOutboundConnections();
}
public Renderer getRenderer(NodeContext ctx, Class type) {
return new LeaveApplicationHandler(ctx);
}
public ResponseHandler getResponseHandler(NodeContext ctx, Class type) {
return new LeaveApplicationHandler(ctx);
}
}