91a6403df221c7ccdbbc9adf7cc4283d39d36e9c
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.service.parameters.eventprotocol;
22
23 import org.onap.policy.apex.service.parameters.ApexParameterValidator;
24
25 /**
26  * An event protocol parameter class for token delimited textual event protocols that may be specialized by event
27  * protocol plugins that require plugin specific parameters.
28  *
29  * <p>
30  * The following parameters are defined:
31  * <ol>
32  * <li>startDelimiterToken: the token string that delimits the start of text blocks that contain events.
33  * <li>endDelimiterToken: the token string that delimits the end of text blocks that contain events, this parameter is
34  * optional and defaults to null.
35  * <li>delimiterAtStart: indicates if the first text block should have a delimiter at the start (true), or whether
36  * processing of the first block should begin at the start of the text (false). The parameter is optional and defaults
37  * to true.
38  * </ol>
39  *
40  * @author Liam Fallon (liam.fallon@ericsson.com)
41  */
42 public abstract class EventProtocolTextTokenDelimitedParameters extends EventProtocolParameters
43                 implements ApexParameterValidator {
44     // The delimiter token for text blocks
45     private String startDelimiterToken = null;
46     private String endDelimiterToken = null;
47     private boolean delimiterAtStart = true;
48
49     /**
50      * Constructor to create an event protocol parameters instance with the name of a sub class of this class.
51      *
52      * @param parameterClassName
53      *        the class name of a sub class of this class
54      */
55     public EventProtocolTextTokenDelimitedParameters(final String parameterClassName) {
56         super(parameterClassName);
57     }
58
59     /**
60      * Gets the start delimiter token that delimits events in the text.
61      *
62      * @return the start delimiter token
63      */
64     public String getStartDelimiterToken() {
65         return startDelimiterToken;
66     }
67
68     /**
69      * Sets the start delimiter token that delimits events in the text.
70      *
71      * @param startDelimiterToken
72      *        delimiterToken the delimiter token
73      */
74     public void setStartDelimiterToken(final String startDelimiterToken) {
75         this.startDelimiterToken = startDelimiterToken;
76     }
77
78     /**
79      * Gets the end delimiter token that delimits events in the text.
80      *
81      * @return the end delimiter token
82      */
83     public String getEndDelimiterToken() {
84         return endDelimiterToken;
85     }
86
87     /**
88      * Sets the end delimiter token that delimits events in the text.
89      *
90      * @param endDelimiterToken
91      *        delimiterToken the delimiter token
92      */
93     public void setEndDelimiterToken(final String endDelimiterToken) {
94         this.endDelimiterToken = endDelimiterToken;
95     }
96
97     /**
98      * Does there have to be a delimiter at the start of the first text block?
99      * 
100      * @return true if there must be a delimiter at the start of the text block
101      */
102     public boolean isDelimiterAtStart() {
103         return delimiterAtStart;
104     }
105
106     /**
107      * Sets if there has to be a delimiter at the start of the first text block?
108      * 
109      * @param delimiterAtStart
110      *        true if there must be a delimiter at the start of the text block
111      */
112     public void setDelimiterAtStart(boolean delimiterAtStart) {
113         this.delimiterAtStart = delimiterAtStart;
114     }
115
116     @Override
117     public String toString() {
118         return "EventProtocolTextTokenDelimitedParameters [startDelimiterToken=" + startDelimiterToken
119                         + ", endDelimiterToken=" + endDelimiterToken + ", delimiterAtStart=" + delimiterAtStart + "]";
120     }
121
122     /*
123      * (non-Javadoc)
124      *
125      * @see org.onap.policy.apex.service.parameters.ApexParameterValidator#validate()
126      */
127     @Override
128     public String validate() {
129         final StringBuilder errorMessageBuilder = new StringBuilder();
130
131         errorMessageBuilder.append(super.validate());
132
133         if (startDelimiterToken == null || startDelimiterToken.length() == 0) {
134             errorMessageBuilder.append("  text start delimiter token not specified or is blank\n");
135         }
136
137         return errorMessageBuilder.toString();
138     }
139 }