xref: /illumos-gate/usr/src/lib/libslp/javalib/com/sun/slp/SLPV1SDAAdvert.java (revision 24da5b34f49324ed742a340010ed5bd3d4e06625)
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 //  SLPV1SDAAdvert.java: SLPv1 DAAdvert, server side.
32 //  Author:           James Kempf
33 //  Created On:       Thu Sep 10 11:00:26 1998
34 //  Last Modified By: James Kempf
35 //  Last Modified On: Mon Nov  2 15:55:47 1998
36 //  Update Count:     27
37 //
38 
39 
40 package com.sun.slp;
41 
42 import java.util.*;
43 import java.io.*;
44 
45 
46 /**
47  * The SLPV1SDAAdvert class models the SLPv1 DAAdvert message.
48  *
49  * @version %R%.%L% %D%
50  * @author James Kempf
51  */
52 
53 class SLPV1SDAAdvert extends SDAAdvert {
54 
55     SLPV1SDAAdvert(SrvLocHeader hdr,
56 		   short xid,
57 		   long timestamp,
58 		   ServiceURL url,
59 		   Vector scopes,
60 		   Vector attrs)
61 	throws ServiceLocationException {
62 
63 	super(hdr, xid, timestamp, url, scopes, attrs);
64 
65     }
66 
67     // Initialize the message.
68 
69     void initialize(long timestamp,
70 		    ServiceURL url,
71 		    Vector scopes,
72 		    Vector attrs)
73 	throws ServiceLocationException {
74 
75 	// By using the incoming header, we are assured of
76 	//  getting the encoding required by the client.
77 
78 	SLPHeaderV1 hdr = (SLPHeaderV1)this.hdr;
79 
80 	int i, n = scopes.size();
81 
82 	for (i = 0; i < n; i++) {
83 	    hdr.validateScope((String)scopes.elementAt(i));
84 
85 	}
86 
87 	// If the only scope we support is default and we are to
88 	//  support unscoped regs, then advertise us
89 	//  as an unscoped DA. However, if default is there with others,
90 	//  we keep it.
91 
92 	SLPConfig config = SLPConfig.getSLPConfig();
93 
94 	if (config.getAcceptSLPv1UnscopedRegs() &&
95 	    scopes.size() <= 1 &&
96 	    scopes.contains(Defaults.DEFAULT_SCOPE)) {
97 	    scopes.removeAllElements();
98 
99 	}
100 
101 	// Parse out the payload.
102 
103 	ByteArrayOutputStream baos = new ByteArrayOutputStream();
104 
105 	// Parse out the URL.
106 
107 	hdr.parseServiceURLOut(url, false, baos);
108 
109 	// Parse out the scope list. Same in V1 and V2.
110 
111 	hdr.parseCommaSeparatedListOut(scopes, baos);
112 
113 	hdr.payload = baos.toByteArray();
114 
115 	hdr.iNumReplies = 1;
116 
117 	hdr.constructDescription("DAAdvert",
118 				 "         URL=``" + url + "''\n" +
119 				 "         scopes=``" + scopes + "''\n");
120 
121     }
122 }
123