package edu.calpoly.cpe205.fetter; import javax.swing.*; import java.util.*; import java.io.*; import java.lang.reflect.*; import java.lang.*; import java.awt.*; import javax.swing.event.*; import java.awt.event.*; import java.sql.Time; /** * This class represents a field (fields can be found in the Main Test Class, * a Test Data Item of Object type, and in Returned Objects). It provides * methods that give information on the field's type, name, and value. * It also provides methods to set the value of the field. */ // Author: Phillip Hansen // Version History: // Nov 19, 2000 - comments/pseudocode added // Nov 29, 2000 - added code for some methods // Nov 30, 2000 - (Michael Hebron) updated class description // Feb 07, 2001 - (Apel Yahinian) Updated constructor, created model protected value // Feb 13, 2001 - (Jonathon Lee) Added pseudocode for setValue() public class FieldData implements FieldDataInterface { /** * Creates a new instance of FieldData with a Field object *
* Pre-conditions: none * Post-conditions: data has been initialized * @param wrap Field to initialize wrapped with */ public FieldData(Field wrap, ETAMainModel newModel) { // SET wrapped to wrap // SET model to newModel wrapped = wrap; model = newModel; } /** * returns the name of the class that this field is declared in *
* Pre-conditions: none
* Post-conditions: none
* @return String containing the name of the class the field is declared in
*/
public String getDeclaringClass()
{
// CALL getDeclaringClass of wrapped
// CALL classToName of ETAMainModel on returned class
// RETURN the string returned from the classToName call
return ETAMainModel.classToName(wrapped.getDeclaringClass());
}
/**
* updates the value of the field
*
* Pre-conditions: none
* Post-conditions: none
*/
public void updateValue()
{
// TRY
// CALL getMainTestObject on ETAMainModel retuns main
// CALL get on wrapped with the main returns getField
// CALL getName on wrapped returns nameString
// CALL addParameterData on model with getField and nameString
// ENDTRY
// CATCH IllegalAccessException exc
// CALL println of err in ETA with "Sorry ETA was not allowed to
// access this field."
// CALL printStackTrace of exc with err of ETA
// ENDCATCH
try
{
model.addParameterData(wrapped.get(model.getMainTestObject()),
wrapped.getName());
ETA.log.println("[" + (new Time(System.currentTimeMillis())).
toString().substring(0,5) + "] Get Field Value - " +
wrapped.getName());
}
catch(IllegalAccessException exc)
{
ETA.err.println("Sorry ETA was not allowed to acces this field");
exc.printStackTrace(ETA.err);
}
}
/**
* returns the modifiers of the field
*
* Pre-conditions: none
* Post-conditions: none
* @return int containing the modifiers
*/
public int getModifiers()
{
// CALL getModifiers of wrapped
// RETURN the integer returned from the getModifiers call
return wrapped.getModifiers();
}
/**
* creates a primitive object and adds it to the parameter data pool
*
* Pre-conditions: val is a primitive
* Post-conditions: none
* @param val value to be created and added to the parameter data pool
*/
public void createPrimitive(String val)
{
// CALL getValue of PrimitiveValueFactory with val
// INIT tempString
// SET tempString equal to "user created "
// CALL getClass on the object that was returned from the PrimitiveValueFactory
// CALL classToName of ETAMainModel with returned class
// SET tempString equal to tempString and the string returned from classToName
// CALL getNumber of ETAMainModel
// SET tempString equal to tempString and the number returned from ETAMainModel
// CALL addParameterData of ETAMainModel with the object that was returned from the PrimitiveValueFactory and tempString
}
/**
* sets the value of the Field object
*
* Pre-conditions: none
* Post-conditions: none
* @param data ParameterDataInterface to be used in setting the field
*/
public void setValue(ParameterDataInterface data)
{
// CALL getValueObject on data returns valueObject
// CALL getMainTestObject on model returns object
// TRY
// CALL set on wrapped with valueObject and object
// ENDTRY
// CATCH IllegalArgumentException exc
// CALL printStackTrace on exc with err of ETA
// ENDCATCH
// CATCH IllegalAccessException exc
// CALL println of err in ETA with "Sorry ETA was not allowed to
// access this field."
// CALL printStackTrace of exc with err of ETA
// ENDCATCH
try
{
wrapped.set(model.getMainTestObject(),
((ParameterData) data).getValueObject());
ETA.log.println("[" + (new Time(System.currentTimeMillis())).
toString().substring(0,5) + "] Set Field Value - " +
wrapped.getName() + " to " + data.getDescriptiveName());
}
catch(IllegalArgumentException exc)
{
exc.printStackTrace(ETA.err);
}
catch(IllegalAccessException exc)
{
ETA.err.println("Sorry ETA was not allowed to acces this field");
exc.printStackTrace(ETA.err);
}
}
/**
* returns the type of the field
*
* Pre-conditions: none
* Post-conditions: none
* @return String containing the type of the field object
*/
public String getType()
{
// CALL getType of wrapped
// CALL getName of the returned class
// RETURN the string returned from getName
return ETAMainModel.classToName(wrapped.getType());
}
/**
* returns the name of the field
*
* Pre-conditions: none
* Post-conditions: none
* @return String containing the name of the field
*/
public String getName()
{
// CALL getName of wrapped
// RETURN the string returned from the getName call
return wrapped.getName();
}
/**
* field data object
*/
protected Field wrapped;
/**
* etamainmodel model
*/
protected ETAMainModel model;
}