d10d81ce2e7806cb8911e9e7bb84e921fc1f8db3
[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.common.parameters.GroupValidationResult;
24 import org.onap.policy.common.parameters.ValidationStatus;
25
26 /**
27  * An event protocol parameter class for character delimited textual event protocols that may be specialized by event
28  * protocol plugins that require plugin specific parameters.
29  *
30  * <p>
31  * 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      * @param parameterClassName the class name of a sub class of this class
48      */
49     public EventProtocolTextCharDelimitedParameters(final String parameterClassName) {
50         super(parameterClassName);
51     }
52
53     /**
54      * Gets the start character that delimits the start of text blocks.
55      *
56      * @return the start char
57      */
58     public char getStartChar() {
59         return startChar;
60     }
61
62     /**
63      * Sets the start character that delimits the start of text blocks.
64      *
65      * @param startChar the start character
66      */
67     public void setStartChar(final char startChar) {
68         this.startChar = startChar;
69     }
70
71     /**
72      * Gets the end character that delimits the end of text blocks.
73      *
74      * @return the end character
75      */
76     public char getEndChar() {
77         return endChar;
78     }
79
80     /**
81      * Sets the end character that delimits the end of text blocks.
82      *
83      * @param endChar the end character
84      */
85     public void setEndChar(final char endChar) {
86         this.endChar = endChar;
87     }
88
89     /*
90      * (non-Javadoc)
91      * 
92      * @see org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters#toString()
93      */
94     @Override
95     public String toString() {
96         return "EventProtocolTextCharDelimitedParameters {" + super.toString() + "} [startChar=" + startChar
97                         + ", endChar=" + endChar + "]";
98     }
99
100     /*
101      * (non-Javadoc)
102      * 
103      * @see org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters#validate()
104      */
105     @Override
106     public GroupValidationResult validate() {
107         final GroupValidationResult result = super.validate();
108
109         if (startChar == '\0') {
110             result.setResult("startChar", ValidationStatus.INVALID,
111                             "text character delimited start character has not been specified");
112         }
113
114         if (endChar == '\0') {
115             result.setResult("endChar", ValidationStatus.INVALID,
116                             "text character delimited end character has not been specified\n");
117         }
118
119         return result;
120     }
121 }