/*
* Jacareto Copyright (c) 2002-2005
* Applied Computer Science Research Group, Darmstadt University of
* Technology, Institute of Mathematics & Computer Science,
* Ludwigsburg University of Education, and Computer Based
* Learning Research Group, Aachen University. All rights reserved.
*
* Jacareto is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* Jacareto is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with Jacareto; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
package jacareto.convert.datacase;
import jacareto.convert.Converter;
import jacareto.dataset.DataCase;
import jacareto.record.ActionEventRecordable;
import jacareto.struct.StructureElement;
import jacareto.system.Environment;
/**
* A converter which is able to convert a {@link jacareto.record.ActionEventRecordable} to a data
* case, and vice versa.
*
* @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
* @version 1.02
*/
public class DCActionEventConverter extends Converter {
/**
* Creates a new datacase event converter.
*
* @param env the environment
*/
public DCActionEventConverter (Environment env) {
super(env);
}
/**
* Returns whether this converter is able to transform the specified object to a data case.
* This converter is responsible for the given object if it is of type
* <code>ActionEventRecordable</code>.
*
* @param element the structure element
*
* @return true if this converter is responsible for this structure element; otherwise false.
*/
public boolean handlesElement (StructureElement element) {
return (element != null) && element instanceof ActionEventRecordable;
}
/**
* Converts the specified element to a data case, if this converter is responsible for it. For
* responsibility see {@link #handlesElement(StructureElement)}.
*
* @param element the object to convert
*
* @return the record object
*/
public Object convertElement (StructureElement element) {
ActionEventRecordable recordable = (ActionEventRecordable) element;
Object[] values = new Object[6];
values[0] = new Integer(recordable.getID ());
values[1] = recordable.getSourceName ();
values[2] = recordable.getSourceClass ();
values[3] = new Long(recordable.getDuration ());
values[4] = new Integer(recordable.getModifiers ());
values[5] = recordable.getActionCommand ();
String[] valueNames = new String[6];
valueNames[0] = language.getString ("Events.Event.ID");
valueNames[1] = language.getString ("Events.Event.Source");
valueNames[2] = language.getString ("Events.Event.SourceClass");
valueNames[3] = language.getString ("Events.Event.RelativeTime");
valueNames[4] = language.getString ("Events.InputEvent.Modifiers");
valueNames[5] = language.getString ("Events.ActionEvent.Command");
return new DataCase(env, values, valueNames);
}
/**
* Returns <code>false</code> (This converter just converts in one direction at at the moment).
*
* @param other DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public boolean handlesOther (Object other) {
return false;
}
/**
* Returns <code>null</code> (This converter just converts in one direction at at the moment).
*
* @param other DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public StructureElement convertOther (Object other) {
return null;
}
}
|