/*
 * StampSaveHandler.java
 *
 * Created on 15 de Marco de 2005, 15:00
 */

package siprp.data;

import java.util.*;

import com.evolute.utils.jdo.*;
/**
 *
 * @author  fpalma
 */
public class ActualizacaoSaveHandler implements JDOOperationHandlerInterface
{
	public static final ActualizacaoSaveHandler INSTANCE = new ActualizacaoSaveHandler();
	
	/** Creates a new instance of StampSaveHandler */
	public ActualizacaoSaveHandler()
	{
	}
	
	public boolean handle(JDOObject object, int operation, int moment) throws Exception
	{
		if( !( object instanceof ActualizacaoSaveable ) )
		{
			return false;
		}
		switch( operation )
		{
			case OP_SAVE:
				return save( object, moment );
				
			case OP_DELETE:
				return false;
		}
		return false;
	}
	
	protected boolean save( JDOObject object, int moment )
	{
		if( moment != MOMENT_BEFORE )
		{
			return false;
		}
		object.set( ActualizacaoSaveable.ACTUALIZACAO, new Date() );
		return true;
	}
}
