xref: /onnv-gate/usr/src/lib/libslp/javalib/com/sun/slp/SLPV1SDAAdvert.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 //  SLPV1SDAAdvert.java: SLPv1 DAAdvert, server side.
280Sstevel@tonic-gate //  Author:           James Kempf
290Sstevel@tonic-gate //  Created On:       Thu Sep 10 11:00:26 1998
300Sstevel@tonic-gate //  Last Modified By: James Kempf
310Sstevel@tonic-gate //  Last Modified On: Mon Nov  2 15:55:47 1998
320Sstevel@tonic-gate //  Update Count:     27
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 SLPV1SDAAdvert class models the SLPv1 DAAdvert message.
440Sstevel@tonic-gate  *
450Sstevel@tonic-gate  * @author James Kempf
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate 
480Sstevel@tonic-gate class SLPV1SDAAdvert extends SDAAdvert {
490Sstevel@tonic-gate 
SLPV1SDAAdvert(SrvLocHeader hdr, short xid, long timestamp, ServiceURL url, Vector scopes, Vector attrs)500Sstevel@tonic-gate     SLPV1SDAAdvert(SrvLocHeader hdr,
510Sstevel@tonic-gate 		   short xid,
520Sstevel@tonic-gate 		   long timestamp,
530Sstevel@tonic-gate 		   ServiceURL url,
540Sstevel@tonic-gate 		   Vector scopes,
550Sstevel@tonic-gate 		   Vector attrs)
560Sstevel@tonic-gate 	throws ServiceLocationException {
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	super(hdr, xid, timestamp, url, scopes, attrs);
590Sstevel@tonic-gate 
600Sstevel@tonic-gate     }
610Sstevel@tonic-gate 
620Sstevel@tonic-gate     // Initialize the message.
630Sstevel@tonic-gate 
initialize(long timestamp, ServiceURL url, Vector scopes, Vector attrs)640Sstevel@tonic-gate     void initialize(long timestamp,
650Sstevel@tonic-gate 		    ServiceURL url,
660Sstevel@tonic-gate 		    Vector scopes,
670Sstevel@tonic-gate 		    Vector attrs)
680Sstevel@tonic-gate 	throws ServiceLocationException {
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	// By using the incoming header, we are assured of
710Sstevel@tonic-gate 	//  getting the encoding required by the client.
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	SLPHeaderV1 hdr = (SLPHeaderV1)this.hdr;
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	int i, n = scopes.size();
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
780Sstevel@tonic-gate 	    hdr.validateScope((String)scopes.elementAt(i));
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	}
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	// If the only scope we support is default and we are to
830Sstevel@tonic-gate 	//  support unscoped regs, then advertise us
840Sstevel@tonic-gate 	//  as an unscoped DA. However, if default is there with others,
850Sstevel@tonic-gate 	//  we keep it.
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	SLPConfig config = SLPConfig.getSLPConfig();
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	if (config.getAcceptSLPv1UnscopedRegs() &&
900Sstevel@tonic-gate 	    scopes.size() <= 1 &&
910Sstevel@tonic-gate 	    scopes.contains(Defaults.DEFAULT_SCOPE)) {
920Sstevel@tonic-gate 	    scopes.removeAllElements();
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	}
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	// Parse out the payload.
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	ByteArrayOutputStream baos = new ByteArrayOutputStream();
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 	// Parse out the URL.
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	hdr.parseServiceURLOut(url, false, baos);
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 	// Parse out the scope list. Same in V1 and V2.
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	hdr.parseCommaSeparatedListOut(scopes, baos);
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 	hdr.payload = baos.toByteArray();
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	hdr.iNumReplies = 1;
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 	hdr.constructDescription("DAAdvert",
1130Sstevel@tonic-gate 				 "         URL=``" + url + "''\n" +
1140Sstevel@tonic-gate 				 "         scopes=``" + scopes + "''\n");
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate     }
1170Sstevel@tonic-gate }
118