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// SLPV1SSrvReg.java: Message class for SLP service registration request.
2N/A// Author: James Kempf
2N/A// Created On: Thu Oct 9 14:47:48 1997
2N/A// Last Modified By: James Kempf
2N/A// Last Modified On: Thu Mar 25 15:30:25 1999
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 SLPV1SSrvReg class models the server side SLPv1 service registration.
2N/A *
2N/A * @author James Kempf
2N/A */
2N/A
2N/Aclass SLPV1SSrvReg extends SSrvReg {
2N/A
2N/A // For identifying scopes.
2N/A
2N/A static private final String SCOPE_ATTR_ID = "scope";
2N/A
2N/A // Construct a SLPV1SSrvReg from the input stream.
2N/A
2N/A SLPV1SSrvReg(SrvLocHeader hdr, DataInputStream dis)
2N/A throws ServiceLocationException, IOException {
2N/A
2N/A super(hdr, dis);
2N/A
2N/A }
2N/A
2N/A // Initialzie the object from the stream.
2N/A
2N/A void initialize(DataInputStream dis)
2N/A throws ServiceLocationException, IOException {
2N/A
2N/A SLPHeaderV1 hdr = (SLPHeaderV1)getHeader();
2N/A StringBuffer buf = new StringBuffer();
2N/A
2N/A // Parse in the service URL
2N/A
2N/A Hashtable table = new Hashtable();
2N/A
2N/A URL =
2N/A hdr.parseServiceURLIn(dis,
2N/A true,
2N/A ServiceLocationException.INVALID_REGISTRATION);
2N/A
2N/A serviceType = URL.getServiceType().toString();
2N/A
2N/A // Parse in the attribute list.
2N/A
2N/A attrList = hdr.parseAttributeVectorIn(dis);
2N/A
2N/A // Get the scopes. Note that if there's no scope, the request
2N/A // will automatically be rejected as SCOPE_NOT_SUPPORTED.
2N/A
2N/A int i, n = attrList.size();
2N/A Vector scopes = new Vector();
2N/A
2N/A for (i = 0; i < n; i++) {
2N/A ServiceLocationAttribute attr =
2N/A (ServiceLocationAttribute)attrList.elementAt(i);
2N/A String id = attr.getId().toLowerCase().trim();
2N/A
2N/A if (id.equals(SCOPE_ATTR_ID)) {
2N/A Vector vals = attr.getValues();
2N/A int j, m = vals.size();
2N/A
2N/A for (j = 0; j < m; j++) {
2N/A Object o = vals.elementAt(j);
2N/A
2N/A // Must be a string in v1!
2N/A
2N/A if (!(o instanceof String)) {
2N/A throw
2N/A new ServiceLocationException(
2N/A ServiceLocationException.INVALID_REGISTRATION,
2N/A "v1_scope_format",
2N/A new Object[] {vals});
2N/A
2N/A }
2N/A
2N/A String scope = (String)o;
2N/A
2N/A hdr.validateScope(scope);
2N/A
2N/A scopes.addElement(scope);
2N/A }
2N/A }
2N/A }
2N/A
2N/A // If the vector is empty, then add empty string as the scope name.
2N/A // This will cause the service table to throw the registration
2N/A // as scope not supported. If unscoped regs are supported, then
2N/A // change to default scope.
2N/A
2N/A if (scopes.size() <= 0) {
2N/A
2N/A if (!SLPConfig.getSLPConfig().getAcceptSLPv1UnscopedRegs()) {
2N/A scopes.addElement("");
2N/A
2N/A } else {
2N/A scopes.addElement(Defaults.DEFAULT_SCOPE);
2N/A
2N/A }
2N/A }
2N/A
2N/A hdr.scopes = scopes;
2N/A
2N/A // Check if the registration is fresh or not.
2N/A
2N/A hdr.fresh = true;
2N/A
2N/A // Perform lookup for existing.
2N/A
2N/A ServiceStore.ServiceRecord rec =
2N/A ServiceTable.getServiceTable().getServiceRecord(URL, hdr.locale);
2N/A
2N/A if (rec != null) {
2N/A
2N/A // Check scopes.
2N/A
2N/A Vector recScopes = (Vector)rec.getScopes().clone();
2N/A
2N/A DATable.filterScopes(recScopes, scopes, true);
2N/A
2N/A // If it is registered in the same scopes, then it is considered
2N/A // to be the same. Otherwise, it replaces.
2N/A
2N/A if (recScopes.size() == 0) {
2N/A hdr.fresh = false;
2N/A
2N/A }
2N/A }
2N/A
2N/A hdr.constructDescription("SrvReg",
2N/A " URL=``" + URL + "''\n" +
2N/A " attribute list=``" +
2N/A attrList + "''\n");
2N/A
2N/A }
2N/A
2N/A // Return a SrvAck.
2N/A
2N/A SrvLocMsg makeReply(boolean existing) {
2N/A
2N/A SLPHeaderV1 hdr = ((SLPHeaderV1)getHeader()).makeReplyHeader();
2N/A
2N/A hdr.fresh = existing;
2N/A
2N/A // Construct description.
2N/A
2N/A hdr.constructDescription("SrvAck", "");
2N/A
2N/A return hdr;
2N/A
2N/A }
2N/A}