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 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();
148 public static class CustomJacksonCoder extends CustomCoder {
150 public CustomJacksonCoder(String className, String staticCoderField) {
151 super(className, staticCoderField);
154 public CustomJacksonCoder(String customJackson) {
155 super(customJackson);
159 public String toString() {
160 StringBuilder builder = new StringBuilder();
161 builder.append("CustomJacksonCoder [toString()=").append(super.toString()).append("]");
162 return builder.toString();
167 * Coder/Decoder class and Filter container. The decoder class is potential, in order to be
168 * operational needs to be fetched from an available class loader.
170 public static class PotentialCoderFilter {
172 /* decoder class (pending from being able to be fetched and found in some class loader) */
173 protected String codedClass;
175 /* filters to apply to the selection of the decodedClass; */
176 protected JsonProtocolFilter filter;
181 * @param codedClass decoder class
182 * @param filter filters to apply
184 public PotentialCoderFilter(String codedClass, JsonProtocolFilter filter) {
185 this.codedClass = codedClass;
186 this.filter = filter;
192 * @return the decodedClass
194 public String getCodedClass() {
200 * @param decodedClass the decodedClass to set
202 public void setCodedClass(String decodedClass) {
203 this.codedClass = decodedClass;
211 public JsonProtocolFilter getFilter() {
218 * @param filter the filter to set
220 public void setFilter(JsonProtocolFilter filter) {
221 this.filter = filter;
225 public String toString() {
226 StringBuilder builder = new StringBuilder();
228 .append("PotentialCoderFilter [codedClass=")
233 return builder.toString();
237 /* the source topic */
238 protected final String topic;
240 /* List of decoder -> filters */
241 protected final List<PotentialCoderFilter> coderFilters;
243 /* custom gson coder that this controller prefers to use instead of the framework ones */
244 protected CustomGsonCoder customGsonCoder;
246 /* custom jackson coder that this controller prefers to use instead of the framework ones */
247 protected CustomJacksonCoder customJacksonCoder;
252 * @param decoderFilters list of decoders and associated filters
253 * @param topic the topic
255 public TopicCoderFilterConfiguration(
257 List<PotentialCoderFilter> decoderFilters,
258 CustomGsonCoder customGsonCoder,
259 CustomJacksonCoder customJacksonCoder) {
260 this.coderFilters = decoderFilters;
262 this.customGsonCoder = customGsonCoder;
263 this.customJacksonCoder = customJacksonCoder;
270 public String getTopic() {
274 /** Get coder filters.
276 * @return the decoderFilters
278 public List<PotentialCoderFilter> getCoderFilters() {
283 * Get custom gson coder.
285 * @return the customGsonCoder
287 public CustomGsonCoder getCustomGsonCoder() {
288 return customGsonCoder;
292 * Set custom gson coder.
294 * @param customGsonCoder the customGsonCoder to set
296 public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) {
297 this.customGsonCoder = customGsonCoder;
300 /** Get custom jackson coder.
302 * @return the customJacksonCoder
304 public CustomJacksonCoder getCustomJacksonCoder() {
305 return customJacksonCoder;
309 * Set custom Jackson coder.
310 * @param customJacksonCoder the customJacksonCoder to set
312 public void setCustomJacksonCoder(CustomJacksonCoder customJacksonCoder) {
313 this.customJacksonCoder = customJacksonCoder;
317 public String toString() {
318 StringBuilder builder = new StringBuilder();
320 .append("TopicCoderFilterConfiguration [topic=")
322 .append(", coderFilters=")
323 .append(coderFilters)
324 .append(", customGsonCoder=")
325 .append(customGsonCoder)
326 .append(", customJacksonCoder=")
327 .append(customJacksonCoder)
329 return builder.toString();