* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
/**
- *
+ *
*/
package org.onap.ccsdk.sli.core.sli;
import java.util.HashSet;
import java.util.TreeMap;
-import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.commons.text.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SvcLogicNode implements Serializable {
-
+
private static final Logger LOG = LoggerFactory
.getLogger(SvcLogicExprListener.class);
-
+
private static final long serialVersionUID = 2L;
-
+
private String nodeName;
private int nodeId;
private String nodeType;
private HashMap<String, SvcLogicExpression> attributes;
private HashMap<String, SvcLogicNode> outcomes;
private HashMap<String, SvcLogicExpression> parameters;
-
+
public SvcLogicNode(int nodeId, String nodeType, SvcLogicGraph graph)
{
this.nodeId = nodeId;
attributes = new HashMap<> ();
parameters = new HashMap<> ();
outcomes = null;
-
+
}
-
+
public SvcLogicNode(int nodeId, String nodeType, String nodeName, SvcLogicGraph graph) throws DuplicateValueException
{
this.nodeId = nodeId;
outcomes = null;
graph.setNamedNode(nodeName, this);
}
-
-
+
+
public int getNodeId()
{
return nodeId;
}
-
+
public String getNodeName()
{
return nodeName;
}
-
+
public String getNodeType()
{
return nodeType;
}
-
+
public SvcLogicGraph getGraph()
{
return graph;
}
-
+
public int getNumOutcomes()
{
if (outcomes == null)
return outcomes.size();
}
}
-
+
public SvcLogicExpression getAttribute(String name)
{
if (attributes.containsKey(name))
{
return null;
}
-
+
}
-
+
public void setAttribute(String name, String value) throws SvcLogicException
{
setAttribute(name, new SvcLogicAtom("STRING", value));
}
-
+
public void setAttribute(String name, SvcLogicExpression value) throws SvcLogicException
{
if (attributes.containsKey(name))
{
throw new DuplicateValueException("Duplicate attribute "+name);
}
-
+
attributes.put(name, value);
}
-
+
public void mapParameter(String name, String value) throws SvcLogicException
{
-
+
if (parameters.containsKey(name))
{
throw new DuplicateValueException("Duplicate parameter "+name);
int lastParen = value.lastIndexOf("`");
String evalExpr = value.trim().substring(1, lastParen);
parmValue = SvcLogicExpressionFactory.parse(evalExpr);
-
+
}
else
{
throw new SvcLogicException(e.getMessage());
}
}
-
+
public SvcLogicExpression getParameter(String name)
{
if (parameters.containsKey(name))
return null;
}
}
-
+
public boolean isVisited() {
return visited;
}
public void setVisited(boolean visited, boolean recursive) {
this.visited = visited;
-
+
if (recursive)
{
Set<Map.Entry<String, SvcLogicNode>> outcomeSet = getOutcomeSet();
-
+
if (outcomeSet == null)
{
return;
}
-
+
for (Iterator<Map.Entry<String, SvcLogicNode>> iter = outcomeSet.iterator(); iter.hasNext();)
{
Map.Entry<String, SvcLogicNode> curOutcome = iter.next();
}
}
}
-
+
public void addOutcome(String outcomeValue, SvcLogicNode node) throws SvcLogicException
{
if (outcomes == null)
{
outcomes = new HashMap<>();
}
-
+
if (outcomeValue.length() == 0) {
outcomeValue = "\"\"";
}
{
throw new DuplicateValueException("Duplicate outcome value "+outcomeValue);
}
-
+
outcomes.put(outcomeValue, node);
}
-
+
public Set<Map.Entry<String, SvcLogicNode>> getOutcomeSet()
{
if (outcomes == null)
{
return new HashSet<>();
}
-
+
return outcomes.entrySet();
-
+
}
-
+
public Set<Map.Entry<String, SvcLogicExpression>> getParameterSet()
{
if (parameters == null)
{
return new HashSet<>();
}
-
+
return parameters.entrySet();
-
+
}
-
+
public void printAsGv(PrintStream pstr)
{
-
+
if (visited)
{
return;
{
visited = true;
}
-
+
StringBuffer sbuff = new StringBuffer();
-
+
sbuff.append("node");
sbuff.append(nodeId);
sbuff.append(" [ shape=none, margin=0, label=<<table border=\"0\" cellborder=\"1\" align=\"left\">");
sbuff.append(nodeName);
sbuff.append("</td></tr>");
}
-
+
Set<Map.Entry<String, SvcLogicExpression>> attrSet = attributes.entrySet();
for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = attrSet.iterator() ; iter.hasNext();)
{
sbuff.append("</td></tr>");
}
sbuff.append("</table>>];");
-
+
pstr.println(sbuff.toString());
-
-
+
+
if (outcomes != null)
{
TreeMap<String, SvcLogicNode> sortedOutcomes = new TreeMap<>(outcomes);
Set<Map.Entry<String, SvcLogicNode>> outcomeSet = sortedOutcomes.entrySet();
-
+
for (Iterator<Map.Entry<String, SvcLogicNode>> iter = outcomeSet.iterator(); iter.hasNext();)
{
Map.Entry<String, SvcLogicNode> curOutcome = iter.next();
}
}
}
-
+
public void printAsXml(PrintStream pstr, int indentLvl)
{
if (visited)
}
pstr.print("<");
pstr.print(this.getNodeType());
-
+
Set<Map.Entry<String, SvcLogicExpression>> attrSet = attributes.entrySet();
for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = attrSet.iterator() ; iter.hasNext();)
{
pstr.print(curAttr.getValue());
pstr.print("'`");
}
-
+
if ((parameters == null || parameters.isEmpty()) &&
(outcomes == null || outcomes.isEmpty()))
{
{
pstr.print(">\n");
}
-
+
// Print parameters (if any)
if (parameters != null)
{
pstr.print("</outcome>\n");
}
}
-
+
// Print node end tag
for (int i = 0 ; i < indentLvl ; i++)
{
pstr.print(this.getNodeType());
pstr.print(">\n");
pstr.flush();
-
+
}
{
return null;
}
-
+
if (outcomes.containsKey(value))
{
return outcomes.get(value);