2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.drools.protocol.coders;
23 import java.util.List;
24 import lombok.AllArgsConstructor;
27 import lombok.ToString;
31 public class TopicCoderFilterConfiguration {
34 * Custom coder, contains class and static field to access parser that the controller desires to
35 * use instead of the framework provided parser.
40 public abstract static class CustomCoder {
41 protected String classContainer;
42 protected String staticCoderField;
45 * create custom coder from raw string in the following format (typically embedded in a property
48 * <p>Note this is to support decoding/encoding of partial structures that are only known by the
51 * @param rawCustomCoder with format: <class-containing-custom-coder>,<static-coder-field>.
53 protected CustomCoder(String rawCustomCoder) {
54 if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) {
56 this.classContainer = rawCustomCoder.substring(0, rawCustomCoder.indexOf(','));
57 if (this.classContainer == null || this.classContainer.isEmpty()) {
58 throw new IllegalArgumentException(
59 "No classname to create CustomCoder cannot be created");
62 this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(',') + 1);
63 if (this.staticCoderField == null || this.staticCoderField.isEmpty()) {
64 throw new IllegalArgumentException(
65 "No staticCoderField to create CustomCoder cannot be created for class " + classContainer);
73 * @param className class name
74 * @param staticCoderField static coder field
76 protected CustomCoder(String className, String staticCoderField) {
77 if (className == null || className.isEmpty()) {
78 throw new IllegalArgumentException("No classname to create CustomCoder cannot be created");
81 if (staticCoderField == null || staticCoderField.isEmpty()) {
82 throw new IllegalArgumentException(
83 "No staticCoderField to create CustomCoder cannot be created for class " + className);
86 this.classContainer = className;
87 this.staticCoderField = staticCoderField;
91 @ToString(callSuper = true)
92 public static class CustomGsonCoder extends CustomCoder {
94 public CustomGsonCoder(String className, String staticCoderField) {
95 super(className, staticCoderField);
98 public CustomGsonCoder(String customGson) {
104 * Coder/Decoder class and Filter container. The decoder class is potential, in order to be
105 * operational needs to be fetched from an available class loader.
111 public static class PotentialCoderFilter {
113 /* decoder class (pending from being able to be fetched and found in some class loader) */
114 protected String codedClass;
116 /* filters to apply to the selection of the decodedClass */
117 protected JsonProtocolFilter filter;
120 /* the source topic */
121 protected final String topic;
123 /* List of decoder -> filters */
124 protected final List<PotentialCoderFilter> coderFilters;
126 /* custom gson coder that this controller prefers to use instead of the framework ones */
128 protected CustomGsonCoder customGsonCoder;
133 * @param topic the topic
134 * @param decoderFilters list of decoders and associated filters
135 * @param customGsonCoder GSON coder
137 public TopicCoderFilterConfiguration(
139 List<PotentialCoderFilter> decoderFilters,
140 CustomGsonCoder customGsonCoder) {
141 this.coderFilters = decoderFilters;
143 this.customGsonCoder = customGsonCoder;