17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 59a70fc3bSMark J. Nelson * Common Development and Distribution License (the "License"). 69a70fc3bSMark J. Nelson * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 227c478bd9Sstevel@tonic-gate * Copyright (c) 1999 by Sun Microsystems, Inc. 237c478bd9Sstevel@tonic-gate * All rights reserved. 247c478bd9Sstevel@tonic-gate * 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate // UARequester.java: Requester operations for UA. 287c478bd9Sstevel@tonic-gate // Author: James Kempf 297c478bd9Sstevel@tonic-gate // Created On: Thu Jan 8 15:17:35 1998 307c478bd9Sstevel@tonic-gate // Last Modified By: James Kempf 317c478bd9Sstevel@tonic-gate // Last Modified On: Mon Feb 22 13:47:06 1999 327c478bd9Sstevel@tonic-gate // Update Count: 78 337c478bd9Sstevel@tonic-gate // 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate package com.sun.slp; 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate import java.util.*; 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /** 407c478bd9Sstevel@tonic-gate * The URequester class implements the Locator interface. 417c478bd9Sstevel@tonic-gate * It handles the request for the API. If any of the parameters 427c478bd9Sstevel@tonic-gate * are missing, they will be supplied with a default value if 437c478bd9Sstevel@tonic-gate * possible. If a cached value may be supplied, it will be. 447c478bd9Sstevel@tonic-gate * If no DA is present, and convergence is used to gather 457c478bd9Sstevel@tonic-gate * results, these will be merged into one result. 467c478bd9Sstevel@tonic-gate * 477c478bd9Sstevel@tonic-gate * @author Erik Guttman, James Kempf 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate class UARequester extends Object implements Locator { 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate private static SLPConfig config = null; 547c478bd9Sstevel@tonic-gate private static DATable dat = null; 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate private Locale locale; 577c478bd9Sstevel@tonic-gate UARequester(Locale nlocale)587c478bd9Sstevel@tonic-gate UARequester(Locale nlocale) { 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate Assert.nonNullParameter(nlocale, "locale"); 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate if (config == null) { 637c478bd9Sstevel@tonic-gate config = SLPConfig.getSLPConfig(); 647c478bd9Sstevel@tonic-gate } 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate if (dat == null) { 677c478bd9Sstevel@tonic-gate dat = DATable.getDATable(); 687c478bd9Sstevel@tonic-gate } 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate locale = nlocale; 717c478bd9Sstevel@tonic-gate } 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /** 747c478bd9Sstevel@tonic-gate * Return the Locator's locale object. All requests are made in 757c478bd9Sstevel@tonic-gate * this locale. 767c478bd9Sstevel@tonic-gate * 777c478bd9Sstevel@tonic-gate * @return The Locale object. 787c478bd9Sstevel@tonic-gate */ 797c478bd9Sstevel@tonic-gate getLocale()807c478bd9Sstevel@tonic-gate public Locale getLocale() { 817c478bd9Sstevel@tonic-gate return locale; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate } 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate /** 867c478bd9Sstevel@tonic-gate * Return an enumeration of known service types for this scope and naming 877c478bd9Sstevel@tonic-gate * authority. Unless a proprietary or experimental service is being 887c478bd9Sstevel@tonic-gate * discovered, the namingAuthority parameter should be the empty 897c478bd9Sstevel@tonic-gate * string, "". 907c478bd9Sstevel@tonic-gate * 917c478bd9Sstevel@tonic-gate * @param NA The naming authority, "" for default, 927c478bd9Sstevel@tonic-gate * '*' for any naming authority. 937c478bd9Sstevel@tonic-gate * @param scopes The SLP scopes of the types. 947c478bd9Sstevel@tonic-gate * @return ServiceLocationEnumeration of ServiceType objects for 957c478bd9Sstevel@tonic-gate * the service type names. 967c478bd9Sstevel@tonic-gate * @exception IllegalArgumentException If any of the parameters are 977c478bd9Sstevel@tonic-gate * null or syntactically incorrect. 987c478bd9Sstevel@tonic-gate * @exception ServiceLocationException An exception is thrown if the 997c478bd9Sstevel@tonic-gate * operation fails. 1007c478bd9Sstevel@tonic-gate */ 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate public synchronized ServiceLocationEnumeration findServiceTypes(String NA, Vector scopes)1037c478bd9Sstevel@tonic-gate findServiceTypes(String NA, Vector scopes) 1047c478bd9Sstevel@tonic-gate throws ServiceLocationException { 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate Assert.nonNullParameter(NA, " NA"); 1077c478bd9Sstevel@tonic-gate Assert.nonNullParameter(scopes, "scopes"); 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate // Formulate and send off messages. 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate Vector msgs = createMessages(SrvLocHeader.SrvTypeRqst, 1127c478bd9Sstevel@tonic-gate NA, 1137c478bd9Sstevel@tonic-gate null, 1147c478bd9Sstevel@tonic-gate null, 1157c478bd9Sstevel@tonic-gate scopes); 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate // Collate results. 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate Vector ret = new Vector(); 1207c478bd9Sstevel@tonic-gate int i, n = msgs.size(); 1217c478bd9Sstevel@tonic-gate int max = config.getMaximumResults(); 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++) { 1247c478bd9Sstevel@tonic-gate CSrvTypeMsg msg = (CSrvTypeMsg)msgs.elementAt(i); 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate // Check for errors. 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate checkForError(msg, msgs); 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate Vector serviceTypes = msg.serviceTypes; 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate addUnique(serviceTypes, ret, max); 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate } 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate // Return. 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate return new ServiceLocationEnumerator(ret); 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate /** 1427c478bd9Sstevel@tonic-gate * Return an enumeration of ServiceURL objects for services matching 1437c478bd9Sstevel@tonic-gate * the query. The services are returned from the locale of the 1447c478bd9Sstevel@tonic-gate * locator. 1457c478bd9Sstevel@tonic-gate * 1467c478bd9Sstevel@tonic-gate * @param type The type of the service (e.g. printer, etc.). 1477c478bd9Sstevel@tonic-gate * @param scopes The SLP scopes of the service types. 1487c478bd9Sstevel@tonic-gate * @param query A string with the SLP query. 1497c478bd9Sstevel@tonic-gate * @return ServiceLocationEnumeration of ServiceURL objects for 1507c478bd9Sstevel@tonic-gate * services matching the 1517c478bd9Sstevel@tonic-gate * attributes. 1527c478bd9Sstevel@tonic-gate * @exception ServiceLocationException An exception is returned if the 1537c478bd9Sstevel@tonic-gate * operation fails. 1547c478bd9Sstevel@tonic-gate * @see ServiceURL 1557c478bd9Sstevel@tonic-gate */ 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate public synchronized ServiceLocationEnumeration findServices(ServiceType type, Vector scopes, String query)1587c478bd9Sstevel@tonic-gate findServices(ServiceType type, Vector scopes, String query) 1597c478bd9Sstevel@tonic-gate throws ServiceLocationException { 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate Assert.nonNullParameter(type, "type"); 1627c478bd9Sstevel@tonic-gate Assert.nonNullParameter(scopes, "scopes"); 1637c478bd9Sstevel@tonic-gate Assert.nonNullParameter(query, "query"); 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate // Formulate and send off messages. 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate Vector msgs = createMessages(SrvLocHeader.SrvReq, 1687c478bd9Sstevel@tonic-gate type, 1697c478bd9Sstevel@tonic-gate query, 1707c478bd9Sstevel@tonic-gate type, 1717c478bd9Sstevel@tonic-gate scopes); 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate // Collate results. 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate Vector ret = new Vector(); 1767c478bd9Sstevel@tonic-gate int i, n = msgs.size(); 1777c478bd9Sstevel@tonic-gate int max = config.getMaximumResults(); 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++) { 1807c478bd9Sstevel@tonic-gate SrvLocMsg msg = (SrvLocMsg)msgs.elementAt(i); 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate // Check for errors. 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate checkForError(msg, msgs); 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate // Be sure to account for DAAdverts and SAAdverts. 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate Vector serviceURLs = null; 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate if (msg instanceof CSrvMsg) { 1917c478bd9Sstevel@tonic-gate serviceURLs = ((CSrvMsg)msg).serviceURLs; 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate } else if (msg instanceof CSAAdvert) { 1947c478bd9Sstevel@tonic-gate serviceURLs = new Vector(); 1957c478bd9Sstevel@tonic-gate serviceURLs.addElement(((CSAAdvert)msg).URL); 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate } else if (msg instanceof CDAAdvert) { 1987c478bd9Sstevel@tonic-gate serviceURLs = new Vector(); 1997c478bd9Sstevel@tonic-gate serviceURLs.addElement(((CDAAdvert)msg).URL); 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate addUnique(serviceURLs, ret, max); 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate // Return. 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate return new ServiceLocationEnumerator(ret); 2107c478bd9Sstevel@tonic-gate } 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate /** 2137c478bd9Sstevel@tonic-gate * Return the attributes for the service URL, using the locale 2147c478bd9Sstevel@tonic-gate * of the locator. 2157c478bd9Sstevel@tonic-gate * 2167c478bd9Sstevel@tonic-gate * @param URL The service URL. 2177c478bd9Sstevel@tonic-gate * @param scopes The SLP scopes of the service. 2187c478bd9Sstevel@tonic-gate * @param attributeIds A vector of strings identifying the desired 2197c478bd9Sstevel@tonic-gate * attributes. A null value means return all 2207c478bd9Sstevel@tonic-gate * the attributes. <b>Partial id strings</b> may 2217c478bd9Sstevel@tonic-gate * begin with '*' to match all ids which end with 2227c478bd9Sstevel@tonic-gate * the given suffix, or end with '*' to match all 2237c478bd9Sstevel@tonic-gate * ids which begin with a given prefix, or begin 2247c478bd9Sstevel@tonic-gate * and end with '*' to do substring matching for 2257c478bd9Sstevel@tonic-gate * ids containing the given partial id. 2267c478bd9Sstevel@tonic-gate * @return ServiceLocationEnumeration of ServiceLocationAttribute 2277c478bd9Sstevel@tonic-gate * objects matching the ids. 2287c478bd9Sstevel@tonic-gate * @exception ServiceLocationException An exception is returned if the 2297c478bd9Sstevel@tonic-gate * operation fails. 2307c478bd9Sstevel@tonic-gate * @exception IllegalArgumentException If any of the parameters are 2317c478bd9Sstevel@tonic-gate * null or syntactically incorrect. 2327c478bd9Sstevel@tonic-gate * @see ServiceLocationAttribute 2337c478bd9Sstevel@tonic-gate * 2347c478bd9Sstevel@tonic-gate */ 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate public synchronized ServiceLocationEnumeration findAttributes(ServiceURL URL, Vector scopes, Vector attributeIds)2377c478bd9Sstevel@tonic-gate findAttributes(ServiceURL URL, Vector scopes, Vector attributeIds) 2387c478bd9Sstevel@tonic-gate throws ServiceLocationException { 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate Assert.nonNullParameter(URL, "URL"); 2417c478bd9Sstevel@tonic-gate Assert.nonNullParameter(scopes, "scopes"); 2427c478bd9Sstevel@tonic-gate Assert.nonNullParameter(attributeIds, "attributeIds"); 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate Vector msgs = createMessages(SrvLocHeader.AttrRqst, 2457c478bd9Sstevel@tonic-gate URL, 2467c478bd9Sstevel@tonic-gate attributeIds, 2477c478bd9Sstevel@tonic-gate URL.getServiceType(), 2487c478bd9Sstevel@tonic-gate scopes); 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate // Check results. 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate Vector ret = new Vector(); 2537c478bd9Sstevel@tonic-gate int i, n = msgs.size(); 2547c478bd9Sstevel@tonic-gate int max = config.getMaximumResults(); 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate // We only take the first message that came back and is OK. 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++) { 2597c478bd9Sstevel@tonic-gate SrvLocMsg msg = (SrvLocMsg)msgs.elementAt(i); 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate // Check for errors. 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate checkForError(msg, msgs); 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate // Select out attribute list. 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate if (msg instanceof CAttrMsg) { 2687c478bd9Sstevel@tonic-gate ret = ((CAttrMsg)msg).attrList; 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate } else if (msg instanceof CSAAdvert) { 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate // Need to check that URL matches. 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate CSAAdvert smsg = (CSAAdvert)msg; 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate if (!URL.equals(smsg.URL)) { 2777c478bd9Sstevel@tonic-gate continue; 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate ret = smsg.attrs; 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate } else if (msg instanceof CDAAdvert) { 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate // Need to check that URL matches. 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate CDAAdvert smsg = (CDAAdvert)msg; 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate if (!URL.equals(smsg.URL)) { 2907c478bd9Sstevel@tonic-gate continue; 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate ret = smsg.attrs; 2957c478bd9Sstevel@tonic-gate } 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate // Truncate, if return is larger than maximum. 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate if (ret.size() > max) { 3007c478bd9Sstevel@tonic-gate ret.setSize(max); 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate } 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate // Break out, we only need one. 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate break; 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate } 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate // Return. 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate return new ServiceLocationEnumerator(ret); 3137c478bd9Sstevel@tonic-gate } 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate /** 3167c478bd9Sstevel@tonic-gate * Return all attributes for all service URL's having this 3177c478bd9Sstevel@tonic-gate * service type in the locale of the Locator. 3187c478bd9Sstevel@tonic-gate * 3197c478bd9Sstevel@tonic-gate * @param type The service type. 3207c478bd9Sstevel@tonic-gate * @param scopes The SLP scopes of the service type. 3217c478bd9Sstevel@tonic-gate * @param attributeIds A vector of strings identifying the desired 3227c478bd9Sstevel@tonic-gate * attributes. A null value means return all 3237c478bd9Sstevel@tonic-gate * the attributes. <b>Partial id strings</b> may 3247c478bd9Sstevel@tonic-gate * begin with '*' to match all ids which end with 3257c478bd9Sstevel@tonic-gate * the given suffix, or end with '*' to match all 3267c478bd9Sstevel@tonic-gate * ids which begin with a given prefix, or begin 3277c478bd9Sstevel@tonic-gate * and end with '*' to do substring matching for 3287c478bd9Sstevel@tonic-gate * ids containing the given partial id. 3297c478bd9Sstevel@tonic-gate * @return ServiceLocationEnumeration of ServiceLocationAttribute 3307c478bd9Sstevel@tonic-gate * objects matching the ids. 3317c478bd9Sstevel@tonic-gate * @exception ServiceLocationException An exception is returned if the 3327c478bd9Sstevel@tonic-gate * operation fails. 3337c478bd9Sstevel@tonic-gate * @exception IllegalArgumentException If any of the parameters are 3347c478bd9Sstevel@tonic-gate * null or syntactically incorrect. 3357c478bd9Sstevel@tonic-gate * @see ServiceLocationAttribute 3367c478bd9Sstevel@tonic-gate * 3377c478bd9Sstevel@tonic-gate */ 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate public synchronized ServiceLocationEnumeration findAttributes(ServiceType type, Vector scopes, Vector attributeIds)3407c478bd9Sstevel@tonic-gate findAttributes(ServiceType type, Vector scopes, Vector attributeIds) 3417c478bd9Sstevel@tonic-gate throws ServiceLocationException { 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate Assert.nonNullParameter(type, "URL"); 3447c478bd9Sstevel@tonic-gate Assert.nonNullParameter(scopes, "scopes"); 3457c478bd9Sstevel@tonic-gate Assert.nonNullParameter(attributeIds, "attributeIds"); 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate // Formulate and send off messages. 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate Vector msgs = createMessages(SrvLocHeader.AttrRqst, 3507c478bd9Sstevel@tonic-gate type, 3517c478bd9Sstevel@tonic-gate attributeIds, 3527c478bd9Sstevel@tonic-gate type, 3537c478bd9Sstevel@tonic-gate scopes); 3547c478bd9Sstevel@tonic-gate // Collate results. 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate Vector ret = new Vector(); 3577c478bd9Sstevel@tonic-gate int i, n = msgs.size(); 3587c478bd9Sstevel@tonic-gate int max = config.getMaximumResults(); 3597c478bd9Sstevel@tonic-gate Hashtable ht = new Hashtable(); 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate for (i = 0; i < n && ret.size() < max; i++) { 3627c478bd9Sstevel@tonic-gate SrvLocMsg msg = (SrvLocMsg)msgs.elementAt(i); 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate // Check for errors. 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate checkForError(msg, msgs); 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate Vector attrList = null; 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate // Get the instance variable. 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate if (msg instanceof CAttrMsg) { 3737c478bd9Sstevel@tonic-gate attrList = ((CAttrMsg)msg).attrList; 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate } else if (msg instanceof CSAAdvert) { 3767c478bd9Sstevel@tonic-gate attrList = ((CSAAdvert)msg).attrs; 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate } else if (msg instanceof CDAAdvert) { 3797c478bd9Sstevel@tonic-gate attrList = ((CDAAdvert)msg).attrs; 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate } 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate // Merge any duplicates. 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate int j, m = attrList.size(); 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate for (j = 0; j < m; j++) { 3887c478bd9Sstevel@tonic-gate ServiceLocationAttribute attr = 3897c478bd9Sstevel@tonic-gate (ServiceLocationAttribute)attrList.elementAt(j); 390*55fea89dSDan Cross 3917c478bd9Sstevel@tonic-gate ServiceLocationAttribute.mergeDuplicateAttributes(attr, 3927c478bd9Sstevel@tonic-gate ht, 3937c478bd9Sstevel@tonic-gate ret, 3947c478bd9Sstevel@tonic-gate true); 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate if (ret.size() >= max) { 3977c478bd9Sstevel@tonic-gate break; 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate } 4007c478bd9Sstevel@tonic-gate } 4017c478bd9Sstevel@tonic-gate } 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate // Return. 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate return new ServiceLocationEnumerator(ret); 4067c478bd9Sstevel@tonic-gate } 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate // Execute the message request, returning messages. 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate private Vector createMessages(int msgType, Object t1, Object t2, ServiceType type, Vector scopes)4117c478bd9Sstevel@tonic-gate createMessages(int msgType, 4127c478bd9Sstevel@tonic-gate Object t1, 4137c478bd9Sstevel@tonic-gate Object t2, 4147c478bd9Sstevel@tonic-gate ServiceType type, 4157c478bd9Sstevel@tonic-gate Vector scopes) 4167c478bd9Sstevel@tonic-gate throws ServiceLocationException { 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate // Validate, lower case scopes. 4197c478bd9Sstevel@tonic-gate 4207c478bd9Sstevel@tonic-gate DATable.validateScopes(scopes, locale); 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate SrvLocMsg multiMsg = null; 4237c478bd9Sstevel@tonic-gate SrvLocMsg uniMsg = null; 4247c478bd9Sstevel@tonic-gate Vector daAddresses = null; 4257c478bd9Sstevel@tonic-gate Vector multiCastScopes = null; 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate // Get the hashtable of unicast DA addresses and multicast scopes. 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate Hashtable daRecords = dat.findDAScopes(scopes); 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate // Get multicast scopes and DA addresses. 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate multiCastScopes = 4347c478bd9Sstevel@tonic-gate (Vector)daRecords.get(DATable.MULTICAST_KEY); 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate daAddresses = 4377c478bd9Sstevel@tonic-gate (Vector)daRecords.get(DATable.UNICAST_KEY); 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate // Special case for service request and attribute request 4407c478bd9Sstevel@tonic-gate // if the user is looking for a special SLP type. 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate if (((msgType == SrvLocHeader.SrvReq) || 4437c478bd9Sstevel@tonic-gate (msgType == SrvLocHeader.AttrRqst)) && 4447c478bd9Sstevel@tonic-gate (type.equals(Defaults.DA_SERVICE_TYPE) || 4457c478bd9Sstevel@tonic-gate type.equals(Defaults.SA_SERVICE_TYPE))) { 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate multiCastScopes = scopes; 4487c478bd9Sstevel@tonic-gate daAddresses = null; 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate // Get query. If an attribute request, then the user 4517c478bd9Sstevel@tonic-gate // needs to sort out the attributes. 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate String query = ""; 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate if (msgType == SrvLocHeader.SrvReq) { 4567c478bd9Sstevel@tonic-gate query = (String)t2; 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate } 4597c478bd9Sstevel@tonic-gate 4607c478bd9Sstevel@tonic-gate multiMsg = new CSrvMsg(locale, type, multiCastScopes, query); 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate } else { 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate // Handle a regular message. 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate // Multicast scopes are all scopes not supported by any DA. 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate if (multiCastScopes != null) { 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate switch (msgType) { 4717c478bd9Sstevel@tonic-gate 4727c478bd9Sstevel@tonic-gate case SrvLocHeader.SrvTypeRqst: 4737c478bd9Sstevel@tonic-gate multiMsg = 4747c478bd9Sstevel@tonic-gate new CSrvTypeMsg(locale, (String)t1, multiCastScopes); 4757c478bd9Sstevel@tonic-gate break; 4767c478bd9Sstevel@tonic-gate 4777c478bd9Sstevel@tonic-gate case SrvLocHeader.SrvReq: 4787c478bd9Sstevel@tonic-gate multiMsg = 4797c478bd9Sstevel@tonic-gate new CSrvMsg(locale, type, multiCastScopes, (String)t2); 4807c478bd9Sstevel@tonic-gate break; 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate case SrvLocHeader.AttrRqst: 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate if (t1 instanceof ServiceURL) { 4857c478bd9Sstevel@tonic-gate multiMsg = 4867c478bd9Sstevel@tonic-gate new CAttrMsg(locale, 4877c478bd9Sstevel@tonic-gate (ServiceURL)t1, 4887c478bd9Sstevel@tonic-gate multiCastScopes, 4897c478bd9Sstevel@tonic-gate (Vector)t2); 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate } else { 4927c478bd9Sstevel@tonic-gate multiMsg = 4937c478bd9Sstevel@tonic-gate new CAttrMsg(locale, 4947c478bd9Sstevel@tonic-gate type, 4957c478bd9Sstevel@tonic-gate multiCastScopes, 4967c478bd9Sstevel@tonic-gate (Vector)t2); 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate } 4997c478bd9Sstevel@tonic-gate } 5007c478bd9Sstevel@tonic-gate } 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate // Unicast only requires a single message because the DAs will 5037c478bd9Sstevel@tonic-gate // ignore any scopes they do not support, just as long as 5047c478bd9Sstevel@tonic-gate // they support one of them. 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate if (daAddresses != null) { 5077c478bd9Sstevel@tonic-gate switch (msgType) { 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate case SrvLocHeader.SrvTypeRqst: 5107c478bd9Sstevel@tonic-gate uniMsg = 5117c478bd9Sstevel@tonic-gate new CSrvTypeMsg(locale, (String)t1, scopes); 5127c478bd9Sstevel@tonic-gate break; 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate case SrvLocHeader.SrvReq: 5157c478bd9Sstevel@tonic-gate uniMsg = 5167c478bd9Sstevel@tonic-gate new CSrvMsg(locale, type, scopes, (String)t2); 5177c478bd9Sstevel@tonic-gate break; 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate case SrvLocHeader.AttrRqst: 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate if (t1 instanceof ServiceURL) { 5227c478bd9Sstevel@tonic-gate uniMsg = 5237c478bd9Sstevel@tonic-gate new CAttrMsg(locale, 5247c478bd9Sstevel@tonic-gate (ServiceURL)t1, 5257c478bd9Sstevel@tonic-gate scopes, 5267c478bd9Sstevel@tonic-gate (Vector)t2); 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate } else { 5297c478bd9Sstevel@tonic-gate uniMsg = 5307c478bd9Sstevel@tonic-gate new CAttrMsg(locale, 5317c478bd9Sstevel@tonic-gate type, 5327c478bd9Sstevel@tonic-gate scopes, 5337c478bd9Sstevel@tonic-gate (Vector)t2); 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate } 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate } 5387c478bd9Sstevel@tonic-gate } 5397c478bd9Sstevel@tonic-gate } 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate // Send off messages, return results. 5427c478bd9Sstevel@tonic-gate 5437c478bd9Sstevel@tonic-gate return Transact.transactUA(daAddresses, 5447c478bd9Sstevel@tonic-gate uniMsg, 5457c478bd9Sstevel@tonic-gate multiMsg, 5467c478bd9Sstevel@tonic-gate config.getMulticastAddress()); 5477c478bd9Sstevel@tonic-gate } 5487c478bd9Sstevel@tonic-gate 5497c478bd9Sstevel@tonic-gate // Check message for error code. 5507c478bd9Sstevel@tonic-gate 5517c478bd9Sstevel@tonic-gate private static void checkForError(SrvLocMsg msg, Vector v)5527c478bd9Sstevel@tonic-gate checkForError(SrvLocMsg msg, Vector v) 5537c478bd9Sstevel@tonic-gate throws ServiceLocationException { 5547c478bd9Sstevel@tonic-gate int err = msg.getErrorCode(); 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate if (err != ServiceLocationException.OK) { 5577c478bd9Sstevel@tonic-gate if (v.size() == 1) { 5587c478bd9Sstevel@tonic-gate config.writeLog("single_exception", 5597c478bd9Sstevel@tonic-gate new Object[] { 5607c478bd9Sstevel@tonic-gate new Integer(err)}); 5617c478bd9Sstevel@tonic-gate throw 5627c478bd9Sstevel@tonic-gate new ServiceLocationException((short)err, 5637c478bd9Sstevel@tonic-gate "remote_error", 5647c478bd9Sstevel@tonic-gate new Object[] {}); 5657c478bd9Sstevel@tonic-gate } else { 5667c478bd9Sstevel@tonic-gate config.writeLog("multiple_exception", 5677c478bd9Sstevel@tonic-gate new Object[] { 5687c478bd9Sstevel@tonic-gate new Integer(err)}); 5697c478bd9Sstevel@tonic-gate } 5707c478bd9Sstevel@tonic-gate } 5717c478bd9Sstevel@tonic-gate } 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate // Process the incoming vector, adding any unique returns. 5747c478bd9Sstevel@tonic-gate addUnique(Vector incoming, Vector returns, int max)5757c478bd9Sstevel@tonic-gate private static void addUnique(Vector incoming, Vector returns, int max) { 5767c478bd9Sstevel@tonic-gate 5777c478bd9Sstevel@tonic-gate int i, n = incoming.size(); 5787c478bd9Sstevel@tonic-gate 5797c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++) { 5807c478bd9Sstevel@tonic-gate Object o = incoming.elementAt(i); 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate if (!returns.contains(o) && returns.size() < max) { 5837c478bd9Sstevel@tonic-gate returns.addElement(o); 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate } 5867c478bd9Sstevel@tonic-gate } 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate } 590