1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.metricshub.wbem.sblim.slp.internal.msg;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 import java.util.Iterator;
47 import java.util.List;
48 import java.util.SortedSet;
49 import java.util.TreeSet;
50 import org.metricshub.wbem.sblim.slp.ServiceLocationException;
51 import org.metricshub.wbem.sblim.slp.internal.msg.SLPMessage;
52
53
54
55
56
57 public abstract class RequestMessage extends SLPMessage {
58 private SortedSet<String> iPrevResponderSet;
59
60 private List<String> iScopeList;
61
62
63
64
65
66
67
68
69
70
71 public RequestMessage(int pFunctionID, SortedSet<String> pPrevResponderSet, List<String> pScopeList) {
72 super(pFunctionID);
73 init(pPrevResponderSet, pScopeList);
74 }
75
76
77
78
79
80
81
82
83
84
85
86 public RequestMessage(
87 int pFunctionID,
88 String pLangTag,
89 SortedSet<String> pPrevResponderSet,
90 List<String> pScopeList
91 ) {
92 super(pFunctionID, pLangTag);
93 init(pPrevResponderSet, pScopeList);
94 }
95
96
97
98
99
100
101
102
103
104
105 public RequestMessage(MsgHeader pHeader, SortedSet<String> pPrevResponderSet, List<String> pScopeList) {
106 super(pHeader);
107 init(pPrevResponderSet, pScopeList);
108 }
109
110
111
112
113
114
115 public SortedSet<String> getPrevResponderSet() {
116 return this.iPrevResponderSet;
117 }
118
119
120
121
122
123
124 public Iterator<String> getPrevRespondersItr() {
125 return this.iPrevResponderSet == null ? null : this.iPrevResponderSet.iterator();
126 }
127
128
129
130
131
132
133
134 public boolean updatePrevResponders(String pResponder) {
135 if (this.iPrevResponderSet == null) this.iPrevResponderSet = new TreeSet<String>();
136 return this.iPrevResponderSet.add(pResponder);
137 }
138
139
140
141
142
143
144 public List<String> getScopeList() {
145 return this.iScopeList;
146 }
147
148
149
150
151
152
153
154 public boolean isAllowedResponseType(SLPMessage pRspMsg) {
155 if (pRspMsg == null) return false;
156 int id = pRspMsg.getFunctionID();
157 int[] rspIDs = getAllowedResponseIDs();
158 if (rspIDs == null) return true;
159 for (int i = 0; i < rspIDs.length; i++) if (id == rspIDs[i]) return true;
160 return false;
161 }
162
163
164
165
166
167
168
169
170
171
172 public byte[] serializeWithoutResponders(boolean pSetMulticastFlag, boolean pDatagramLimited, boolean pKeepXID)
173 throws ServiceLocationException {
174 return serialize(pSetMulticastFlag, pDatagramLimited, pKeepXID, new SkipResponders());
175 }
176
177 @Override
178 protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pSkipResponders)
179 throws ServiceLocationException {
180 if (
181 !pOutStr.writeStringList(pSkipResponders == null ? getPrevRespondersItr() : null)
182 ) throw new ServiceLocationException(
183 ServiceLocationException.PREVIOUS_RESPONDER_OVERFLOW,
184 "Previous responder list has overflowed!"
185 );
186 return serializeRequestBody(pOutStr);
187 }
188
189 protected abstract boolean serializeRequestBody(SLPOutputStream pOutStr) throws ServiceLocationException;
190
191 protected abstract int[] getAllowedResponseIDs();
192
193 private void init(SortedSet<String> pPrevResponderSet, List<String> pScopeList) {
194 this.iPrevResponderSet = pPrevResponderSet;
195 this.iScopeList = pScopeList;
196 }
197
198 class SkipResponders extends SerializeOption {
199
200
201
202
203 }
204 }