2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2020 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;
25 public class TopicCoderFilterConfiguration {
28 * Custom coder, contains class and static field to access parser that the controller desires to
29 * use instead of the framework provided parser.
31 public abstract static class CustomCoder {
32 protected String className;
33 protected String staticCoderField;
36 * create custom coder from raw string in the following format (typically embedded in a property
39 * <p>Note this is to support decoding/encoding of partial structures that are only known by the
42 * @param rawCustomCoder with format: <class-containing-custom-coder>,<static-coder-field>.
44 public CustomCoder(String rawCustomCoder) {
45 if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) {
47 this.className = rawCustomCoder.substring(0, rawCustomCoder.indexOf(','));
48 if (this.className == null || this.className.isEmpty()) {
49 throw new IllegalArgumentException(
50 "No classname to create CustomCoder cannot be created");
53 this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(',') + 1);
54 if (this.staticCoderField == null || this.staticCoderField.isEmpty()) {
55 throw new IllegalArgumentException(
56 "No staticCoderField to create CustomCoder cannot be created for class " + className);
64 * @param className class name
65 * @param staticCoderField static coder field
67 public CustomCoder(String className, String staticCoderField) {
68 if (className == null || className.isEmpty()) {
69 throw new IllegalArgumentException("No classname to create CustomCoder cannot be created");
72 if (staticCoderField == null || staticCoderField.isEmpty()) {
73 throw new IllegalArgumentException(
74 "No staticCoderField to create CustomCoder cannot be created for class " + className);
77 this.className = className;
78 this.staticCoderField = staticCoderField;
82 * Get class container.
84 * @return the className
86 public String getClassContainer() {
91 * Set class container.
93 * @param className the className to set
95 public void setClassContainer(String className) {
96 this.className = className;
100 * Get static coder field.
102 * @return the staticCoderField
104 public String getStaticCoderField() {
105 return staticCoderField;
109 * Set static coder field.
111 * @param staticCoderField the staticGson to set
113 public void setStaticCoderField(String staticCoderField) {
114 this.staticCoderField = staticCoderField;
118 public String toString() {
119 StringBuilder builder = new StringBuilder();
121 .append("CustomCoder [className=")
123 .append(", staticCoderField=")
124 .append(staticCoderField)
126 return builder.toString();
130 public static class CustomGsonCoder extends CustomCoder {
132 public CustomGsonCoder(String className, String staticCoderField) {
133 super(className, staticCoderField);
136 public CustomGsonCoder(String customGson) {
141 public String toString() {
142 StringBuilder builder = new StringBuilder();
143 builder.append("CustomGsonCoder [toString()=").append(super.toString()).append("]");
144 return builder.toString();
149 * Coder/Decoder class and Filter container. The decoder class is potential, in order to be
150 * operational needs to be fetched from an available class loader.
152 public static class PotentialCoderFilter {
154 /* decoder class (pending from being able to be fetched and found in some class loader) */
155 protected String codedClass;
157 /* filters to apply to the selection of the decodedClass */
158 protected JsonProtocolFilter filter;
163 * @param codedClass decoder class
164 * @param filter filters to apply
166 public PotentialCoderFilter(String codedClass, JsonProtocolFilter filter) {
167 this.codedClass = codedClass;
168 this.filter = filter;
174 * @return the decodedClass
176 public String getCodedClass() {
182 * @param decodedClass the decodedClass to set
184 public void setCodedClass(String decodedClass) {
185 this.codedClass = decodedClass;
193 public JsonProtocolFilter getFilter() {
200 * @param filter the filter to set
202 public void setFilter(JsonProtocolFilter filter) {
203 this.filter = filter;
207 public String toString() {
208 StringBuilder builder = new StringBuilder();
210 .append("PotentialCoderFilter [codedClass=")
215 return builder.toString();
219 /* the source topic */
220 protected final String topic;
222 /* List of decoder -> filters */
223 protected final List<PotentialCoderFilter> coderFilters;
225 /* custom gson coder that this controller prefers to use instead of the framework ones */
226 protected CustomGsonCoder customGsonCoder;
231 * @param topic the topic
232 * @param decoderFilters list of decoders and associated filters
233 * @param customGsonCoder GSON coder
235 public TopicCoderFilterConfiguration(
237 List<PotentialCoderFilter> decoderFilters,
238 CustomGsonCoder customGsonCoder) {
239 this.coderFilters = decoderFilters;
241 this.customGsonCoder = customGsonCoder;
248 public String getTopic() {
252 /** Get coder filters.
254 * @return the decoderFilters
256 public List<PotentialCoderFilter> getCoderFilters() {
261 * Get custom gson coder.
263 * @return the customGsonCoder
265 public CustomGsonCoder getCustomGsonCoder() {
266 return customGsonCoder;
270 * Set custom gson coder.
272 * @param customGsonCoder the customGsonCoder to set
274 public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) {
275 this.customGsonCoder = customGsonCoder;
279 public String toString() {
280 StringBuilder builder = new StringBuilder();
282 .append("TopicCoderFilterConfiguration [topic=")
284 .append(", coderFilters=")
285 .append(coderFilters)
286 .append(", customGsonCoder=")
287 .append(customGsonCoder)
289 return builder.toString();