2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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
29 * desires to 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
37 * (typically embedded in a property file):
39 * Note this is to support decoding/encoding of partial structures that are
40 * only known by the model.
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("No classname to create CustomCoder cannot be created");
52 this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(",")+1);
53 if (this.staticCoderField == null || this.staticCoderField.isEmpty()) {
54 throw new IllegalArgumentException
55 ("No staticCoderField to create CustomCoder cannot be created for class " +
62 * @param classContainer
63 * @param staticCoderField
65 public CustomCoder(String className, String staticCoderField) {
66 if (className == null || className.isEmpty()) {
67 throw new IllegalArgumentException("No classname to create CustomCoder cannot be created");
70 if (staticCoderField == null || staticCoderField.isEmpty()) {
71 throw new IllegalArgumentException
72 ("No staticCoderField to create CustomCoder cannot be created for class " +
76 this.className = className;
77 this.staticCoderField = staticCoderField;
81 * @return the className
83 public String getClassContainer() {
88 * @param className the className to set
90 public void setClassContainer(String className) {
91 this.className = className;
95 * @return the staticCoderField
97 public String getStaticCoderField() {
98 return staticCoderField;
102 * @param staticCoderField the staticGson to set
104 public void setStaticCoderField(String staticCoderField) {
105 this.staticCoderField = staticCoderField;
109 public String toString() {
110 StringBuilder builder = new StringBuilder();
111 builder.append("CustomCoder [className=").append(className).append(", staticCoderField=")
112 .append(staticCoderField).append("]");
113 return builder.toString();
117 public static class CustomGsonCoder extends CustomCoder {
119 public CustomGsonCoder(String className, String staticCoderField) {
120 super(className, staticCoderField);
123 public CustomGsonCoder(String customGson) {
128 public String toString() {
129 StringBuilder builder = new StringBuilder();
130 builder.append("CustomGsonCoder [toString()=").append(super.toString()).append("]");
131 return builder.toString();
136 public static class CustomJacksonCoder extends CustomCoder {
138 public CustomJacksonCoder(String className, String staticCoderField) {
139 super(className, staticCoderField);
142 public CustomJacksonCoder(String customJackson) {
143 super(customJackson);
147 public String toString() {
148 StringBuilder builder = new StringBuilder();
149 builder.append("CustomJacksonCoder [toString()=").append(super.toString()).append("]");
150 return builder.toString();
156 * Coder/Decoder class and Filter container. The decoder class is potential,
157 * in order to be operational needs to be fetched from an available
161 public static class PotentialCoderFilter {
164 * decoder class (pending from being able to be fetched and found
165 * in some class loader)
167 protected String codedClass;
170 * filters to apply to the selection of the decodedClass;
172 protected JsonProtocolFilter filter;
177 * @param codedClass decoder class
178 * @param filter filters to apply
180 public PotentialCoderFilter(String codedClass, JsonProtocolFilter filter) {
181 this.codedClass = codedClass;
182 this.filter = filter;
186 * @return the decodedClass
188 public String getCodedClass() {
193 * @param decodedClass the decodedClass to set
195 public void setCodedClass(String decodedClass) {
196 this.codedClass = decodedClass;
202 public JsonProtocolFilter getFilter() {
207 * @param filter the filter to set
209 public void setFilter(JsonProtocolFilter filter) {
210 this.filter = filter;
214 public String toString() {
215 StringBuilder builder = new StringBuilder();
216 builder.append("PotentialCoderFilter [codedClass=").append(codedClass).append(", filter=").append(filter)
218 return builder.toString();
225 protected final String topic;
228 * List of decoder -> filters
230 protected final List<PotentialCoderFilter> coderFilters;
233 * custom gson coder that this controller prefers to use instead of the framework ones
235 protected CustomGsonCoder customGsonCoder;
238 * custom jackson coder that this controller prefers to use instead of the framework ones
240 protected CustomJacksonCoder customJacksonCoder;
245 * @param decoderFilters list of decoders and associated filters
246 * @param topic the topic
248 public TopicCoderFilterConfiguration(String topic, List<PotentialCoderFilter> decoderFilters,
249 CustomGsonCoder customGsonCoder,
250 CustomJacksonCoder customJacksonCoder) {
251 this.coderFilters = decoderFilters;
253 this.customGsonCoder = customGsonCoder;
254 this.customJacksonCoder = customJacksonCoder;
260 public String getTopic() {
265 * @return the decoderFilters
267 public List<PotentialCoderFilter> getCoderFilters() {
272 * @return the customGsonCoder
274 public CustomGsonCoder getCustomGsonCoder() {
275 return customGsonCoder;
279 * @param customGsonCoder the customGsonCoder to set
281 public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) {
282 this.customGsonCoder = customGsonCoder;
286 * @return the customJacksonCoder
288 public CustomJacksonCoder getCustomJacksonCoder() {
289 return customJacksonCoder;
293 * @param customJacksonCoder the customJacksonCoder to set
295 public void setCustomJacksonCoder(CustomJacksonCoder customJacksonCoder) {
296 this.customJacksonCoder = customJacksonCoder;
300 public String toString() {
301 StringBuilder builder = new StringBuilder();
302 builder.append("TopicCoderFilterConfiguration [topic=").append(topic).append(", coderFilters=")
303 .append(coderFilters).append(", customGsonCoder=").append(customGsonCoder)
304 .append(", customJacksonCoder=").append(customJacksonCoder).append("]");
305 return builder.toString();