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