xref: /illumos-gate/usr/src/lib/libslp/javalib/com/sun/slp/CSrvReg.java (revision 4eaa471005973e11a6110b69fe990530b3b95a38)
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 //  CSrvReg.java:    Service Registration, Client Side.
28 //  Author:           James Kempf
29 //  Created On:       Tue Feb 10 12:15:43 1998
30 //  Last Modified By: James Kempf
31 //  Last Modified On: Tue Oct 27 10:57:38 1998
32 //  Update Count:     49
33 //
34 
35 package com.sun.slp;
36 
37 import java.util.*;
38 import java.io.*;
39 
40 
41 /**
42  * The CSrvReg class models the client side SLP service registration
43  * message.
44  *
45  * @author James Kempf
46  */
47 
48 class CSrvReg extends SrvLocMsgImpl {
49 
50     ServiceURL URL;
51 
52     // Construct a CSrvReg from the arguments. This is the SrvReg for
53 
54     CSrvReg(boolean fresh,
55 	    Locale locale,
56 	    ServiceURL urlEntry,
57 	    Vector scopes,
58 	    Vector attrs,
59 	    Hashtable URLSignatures,
60 	    Hashtable attrSignatures)
61 	throws ServiceLocationException {
62 
63 	this.URL = urlEntry;
64 
65 	// We do heavy checking of attributes here so that any registrations
66 	//  are correct.
67 
68 	Hashtable attrHash = new Hashtable();
69 	int i, n = attrs.size();
70 
71 	// Verify each attribute, merging duplicates in the vector
72 	//  and throwing an error if any duplicates have mismatched types.
73 
74 	Vector attrList = new Vector();
75 
76 	for (i = 0; i < n; i++) {
77 	    Object o = attrs.elementAt(i);
78 
79 	    if (!(o instanceof ServiceLocationAttribute)) {
80 		throw
81 		    new IllegalArgumentException(
82 		SLPConfig.getSLPConfig().formatMessage("not_an_attribute",
83 						       new Object[0]));
84 	    }
85 
86 	    // Make a new copy of the attribute, so we can modify it.
87 
88 	    ServiceLocationAttribute attr = (ServiceLocationAttribute)o;
89 
90 	    ServiceLocationAttribute.mergeDuplicateAttributes(
91 		new ServiceLocationAttribute(attr.getId(), attr.getValues()),
92 		attrHash,
93 		attrList,
94 		false);
95 	}
96 
97 	this.initialize(fresh,
98 			locale,
99 			urlEntry,
100 			scopes,
101 			attrList,
102 			URLSignatures,
103 			attrSignatures);
104 
105     }
106 
107     // Initialize the object. V1 will do it differently.
108 
109     void initialize(boolean fresh,
110 		    Locale locale,
111 		    ServiceURL urlEntry,
112 		    Vector scopes,
113 		    Vector attrs,
114 		    Hashtable URLSignatures,
115 		    Hashtable attrSignatures)
116 	throws ServiceLocationException {
117 
118 	SLPConfig config = SLPConfig.getSLPConfig();
119 	SLPHeaderV2 hdr = new SLPHeaderV2(SrvLocHeader.SrvReg, fresh, locale);
120 	this.hdr = hdr;
121 	hdr.scopes = (Vector)scopes.clone();
122 
123 	ByteArrayOutputStream baos = new ByteArrayOutputStream();
124 
125 	// Parse out the URL. Ignore overflow.
126 
127 	hdr.parseServiceURLOut(urlEntry,
128 			       config.getHasSecurity(),
129 			       URLSignatures,
130 			       baos,
131 			       false);
132 
133 	// Parse out service type. It may be different from the
134 	//  service URL.
135 
136 	ServiceType serviceType = urlEntry.getServiceType();
137 
138 	hdr.putString(serviceType.toString(), baos);
139 
140 	// Escape scope strings.
141 
142 	hdr.escapeScopeStrings(scopes);
143 
144 	// Parse out the scope list.
145 
146 	hdr.parseCommaSeparatedListOut(scopes, baos);
147 
148 	// Parse out the attribute list.
149 
150 	hdr.parseAttributeVectorOut(attrs,
151 				    urlEntry.getLifetime(),
152 				    config.getHasSecurity(),
153 				    attrSignatures,
154 				    baos,
155 				    true);
156 
157 	hdr.payload = baos.toByteArray();
158 
159     }
160 
161 }
162