use of oms3.Notification.DataflowEvent in project hortonmachine by TheHortonMachine.
the class Efficiency method setup.
public void setup(Object comp) {
if (obs == null || sim == null) {
throw new ComponentException("obs/sim variable not set.");
}
if (comp instanceof Compound) {
Compound c = (Compound) comp;
c.addListener(new Listener() {
@Override
public void notice(Type T, EventObject E) {
if (T == Type.OUT) {
DataflowEvent e = (DataflowEvent) E;
if (e.getAccess().getField().getName().equals(obs)) {
if (obs_idx == null) {
obs_l.add((Number) e.getValue());
} else {
obs_l.add((Number) Util.accessArray(obs, e.getValue(), obs_idx));
}
} else if (e.getAccess().getField().getName().equals(sim)) {
// TODO use arrays here too.
sim_l.add((Number) e.getValue());
}
if (e.getAccess().getField().getName().equals(precip)) {
precip_l.add((Number) e.getValue());
}
// System.err.println(E.getAccess().getField().getName() + "/" +
// E.getComponent().getClass().getName() + E.getValue());
}
}
});
}
}
use of oms3.Notification.DataflowEvent in project hortonmachine by TheHortonMachine.
the class FieldAccess method in.
/**
* a field is receiving a new value (in)
*
* @throws java.lang.Exception
*/
@Override
public void in() throws Exception {
if (data == null) {
// throw new ComponentException("Not connected: " + toString());
if (log.isLoggable(Level.WARNING)) {
log.warning("@In not connected : " + toString() + ", using default value.");
}
return;
}
Object val = data.getValue();
// fire only if there is a listener
if (ens.shouldFire()) {
DataflowEvent e = new DataflowEvent(ens.getController(), this, val);
// DataflowEvent e = new DataflowEvent(ens.getController(), this, access.toObject());
ens.fireIn(e);
// the value might be altered
val = e.getValue();
}
if (val != null && field.getType() != val.getClass() && !field.getType().isAssignableFrom(val.getClass())) {
// // default type conversion fails, we need to convert.
// // this will use the Conversions SPI.
val = Conversions.convert(val, field.getType());
}
// access.pass((Access) val);
setFieldValue(val);
}
use of oms3.Notification.DataflowEvent in project hortonmachine by TheHortonMachine.
the class FieldObjectAccess method out.
/**
* a field is sending a new value (out)
*
* @throws java.lang.Exception
*/
@Override
public void out() throws Exception {
Object val = fa.getFieldValue();
if (ens.shouldFire()) {
DataflowEvent e = new DataflowEvent(ens.getController(), this, val);
// // DataflowEvent e = new DataflowEvent(ens.getController(), this, access.toObject());
ens.fireOut(e);
// // the value might be altered
val = e.getValue();
}
// if data==null this unconsumed @Out, its OK but we do not want to set it.
if (data != null) {
data.setFieldValue(val);
}
fa.out();
}
use of oms3.Notification.DataflowEvent in project hortonmachine by TheHortonMachine.
the class FieldAccess method out.
/**
* a field is sending a new value (out)
*
* @return the object value in out
* @throws java.lang.Exception
*/
@Override
public void out() throws Exception {
Object val = getFieldValue();
if (ens.shouldFire()) {
DataflowEvent e = new DataflowEvent(ens.getController(), this, val);
// DataflowEvent e = new DataflowEvent(ens.getController(), this, access.toObject());
ens.fireOut(e);
// the value might be altered
val = e.getValue();
}
// if data==null this unconsumed @Out, its OK but we do not want to set it.
if (data != null) {
data.setValue(val);
}
}
use of oms3.Notification.DataflowEvent in project hortonmachine by TheHortonMachine.
the class FieldObjectAccess method in.
// boolean canConnect(FieldObjectAccess other) {
// return other.field.getType().isAssignableFrom(field.getType());
// }
/**
* a field is receiving a new value (in)
*
* @throws java.lang.Exception
*/
@Override
public void in() throws Exception {
if (data == null) {
throw new ComponentException("Not connected: " + toString());
}
Object val = data.getFieldValue();
// fire only if there is a listener
if (ens.shouldFire()) {
DataflowEvent e = new DataflowEvent(ens.getController(), this, val);
// // DataflowEvent e = new DataflowEvent(ens.getController(), this, access.toObject());
ens.fireIn(e);
// // the value might be altered
val = e.getValue();
}
// access.pass((Access) val);
fa.setFieldValue(val);
}
Aggregations