2010-02-03 03:29:47 +01:00
|
|
|
package com.metaweb.gridworks.model;
|
2010-01-24 22:09:50 +01:00
|
|
|
|
2010-01-25 23:51:25 +01:00
|
|
|
import java.io.Serializable;
|
2010-01-27 02:48:42 +01:00
|
|
|
import java.util.Properties;
|
2010-01-25 23:51:25 +01:00
|
|
|
|
|
|
|
import org.json.JSONException;
|
2010-02-01 20:16:09 +01:00
|
|
|
import org.json.JSONWriter;
|
2010-01-25 23:51:25 +01:00
|
|
|
|
2010-02-03 03:29:47 +01:00
|
|
|
import com.metaweb.gridworks.Jsonizable;
|
2010-03-01 01:21:13 +01:00
|
|
|
import com.metaweb.gridworks.expr.EvalError;
|
|
|
|
import com.metaweb.gridworks.expr.ExpressionUtils;
|
2010-02-03 03:29:47 +01:00
|
|
|
import com.metaweb.gridworks.expr.HasFields;
|
2010-01-27 02:48:42 +01:00
|
|
|
|
2010-02-01 20:16:09 +01:00
|
|
|
public class Cell implements Serializable, HasFields, Jsonizable {
|
2010-03-03 05:19:58 +01:00
|
|
|
private static final long serialVersionUID = -5891067829205458102L;
|
|
|
|
|
|
|
|
final public Object value;
|
|
|
|
final public Recon recon;
|
|
|
|
|
|
|
|
public Cell(Object value, Recon recon) {
|
|
|
|
this.value = value;
|
|
|
|
this.recon = recon;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object getField(String name, Properties bindings) {
|
|
|
|
if ("value".equals(name)) {
|
|
|
|
return value;
|
|
|
|
} else if ("recon".equals(name)) {
|
|
|
|
return recon;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2010-02-01 20:16:09 +01:00
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
public void write(JSONWriter writer, Properties options) throws JSONException {
|
|
|
|
writer.object();
|
|
|
|
if (ExpressionUtils.isError(value)) {
|
2010-03-01 01:21:13 +01:00
|
|
|
writer.key("e");
|
|
|
|
writer.value(((EvalError) value).message);
|
2010-03-03 05:19:58 +01:00
|
|
|
} else {
|
|
|
|
writer.key("v");
|
|
|
|
writer.value(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recon != null) {
|
|
|
|
writer.key("r");
|
|
|
|
recon.write(writer, options);
|
|
|
|
}
|
|
|
|
writer.endObject();
|
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|