4028a9d31bfe093456289cd26b17661792057695
[jalview.git] / src / jalview / json / binding / v1 / BioJSRepositoryPojo.java
1 package jalview.json.binding.v1;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Iterator;
6
7 import org.json.simple.JSONArray;
8 import org.json.simple.JSONObject;
9 import org.json.simple.parser.JSONParser;
10 import org.json.simple.parser.ParseException;
11
12 public class BioJSRepositoryPojo
13 {
14
15   private String description;
16
17   private String latestReleaseVersion;
18
19   private Collection<BioJSReleasePojo> releases = new ArrayList<BioJSReleasePojo>();
20
21   public BioJSRepositoryPojo()
22   {
23   }
24
25   public BioJSRepositoryPojo(String jsonString)
26   {
27     try
28     {
29       parse(jsonString);
30     } catch (ParseException e)
31     {
32       e.printStackTrace();
33     }
34   }
35
36   @SuppressWarnings("unchecked")
37   private void parse(String jsonString) throws ParseException
38   {
39     JSONParser jsonParser = new JSONParser();
40     JSONObject JsonObj = (JSONObject) jsonParser.parse(jsonString);
41     this.description = (String) JsonObj.get("description");
42     this.latestReleaseVersion = (String) JsonObj
43             .get("latestReleaseVersion");
44
45     JSONArray repositoriesJsonArray = (JSONArray) JsonObj
46 .get("releases");
47     for (Iterator<JSONObject> repoIter = repositoriesJsonArray.iterator(); repoIter
48             .hasNext();)
49     {
50       JSONObject repoObj = repoIter.next();
51       BioJSReleasePojo repo = new BioJSReleasePojo();
52       repo.setType((String) repoObj.get("type"));
53       repo.setUrl((String) repoObj.get("url"));
54       repo.setVersion((String) repoObj.get("version"));
55       this.getReleases().add(repo);
56     }
57   }
58
59   public String getDescription()
60   {
61     return description;
62   }
63
64   public void setDescription(String description)
65   {
66     this.description = description;
67   }
68
69
70   public String getLatestReleaseVersion()
71   {
72     return latestReleaseVersion;
73   }
74
75   public void setLatestReleaseVersion(String latestReleaseVersion)
76   {
77     this.latestReleaseVersion = latestReleaseVersion;
78   }
79
80   public Collection<BioJSReleasePojo> getReleases()
81   {
82     return releases;
83   }
84
85   public void setReleases(Collection<BioJSReleasePojo> releases)
86   {
87     this.releases = releases;
88   }
89
90 }