Sonar Fixes, Formatting
[aaf/authz.git] / cadi / core / src / main / java / org / onap / aaf / cadi / wsse / XEvent.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.cadi.wsse;
23
24 import javax.xml.namespace.QName;
25 import javax.xml.stream.events.XMLEvent;
26
27 /**
28  * XEvent
29  *
30  * This mechanism mimics a minimal portion of StAX "XMLEvent", enough to work with minimal XReader.
31  *
32  * We implement the same interface, as much as minimally necessary, as XMLEvent for these small usages so as to
33  * be interchangeable in the future, if so desired
34  *
35  * @author Jonathan
36  *
37  */
38 // @SuppressWarnings("restriction")
39 public abstract class XEvent {
40
41     public abstract int getEventType();
42
43     public StartElement asStartElement() {
44         return (StartElement)this;
45     }
46
47     public Characters asCharacters() {
48         return (Characters)this;
49     }
50
51     public EndElement asEndElement() {
52         return (EndElement)this;
53     }
54
55     public static abstract class NamedXEvent extends XEvent {
56         private QName qname;
57
58         public NamedXEvent(QName qname) {
59             this.qname = qname;
60         }
61
62         public QName getName() {
63             return qname;
64         }
65     }
66     public static class StartElement extends NamedXEvent {
67
68         public StartElement(String ns, String tag) {
69             super(new QName(ns,tag));
70         }
71
72         @Override
73         public int getEventType() {
74             return XMLEvent.START_ELEMENT;
75         }
76     }
77
78     public static class EndElement extends NamedXEvent {
79         public EndElement(String ns, String tag) {
80             super(new QName(ns,tag));
81         }
82
83         @Override
84         public int getEventType() {
85             return XMLEvent.END_ELEMENT;
86         }
87     }
88
89     public static class Characters extends XEvent {
90         private String data;
91
92         public Characters(String data) {
93             this.data = data;
94         }
95         @Override
96         public int getEventType() {
97             return XMLEvent.CHARACTERS;
98         }
99
100         public String getData() {
101             return data;
102         }
103     }
104
105     public static class StartDocument extends XEvent {
106
107         @Override
108         public int getEventType() {
109             return XMLEvent.START_DOCUMENT;
110         }
111
112     }
113
114     public static class EndDocument extends XEvent {
115
116         @Override
117         public int getEventType() {
118             return XMLEvent.END_DOCUMENT;
119         }
120
121     }
122     public static class Comment extends XEvent {
123         public final String value;
124         public Comment(String value) {
125             this.value = value;
126         }
127
128         @Override
129         public int getEventType() {
130             return XMLEvent.COMMENT;
131         }
132
133     }
134
135 }