2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.distribution.reception.parameters;
23 import org.onap.policy.common.logging.flexlogger.FlexLogger;
24 import org.onap.policy.common.logging.flexlogger.Logger;
25 import org.onap.policy.common.parameters.GroupValidationResult;
26 import org.onap.policy.common.parameters.ParameterGroup;
27 import org.onap.policy.common.parameters.ValidationStatus;
30 * Class to hold all the policy decoder parameters.
32 * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
34 public class PolicyDecoderParameters implements ParameterGroup {
36 private static final Logger LOGGER = FlexLogger.getLogger(PolicyDecoderParameters.class);
38 private String decoderType;
39 private String decoderClassName;
40 private String decoderConfigurationName;
43 * Constructor for instantiating PolicyDecoderParameters.
45 * @param decoderType the policy decoder type
46 * @param decoderClassName the policy decoder class name
47 * @param decoderConfigurationName the policy decoder configuration name
49 public PolicyDecoderParameters(final String decoderType, final String decoderClassName,
50 final String decoderConfigurationName) {
51 this.decoderType = decoderType;
52 this.decoderClassName = decoderClassName;
53 this.decoderConfigurationName = decoderConfigurationName;
57 * Return the decoderType of this PolicyDecoderParameters instance.
59 * @return the decoderType
61 public String getDecoderType() {
66 * Return the decoderClassName of this PolicyDecoderParameters instance.
68 * @return the decoderClassName
70 public String getDecoderClassName() {
71 return decoderClassName;
75 * Return the name of the decoder configuration of this {@link PolicyDecoderParameters} instance.
77 * @return the the name of the decoder configuration
79 public String getDecoderConfigurationName() {
80 return decoderConfigurationName;
87 public String getName() {
95 public void setName(final String name) {
96 this.decoderType = name;
103 public GroupValidationResult validate() {
104 final GroupValidationResult validationResult = new GroupValidationResult(this);
105 if (decoderType == null || decoderType.trim().length() == 0) {
106 validationResult.setResult("decoderType", ValidationStatus.INVALID, "must be a non-blank string");
108 if (decoderClassName == null || decoderClassName.trim().length() == 0) {
109 validationResult.setResult("decoderClassName", ValidationStatus.INVALID,
110 "must be a non-blank string containing full class name of the decoder");
112 validatePolicyDecoderClass(validationResult);
114 return validationResult;
117 private void validatePolicyDecoderClass(final GroupValidationResult validationResult) {
119 Class.forName(decoderClassName);
120 } catch (final ClassNotFoundException exp) {
121 LOGGER.trace("policy decoder class not found in classpath", exp);
122 validationResult.setResult("decoderClassName", ValidationStatus.INVALID,
123 "policy decoder class not found in classpath");