xref: /onnv-gate/usr/src/lib/libslp/javalib/com/sun/slp/SLPV1CDAAdvert.java (revision 7298:b69e27387f74)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7298SMark.J.Nelson@Sun.COM  * Common Development and Distribution License (the "License").
6*7298SMark.J.Nelson@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
220Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
230Sstevel@tonic-gate  * All rights reserved.
240Sstevel@tonic-gate  *
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate //  SLPV1CDAAdvert.java: SLP V1 compatible client side DAAdvert
280Sstevel@tonic-gate //  Author:           James Kempf
290Sstevel@tonic-gate //  Created On:       Fri Oct  9 14:20:16 1998
300Sstevel@tonic-gate //  Last Modified By: James Kempf
310Sstevel@tonic-gate //  Last Modified On: Mon Nov  2 15:59:49 1998
320Sstevel@tonic-gate //  Update Count:     10
330Sstevel@tonic-gate //
340Sstevel@tonic-gate 
350Sstevel@tonic-gate 
360Sstevel@tonic-gate package com.sun.slp;
370Sstevel@tonic-gate 
380Sstevel@tonic-gate import java.util.*;
390Sstevel@tonic-gate import java.io.*;
400Sstevel@tonic-gate 
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /**
430Sstevel@tonic-gate  * The SLPV1CDAAdvert class models the SLP V1 DAAdvert message, client side.
440Sstevel@tonic-gate  *
450Sstevel@tonic-gate  * @author James Kempf
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate 
480Sstevel@tonic-gate class SLPV1CDAAdvert extends CDAAdvert {
490Sstevel@tonic-gate 
500Sstevel@tonic-gate     boolean unsolicited = true;   // we assume unsolicited, set if solicited.
510Sstevel@tonic-gate 
520Sstevel@tonic-gate     // Construct a SLPV1CDAAdvert from the byte input stream.
530Sstevel@tonic-gate 
SLPV1CDAAdvert(SLPHeaderV1 hdr, DataInputStream dis)540Sstevel@tonic-gate     SLPV1CDAAdvert(SLPHeaderV1 hdr, DataInputStream dis)
550Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
560Sstevel@tonic-gate 	super(hdr, dis);
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	// Super initializes it.
590Sstevel@tonic-gate 
600Sstevel@tonic-gate     }
610Sstevel@tonic-gate 
620Sstevel@tonic-gate     // Initialize object from input stream.
630Sstevel@tonic-gate 
initialize(DataInputStream dis)640Sstevel@tonic-gate     protected void initialize(DataInputStream dis)
650Sstevel@tonic-gate 	throws ServiceLocationException, IOException {
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 	SLPHeaderV1 hdr = (SLPHeaderV1)getHeader();
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 	// Parse in error code.
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	hdr.errCode = (short)hdr.getInt(dis);
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	// Don't parse the rest if there's an error.
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	if (hdr.errCode != ServiceLocationException.OK) {
760Sstevel@tonic-gate 	    return;
770Sstevel@tonic-gate 	}
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 	// Parse in DA's service URL.
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	URL =
820Sstevel@tonic-gate 	    hdr.parseServiceURLIn(dis,
830Sstevel@tonic-gate 				  false,
840Sstevel@tonic-gate 				  ServiceLocationException.PARSE_ERROR);
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 	// Validate the service URL.
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	ServiceType serviceType = URL.getServiceType();
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	if (!serviceType.equals(Defaults.DA_SERVICE_TYPE)) {
910Sstevel@tonic-gate 	    throw
920Sstevel@tonic-gate 		new ServiceLocationException(
930Sstevel@tonic-gate 				ServiceLocationException.PARSE_ERROR,
940Sstevel@tonic-gate 				"not_right_url",
950Sstevel@tonic-gate 				new Object[] {URL, "DA"});
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	}
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	// Parse in the scope list.
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 	StringBuffer buf = new StringBuffer();
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	hdr.getString(buf, dis);
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	hdr.scopes = hdr.parseCommaSeparatedListIn(buf.toString(), true);
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	// Validate the scope list.
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 	int i, n = hdr.scopes.size();
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
1120Sstevel@tonic-gate 	    String scope = (String)hdr.scopes.elementAt(i);
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	    SLPHeaderV1.validateScope(scope);
1150Sstevel@tonic-gate 	    hdr.scopes.setElementAt(scope.toLowerCase().trim(), i);
1160Sstevel@tonic-gate 	}
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 	// If they are unscoped and we support unscoped regs, then
1190Sstevel@tonic-gate 	//  change the scope name to default. We don't check whether we
1200Sstevel@tonic-gate 	//  support default or not. We actually don't use these at
1210Sstevel@tonic-gate 	//  the moment, but we still keep track of them in case we
1220Sstevel@tonic-gate 	//  ever do reg forwarding.
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	SLPConfig config = SLPConfig.getSLPConfig();
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	if (config.getAcceptSLPv1UnscopedRegs() &&
1270Sstevel@tonic-gate 	    hdr.scopes.size() == 0) {
1280Sstevel@tonic-gate 	    hdr.scopes.addElement(Defaults.DEFAULT_SCOPE);
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	}
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate 	hdr.iNumReplies = 1;
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate     }
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate     // Can't tell if the DA is going down or not from the advert in V1,
1370Sstevel@tonic-gate     //  but it doesn't matter since they won't tell us anyway.
1380Sstevel@tonic-gate 
isGoingDown()1390Sstevel@tonic-gate     boolean isGoingDown() {
1400Sstevel@tonic-gate 	return false;
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate     }
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate     // Return true if the advert was unsolicited.
1450Sstevel@tonic-gate 
isUnsolicited()1460Sstevel@tonic-gate     boolean isUnsolicited() {
1470Sstevel@tonic-gate 	return unsolicited;
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate     }
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate     // Set unSolicited flag.
1520Sstevel@tonic-gate 
setIsUnsolicited(boolean flag)1530Sstevel@tonic-gate     void setIsUnsolicited(boolean flag) {
1540Sstevel@tonic-gate 	unsolicited = flag;
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate     }
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate }
159