DataModel
The DataModel is a placeholder for the beans to store data, and to share data across beans. Any bean can get the DataModel from the IHWMFrameWork handle.
import com.altair.hwm.datamodel;
IHWMDataModel hwmDataModel = m_hwmFrameWork.GetDataModel();
The beans can store and retrieve any data into or from the DataModel. Any stored data must be given a name so that it can be retrieved using that name.
/**
* The main function wherein, something will be done when the
* button is pressed
*/
public void DoSomething()
IHWMDataModel hwmDataModel = m_hwmFrameWork.GetDataModel();
double dMeshSize = 10.37;
hwmDataModel.SetProperty("Mesh Size", new Double(dMeshSize));
double dMeshSizeRetrieved =
((Double)hwmDataModel.GetProperty("Mesh Size")).doubleValue();
MYTest myTest = new MYTest();
myTest.PopulateData();
hwmDataModel.SetProperty("My Test Data", myTest);
MYTest myTestRetrieved =
(MYTest)hwmDataModel.GetProperty("My Test Data");
hwmDataModel.SetPropertyAsTransient("My TestData", true);
}
When any property is set for a bean, the DataModel fires an event. Other beans can be added as listeners to these properties.
/**
* This method is called by the HWPM engine to set the interface with
* which a bean can communicate directly with the HWPM classes.
* @param hwmFrameWork The interface with which a bean can
* communicate with HWPM.
*/
public void SetFrameWork(IHWMFrameWork hwmFrameWork)
m_hwmFrameWork = hwmFrameWork;
IHWMDataModel hwmDataModel = m_hwmFrameWork.GetDataModel();
// Add self as listener to any datamodel property change
hwmDataModel.addPropertyChangeListener(this);
// Add self as listener to a specific datamodel property change.
// Assume some other bean is generating this info
hwmDataModel.addPropertyChangeListener(this, "TEMPERATURE");
}
The DataModel persists any information that is placed in it (unless it is specified as transient).
It is possible for a developer to write their own class and place an instance of that class in the DataModel. For the DataModel to persist the information of that instance, that class must implement either Externalizable or Serializable. Externalizable is recommended since Java does not guarantee downward compatibility of serialized classes.
If two instances of the same bean in the same process both save similar data (MESH_SIZE, for example) in the DataModel, and both instances call their data as MESH_SIZE, the data of one will be overwritten by the data of the other. To avoid this problem, you can prefix/namespace the data name with the name of the bean instance (the name of the bean instance was passed on to the bean instance by the Process Manager engine).
hwmDataModel.SetProperty(
m_strBeanName+"::MESH_SIZE", new Double(dMeshSize));