2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1999 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A *
2N/A */
2N/A
2N/A// CSrvTypeMsg.java: Message class for SLP service type reply
2N/A// Author: James Kempf
2N/A// Created On: Thu Oct 9 16:15:36 1997
2N/A// Last Modified By: James Kempf
2N/A// Last Modified On: Tue Oct 27 10:57:38 1998
2N/A// Update Count: 80
2N/A//
2N/A
2N/Apackage com.sun.slp;
2N/A
2N/Aimport java.util.*;
2N/Aimport java.io.*;
2N/A
2N/A
2N/A/**
2N/A * The CSrvTypeMsg class models the SLP service type reply message.
2N/A *
2N/A * @author James Kempf
2N/A */
2N/A
2N/Aclass CSrvTypeMsg extends SrvLocMsgImpl {
2N/A
2N/A // Names contain both the service type and naming authority.
2N/A
2N/A Vector serviceTypes = new Vector(); // vector of Strings
2N/A
2N/A // Only used for testing.
2N/A
2N/A protected CSrvTypeMsg() { }
2N/A
2N/A // Construct a CSrvTypeMsg from the byte input stream. This will be
2N/A // a SrvTypeRply.
2N/A
2N/A CSrvTypeMsg(SLPHeaderV2 hdr, DataInputStream dis)
2N/A throws ServiceLocationException, IOException {
2N/A super(hdr, SrvLocHeader.SrvTypeRply);
2N/A
2N/A // Don't parse the rest if there's an error.
2N/A
2N/A if (hdr.errCode != ServiceLocationException.OK) {
2N/A return;
2N/A }
2N/A
2N/A // Return if packet overflowed.
2N/A
2N/A if (hdr.overflow) {
2N/A return;
2N/A
2N/A }
2N/A
2N/A StringBuffer buf = new StringBuffer();
2N/A
2N/A hdr.getString(buf, dis);
2N/A
2N/A serviceTypes =
2N/A hdr.parseCommaSeparatedListIn(buf.toString(), true);
2N/A
2N/A // Validate service types.
2N/A
2N/A int i, n = serviceTypes.size();
2N/A
2N/A for (i = 0; i < n; i++) {
2N/A
2N/A // Validate.
2N/A
2N/A ServiceType type =
2N/A new ServiceType((String)serviceTypes.elementAt(i));
2N/A
2N/A serviceTypes.setElementAt(type, i);
2N/A
2N/A }
2N/A
2N/A // Set the number of replies.
2N/A
2N/A hdr.iNumReplies = serviceTypes.size();
2N/A
2N/A }
2N/A
2N/A // Construct a CSrvTypeMsg from the arguments. This will be
2N/A // a SrvTypeRqst for transmission to the server.
2N/A
2N/A CSrvTypeMsg(Locale locale, String na, Vector scopes)
2N/A throws ServiceLocationException {
2N/A
2N/A SLPHeaderV2 hdr =
2N/A new SLPHeaderV2(SrvLocHeader.SrvTypeRqst, false, locale);
2N/A this.hdr = hdr;
2N/A hdr.scopes = (Vector)scopes.clone();
2N/A
2N/A // Convert names.
2N/A
2N/A String namingAuthority = na.toLowerCase();
2N/A
2N/A // Verify.
2N/A
2N/A if (!namingAuthority.equals(Defaults.ALL_AUTHORITIES)) {
2N/A ServiceType.validateTypeComponent(namingAuthority);
2N/A
2N/A }
2N/A
2N/A // Check for IANA.
2N/A
2N/A if (namingAuthority.equals(ServiceType.IANA)) {
2N/A throw
2N/A new ServiceLocationException(
2N/A ServiceLocationException.PARSE_ERROR,
2N/A "service_type_syntax",
2N/A new Object[] { namingAuthority });
2N/A }
2N/A
2N/A // Set up previous responders.
2N/A
2N/A hdr.previousResponders = new Vector();
2N/A
2N/A // Make payload.
2N/A
2N/A ByteArrayOutputStream baos = new ByteArrayOutputStream();
2N/A
2N/A // Parse out the naming authority name.
2N/A
2N/A parseNamingAuthorityOut(hdr, namingAuthority, baos);
2N/A
2N/A // Escape scope strings.
2N/A
2N/A hdr.escapeScopeStrings(scopes);
2N/A
2N/A // Parse out the scope.
2N/A
2N/A hdr.parseCommaSeparatedListOut(scopes, baos);
2N/A
2N/A hdr.payload = baos.toByteArray();
2N/A
2N/A }
2N/A
2N/A // Parse out the naming authority.
2N/A
2N/A protected void
2N/A parseNamingAuthorityOut(SLPHeaderV2 hdr,
2N/A String name,
2N/A ByteArrayOutputStream baos) {
2N/A
2N/A // Write out the naming authority.
2N/A
2N/A if (name.length() <= 0) {
2N/A hdr.putInt(0, baos);
2N/A
2N/A } else if (name.equals(Defaults.ALL_AUTHORITIES)) {
2N/A hdr.putInt(0xFFFF, baos);
2N/A
2N/A } else {
2N/A hdr.putString(name, baos);
2N/A
2N/A }
2N/A
2N/A }
2N/A
2N/A}