a51accbb9c2167af206bb6aab5e928af611293f9
[ccsdk/sli.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
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.onap.ccsdk.sli.core.sli.provider.base;
23
24 import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
26 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public abstract class AbstractSvcLogicNodeExecutor {
35         protected SvcLogicResolver resolver;
36         public abstract SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException;
37
38         private static final Logger LOG = LoggerFactory.getLogger(AbstractSvcLogicNodeExecutor.class);
39
40     protected String evaluateNodeTest(SvcLogicNode node, SvcLogicContext ctx)
41                         throws SvcLogicException {
42                 if (node == null) {
43                         return null;
44                 }
45
46                 return (SvcLogicExpressionResolver.evaluate(node.getAttribute("test"),
47                                 node, ctx));
48
49         }
50
51     public void setResolver(SvcLogicResolver resolver) {
52                 this.resolver = resolver;
53         }
54
55         protected SvcLogicAdaptor getAdaptor(String adaptorName) {
56         return resolver.getSvcLogicAdaptor(adaptorName);
57     }
58
59     protected SvcLogicResource getSvcLogicResource(String resourceName) {
60         return resolver.getSvcLogicResource(resourceName);
61     }
62
63     protected SvcLogicRecorder getSvcLogicRecorder(String recorderName) {
64         return resolver.getSvcLogicRecorder(recorderName);
65     }
66
67     protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName){
68         return resolver.getSvcLogicJavaPlugin(pluginName);
69     }
70
71     protected SvcLogicNode getNextNode(SvcLogicNode node, String outValue) {
72         SvcLogicNode nextNode = node.getOutcomeValue(outValue);
73         if (nextNode != null) {
74             if (LOG.isDebugEnabled()) {
75                 LOG.debug("about to execute " + outValue + " branch");
76             }
77             return (nextNode);
78         }
79
80         nextNode = node.getOutcomeValue("Other");
81         if (nextNode != null) {
82             if (LOG.isDebugEnabled()) {
83                 LOG.debug("about to execute Other branch");
84             }
85         } else {
86             if (LOG.isDebugEnabled()) {
87                 LOG.debug("no " + outValue + " or Other branch found");
88             }
89         }
90         return (nextNode);
91     }
92     
93 }