Update groupId to org.onap.ccsdk.sli
[ccsdk/sli/core.git] / sli / common / src / main / java / org / onap / ccsdk / sli / core / sli / SvcLogicGraph.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.ccsdk.sli.core.sli;
22
23 import java.io.PrintStream;
24 import java.io.Serializable;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 public class SvcLogicGraph implements Serializable {
29         
30         /**
31          * 
32          */
33         private static final long serialVersionUID = 1L;
34         
35         private String module = null;
36         private String rpc = null;
37         private String mode = null;
38         private String version = null;
39         
40         private Map<String, Serializable> attributes;
41         private Map<String, SvcLogicNode> namedNodes;
42         private SvcLogicNode rootNode;
43         
44         public SvcLogicGraph()
45         {
46                 attributes = new HashMap<String, Serializable>();
47                 namedNodes = new HashMap<String, SvcLogicNode>();
48                 rootNode = null;
49         }
50         
51         
52         public String getModule() {
53                 return module;
54         }
55
56
57         public void setModule(String module) {
58                 this.module = module;
59         }
60
61
62         public String getRpc() {
63                 return rpc;
64         }
65
66
67         public void setRpc(String rpc) {
68                 this.rpc = rpc;
69         }
70
71         
72
73
74         public String getMode() {
75                 return mode;
76         }
77
78
79         public void setMode(String mode) {
80                 this.mode = mode;
81         }
82
83
84         public String getVersion() {
85                 return version;
86         }
87
88
89         public void setVersion(String version) {
90                 this.version = version;
91         }
92
93
94         public void setRootNode(SvcLogicNode rootNode)
95         {
96                 this.rootNode = rootNode;
97         }
98         
99         public SvcLogicNode getRootNode()
100         {
101                 return(rootNode);
102         }
103         
104         public Serializable getAttribute(String name)
105         {
106                 if (attributes.containsKey(name))
107                 {
108                         return(attributes.get(name));
109                 }
110                 else
111                 {
112                         return(null);
113                 }
114                         
115         }
116         
117         public void setAttribute(String name, Serializable value) throws DuplicateValueException
118         {
119                 if (attributes.containsKey(name))
120                 {
121                         throw new DuplicateValueException("Duplicate attribute "+name);
122                 }
123                 
124                 attributes.put(name, value);
125         }
126         
127         public SvcLogicNode getNamedNode(String nodeName)
128         {
129                 if (namedNodes.containsKey(nodeName))
130                 {
131                         return(namedNodes.get(nodeName));
132                 }
133                 else
134                 {
135                         return(null);
136                 }
137         }
138
139         public void setNamedNode(String nodeName, SvcLogicNode node) throws DuplicateValueException
140         {
141                 if (namedNodes.containsKey(nodeName))
142                 {
143                         throw new DuplicateValueException("Duplicate node name "+nodeName);
144                 }
145                 
146                 namedNodes.put(nodeName, node);
147         }
148         
149         
150         
151         public void printAsGv(PrintStream pstr)
152         {
153                 pstr.println("digraph g {");
154                 pstr.println("START [label=\"START\\n"+module+":"+rpc+"\"];");
155                 
156                 if (rootNode != null)
157                 {
158                         pstr.println("START -> node"+rootNode.getNodeId()+";");
159                         rootNode.setVisited(false, true);
160                         rootNode.printAsGv(pstr);
161                 }
162                 pstr.println("}");
163         }
164         
165         public void printAsXml(PrintStream pstr)
166         {
167                 pstr.println("<service-logic module='"+getModule()+"' version='"+getVersion()+"'>");
168                 pstr.println("  <method rpc='"+getRpc()+"' mode='"+getMode()+"'>");
169                 if (rootNode != null)
170                 {
171                         rootNode.setVisited(false, true);
172                         rootNode.printAsXml(pstr, 2);
173                 }
174                 pstr.println("  </method>");
175                 pstr.println("</service-logic>");
176         }
177         
178         @Override
179         public String toString() {
180             return "SvcLogicGraph [module=" + module + ", rpc=" + rpc + ", mode=" + mode + ", version=" + version + "]";
181         }
182         
183 }