f8873ada4bb54eee0fb75caa263a0ccec7fe15f7
[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 character delimited textual event protocols that may be
27  * specialized by event protocol plugins that require plugin specific parameters.
28  *
29  * <p>
30  * The following parameters are defined:
31  * <ol>
32  * <li>startChar: starting character delimiter for text blocks containing an event.
33  * <li>endChar: ending character delimiter for text blocks containing an event.
34  * </ol>
35  *
36  * @author Liam Fallon (liam.fallon@ericsson.com)
37  */
38 public abstract class EventProtocolTextCharDelimitedParameters extends EventProtocolParameters
39         implements ApexParameterValidator {
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
46      * this class.
47      *
48      * @param parameterClassName the class name of a sub class of this class
49      */
50     public EventProtocolTextCharDelimitedParameters(final String parameterClassName) {
51         super(parameterClassName);
52     }
53
54     /**
55      * Gets the start character that delimits the start of text blocks.
56      *
57      * @return the start char
58      */
59     public char getStartChar() {
60         return startChar;
61     }
62
63     /**
64      * Sets the start character that delimits the start of text blocks.
65      *
66      * @param startChar the start character
67      */
68     public void setStartChar(final char startChar) {
69         this.startChar = startChar;
70     }
71
72     /**
73      * Gets the end character that delimits the end of text blocks.
74      *
75      * @return the end character
76      */
77     public char getEndChar() {
78         return endChar;
79     }
80
81     /**
82      * Sets the end character that delimits the end of text blocks.
83      *
84      * @param endChar the end character
85      */
86     public void setEndChar(final char endChar) {
87         this.endChar = endChar;
88     }
89
90     /*
91      * (non-Javadoc)
92      * 
93      * @see org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters#toString()
94      */
95     @Override
96     public String toString() {
97         return "EventProtocolTextCharDelimitedParameters {" + super.toString() + "} [startChar=" + startChar
98                 + ", endChar=" + endChar + "]";
99     }
100
101     /*
102      * (non-Javadoc)
103      * 
104      * @see org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters#validate()
105      */
106     @Override
107     public String validate() {
108         final StringBuilder errorMessageBuilder = new StringBuilder();
109
110         errorMessageBuilder.append(super.validate());
111
112         if (startChar == '\0') {
113             errorMessageBuilder.append("  text character delimited start character has not been specified\n");
114         }
115
116         if (endChar == '\0') {
117             errorMessageBuilder.append("  text character delimited end character has not been specified\n");
118         }
119
120         return errorMessageBuilder.toString();
121     }
122 }