xref: /illumos-gate/usr/src/lib/libslp/javalib/com/sun/slp/SLPV1CDAAdvert.java (revision 628e3cbed6489fa1db545d8524a06cd6535af456)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1999 by Sun Microsystems, Inc.
23  * All rights reserved.
24  *
25  */
26 
27 //  SLPV1CDAAdvert.java: SLP V1 compatible client side DAAdvert
28 //  Author:           James Kempf
29 //  Created On:       Fri Oct  9 14:20:16 1998
30 //  Last Modified By: James Kempf
31 //  Last Modified On: Mon Nov  2 15:59:49 1998
32 //  Update Count:     10
33 //
34 
35 
36 package com.sun.slp;
37 
38 import java.util.*;
39 import java.io.*;
40 
41 
42 /**
43  * The SLPV1CDAAdvert class models the SLP V1 DAAdvert message, client side.
44  *
45  * @author James Kempf
46  */
47 
48 class SLPV1CDAAdvert extends CDAAdvert {
49 
50     boolean unsolicited = true;   // we assume unsolicited, set if solicited.
51 
52     // Construct a SLPV1CDAAdvert from the byte input stream.
53 
54     SLPV1CDAAdvert(SLPHeaderV1 hdr, DataInputStream dis)
55 	throws ServiceLocationException, IOException {
56 	super(hdr, dis);
57 
58 	// Super initializes it.
59 
60     }
61 
62     // Initialize object from input stream.
63 
64     protected void initialize(DataInputStream dis)
65 	throws ServiceLocationException, IOException {
66 
67 	SLPHeaderV1 hdr = (SLPHeaderV1)getHeader();
68 
69 	// Parse in error code.
70 
71 	hdr.errCode = (short)hdr.getInt(dis);
72 
73 	// Don't parse the rest if there's an error.
74 
75 	if (hdr.errCode != ServiceLocationException.OK) {
76 	    return;
77 	}
78 
79 	// Parse in DA's service URL.
80 
81 	URL =
82 	    hdr.parseServiceURLIn(dis,
83 				  false,
84 				  ServiceLocationException.PARSE_ERROR);
85 
86 	// Validate the service URL.
87 
88 	ServiceType serviceType = URL.getServiceType();
89 
90 	if (!serviceType.equals(Defaults.DA_SERVICE_TYPE)) {
91 	    throw
92 		new ServiceLocationException(
93 				ServiceLocationException.PARSE_ERROR,
94 				"not_right_url",
95 				new Object[] {URL, "DA"});
96 
97 	}
98 
99 	// Parse in the scope list.
100 
101 	StringBuffer buf = new StringBuffer();
102 
103 	hdr.getString(buf, dis);
104 
105 	hdr.scopes = hdr.parseCommaSeparatedListIn(buf.toString(), true);
106 
107 	// Validate the scope list.
108 
109 	int i, n = hdr.scopes.size();
110 
111 	for (i = 0; i < n; i++) {
112 	    String scope = (String)hdr.scopes.elementAt(i);
113 
114 	    SLPHeaderV1.validateScope(scope);
115 	    hdr.scopes.setElementAt(scope.toLowerCase().trim(), i);
116 	}
117 
118 	// If they are unscoped and we support unscoped regs, then
119 	//  change the scope name to default. We don't check whether we
120 	//  support default or not. We actually don't use these at
121 	//  the moment, but we still keep track of them in case we
122 	//  ever do reg forwarding.
123 
124 	SLPConfig config = SLPConfig.getSLPConfig();
125 
126 	if (config.getAcceptSLPv1UnscopedRegs() &&
127 	    hdr.scopes.size() == 0) {
128 	    hdr.scopes.addElement(Defaults.DEFAULT_SCOPE);
129 
130 	}
131 
132 	hdr.iNumReplies = 1;
133 
134     }
135 
136     // Can't tell if the DA is going down or not from the advert in V1,
137     //  but it doesn't matter since they won't tell us anyway.
138 
139     boolean isGoingDown() {
140 	return false;
141 
142     }
143 
144     // Return true if the advert was unsolicited.
145 
146     boolean isUnsolicited() {
147 	return unsolicited;
148 
149     }
150 
151     // Set unSolicited flag.
152 
153     void setIsUnsolicited(boolean flag) {
154 	unsolicited = flag;
155 
156     }
157 
158 }
159