2 x * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Modifications copyright (C) 2017 AT&T Intellectual Property. All rights
10 * ================================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 * ============LICENSE_END=========================================================
25 package org.onap.ccsdk.sli.core.sli;
27 import java.io.PrintStream;
28 import java.io.Serializable;
29 import java.util.HashMap;
32 public class SvcLogicGraph implements Serializable {
37 private static final long serialVersionUID = 1L;
39 private String module = null;
40 private String rpc = null;
41 private String mode = null;
42 private String version = null;
44 private String md5sum = null;
46 private Map<String, Serializable> attributes;
47 private Map<String, SvcLogicNode> namedNodes;
48 private SvcLogicNode rootNode;
50 public SvcLogicGraph()
52 attributes = new HashMap<>();
53 namedNodes = new HashMap<>();
57 public String getMd5sum() {
62 public void setMd5sum(String md5sum) {
68 public String getModule() {
73 public void setModule(String module) {
78 public String getRpc() {
83 public void setRpc(String rpc) {
90 public String getMode() {
95 public void setMode(String mode) {
100 public String getVersion() {
105 public void setVersion(String version) {
106 this.version = version;
110 public void setRootNode(SvcLogicNode rootNode)
112 this.rootNode = rootNode;
115 public SvcLogicNode getRootNode()
120 public Serializable getAttribute(String name)
122 if (attributes.containsKey(name))
124 return(attributes.get(name));
133 public void setAttribute(String name, Serializable value) throws DuplicateValueException
135 if (attributes.containsKey(name))
137 throw new DuplicateValueException("Duplicate attribute "+name);
140 attributes.put(name, value);
143 public SvcLogicNode getNamedNode(String nodeName)
145 if (namedNodes.containsKey(nodeName))
147 return(namedNodes.get(nodeName));
155 public void setNamedNode(String nodeName, SvcLogicNode node) throws DuplicateValueException
157 if (namedNodes.containsKey(nodeName))
159 throw new DuplicateValueException("Duplicate node name "+nodeName);
162 namedNodes.put(nodeName, node);
167 public void printAsGv(PrintStream pstr)
169 pstr.println("digraph g {");
170 pstr.println("START [label=\"START\\n"+module+":"+rpc+"\"];");
172 if (rootNode != null)
174 pstr.println("START -> node"+rootNode.getNodeId()+";");
175 rootNode.setVisited(false, true);
176 rootNode.printAsGv(pstr);
181 public void printAsXml(PrintStream pstr)
183 pstr.println("<service-logic module='"+getModule()+"' version='"+getVersion()+"'>");
184 pstr.println(" <method rpc='"+getRpc()+"' mode='"+getMode()+"'>");
185 if (rootNode != null)
187 rootNode.setVisited(false, true);
188 rootNode.printAsXml(pstr, 2);
190 pstr.println(" </method>");
191 pstr.println("</service-logic>");
195 public String toString() {
196 return "SvcLogicGraph [module=" + module + ", rpc=" + rpc + ", mode=" + mode + ", version=" + version + ", md5sum=" + md5sum + "]";