Mercurial > hg > Members > nobuyasu > TOModel
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/models/NodeModel.java Wed Sep 26 14:43:57 2012 +0900 @@ -0,0 +1,62 @@ +package models; + +import java.util.HashMap; +import java.util.Iterator; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.tinkerpop.blueprints.Vertex; + +public class NodeModel { + + private Vertex vertex; + private Object id; + final String NODE_TYPE = "nodeType"; + + JSONObject properties = new JSONObject(); + + public NodeModel(Vertex vertex) { + this.vertex = vertex; + this.id = vertex.getId(); + } + + public JSONObject getProperties() throws JSONException { + for (String key: vertex.getPropertyKeys() ) { + properties.put(key, vertex.getProperty(key)); + } + return properties; + } + + public void setId(Object id) { + this.id = id; + } + + public Object getId() { + return this.id; + } + + public Vertex getVertex() { + return this.vertex; + } + + public void setProperty(String key, Object value) throws JSONException { + properties.put(key, value); + } + + public void setPropetiesFromJson(JSONObject jobj) throws JSONException { + Iterator<String> iter = jobj.keys(); + for (String key=iter.next(); iter.hasNext(); key=iter.next()) { + this.setProperty(key, jobj.get(key)); + } + } + + public JSONObject getNodeJson() throws JSONException { + JSONObject jobj = new JSONObject(); + jobj.put("id",this.id); + jobj.put("data", this.properties); + return jobj; + } + + +}