2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.sli.core.sli;
23 import java.io.PrintStream;
24 import java.io.Serializable;
25 import java.util.HashMap;
28 public class SvcLogicGraph implements Serializable {
33 private static final long serialVersionUID = 1L;
35 private String module = null;
36 private String rpc = null;
37 private String mode = null;
38 private String version = null;
40 private Map<String, Serializable> attributes;
41 private Map<String, SvcLogicNode> namedNodes;
42 private SvcLogicNode rootNode;
44 public SvcLogicGraph()
46 attributes = new HashMap<String, Serializable>();
47 namedNodes = new HashMap<String, SvcLogicNode>();
52 public String getModule() {
57 public void setModule(String module) {
62 public String getRpc() {
67 public void setRpc(String rpc) {
74 public String getMode() {
79 public void setMode(String mode) {
84 public String getVersion() {
89 public void setVersion(String version) {
90 this.version = version;
94 public void setRootNode(SvcLogicNode rootNode)
96 this.rootNode = rootNode;
99 public SvcLogicNode getRootNode()
104 public Serializable getAttribute(String name)
106 if (attributes.containsKey(name))
108 return(attributes.get(name));
117 public void setAttribute(String name, Serializable value) throws DuplicateValueException
119 if (attributes.containsKey(name))
121 throw new DuplicateValueException("Duplicate attribute "+name);
124 attributes.put(name, value);
127 public SvcLogicNode getNamedNode(String nodeName)
129 if (namedNodes.containsKey(nodeName))
131 return(namedNodes.get(nodeName));
139 public void setNamedNode(String nodeName, SvcLogicNode node) throws DuplicateValueException
141 if (namedNodes.containsKey(nodeName))
143 throw new DuplicateValueException("Duplicate node name "+nodeName);
146 namedNodes.put(nodeName, node);
151 public void printAsGv(PrintStream pstr)
153 pstr.println("digraph g {");
154 pstr.println("START [label=\"START\\n"+module+":"+rpc+"\"];");
156 if (rootNode != null)
158 pstr.println("START -> node"+rootNode.getNodeId()+";");
159 rootNode.setVisited(false, true);
160 rootNode.printAsGv(pstr);
165 public void printAsXml(PrintStream pstr)
167 pstr.println("<service-logic module='"+getModule()+"' version='"+getVersion()+"'>");
168 pstr.println(" <method rpc='"+getRpc()+"' mode='"+getMode()+"'>");
169 if (rootNode != null)
171 rootNode.setVisited(false, true);
172 rootNode.printAsXml(pstr, 2);
174 pstr.println(" </method>");
175 pstr.println("</service-logic>");
179 public String toString() {
180 return "SvcLogicGraph [module=" + module + ", rpc=" + rpc + ", mode=" + mode + ", version=" + version + "]";