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