}
public JSONObject call() throws RpcException {
try {
Gadget gadget = processor.process(context);
GadgetSpec spec = gadget.getSpec();
JSONObject gadgetJson = new JSONObject();
ModulePrefs prefs = spec.getModulePrefs();
// TODO: modularize response fields based on requested items.
JSONObject views = new JSONObject();
for (View view : spec.getViews().values()) {
views.put(view.getName(), new JSONObject()
// .put("content", view.getContent())
.put("type", view.getType().toString())
.put("quirks", view.getQuirks())
.put("preferredHeight", view.getPreferredHeight())
.put("preferredWidth", view.getPreferredWidth()));
}
// Features.
Set<String> feats = prefs.getFeatures().keySet();
String[] features = feats.toArray(new String[feats.size()]);
// Links
JSONObject links = new JSONObject();
for (LinkSpec link : prefs.getLinks().values()) {
links.put(link.getRel(), link.getHref());
}
JSONObject userPrefs = new JSONObject();
// User pref specs
for (UserPref pref : spec.getUserPrefs()) {
JSONObject up = new JSONObject()
.put("displayName", pref.getDisplayName())
.put("type", pref.getDataType().toString().toLowerCase())
.put("default", pref.getDefaultValue())
.put("enumValues", pref.getEnumValues())