View Javadoc
1   /*
2     (C) Copyright IBM Corp. 2007, 2009
3   
4     THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
5     ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
6     CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
7   
8     You can obtain a current copy of the Eclipse Public License from
9     http://www.opensource.org/licenses/eclipse-1.0.php
10  
11    @author : Endre Bak, IBM, ebak@de.ibm.com
12   * 
13   * Change History
14   * Flag       Date        Prog         Description
15   *------------------------------------------------------------------------------- 
16   * 1804402    2007-09-28  ebak         IPv6 ready SLP
17   * 1892103    2008-02-15  ebak         SLP improvements
18   * 2003590    2008-06-30  blaschke-oss Change licensing from CPL to EPL
19   * 2524131    2009-01-21  raman_arora  Upgrade client to JDK 1.5 (Phase 1)
20   * 2531371    2009-02-10  raman_arora  Upgrade client to JDK 1.5 (Phase 2) 
21   */
22  
23  package org.metricshub.wbem.sblim.slp.internal.msg;
24  
25  /*-
26   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
27   * WBEM Java Client
28   * ჻჻჻჻჻჻
29   * Copyright 2023 - 2025 MetricsHub
30   * ჻჻჻჻჻჻
31   * Licensed under the Apache License, Version 2.0 (the "License");
32   * you may not use this file except in compliance with the License.
33   * You may obtain a copy of the License at
34   *
35   *      http://www.apache.org/licenses/LICENSE-2.0
36   *
37   * Unless required by applicable law or agreed to in writing, software
38   * distributed under the License is distributed on an "AS IS" BASIS,
39   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40   * See the License for the specific language governing permissions and
41   * limitations under the License.
42   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
43   */
44  
45  import java.io.IOException;
46  import java.util.List;
47  import java.util.SortedSet;
48  import org.metricshub.wbem.sblim.slp.ServiceLocationException;
49  import org.metricshub.wbem.sblim.slp.ServiceURL;
50  
51  /*
52   * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
53   * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service
54   * Location header (function = AttrRqst = 6) |
55   * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of
56   * PRList | <PRList> String \
57   * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of
58   * URL | URL \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
59   * length of <scope-list> | <scope-list> string \
60   * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of
61   * <tag-list> string | <tag-list> string \
62   * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of
63   * <SLP SPI> string | <SLP SPI> string \
64   * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65   */
66  
67  /**
68   * AttributeRequest message
69   *
70   */
71  public class AttributeRequest extends RequestMessage {
72  	private String iURLStr;
73  
74  	private List<String> iTagList;
75  
76  	private List<String> iSPIList;
77  
78  	private static final int[] ALLOWED_RSPS = { ATTR_RPLY };
79  
80  	/**
81  	 * parse
82  	 *
83  	 * @param pHdr
84  	 * @param pInStr
85  	 * @return SLPMessage
86  	 * @throws ServiceLocationException
87  	 * @throws IOException
88  	 */
89  	public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException {
90  		return new AttributeRequest(
91  			pHdr,
92  			pInStr.readStringSet(),
93  			pInStr.readString(),
94  			pInStr.readStringList(),
95  			pInStr.readStringList(),
96  			pInStr.readStringList()
97  		);
98  	}
99  
100 	/**
101 	 * Ctor.
102 	 *
103 	 * @param pPrevResponderSet
104 	 *            - set of address strings
105 	 * @param pURLStr
106 	 * @param pScopeList
107 	 *            - list of scope strings
108 	 * @param pTagList
109 	 * @param pSPIList
110 	 */
111 	public AttributeRequest(
112 		SortedSet<String> pPrevResponderSet,
113 		String pURLStr,
114 		List<String> pScopeList,
115 		List<String> pTagList,
116 		List<String> pSPIList
117 	) {
118 		super(ATTR_RQST, pPrevResponderSet, pScopeList);
119 		init(pURLStr, pTagList, pSPIList);
120 	}
121 
122 	/**
123 	 * Ctor.
124 	 *
125 	 * @param pLangTag
126 	 * @param pPrevResponderSet
127 	 *            - set of address strings
128 	 * @param pURLStr
129 	 * @param pScopeList
130 	 *            - list of scope strings
131 	 * @param pTagList
132 	 * @param pSPIList
133 	 */
134 	public AttributeRequest(
135 		String pLangTag,
136 		SortedSet<String> pPrevResponderSet,
137 		String pURLStr,
138 		List<String> pScopeList,
139 		List<String> pTagList,
140 		List<String> pSPIList
141 	) {
142 		super(ATTR_RQST, pLangTag, pPrevResponderSet, pScopeList);
143 		init(pURLStr, pTagList, pSPIList);
144 	}
145 
146 	/**
147 	 * Ctor.
148 	 *
149 	 * @param pHeader
150 	 * @param pPrevResponderSet
151 	 *            - set of address strings
152 	 * @param pURLStr
153 	 * @param pScopeList
154 	 *            - list of scope strings
155 	 * @param pTagList
156 	 * @param pSPIList
157 	 */
158 	public AttributeRequest(
159 		MsgHeader pHeader,
160 		SortedSet<String> pPrevResponderSet,
161 		String pURLStr,
162 		List<String> pScopeList,
163 		List<String> pTagList,
164 		List<String> pSPIList
165 	) {
166 		super(pHeader, pPrevResponderSet, pScopeList);
167 		init(pURLStr, pTagList, pSPIList);
168 	}
169 
170 	/**
171 	 * getServiceURL
172 	 *
173 	 * @return ServiceURL
174 	 */
175 	public ServiceURL getServiceURL() {
176 		return new ServiceURL(this.iURLStr, 65535);
177 	}
178 
179 	@Override
180 	protected boolean serializeRequestBody(SLPOutputStream pOutStr) {
181 		return (
182 			pOutStr.write(this.iURLStr) &&
183 			pOutStr.writeStringList(getScopeList()) &&
184 			pOutStr.writeStringList(this.iTagList) &&
185 			pOutStr.writeStringList(this.iSPIList)
186 		);
187 	}
188 
189 	@Override
190 	protected int[] getAllowedResponseIDs() {
191 		return ALLOWED_RSPS;
192 	}
193 
194 	private void init(String pURLStr, List<String> pTagList, List<String> pSPIList) {
195 		this.iURLStr = pURLStr;
196 		this.iTagList = pTagList;
197 		this.iSPIList = pSPIList;
198 	}
199 }