2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.connector.remoterpc.dto;
10 import java.io.Serializable;
13 import com.fasterxml.jackson.databind.JsonNode;
14 import com.fasterxml.jackson.databind.ObjectMapper;
15 import org.opendaylight.controller.sal.connector.api.RpcRouter;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
19 public class RouteIdentifierImpl implements RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier>,Serializable {
21 transient ObjectMapper mapper = new ObjectMapper();
23 private QName context;
25 private InstanceIdentifier route;
28 public QName getContext() {
33 public QName getType() {
38 public InstanceIdentifier getRoute() {
42 public void setContext(QName context) {
43 this.context = context;
46 public void setType(QName type) {
50 public void setRoute(InstanceIdentifier route) {
55 public String toString() {
57 return mapper.writeValueAsString(this);
58 } catch (Throwable e) {
62 return super.toString();
65 public RpcRouter.RouteIdentifier fromString(String input)
68 JsonNode root = mapper.readTree(input);
69 this.context = parseQName(root.get("context"));
70 this.type = parseQName(root.get("type"));
75 private QName parseQName(JsonNode node){
76 if (node == null) return null;
78 String namespace = (node.get("namespace") != null) ?
79 node.get("namespace").asText() : "";
81 String localName = (node.get("localName") != null) ?
82 node.get("localName").asText() : "";
84 URI uri = URI.create(namespace);
85 return new QName(uri, localName);