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.reception.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 decoder parameters.
33 * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
35 public class PolicyDecoderParameters implements ParameterGroup {
37 private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderParameters.class);
39 private String decoderType;
40 private String decoderClassName;
41 private String decoderConfigurationName;
44 * Constructor for instantiating PolicyDecoderParameters.
46 * @param decoderType the policy decoder type
47 * @param decoderClassName the policy decoder class name
48 * @param decoderConfigurationName the policy decoder configuration name
50 public PolicyDecoderParameters(final String decoderType, final String decoderClassName,
51 final String decoderConfigurationName) {
52 this.decoderType = decoderType;
53 this.decoderClassName = decoderClassName;
54 this.decoderConfigurationName = decoderConfigurationName;
58 * Return the decoderType of this PolicyDecoderParameters instance.
60 * @return the decoderType
62 public String getDecoderType() {
67 * Return the decoderClassName of this PolicyDecoderParameters instance.
69 * @return the decoderClassName
71 public String getDecoderClassName() {
72 return decoderClassName;
76 * Return the name of the decoder configuration of this {@link PolicyDecoderParameters} instance.
78 * @return the the name of the decoder configuration
80 public String getDecoderConfigurationName() {
81 return decoderConfigurationName;
88 public String getName() {
89 return getDecoderType();
96 public void setName(final String name) {
97 this.decoderType = name;
104 public GroupValidationResult validate() {
105 final GroupValidationResult validationResult = new GroupValidationResult(this);
106 if (decoderType == null || decoderType.trim().length() == 0) {
107 validationResult.setResult("decoderType", ValidationStatus.INVALID, "must be a non-blank string");
109 if (decoderClassName == null || decoderClassName.trim().length() == 0) {
110 validationResult.setResult("decoderClassName", ValidationStatus.INVALID,
111 "must be a non-blank string containing full class name of the decoder");
113 validatePolicyDecoderClass(validationResult);
115 return validationResult;
118 private void validatePolicyDecoderClass(final GroupValidationResult validationResult) {
120 Class.forName(decoderClassName);
121 } catch (final ClassNotFoundException exp) {
122 LOGGER.trace("policy decoder class not found in classpath", exp);
123 validationResult.setResult("decoderClassName", ValidationStatus.INVALID,
124 "policy decoder class not found in classpath");