diff options
Diffstat (limited to 'policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java')
-rw-r--r-- | policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java | 582 |
1 files changed, 302 insertions, 280 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java index 7c1b128f..f7fc4d21 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java @@ -24,286 +24,308 @@ import java.util.List; public class TopicCoderFilterConfiguration { - /** - * Custom coder, contains class and static field to access parser that the controller - * desires to use instead of the framework provided parser - */ - public abstract static class CustomCoder { - protected String className; - protected String staticCoderField; - - /** - * create custom coder from raw string in the following format - * (typically embedded in a property file): - * - * Note this is to support decoding/encoding of partial structures that are - * only known by the model. - * - * @param rawCustomCoder with format: <class-containing-custom-coder>,<static-coder-field> - */ - public CustomCoder(String rawCustomCoder) { - if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) { - - this.className = rawCustomCoder.substring(0,rawCustomCoder.indexOf(",")); - if (this.className == null || this.className.isEmpty()) { - throw new IllegalArgumentException("No classname to create CustomCoder cannot be created"); - } - - this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(",")+1); - if (this.staticCoderField == null || this.staticCoderField.isEmpty()) { - throw new IllegalArgumentException - ("No staticCoderField to create CustomCoder cannot be created for class " + - className); - } - - } - } - /** - * @param classContainer - * @param staticCoderField - */ - public CustomCoder(String className, String staticCoderField) { - if (className == null || className.isEmpty()) { - throw new IllegalArgumentException("No classname to create CustomCoder cannot be created"); - } - - if (staticCoderField == null || staticCoderField.isEmpty()) { - throw new IllegalArgumentException - ("No staticCoderField to create CustomCoder cannot be created for class " + - className); - } - - this.className = className; - this.staticCoderField = staticCoderField; - } - - /** - * @return the className - */ - public String getClassContainer() { - return className; - } - - /** - * @param className the className to set - */ - public void setClassContainer(String className) { - this.className = className; - } - - /** - * @return the staticCoderField - */ - public String getStaticCoderField() { - return staticCoderField; - } - - /** - * @param staticCoderField the staticGson to set - */ - public void setStaticCoderField(String staticCoderField) { - this.staticCoderField = staticCoderField; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("CustomCoder [className=").append(className).append(", staticCoderField=") - .append(staticCoderField).append("]"); - return builder.toString(); - } - } - - public static class CustomGsonCoder extends CustomCoder { - - public CustomGsonCoder(String className, String staticCoderField) { - super(className, staticCoderField); - } - - public CustomGsonCoder(String customGson) { - super(customGson); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("CustomGsonCoder [toString()=").append(super.toString()).append("]"); - return builder.toString(); - } - - } - - public static class CustomJacksonCoder extends CustomCoder { - - public CustomJacksonCoder(String className, String staticCoderField) { - super(className, staticCoderField); - } - - public CustomJacksonCoder(String customJackson) { - super(customJackson); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("CustomJacksonCoder [toString()=").append(super.toString()).append("]"); - return builder.toString(); - } - - } - - /** - * Coder/Decoder class and Filter container. The decoder class is potential, - * in order to be operational needs to be fetched from an available - * class loader. - * - */ - public static class PotentialCoderFilter { - - /** - * decoder class (pending from being able to be fetched and found - * in some class loader) - */ - protected String codedClass; - - /** - * filters to apply to the selection of the decodedClass; - */ - protected JsonProtocolFilter filter; - - /** - * constructor - * - * @param codedClass decoder class - * @param filter filters to apply - */ - public PotentialCoderFilter(String codedClass, JsonProtocolFilter filter) { - this.codedClass = codedClass; - this.filter = filter; - } - - /** - * @return the decodedClass - */ - public String getCodedClass() { - return codedClass; - } - - /** - * @param decodedClass the decodedClass to set - */ - public void setCodedClass(String decodedClass) { - this.codedClass = decodedClass; - } - - /** - * @return the filter - */ - public JsonProtocolFilter getFilter() { - return filter; - } - - /** - * @param filter the filter to set - */ - public void setFilter(JsonProtocolFilter filter) { - this.filter = filter; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("PotentialCoderFilter [codedClass=").append(codedClass).append(", filter=").append(filter) - .append("]"); - return builder.toString(); - } - } - - /** - * the source topic - */ - protected final String topic; - - /** - * List of decoder -> filters - */ - protected final List<PotentialCoderFilter> coderFilters; - - /** - * custom gson coder that this controller prefers to use instead of the framework ones - */ - protected CustomGsonCoder customGsonCoder; - - /** - * custom jackson coder that this controller prefers to use instead of the framework ones - */ - protected CustomJacksonCoder customJacksonCoder; - - /** - * Constructor - * - * @param decoderFilters list of decoders and associated filters - * @param topic the topic - */ - public TopicCoderFilterConfiguration(String topic, List<PotentialCoderFilter> decoderFilters, - CustomGsonCoder customGsonCoder, - CustomJacksonCoder customJacksonCoder) { - this.coderFilters = decoderFilters; - this.topic = topic; - this.customGsonCoder = customGsonCoder; - this.customJacksonCoder = customJacksonCoder; - } - - /** - * @return the topic - */ - public String getTopic() { - return topic; - } - - /** - * @return the decoderFilters - */ - public List<PotentialCoderFilter> getCoderFilters() { - return coderFilters; - } - - /** - * @return the customGsonCoder - */ - public CustomGsonCoder getCustomGsonCoder() { - return customGsonCoder; - } - - /** - * @param customGsonCoder the customGsonCoder to set - */ - public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) { - this.customGsonCoder = customGsonCoder; - } - - /** - * @return the customJacksonCoder - */ - public CustomJacksonCoder getCustomJacksonCoder() { - return customJacksonCoder; - } - - /** - * @param customJacksonCoder the customJacksonCoder to set - */ - public void setCustomJacksonCoder(CustomJacksonCoder customJacksonCoder) { - this.customJacksonCoder = customJacksonCoder; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("TopicCoderFilterConfiguration [topic=").append(topic).append(", coderFilters=") - .append(coderFilters).append(", customGsonCoder=").append(customGsonCoder) - .append(", customJacksonCoder=").append(customJacksonCoder).append("]"); - return builder.toString(); - } + /** + * Custom coder, contains class and static field to access parser that the controller desires to + * use instead of the framework provided parser. + */ + public abstract static class CustomCoder { + protected String className; + protected String staticCoderField; + /** + * create custom coder from raw string in the following format (typically embedded in a property + * file): + * + * <p>Note this is to support decoding/encoding of partial structures that are only known by the + * model. + * + * @param rawCustomCoder with format: <class-containing-custom-coder>,<static-coder-field>. + */ + public CustomCoder(String rawCustomCoder) { + if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) { + this.className = rawCustomCoder.substring(0, rawCustomCoder.indexOf(",")); + if (this.className == null || this.className.isEmpty()) { + throw new IllegalArgumentException( + "No classname to create CustomCoder cannot be created"); + } + + this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(",") + 1); + if (this.staticCoderField == null || this.staticCoderField.isEmpty()) { + throw new IllegalArgumentException( + "No staticCoderField to create CustomCoder cannot be created for class " + className); + } + } + } + + /** + * Constructor. + * + * @param className class name + * @param staticCoderField static coder field + */ + public CustomCoder(String className, String staticCoderField) { + if (className == null || className.isEmpty()) { + throw new IllegalArgumentException("No classname to create CustomCoder cannot be created"); + } + + if (staticCoderField == null || staticCoderField.isEmpty()) { + throw new IllegalArgumentException( + "No staticCoderField to create CustomCoder cannot be created for class " + className); + } + + this.className = className; + this.staticCoderField = staticCoderField; + } + + /** + * Get class container. + * + * @return the className + **/ + public String getClassContainer() { + return className; + } + + /** + * Set class container. + * + * @param className the className to set + **/ + public void setClassContainer(String className) { + this.className = className; + } + + /** + * Get static coder field. + * + * @return the staticCoderField + **/ + public String getStaticCoderField() { + return staticCoderField; + } + + /** + * Set static coder field. + * + * @param staticCoderField the staticGson to set + **/ + public void setStaticCoderField(String staticCoderField) { + this.staticCoderField = staticCoderField; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder + .append("CustomCoder [className=") + .append(className) + .append(", staticCoderField=") + .append(staticCoderField) + .append("]"); + return builder.toString(); + } + } + + public static class CustomGsonCoder extends CustomCoder { + + public CustomGsonCoder(String className, String staticCoderField) { + super(className, staticCoderField); + } + + public CustomGsonCoder(String customGson) { + super(customGson); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CustomGsonCoder [toString()=").append(super.toString()).append("]"); + return builder.toString(); + } + } + + public static class CustomJacksonCoder extends CustomCoder { + + public CustomJacksonCoder(String className, String staticCoderField) { + super(className, staticCoderField); + } + + public CustomJacksonCoder(String customJackson) { + super(customJackson); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CustomJacksonCoder [toString()=").append(super.toString()).append("]"); + return builder.toString(); + } + } + + /** + * Coder/Decoder class and Filter container. The decoder class is potential, in order to be + * operational needs to be fetched from an available class loader. + */ + public static class PotentialCoderFilter { + + /* decoder class (pending from being able to be fetched and found in some class loader) */ + protected String codedClass; + + /* filters to apply to the selection of the decodedClass; */ + protected JsonProtocolFilter filter; + + /** + * constructor. + * + * @param codedClass decoder class + * @param filter filters to apply + */ + public PotentialCoderFilter(String codedClass, JsonProtocolFilter filter) { + this.codedClass = codedClass; + this.filter = filter; + } + + /** + * Get coded class. + * + * @return the decodedClass + **/ + public String getCodedClass() { + return codedClass; + } + + /** Set coded class. + * + * @param decodedClass the decodedClass to set + **/ + public void setCodedClass(String decodedClass) { + this.codedClass = decodedClass; + } + + /** + * Get filter. + * + * @return the filter + **/ + public JsonProtocolFilter getFilter() { + return filter; + } + + /** + * Set filter. + * + * @param filter the filter to set + **/ + public void setFilter(JsonProtocolFilter filter) { + this.filter = filter; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder + .append("PotentialCoderFilter [codedClass=") + .append(codedClass) + .append(", filter=") + .append(filter) + .append("]"); + return builder.toString(); + } + } + + /* the source topic */ + protected final String topic; + + /* List of decoder -> filters */ + protected final List<PotentialCoderFilter> coderFilters; + + /* custom gson coder that this controller prefers to use instead of the framework ones */ + protected CustomGsonCoder customGsonCoder; + + /* custom jackson coder that this controller prefers to use instead of the framework ones */ + protected CustomJacksonCoder customJacksonCoder; + + /** + * Constructor. + * + * @param decoderFilters list of decoders and associated filters + * @param topic the topic + */ + public TopicCoderFilterConfiguration( + String topic, + List<PotentialCoderFilter> decoderFilters, + CustomGsonCoder customGsonCoder, + CustomJacksonCoder customJacksonCoder) { + this.coderFilters = decoderFilters; + this.topic = topic; + this.customGsonCoder = customGsonCoder; + this.customJacksonCoder = customJacksonCoder; + } + + /** + * Get topic. + * @return the topic + **/ + public String getTopic() { + return topic; + } + + /** Get coder filters. + * + * @return the decoderFilters + **/ + public List<PotentialCoderFilter> getCoderFilters() { + return coderFilters; + } + + /** + * Get custom gson coder. + * + * @return the customGsonCoder + **/ + public CustomGsonCoder getCustomGsonCoder() { + return customGsonCoder; + } + + /** + * Set custom gson coder. + * + * @param customGsonCoder the customGsonCoder to set + **/ + public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) { + this.customGsonCoder = customGsonCoder; + } + + /** Get custom jackson coder. + * + * @return the customJacksonCoder + **/ + public CustomJacksonCoder getCustomJacksonCoder() { + return customJacksonCoder; + } + + /** + * Set custom Jackson coder. + * @param customJacksonCoder the customJacksonCoder to set + **/ + public void setCustomJacksonCoder(CustomJacksonCoder customJacksonCoder) { + this.customJacksonCoder = customJacksonCoder; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder + .append("TopicCoderFilterConfiguration [topic=") + .append(topic) + .append(", coderFilters=") + .append(coderFilters) + .append(", customGsonCoder=") + .append(customGsonCoder) + .append(", customJacksonCoder=") + .append(customJacksonCoder) + .append("]"); + return builder.toString(); + } } |