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