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