1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1999 by Sun Microsystems, Inc.
* All rights reserved.
*
*/
// SLPV1SSrvReg.java: Message class for SLP service registration request.
// Author: James Kempf
// Created On: Thu Oct 9 14:47:48 1997
// Last Modified By: James Kempf
// Last Modified On: Thu Mar 25 15:30:25 1999
// Update Count: 80
//
package com.sun.slp;
import java.util.*;
import java.io.*;
/**
* The SLPV1SSrvReg class models the server side SLPv1 service registration.
*
* @author James Kempf
*/
class SLPV1SSrvReg extends SSrvReg {
// For identifying scopes.
static private final String SCOPE_ATTR_ID = "scope";
// Construct a SLPV1SSrvReg from the input stream.
SLPV1SSrvReg(SrvLocHeader hdr, DataInputStream dis)
throws ServiceLocationException, IOException {
super(hdr, dis);
}
// Initialzie the object from the stream.
void initialize(DataInputStream dis)
throws ServiceLocationException, IOException {
SLPHeaderV1 hdr = (SLPHeaderV1)getHeader();
StringBuffer buf = new StringBuffer();
// Parse in the service URL
Hashtable table = new Hashtable();
URL =
hdr.parseServiceURLIn(dis,
true,
ServiceLocationException.INVALID_REGISTRATION);
serviceType = URL.getServiceType().toString();
// Parse in the attribute list.
attrList = hdr.parseAttributeVectorIn(dis);
// Get the scopes. Note that if there's no scope, the request
// will automatically be rejected as SCOPE_NOT_SUPPORTED.
int i, n = attrList.size();
Vector scopes = new Vector();
for (i = 0; i < n; i++) {
ServiceLocationAttribute attr =
(ServiceLocationAttribute)attrList.elementAt(i);
String id = attr.getId().toLowerCase().trim();
if (id.equals(SCOPE_ATTR_ID)) {
Vector vals = attr.getValues();
int j, m = vals.size();
for (j = 0; j < m; j++) {
Object o = vals.elementAt(j);
// Must be a string in v1!
if (!(o instanceof String)) {
throw
new ServiceLocationException(
ServiceLocationException.INVALID_REGISTRATION,
"v1_scope_format",
new Object[] {vals});
}
String scope = (String)o;
hdr.validateScope(scope);
scopes.addElement(scope);
}
}
}
// If the vector is empty, then add empty string as the scope name.
// This will cause the service table to throw the registration
// as scope not supported. If unscoped regs are supported, then
// change to default scope.
if (scopes.size() <= 0) {
if (!SLPConfig.getSLPConfig().getAcceptSLPv1UnscopedRegs()) {
scopes.addElement("");
} else {
scopes.addElement(Defaults.DEFAULT_SCOPE);
}
}
hdr.scopes = scopes;
// Check if the registration is fresh or not.
hdr.fresh = true;
// Perform lookup for existing.
ServiceStore.ServiceRecord rec =
ServiceTable.getServiceTable().getServiceRecord(URL, hdr.locale);
if (rec != null) {
// Check scopes.
Vector recScopes = (Vector)rec.getScopes().clone();
DATable.filterScopes(recScopes, scopes, true);
// If it is registered in the same scopes, then it is considered
// to be the same. Otherwise, it replaces.
if (recScopes.size() == 0) {
hdr.fresh = false;
}
}
hdr.constructDescription("SrvReg",
" URL=``" + URL + "''\n" +
" attribute list=``" +
attrList + "''\n");
}
// Return a SrvAck.
SrvLocMsg makeReply(boolean existing) {
SLPHeaderV1 hdr = ((SLPHeaderV1)getHeader()).makeReplyHeader();
hdr.fresh = existing;
// Construct description.
hdr.constructDescription("SrvAck", "");
return hdr;
}
}
|