Merge branch 'dev1'
diff --git a/src/main/java/net/onrc/onos/util/GraphDBOperation.java b/src/main/java/net/onrc/onos/util/GraphDBOperation.java
index a87d5f5..de4b8b4 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBOperation.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBOperation.java
@@ -24,9 +24,9 @@
 	public GraphDBOperation(GraphDBConnection dbConnection) {
 		this.conn = dbConnection;
 	}
-	
+
 	@Override
- 	public ISwitchObject newSwitch(String dpid) {
+	public ISwitchObject newSwitch(String dpid) {
 		FramedGraph<TitanGraph> fg = conn.getFramedGraph();	
 		ISwitchObject obj = fg.addVertex(null,ISwitchObject.class);
 		if (obj != null) {
@@ -37,57 +37,72 @@
 	}
 
 	@Override
-	public void removeSwitch(ISwitchObject sw) {
-		FramedGraph<TitanGraph> fg = conn.getFramedGraph();	
-		fg.removeVertex(sw.asVertex());		
-	}
-	
-	@Override
 	public ISwitchObject searchSwitch(String dpid) {
 		// TODO Auto-generated method stub
 		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
 		
 		return (fg != null && fg.getVertices("dpid",dpid).iterator().hasNext()) ? 
 				fg.getVertices("dpid",dpid,ISwitchObject.class).iterator().next() : null;
-    			
+				
 	}
 
 	@Override
-	public IDeviceObject searchDevice(String macAddr) {
-		// TODO Auto-generated method stub
-		FramedGraph<TitanGraph> fg = conn.getFramedGraph();	
-		return (fg != null && fg.getVertices("dl_address",macAddr).iterator().hasNext()) ? fg.getVertices("dl_address",macAddr,
-    			IDeviceObject.class).iterator().next() : null;
-    			
+	public ISwitchObject searchActiveSwitch(String dpid) {
+	
+	    ISwitchObject sw = searchSwitch(dpid);
+	    if ((sw != null) &&
+	        sw.getState().equals(SwitchState.ACTIVE.toString())) {
+	        return sw;
+	    }
+	    return null;
 	}
 
 	@Override
-	public IPortObject searchPort(String dpid, short number) {
-		ISwitchObject sw = searchSwitch(dpid);
-		if (sw != null) {
-			
-			IPortObject port = null;
-			
-			// Requires Frames 2.3.0
-			
-			try {
-				port = sw.getPort(number);
-			} catch (Exception e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
+	public Iterable<ISwitchObject> getAllSwitches() {
+		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+		Iterable<ISwitchObject> switches =  fg.getVertices("type","switch",ISwitchObject.class);
+		return switches;
+	}
+
+	@Override
+	public Iterable<ISwitchObject> getActiveSwitches() {
+		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+		Iterable<ISwitchObject> switches =  fg.getVertices("type","switch",ISwitchObject.class);
+		List<ISwitchObject> activeSwitches = new ArrayList<ISwitchObject>();
+	
+		for (ISwitchObject sw: switches) {
+			if(sw.getState().equals(SwitchState.ACTIVE.toString())) {
+				activeSwitches.add(sw);
 			}
-			
-			return port;
 		}
-		
-//		if (sw != null) {
-//			GremlinPipeline<Vertex, IPortObject> pipe = new GremlinPipeline<Vertex, IPortObject>();
-//			pipe.start(sw.asVertex());
-//			pipe.out("on").has("number", number);
-//			FramedVertexIterable<IPortObject> r = new FramedVertexIterable<IPortObject>(conn.getFramedGraph(), (Iterable) pipe, IPortObject.class);
-//			return r != null && r.iterator().hasNext() ? r.iterator().next() : null;
-//		}
-		return null;
+		return activeSwitches;
+	}
+
+	@Override
+	public Iterable<ISwitchObject> getInactiveSwitches() {
+		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+		Iterable<ISwitchObject> switches =  fg.getVertices("type","switch",ISwitchObject.class);
+		List<ISwitchObject> inactiveSwitches = new ArrayList<ISwitchObject>();
+	
+		for (ISwitchObject sw: switches) {
+			if(sw.getState().equals(SwitchState.INACTIVE.toString())) {
+				inactiveSwitches.add(sw);
+			}
+		}
+		return inactiveSwitches;
+	}
+
+	@Override
+	public Iterable<IFlowEntry> getAllSwitchNotUpdatedFlowEntries() {
+		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+		//TODO: Should use an enum for flow_switch_state
+		return fg.getVertices("switch_state", "FE_SWITCH_NOT_UPDATED", IFlowEntry.class);
+	}
+
+	@Override
+	public void removeSwitch(ISwitchObject sw) {
+		FramedGraph<TitanGraph> fg = conn.getFramedGraph();	
+		fg.removeVertex(sw.asVertex());		
 	}
 
 	@Override
@@ -100,7 +115,43 @@
 		}
 		return obj;
 	}
-	
+
+	@Override
+		public IPortObject searchPort(String dpid, short number) {
+			ISwitchObject sw = searchSwitch(dpid);
+			if (sw != null) {
+				
+				IPortObject port = null;
+				
+				// Requires Frames 2.3.0
+				
+				try {
+					port = sw.getPort(number);
+				} catch (Exception e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+				
+				return port;
+			}
+			
+	//		if (sw != null) {
+	//			GremlinPipeline<Vertex, IPortObject> pipe = new GremlinPipeline<Vertex, IPortObject>();
+	//			pipe.start(sw.asVertex());
+	//			pipe.out("on").has("number", number);
+	//			FramedVertexIterable<IPortObject> r = new FramedVertexIterable<IPortObject>(conn.getFramedGraph(), (Iterable) pipe, IPortObject.class);
+	//			return r != null && r.iterator().hasNext() ? r.iterator().next() : null;
+	//		}
+			return null;
+		}
+
+	@Override
+		public void removePort(IPortObject port) {
+			FramedGraph<TitanGraph> fg = conn.getFramedGraph();	
+	//		EventGraph<TitanGraph> eg = conn.getEventGraph();
+			if (fg != null) fg.removeVertex(port.asVertex());		
+		}
+
 	@Override
 	public IDeviceObject newDevice() {
 		FramedGraph<TitanGraph> fg = conn.getFramedGraph();	
@@ -108,18 +159,14 @@
 		if (obj != null) obj.setType("device");
 		return obj;
 	}
-	
-	@Override
-	public void removePort(IPortObject port) {
-		FramedGraph<TitanGraph> fg = conn.getFramedGraph();	
-//		EventGraph<TitanGraph> eg = conn.getEventGraph();
-		if (fg != null) fg.removeVertex(port.asVertex());		
-	}
 
 	@Override
-	public void removeDevice(IDeviceObject dev) {
+	public IDeviceObject searchDevice(String macAddr) {
+		// TODO Auto-generated method stub
 		FramedGraph<TitanGraph> fg = conn.getFramedGraph();	
-		if (fg != null) fg.removeVertex(dev.asVertex());		
+		return (fg != null && fg.getVertices("dl_address",macAddr).iterator().hasNext()) ? fg.getVertices("dl_address",macAddr,
+    			IDeviceObject.class).iterator().next() : null;
+    			
 	}
 
 	@Override
@@ -129,12 +176,9 @@
 	}
 
 	@Override
-	public IFlowPath searchFlowPath(FlowId flowId) {
-		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
-		
-		return fg.getVertices("flow_id", flowId.toString()).iterator().hasNext() ? 
-		    fg.getVertices("flow_id", flowId.toString(),
-				   IFlowPath.class).iterator().next() : null;
+	public void removeDevice(IDeviceObject dev) {
+		FramedGraph<TitanGraph> fg = conn.getFramedGraph();	
+		if (fg != null) fg.removeVertex(dev.asVertex());		
 	}
 
 	@Override
@@ -146,9 +190,12 @@
 	}
 
 	@Override
-	public void removeFlowPath(IFlowPath flowPath) {
+	public IFlowPath searchFlowPath(FlowId flowId) {
 		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
-		fg.removeVertex(flowPath.asVertex());
+		
+		return fg.getVertices("flow_id", flowId.toString()).iterator().hasNext() ? 
+		    fg.getVertices("flow_id", flowId.toString(),
+				   IFlowPath.class).iterator().next() : null;
 	}
 
 	@Override
@@ -177,12 +224,9 @@
 	}
 
 	@Override
-	public IFlowEntry searchFlowEntry(FlowEntryId flowEntryId) {
+	public void removeFlowPath(IFlowPath flowPath) {
 		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
-		
-		return fg.getVertices("flow_entry_id", flowEntryId.toString()).iterator().hasNext() ? 
-		    fg.getVertices("flow_entry_id", flowEntryId.toString(),
-				   IFlowEntry.class).iterator().next() : null;
+		fg.removeVertex(flowPath.asVertex());
 	}
 
 	@Override
@@ -194,9 +238,12 @@
 	}
 
 	@Override
-	public void removeFlowEntry(IFlowEntry flowEntry) {
+	public IFlowEntry searchFlowEntry(FlowEntryId flowEntryId) {
 		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
-		fg.removeVertex(flowEntry.asVertex());
+		
+		return fg.getVertices("flow_entry_id", flowEntryId.toString()).iterator().hasNext() ? 
+		    fg.getVertices("flow_entry_id", flowEntryId.toString(),
+				   IFlowEntry.class).iterator().next() : null;
 	}
 
 	@Override
@@ -205,57 +252,10 @@
 		
 		return fg.getVertices("type", "flow_entry", IFlowEntry.class);
 	}
-	
+
 	@Override
-	public Iterable<IFlowEntry> getAllSwitchNotUpdatedFlowEntries() {
+	public void removeFlowEntry(IFlowEntry flowEntry) {
 		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
-		//TODO: Should use an enum for flow_switch_state
-		return fg.getVertices("switch_state", "FE_SWITCH_NOT_UPDATED", IFlowEntry.class);
-	}
-
-	@Override
-	public Iterable<ISwitchObject> getActiveSwitches() {
-		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
-		Iterable<ISwitchObject> switches =  fg.getVertices("type","switch",ISwitchObject.class);
-		List<ISwitchObject> activeSwitches = new ArrayList<ISwitchObject>();
-
-		for (ISwitchObject sw: switches) {
-			if(sw.getState().equals(SwitchState.ACTIVE.toString())) {
-				activeSwitches.add(sw);
-			}
-		}
-		return activeSwitches;
-	}
-
-	@Override
-	public Iterable<ISwitchObject> getAllSwitches() {
-		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
-		Iterable<ISwitchObject> switches =  fg.getVertices("type","switch",ISwitchObject.class);
-		return switches;
-	}
-
-	@Override
-	public Iterable<ISwitchObject> getInactiveSwitches() {
-		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
-		Iterable<ISwitchObject> switches =  fg.getVertices("type","switch",ISwitchObject.class);
-		List<ISwitchObject> inactiveSwitches = new ArrayList<ISwitchObject>();
-
-		for (ISwitchObject sw: switches) {
-			if(sw.getState().equals(SwitchState.INACTIVE.toString())) {
-				inactiveSwitches.add(sw);
-			}
-		}
-		return inactiveSwitches;
-	}
-
-	@Override
-	public ISwitchObject searchActiveSwitch(String dpid) {
-
-        ISwitchObject sw = searchSwitch(dpid);
-        if ((sw != null) &&
-            sw.getState().equals(SwitchState.ACTIVE.toString())) {
-            return sw;
-        }
-        return null;
+		fg.removeVertex(flowEntry.asVertex());
 	}
 }