comparison app/models/NodeModel.java @ 4:e12d0b6dbe02 draft default tip

add some files
author e085711
date Wed, 26 Sep 2012 14:43:57 +0900
parents
children
comparison
equal deleted inserted replaced
3:5a097a2336fa 4:e12d0b6dbe02
1 package models;
2
3 import java.util.HashMap;
4 import java.util.Iterator;
5
6 import org.json.JSONException;
7 import org.json.JSONObject;
8
9 import com.tinkerpop.blueprints.Vertex;
10
11 public class NodeModel {
12
13 private Vertex vertex;
14 private Object id;
15 final String NODE_TYPE = "nodeType";
16
17 JSONObject properties = new JSONObject();
18
19 public NodeModel(Vertex vertex) {
20 this.vertex = vertex;
21 this.id = vertex.getId();
22 }
23
24 public JSONObject getProperties() throws JSONException {
25 for (String key: vertex.getPropertyKeys() ) {
26 properties.put(key, vertex.getProperty(key));
27 }
28 return properties;
29 }
30
31 public void setId(Object id) {
32 this.id = id;
33 }
34
35 public Object getId() {
36 return this.id;
37 }
38
39 public Vertex getVertex() {
40 return this.vertex;
41 }
42
43 public void setProperty(String key, Object value) throws JSONException {
44 properties.put(key, value);
45 }
46
47 public void setPropetiesFromJson(JSONObject jobj) throws JSONException {
48 Iterator<String> iter = jobj.keys();
49 for (String key=iter.next(); iter.hasNext(); key=iter.next()) {
50 this.setProperty(key, jobj.get(key));
51 }
52 }
53
54 public JSONObject getNodeJson() throws JSONException {
55 JSONObject jobj = new JSONObject();
56 jobj.put("id",this.id);
57 jobj.put("data", this.properties);
58 return jobj;
59 }
60
61
62 }