PageRenderTime 16ms CodeModel.GetById 13ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/hippo/src/main/java/com/googlecode/hdbc/view/policy/ActiveExperimentsOutputPolicy.java

http://hdbc.googlecode.com/
Java | 35 lines | 23 code | 8 blank | 4 comment | 1 complexity | 7deec39fccdd332bbe664b50193b6507 MD5 | raw file
 1package com.googlecode.hdbc.view.policy;
 2
 3import java.util.List;
 4import java.util.Map;
 5
 6import net.sf.json.JSONArray;
 7import net.sf.json.JSONObject;
 8
 9import com.googlecode.hdbc.controller.ModelAttributes;
10import com.googlecode.hdbc.model.record.ExperimentData;
11import com.googlecode.hdbc.view.JsonKeys;
12
13/**
14 * Creates a view string of the form 
15 * {data: [{ExperimentData.toJson()}, {...}, ...]}
16 */
17public class ActiveExperimentsOutputPolicy implements ICustomOutputPolicy {
18
19	@SuppressWarnings("unchecked")
20	@Override
21	public Map<String, Object> customOutput(Map<String, Object> model) {
22		List<ExperimentData> experiments = (List<ExperimentData>) model.get(ModelAttributes.COLLECTION);
23		
24		JSONArray array = new JSONArray();
25		for (ExperimentData experiment : experiments) {
26			JSONObject elmnt = experiment.toJson();
27			array.add(elmnt);
28		}
29		
30		JSONObject jsn = new JSONObject();
31		jsn.put(JsonKeys.data, array);
32		return jsn;
33	}
34
35}