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 // SLPV1SSrvTypeMsg.java: SLPV1 Compatibility SrvType message 28 // Author: James Kempf 29 // Created On: Mon Sep 14 10:49:05 1998 30 // Last Modified By: James Kempf 31 // Last Modified On: Tue Oct 27 10:57:39 1998 32 // Update Count: 11 33 // 34 35 36 package com.sun.slp; 37 38 import java.util.*; 39 import java.io.*; 40 41 42 /** 43 * The SLPV1SSrvTypeMsg class models the SLPv1 service type request message. 44 * 45 * @author James Kempf 46 */ 47 48 49 class SLPV1SSrvTypeMsg extends SSrvTypeMsg { 50 51 // Construct a SLPV1SSrvTypeMsg from the byte input stream. This will be 52 // a SrvTypeRqst. 53 SLPV1SSrvTypeMsg(SrvLocHeader hdr, DataInputStream dis)54 SLPV1SSrvTypeMsg(SrvLocHeader hdr, DataInputStream dis) 55 throws ServiceLocationException, IOException { 56 57 super(hdr, dis); 58 59 } 60 initialize(DataInputStream dis)61 void initialize(DataInputStream dis) 62 throws ServiceLocationException, IOException { 63 64 SLPHeaderV1 hdr = (SLPHeaderV1)getHeader(); 65 StringBuffer buf = new StringBuffer(); 66 67 // First get the previous responder. 68 69 hdr.parsePreviousRespondersIn(dis); 70 71 // Now get naming authority. 72 73 namingAuthority = parseNamingAuthorityIn(hdr, dis, hdr.charCode); 74 75 // If it's IANA, make it be null. 76 77 if (namingAuthority.equalsIgnoreCase(ServiceType.IANA)) { 78 namingAuthority = ""; 79 80 } 81 82 // Finally get scope. 83 84 buf.setLength(0); 85 86 hdr.getString(buf, dis); 87 88 String scope = buf.toString().trim().toLowerCase(); 89 90 hdr.validateScope(scope); 91 92 // Change unscoped to default. 93 94 if (scope.length() <= 0) { 95 scope = Defaults.DEFAULT_SCOPE; 96 97 } 98 99 hdr.scopes = new Vector(); 100 hdr.scopes.addElement(scope); 101 102 // Construct description. 103 104 hdr.constructDescription("SrvTypeRqst", 105 " naming authority=``" + 106 namingAuthority + "''\n"); 107 } 108 109 // Construct a SSrvTypeMsg from the arguments. This will be a 110 // SrvTypeRply for transmission to client. 111 makeReply(Vector typeNames)112 SrvLocMsg makeReply(Vector typeNames) 113 throws ServiceLocationException { 114 115 SLPHeaderV1 hdr = 116 ((SLPHeaderV1)getHeader()).makeReplyHeader(); 117 118 // Construct payload. 119 120 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 121 122 // Edit service type names to remove nonService: and abstract types. 123 124 int i; 125 126 for (i = 0; i < typeNames.size(); i++) { 127 String name = (String)typeNames.elementAt(i); 128 ServiceType type = new ServiceType(name); 129 130 if (type.isAbstractType() || !type.isServiceURL()) { 131 typeNames.removeElement(name); 132 133 } 134 } 135 136 hdr.iNumReplies = typeNames.size(); 137 138 hdr.putStringVector(typeNames, baos); 139 140 hdr.payload = baos.toByteArray(); 141 142 hdr.constructDescription("SrvTypeRply", 143 " types=``" + typeNames + "''\n"); 144 145 return hdr; 146 } 147 } 148