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