d15d7ed47229bd42f704f7397de7c7f94904bd32
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.service.parameters.eventprotocol;
23
24 import org.onap.policy.common.parameters.GroupValidationResult;
25 import org.onap.policy.common.parameters.ValidationStatus;
26
27 /**
28  * An event protocol parameter class for character delimited textual event protocols that may be specialized by event
29  * protocol plugins that require plugin specific parameters.
30  *
31  * <p>The following parameters are defined:
32  * <ol>
33  * <li>startChar: starting character delimiter for text blocks containing an event.
34  * <li>endChar: ending character delimiter for text blocks containing an event.
35  * </ol>
36  *
37  * @author Liam Fallon (liam.fallon@ericsson.com)
38  */
39 public abstract class EventProtocolTextCharDelimitedParameters extends EventProtocolParameters {
40     // The starting and ending character delimiter
41     private char startChar = '\0';
42     private char endChar = '\0';
43
44     /**
45      * Constructor to create an event protocol parameters instance with the name of a sub class of this class.
46      */
47     protected EventProtocolTextCharDelimitedParameters() {
48         super();
49     }
50
51     /**
52      * Gets the start character that delimits the start of text blocks.
53      *
54      * @return the start char
55      */
56     public char getStartChar() {
57         return startChar;
58     }
59
60     /**
61      * Sets the start character that delimits the start of text blocks.
62      *
63      * @param startChar the start character
64      */
65     public void setStartChar(final char startChar) {
66         this.startChar = startChar;
67     }
68
69     /**
70      * Gets the end character that delimits the end of text blocks.
71      *
72      * @return the end character
73      */
74     public char getEndChar() {
75         return endChar;
76     }
77
78     /**
79      * Sets the end character that delimits the end of text blocks.
80      *
81      * @param endChar the end character
82      */
83     public void setEndChar(final char endChar) {
84         this.endChar = endChar;
85     }
86
87     /**
88      * {@inheritDoc}.
89      */
90     @Override
91     public String toString() {
92         return "EventProtocolTextCharDelimitedParameters {" + super.toString() + "} [startChar=" + startChar
93                         + ", endChar=" + endChar + "]";
94     }
95
96     /**
97      * {@inheritDoc}.
98      */
99     @Override
100     public GroupValidationResult validate() {
101         final GroupValidationResult result = super.validate();
102
103         if (startChar == '\0') {
104             result.setResult("startChar", ValidationStatus.INVALID,
105                             "text character delimited start character has not been specified");
106         }
107
108         if (endChar == '\0') {
109             result.setResult("endChar", ValidationStatus.INVALID,
110                             "text character delimited end character has not been specified\n");
111         }
112
113         return result;
114     }
115 }