3.4.4. Sample Command

Because all of the parameter extraction and transaction setup is done by the command framework, commands themselves can be very simple. The listing below shows the command to update a content provider in BELTS.

/* Copyright 2002-2005, education.au limited and 
                Curriculum Corporation, 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 names education.au limited, Curriculum Corporation nor The 
 Learning
 * Federation nor the names of its contributors may be used to endorse or promote 
 products
 * derived from this software without specific prior written permission.
 *
 * To the extent permitted by law, the copyright owners of this software and its 
 contributors:
 *
 * (i) exclude all warranties in relation to the software; and
 * (ii) exclude liability for all losses, costs, expenses and damages arising in 
 any way
 * from the use of the software whether arising from or in relation to breach of 
 contract,
 * negligence or any other tort, in equity or otherwise. If the software is in 
 breach of a
 * warranty which is implied by law, the copyright owners and contributors 
 liability is
 * limited to the replacement of the software.
 *
 * Created: 8/07/2003
 *
 * $Id: developer.xml,v 1.5 2005/01/25 10:59:59 gregj_jacus Exp $
 */

package au.edu.educationau.belts.command.content.action;

import java.util.Date;

import org.apache.commons.lang.StringUtils;

import au.edu.educationau.belts.command.CommandResult;
import au.edu.educationau.belts.command.container.AbstractBeltsContainerCommand;
import au.edu.educationau.belts.content.Update;

/**
 * UpdateProviderAction causes a update to be run on the provider service named.
 *
 * @author <a href="mailto:kevin@rocketred.com.au">Kevin O'Neill</a>
 * @version $Revision: 1.5 $ - $Date: 2005/01/25 10:59:59 $
 */
public class UpdateProviderAction extends AbstractBeltsContainerCommand
{
	private String _provider;

	public void execute()
	{
		_outcome = CommandResult.OUTCOME_ERROR;

		new Update(_provider).update(new Date(0L));

		_outcome = CommandResult.OUTCOME_OK;
	}

	/**
	 * @param name - provider name to update
	 */
	public void setProvider(String name)
	{
		_provider = name;
	}

	/* (non-Javadoc)
	 * @see au.edu.educationau.belts.command.Command#validate()
	 */
	public boolean validate()
	{
		if (StringUtils.isEmpty(_provider))
		{
			addFieldValidationError("provider");
		}

		return super.validate();
	}
}