2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdnc.sli;
24 import java.io.PrintStream;
25 import java.io.Serializable;
26 import java.util.HashMap;
29 public class SvcLogicGraph implements Serializable {
34 private static final long serialVersionUID = 1L;
36 private String module = null;
37 private String rpc = null;
38 private String mode = null;
39 private String version = null;
41 private Map<String, Serializable> attributes;
42 private Map<String, SvcLogicNode> namedNodes;
43 private SvcLogicNode rootNode;
45 public SvcLogicGraph()
47 attributes = new HashMap<String, Serializable>();
48 namedNodes = new HashMap<String, SvcLogicNode>();
53 public String getModule() {
58 public void setModule(String module) {
63 public String getRpc() {
68 public void setRpc(String rpc) {
75 public String getMode() {
80 public void setMode(String mode) {
85 public String getVersion() {
90 public void setVersion(String version) {
91 this.version = version;
95 public void setRootNode(SvcLogicNode rootNode)
97 this.rootNode = rootNode;
100 public SvcLogicNode getRootNode()
105 public Serializable getAttribute(String name)
107 if (attributes.containsKey(name))
109 return(attributes.get(name));
118 public void setAttribute(String name, Serializable value) throws DuplicateValueException
120 if (attributes.containsKey(name))
122 throw new DuplicateValueException("Duplicate attribute "+name);
125 attributes.put(name, value);
128 public SvcLogicNode getNamedNode(String nodeName)
130 if (namedNodes.containsKey(nodeName))
132 return(namedNodes.get(nodeName));
140 public void setNamedNode(String nodeName, SvcLogicNode node) throws DuplicateValueException
142 if (namedNodes.containsKey(nodeName))
144 throw new DuplicateValueException("Duplicate node name "+nodeName);
147 namedNodes.put(nodeName, node);
152 public void printAsGv(PrintStream pstr)
154 pstr.println("digraph g {");
155 pstr.println("START [label=\"START\\n"+module+":"+rpc+"\"];");
157 if (rootNode != null)
159 pstr.println("START -> node"+rootNode.getNodeId()+";");
160 rootNode.setVisited(false, true);
161 rootNode.printAsGv(pstr);
166 public void printAsXml(PrintStream pstr)
168 pstr.println("<service-logic module='"+getModule()+"' version='"+getVersion()+"'>");
169 pstr.println(" <method rpc='"+getRpc()+"' mode='"+getMode()+"'>");
170 if (rootNode != null)
172 rootNode.setVisited(false, true);
173 rootNode.printAsXml(pstr, 2);
175 pstr.println(" </method>");
176 pstr.println("</service-logic>");
180 public String toString() {
181 return "SvcLogicGraph [module=" + module + ", rpc=" + rpc + ", mode=" + mode + ", version=" + version + "]";