2  * ============LICENSE_START=======================================================
 
   3  *  Copyright (C) 2018 Ericsson. All rights reserved.
 
   4  *  Copyright (C) 2019 Nordix Foundation.
 
   5  * ================================================================================
 
   6  * Licensed under the Apache License, Version 2.0 (the "License");
 
   7  * you may not use this file except in compliance with the License.
 
   8  * You may obtain a copy of the License at
 
  10  *      http://www.apache.org/licenses/LICENSE-2.0
 
  12  * Unless required by applicable law or agreed to in writing, software
 
  13  * distributed under the License is distributed on an "AS IS" BASIS,
 
  14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  15  * See the License for the specific language governing permissions and
 
  16  * limitations under the License.
 
  18  * SPDX-License-Identifier: Apache-2.0
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.onap.policy.distribution.forwarding.parameters;
 
  24 import org.onap.policy.common.parameters.GroupValidationResult;
 
  25 import org.onap.policy.common.parameters.ParameterGroup;
 
  26 import org.onap.policy.common.parameters.ValidationStatus;
 
  27 import org.slf4j.Logger;
 
  28 import org.slf4j.LoggerFactory;
 
  31  * Class to hold all the policy forwarder parameters.
 
  33  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
 
  35 public class PolicyForwarderParameters implements ParameterGroup {
 
  37     private static final Logger LOGGER = LoggerFactory.getLogger(PolicyForwarderParameters.class);
 
  39     private String forwarderType;
 
  40     private String forwarderClassName;
 
  41     private String forwarderConfigurationName;
 
  44      * Constructor for instantiating PolicyForwarderParameters.
 
  46      * @param forwarderType the policy forwarder type
 
  47      * @param forwarderClassName the policy forwarder class name
 
  48      * @param forwarderConfigurationName the name of the configuration for the policy forwarder
 
  50     public PolicyForwarderParameters(final String forwarderType, final String forwarderClassName,
 
  51             final String forwarderConfigurationName) {
 
  52         this.forwarderType = forwarderType;
 
  53         this.forwarderClassName = forwarderClassName;
 
  54         this.forwarderConfigurationName = forwarderConfigurationName;
 
  58      * Return the forwarderType of this PolicyForwarderParameters instance.
 
  60      * @return the forwarderType
 
  62     public String getForwarderType() {
 
  67      * Return the forwarderClassName of this PolicyForwarderParameters instance.
 
  69      * @return the forwarderClassName
 
  71     public String getForwarderClassName() {
 
  72         return forwarderClassName;
 
  76      * Return the name of the forwarder configuration of this PolicyForwarderParameters instance.
 
  78      * @return the the name of the forwarder configuration
 
  80     public String getForwarderConfigurationName() {
 
  81         return forwarderConfigurationName;
 
  88     public String getName() {
 
  89         return getForwarderType();
 
  96     public void setName(final String name) {
 
  97         this.forwarderType = name;
 
 104     public GroupValidationResult validate() {
 
 105         final GroupValidationResult validationResult = new GroupValidationResult(this);
 
 106         if (forwarderType == null || forwarderType.trim().length() == 0) {
 
 107             validationResult.setResult("forwarderType", ValidationStatus.INVALID, "must be a non-blank string");
 
 109         if (forwarderClassName == null || forwarderClassName.trim().length() == 0) {
 
 110             validationResult.setResult("forwarderClassName", ValidationStatus.INVALID,
 
 111                     "must be a non-blank string containing full class name of the forwarder");
 
 113             validatePolicyForwarderClass(validationResult);
 
 115         return validationResult;
 
 118     private void validatePolicyForwarderClass(final GroupValidationResult validationResult) {
 
 120             Class.forName(forwarderClassName);
 
 121         } catch (final ClassNotFoundException exp) {
 
 122             LOGGER.trace("policy forwarder class not found in classpath", exp);
 
 123             validationResult.setResult("forwarderClassName", ValidationStatus.INVALID,
 
 124                     "policy forwarder class not found in classpath");