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 5*9a70fc3bSMark J. Nelson * Common Development and Distribution License (the "License"). 6*9a70fc3bSMark 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 2004 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate * 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 27*9a70fc3bSMark J. Nelson // sldp.java : The service location daemon. 287c478bd9Sstevel@tonic-gate // Author: Erik Guttman 297c478bd9Sstevel@tonic-gate // 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate package com.sun.slp; 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate import java.io.*; 347c478bd9Sstevel@tonic-gate import java.util.*; 357c478bd9Sstevel@tonic-gate import java.net.*; 367c478bd9Sstevel@tonic-gate import java.lang.reflect.*; 377c478bd9Sstevel@tonic-gate import java.awt.*; 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /** 407c478bd9Sstevel@tonic-gate * The slpd class is the main class for the slpd directory agent/ 417c478bd9Sstevel@tonic-gate * service agent server of SLP. Slpd can run in two possible modes, 427c478bd9Sstevel@tonic-gate * depending on the configuration of the classes with which it was shipped 437c478bd9Sstevel@tonic-gate * and information read from the optional configuration file argument: 447c478bd9Sstevel@tonic-gate * 457c478bd9Sstevel@tonic-gate * <ol> 467c478bd9Sstevel@tonic-gate * <li> <b> Service Agent server </b> 477c478bd9Sstevel@tonic-gate * In this mode, slpd functions as a service agent server only. 487c478bd9Sstevel@tonic-gate * Directory agent functionality is disabled. Service agent 497c478bd9Sstevel@tonic-gate * clients on the local machine register and deregister services 507c478bd9Sstevel@tonic-gate * with slpd, and slpd responds to multicast requests for 517c478bd9Sstevel@tonic-gate * services. It passively and actively listens for directory agent 527c478bd9Sstevel@tonic-gate * advertisements, caches them, and forwards them to both 537c478bd9Sstevel@tonic-gate * user agent and service agent clients. A file of serialized 547c478bd9Sstevel@tonic-gate * proxy registrations can be read at startup. 557c478bd9Sstevel@tonic-gate * This mode is normally default. 567c478bd9Sstevel@tonic-gate * 577c478bd9Sstevel@tonic-gate * <li> <b> Directory Agent/Service Agent server </b> 587c478bd9Sstevel@tonic-gate * In this mode, slpd functions as a directory agent 597c478bd9Sstevel@tonic-gate * for port 427 on the local machine. The directory agent 607c478bd9Sstevel@tonic-gate * caches service advertisements, makes directory agent 617c478bd9Sstevel@tonic-gate * advertisements of its services, and responds to requests 627c478bd9Sstevel@tonic-gate * for TCP connections with service agents and user agents. 637c478bd9Sstevel@tonic-gate * In addition, slpd functions in the first mode, as a 647c478bd9Sstevel@tonic-gate * service agent server, for SAs and UAs on the local host. 657c478bd9Sstevel@tonic-gate * 667c478bd9Sstevel@tonic-gate * </ol> 677c478bd9Sstevel@tonic-gate * 687c478bd9Sstevel@tonic-gate * The slpd is invoked as follows:<br> 697c478bd9Sstevel@tonic-gate *<blockquote> 707c478bd9Sstevel@tonic-gate * 717c478bd9Sstevel@tonic-gate * java com.sun.slpd [monitor] [stop] [-f <config file name>] 727c478bd9Sstevel@tonic-gate * 737c478bd9Sstevel@tonic-gate *</blockquote> 747c478bd9Sstevel@tonic-gate * 757c478bd9Sstevel@tonic-gate * The optional monitor argument specifies that a GUI monitor should be 767c478bd9Sstevel@tonic-gate * brought up. The optional stop argument indicates that slpd should 777c478bd9Sstevel@tonic-gate * signal a running slpd to stop. The optional <config file name> argument 787c478bd9Sstevel@tonic-gate * specifies that the named file should be used as the configuration file. 797c478bd9Sstevel@tonic-gate * <p> 807c478bd9Sstevel@tonic-gate * See <a href="slpd.conf.html">slpd.conf</a> for more information on 817c478bd9Sstevel@tonic-gate * configuration file syntax and <a href="slpd.reg.html">slpd.reg</a> 827c478bd9Sstevel@tonic-gate * for more information on proxy registration file syntax. 837c478bd9Sstevel@tonic-gate * 847c478bd9Sstevel@tonic-gate * @author Erik Guttman, James Kempf 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate // Note that the inheritance is *only* so slpd can initialize the 887c478bd9Sstevel@tonic-gate // internals of SLP config. 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate public class slpd extends SLPConfig { 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate private static final String SERVER_BUNDLE_NAME = "com/sun/slp/Server"; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate // Server bundle. Set the parent. 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate static class ServerBundle extends ResourceBundle { 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate private ResourceBundle bundle = null; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate static ResourceBundle getBundle(ResourceBundle parent, Locale locale)1017c478bd9Sstevel@tonic-gate getBundle(ResourceBundle parent, Locale locale) 1027c478bd9Sstevel@tonic-gate throws MissingResourceException { 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate return new ServerBundle(parent, locale); 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate } 1077c478bd9Sstevel@tonic-gate ServerBundle(ResourceBundle parent, Locale locale)1087c478bd9Sstevel@tonic-gate private ServerBundle(ResourceBundle parent, Locale locale) 1097c478bd9Sstevel@tonic-gate throws MissingResourceException { 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate if (parent != null) { 1127c478bd9Sstevel@tonic-gate this.parent = parent; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate try { 1177c478bd9Sstevel@tonic-gate URL[] urls = null; 1187c478bd9Sstevel@tonic-gate urls = new URL[] {new URL("file:/usr/share/lib/locale/")}; 1197c478bd9Sstevel@tonic-gate URLClassLoader ld = new URLClassLoader(urls); 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate bundle = 1227c478bd9Sstevel@tonic-gate ResourceBundle.getBundle(SERVER_BUNDLE_NAME, locale, ld); 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate } catch (MalformedURLException e) { 1257c478bd9Sstevel@tonic-gate // fallthru to default location 1267c478bd9Sstevel@tonic-gate } // No locales in slpd.jar, so propagate the 1277c478bd9Sstevel@tonic-gate // MissingResourceException 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate bundle = bundle != null ? 1307c478bd9Sstevel@tonic-gate bundle : 1317c478bd9Sstevel@tonic-gate ResourceBundle.getBundle(SERVER_BUNDLE_NAME, locale); 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate handleGetObject(String key)1357c478bd9Sstevel@tonic-gate protected Object handleGetObject(String key) 1367c478bd9Sstevel@tonic-gate throws MissingResourceException { 1377c478bd9Sstevel@tonic-gate Object ret = null; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate try { 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate ret = bundle.getObject(key); 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate } catch (MissingResourceException ex) { 1447c478bd9Sstevel@tonic-gate ret = parent.getObject(key); 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate } 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate return ret; 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate getKeys()1527c478bd9Sstevel@tonic-gate public Enumeration getKeys() { 1537c478bd9Sstevel@tonic-gate return bundle.getKeys(); 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate /** 1607c478bd9Sstevel@tonic-gate * Log object for SLP to write to GUI. This class follows the 1617c478bd9Sstevel@tonic-gate * semantics of the other SLP logging classes: 1627c478bd9Sstevel@tonic-gate * 1637c478bd9Sstevel@tonic-gate * This class does not actually write anything until the flush() method 1647c478bd9Sstevel@tonic-gate * in invoked; this will write the concatenation of all messages 1657c478bd9Sstevel@tonic-gate * passed to the write() method since the last invocation of flush(). 1667c478bd9Sstevel@tonic-gate * 1677c478bd9Sstevel@tonic-gate * The actual logging class used can be controlled via the 1687c478bd9Sstevel@tonic-gate * sun.net.slp.loggerClass property. 1697c478bd9Sstevel@tonic-gate * 1707c478bd9Sstevel@tonic-gate * See also the StderrLog and Syslog classes. 1717c478bd9Sstevel@tonic-gate */ 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate static class SLPLog extends Writer { 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate private TextArea taLog = null; 1767c478bd9Sstevel@tonic-gate private StringBuffer buf; 1777c478bd9Sstevel@tonic-gate SLPLog(TextArea nta)1787c478bd9Sstevel@tonic-gate SLPLog(TextArea nta) { 1797c478bd9Sstevel@tonic-gate taLog = nta; 1807c478bd9Sstevel@tonic-gate buf = new StringBuffer(); 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate // Write to the StringBuffer 1857c478bd9Sstevel@tonic-gate write(char[] cbuf, int off, int len)1867c478bd9Sstevel@tonic-gate public void write(char[] cbuf, int off, int len) 1877c478bd9Sstevel@tonic-gate throws IOException { 1887c478bd9Sstevel@tonic-gate buf.append(cbuf, off, len); 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate // Write to the Frame. 1937c478bd9Sstevel@tonic-gate flush()1947c478bd9Sstevel@tonic-gate public void flush() throws IOException { 1957c478bd9Sstevel@tonic-gate String date = SLPConfig.getDateString(); 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate taLog.append( 1987c478bd9Sstevel@tonic-gate "********" + 1997c478bd9Sstevel@tonic-gate date + "\n" + 2007c478bd9Sstevel@tonic-gate buf.toString() + "\n" + 2017c478bd9Sstevel@tonic-gate "********\n"); 2027c478bd9Sstevel@tonic-gate buf = new StringBuffer(); 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate // These is a no-op 2077c478bd9Sstevel@tonic-gate close()2087c478bd9Sstevel@tonic-gate public void close() throws IOException {} 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate } 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate // 2137c478bd9Sstevel@tonic-gate // slpd definition. 2147c478bd9Sstevel@tonic-gate // 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate private static String configFile; // name of configuration file 2177c478bd9Sstevel@tonic-gate private static SLPDgui slpdgui; // GUI monitor, if desired 2187c478bd9Sstevel@tonic-gate private static SLPConfig config; // handles system properties 2197c478bd9Sstevel@tonic-gate private static ServerDATable daTable; // handle recording of DAs 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate // Called by the slpd and subclasses only. 2227c478bd9Sstevel@tonic-gate slpd()2237c478bd9Sstevel@tonic-gate protected slpd() { 2247c478bd9Sstevel@tonic-gate super(); 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate usage()2277c478bd9Sstevel@tonic-gate private static void usage() { 2287c478bd9Sstevel@tonic-gate ResourceBundle bundle = 2297c478bd9Sstevel@tonic-gate getMessageBundleInternal(Locale.getDefault(), null); 2307c478bd9Sstevel@tonic-gate System.err.println(formatMessageInternal("slpd_usage", 2317c478bd9Sstevel@tonic-gate new Object[0], 2327c478bd9Sstevel@tonic-gate bundle)); 2337c478bd9Sstevel@tonic-gate System.exit(1); 2347c478bd9Sstevel@tonic-gate } 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate /** 2377c478bd9Sstevel@tonic-gate * Usage: slpd [monitor] [stop] [-f config-file name]<br> 2387c478bd9Sstevel@tonic-gate * <br> 2397c478bd9Sstevel@tonic-gate * String arguments are: 2407c478bd9Sstevel@tonic-gate * <br> 2417c478bd9Sstevel@tonic-gate * <b> monitor </b> Puts up a rudimentary GUI for the slpd.<br> 2427c478bd9Sstevel@tonic-gate * <b>stop <b> Bring down a running slpd and exit. 2437c478bd9Sstevel@tonic-gate * <b> config-file name </b> Reads the specified configuration file.<br> 2447c478bd9Sstevel@tonic-gate * 2457c478bd9Sstevel@tonic-gate * The default running mode is to have no GUI and to use SLP 2467c478bd9Sstevel@tonic-gate * defined configuration. 2477c478bd9Sstevel@tonic-gate */ 2487c478bd9Sstevel@tonic-gate main(String args[])2497c478bd9Sstevel@tonic-gate public static void main(String args[]) { 2507c478bd9Sstevel@tonic-gate boolean bMon = false; 2517c478bd9Sstevel@tonic-gate boolean bStop = false; 2527c478bd9Sstevel@tonic-gate configFile = null; 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate Thread.currentThread().setName("slpd"); 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate // Process args. 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate if (args.length > 3) { 2597c478bd9Sstevel@tonic-gate usage(); 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate int i, n = args.length; 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++) { 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate // Argument is a config file. 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate if (args[i].equals("-f")) { 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate if (configFile != null) { 2727c478bd9Sstevel@tonic-gate usage(); 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate } 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate // Make sure we can open it. 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate try { 2797c478bd9Sstevel@tonic-gate File f = new File(args[++i]); 2807c478bd9Sstevel@tonic-gate configFile = args[i]; 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate } catch (Exception ex) { 2837c478bd9Sstevel@tonic-gate usage(); 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate } 2867c478bd9Sstevel@tonic-gate } else if (args[i].equals("monitor")) { 2877c478bd9Sstevel@tonic-gate bMon = true; 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate } else if (args[i].equals("stop")) { 2907c478bd9Sstevel@tonic-gate bStop = true; 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate } else { 2937c478bd9Sstevel@tonic-gate usage(); 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate } 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate // Read message bundle file, load config file into properties. 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate ResourceBundle bundle = 3017c478bd9Sstevel@tonic-gate getMessageBundleInternal(Locale.getDefault(), null); 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate try { 3047c478bd9Sstevel@tonic-gate if (configFile != null) { 3057c478bd9Sstevel@tonic-gate Properties props = System.getProperties(); 3067c478bd9Sstevel@tonic-gate props.setProperty("sun.net.slp.configURL", 3077c478bd9Sstevel@tonic-gate "file:" + configFile); 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate } 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate // Create a new SLP Config object from the config file. 3127c478bd9Sstevel@tonic-gate config = initializeSLPConfig(); 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate // Create a GUI if the user asked for one. 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate if (bMon) { 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate try { 3197c478bd9Sstevel@tonic-gate slpdgui = new SLPDgui(configFile); 3207c478bd9Sstevel@tonic-gate SLPLog log = new SLPLog(slpdgui.getTALog()); 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate synchronized (config) { 3237c478bd9Sstevel@tonic-gate config.log = log; 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate slpdgui.setVisible(true); 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate } catch (Exception ex) { 3297c478bd9Sstevel@tonic-gate System.err.println(formatMessageInternal("slpd_no_gui", 3307c478bd9Sstevel@tonic-gate new Object[0], 3317c478bd9Sstevel@tonic-gate bundle)); 3327c478bd9Sstevel@tonic-gate } 3337c478bd9Sstevel@tonic-gate } 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate // Either start or stop the server, depending on what was 3367c478bd9Sstevel@tonic-gate // requested. 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate if (!bStop) { 3397c478bd9Sstevel@tonic-gate start(); 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate } else { 3427c478bd9Sstevel@tonic-gate stop(); 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate } 3457c478bd9Sstevel@tonic-gate } catch (ServiceLocationException ex) { 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate errorExit(bundle, ex); 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate } 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate /** 3547c478bd9Sstevel@tonic-gate * Start the slpd. 3557c478bd9Sstevel@tonic-gate * 3567c478bd9Sstevel@tonic-gate * @param bMon True if initializing with GUI monitor. 3577c478bd9Sstevel@tonic-gate * @exception ServiceLocationException Internal error or network 3587c478bd9Sstevel@tonic-gate * initialization error or 3597c478bd9Sstevel@tonic-gate * internal networking error. 3607c478bd9Sstevel@tonic-gate * 3617c478bd9Sstevel@tonic-gate */ 3627c478bd9Sstevel@tonic-gate start()3637c478bd9Sstevel@tonic-gate static void start() throws ServiceLocationException { 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate // Initialize the service table. 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate ServiceTable table = ServiceTable.getServiceTable(); 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate // Initialize the class name for the DA table to the Sun-specific 3707c478bd9Sstevel@tonic-gate // DA table. 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate Properties props = System.getProperties(); 3737c478bd9Sstevel@tonic-gate props.put(DATable.DA_TABLE_CLASS_PROP, "com.sun.slp.SunServerDATable"); 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate // If there is a request on stdin, process it now 3767c478bd9Sstevel@tonic-gate try { 3777c478bd9Sstevel@tonic-gate if (System.in.available() > 0) { 3787c478bd9Sstevel@tonic-gate RequestHandler rh = 3797c478bd9Sstevel@tonic-gate new RequestHandler(System.in, System.out, config); 3807c478bd9Sstevel@tonic-gate rh.start(); 3817c478bd9Sstevel@tonic-gate } 3827c478bd9Sstevel@tonic-gate } catch (IOException e) {} 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate // Start a StreamListener on loopback to start accepting locals regs 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate StreamListener.initializeStreamListenerOnInterface( 3877c478bd9Sstevel@tonic-gate config.getLoopback()); 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate // Create a ServerDATable from the class. This will initialize 3907c478bd9Sstevel@tonic-gate // active discovery. Note that we need to record our own presence 3917c478bd9Sstevel@tonic-gate // in the DA table because we are not yet listening for requests. 3927c478bd9Sstevel@tonic-gate // We do this after deserialization so that if we discover any 3937c478bd9Sstevel@tonic-gate // DAs, we can perform registrations of the serialized advertisements. 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate daTable = ServerDATable.getServerDATable(); 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate // Deserialize any serialized advertisements and do them now. 3987c478bd9Sstevel@tonic-gate // Waiting until here allows any error messages to appear in 3997c478bd9Sstevel@tonic-gate // the GUI log, if any, and at this point the DA table is ready. 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate table.deserializeTable(); 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate // Need to create datagram and stream listeners, and a 4047c478bd9Sstevel@tonic-gate // DAAdvertiser on all network interfaces. 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate Vector interfaces = config.getInterfaces(); 4077c478bd9Sstevel@tonic-gate int i, n = interfaces.size(); 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++) { 4107c478bd9Sstevel@tonic-gate InetAddress interfac = (InetAddress)interfaces.elementAt(i); 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate // Initialize the complex of listener/sender objects on the 4137c478bd9Sstevel@tonic-gate // interface. This includes a datagram listener, a DAAdvertiser 4147c478bd9Sstevel@tonic-gate // (which shares the same socket as the datagram listener), and 4157c478bd9Sstevel@tonic-gate // a stream listener. 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate Listener.initializeInterfaceManagers(interfac); 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate // If we've been configured as a DA, then create a DA advertiser to 4227c478bd9Sstevel@tonic-gate // periodically advertise our presence on this interface. This 4237c478bd9Sstevel@tonic-gate // is only done on the default interface. 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate if (config.isDA()) { 4267c478bd9Sstevel@tonic-gate DAAdvertiser.initializeDAAdvertiserOnInterface( 4277c478bd9Sstevel@tonic-gate config.getLocalHost()); 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate } 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate // Report scopes and whether DA or SA. 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate Vector discoveredScopes = daTable.findScopes(); 4347c478bd9Sstevel@tonic-gate Vector serverScopes = config.getSAConfiguredScopes(); 4357c478bd9Sstevel@tonic-gate Vector daAttributes = config.getDAAttributes(); 4367c478bd9Sstevel@tonic-gate Vector saAttributes = config.getSAAttributes(); 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate // Report that we are running if tracing is on 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate if (config.regTest() || 4417c478bd9Sstevel@tonic-gate config.traceMsg() || 4427c478bd9Sstevel@tonic-gate config.traceDrop() || 4437c478bd9Sstevel@tonic-gate config.traceDATraffic()) { 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate config.writeLog((config.isDA() ? "hello_da":"hello"), 4467c478bd9Sstevel@tonic-gate new Object[] {interfaces, 4477c478bd9Sstevel@tonic-gate serverScopes, 4487c478bd9Sstevel@tonic-gate discoveredScopes, 4497c478bd9Sstevel@tonic-gate (config.isDA() ? 4507c478bd9Sstevel@tonic-gate daAttributes:saAttributes)}); 4517c478bd9Sstevel@tonic-gate } 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate // If V1 is supported, crank up V1 support as well. 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate if (config.isV1Supported()) { 4567c478bd9Sstevel@tonic-gate SLPV1Manager.start(config, daTable, table); 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate } 4597c478bd9Sstevel@tonic-gate } 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate // Stop a running server by sending a DAAdvert or SAAdvert. 4627c478bd9Sstevel@tonic-gate stop()4637c478bd9Sstevel@tonic-gate static void stop() throws ServiceLocationException { 4647c478bd9Sstevel@tonic-gate 4657c478bd9Sstevel@tonic-gate if (daemonIsDA()) { 4667c478bd9Sstevel@tonic-gate stopDA(); 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate } else { 4697c478bd9Sstevel@tonic-gate stopSA(); 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate } 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate // Determine whether the daemon running on this machine is a DA 4757c478bd9Sstevel@tonic-gate // or not. 4767c478bd9Sstevel@tonic-gate daemonIsDA()4777c478bd9Sstevel@tonic-gate static boolean daemonIsDA() throws ServiceLocationException { 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate // Get a DA table with available DAs. 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate DATable table = 4827c478bd9Sstevel@tonic-gate DATable.getDATable(); 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate // Get DAs. 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate Hashtable das = 4877c478bd9Sstevel@tonic-gate table.findDAScopes(config.getSAConfiguredScopes()); 4887c478bd9Sstevel@tonic-gate Vector daRecs = (Vector)das.get(DATable.UNICAST_KEY); 4897c478bd9Sstevel@tonic-gate Vector interfaces = config.getInterfaces(); 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate // If no DAs, then simply return. 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate if (daRecs == null) { 4947c478bd9Sstevel@tonic-gate return false; 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate } 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate // Find our address in the list, if it exists. 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate int i, n = daRecs.size(); 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++) { 5037c478bd9Sstevel@tonic-gate DATable.DARecord rec = 5047c478bd9Sstevel@tonic-gate (DATable.DARecord)daRecs.elementAt(i); 5057c478bd9Sstevel@tonic-gate Vector daAddresses = rec.daAddresses; 5067c478bd9Sstevel@tonic-gate 5077c478bd9Sstevel@tonic-gate int j, m = interfaces.size(); 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate for (j = 0; j < m; j++) { 5107c478bd9Sstevel@tonic-gate if (daAddresses.contains(interfaces.elementAt(i))) { 5117c478bd9Sstevel@tonic-gate return true; 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate } 5147c478bd9Sstevel@tonic-gate } 5157c478bd9Sstevel@tonic-gate } 5167c478bd9Sstevel@tonic-gate 5177c478bd9Sstevel@tonic-gate return false; 5187c478bd9Sstevel@tonic-gate } 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate // Stop a DA by multicasting the DAAdvert with boot timestamp 0. 5217c478bd9Sstevel@tonic-gate stopDA()5227c478bd9Sstevel@tonic-gate private static void stopDA() throws ServiceLocationException { 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate // Make the DA URL and the DAAdvert. Note that we only need signal 5257c478bd9Sstevel@tonic-gate // on the default local host interface because that is the only 5267c478bd9Sstevel@tonic-gate // one on which the server is listening. 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate ServiceURL url = 5297c478bd9Sstevel@tonic-gate new ServiceURL(Defaults.DA_SERVICE_TYPE + 5307c478bd9Sstevel@tonic-gate "://" + 5317c478bd9Sstevel@tonic-gate config.getLocalHost().getHostAddress(), 5327c478bd9Sstevel@tonic-gate ServiceURL.LIFETIME_DEFAULT); 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate SDAAdvert advert = 5357c478bd9Sstevel@tonic-gate new SDAAdvert(new SLPServerHeaderV2(), 5367c478bd9Sstevel@tonic-gate (short)0x0, // sez we're unsolicited... 5377c478bd9Sstevel@tonic-gate 0L, // sez we're going down... 5387c478bd9Sstevel@tonic-gate url, 5397c478bd9Sstevel@tonic-gate config.getSAConfiguredScopes(), 5407c478bd9Sstevel@tonic-gate new Vector()); // no attributes needed to go down... 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate // Make the DAAdvertiser. 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate DAAdvertiser daadv = new DAAdvertiser(config.getLocalHost(), 5457c478bd9Sstevel@tonic-gate advert.getHeader()); 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate // Send out unsolicted "going down" message. 5487c478bd9Sstevel@tonic-gate 5497c478bd9Sstevel@tonic-gate daadv.sendAdvert(); 5507c478bd9Sstevel@tonic-gate 5517c478bd9Sstevel@tonic-gate // That's it! No need for any messages here. 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate System.exit(0); 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate } 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate // Stop an SA server by unicasting an SA advert with xid 0. 5587c478bd9Sstevel@tonic-gate stopSA()5597c478bd9Sstevel@tonic-gate private static void stopSA() throws ServiceLocationException { 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate // We signal for stop on the local host, which is guaranteed 5627c478bd9Sstevel@tonic-gate // to have an SA listener. 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate ServiceURL url = 5657c478bd9Sstevel@tonic-gate new ServiceURL(Defaults.SA_SERVICE_TYPE + "://" + 5667c478bd9Sstevel@tonic-gate config.getLocalHost().getHostAddress(), 5677c478bd9Sstevel@tonic-gate ServiceURL.LIFETIME_DEFAULT); 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate SSAAdvert advert = new SSAAdvert(Defaults.version, 5707c478bd9Sstevel@tonic-gate (short)0x0, // sez we're going down... 5717c478bd9Sstevel@tonic-gate config.getLocale(), 5727c478bd9Sstevel@tonic-gate url, 5737c478bd9Sstevel@tonic-gate config.getSAConfiguredScopes(), 5747c478bd9Sstevel@tonic-gate new Vector()); 5757c478bd9Sstevel@tonic-gate // don't care about attrs.., 5767c478bd9Sstevel@tonic-gate 5777c478bd9Sstevel@tonic-gate // Send it TCP. We ignore NETWORK_ERROR because it only means 5787c478bd9Sstevel@tonic-gate // that the daemon didn't send us a reply, which is expected. 5797c478bd9Sstevel@tonic-gate 5807c478bd9Sstevel@tonic-gate try { 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate SrvLocMsg msg = 5837c478bd9Sstevel@tonic-gate Transact.transactTCPMsg(config.getLoopback(), advert, false); 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate if (msg.getErrorCode() != ServiceLocationException.OK) { 5867c478bd9Sstevel@tonic-gate config.writeLog("slpd_sa_stop_failure", 5877c478bd9Sstevel@tonic-gate new Object[] { 5887c478bd9Sstevel@tonic-gate new Integer(msg.getErrorCode())}); 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate } 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate } catch (ServiceLocationException ex) { 5937c478bd9Sstevel@tonic-gate 5947c478bd9Sstevel@tonic-gate if (ex.getErrorCode() != ServiceLocationException.NETWORK_ERROR) { 5957c478bd9Sstevel@tonic-gate config.writeLog("slpd_sa_stop_failure", 5967c478bd9Sstevel@tonic-gate new Object[] {new Integer(ex.getErrorCode())}); 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate } 5997c478bd9Sstevel@tonic-gate 6007c478bd9Sstevel@tonic-gate } 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate // That's it! 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate System.exit(0); 6057c478bd9Sstevel@tonic-gate } 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate // Print error message, exit. 6087c478bd9Sstevel@tonic-gate errorExit(ResourceBundle bundle, ServiceLocationException ex)6097c478bd9Sstevel@tonic-gate static void errorExit(ResourceBundle bundle, ServiceLocationException ex) { 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate switch (ex.getErrorCode()) { 6127c478bd9Sstevel@tonic-gate 6137c478bd9Sstevel@tonic-gate case ServiceLocationException.INTERNAL_SYSTEM_ERROR: 6147c478bd9Sstevel@tonic-gate System.err.println(formatMessageInternal("slpd_int_err", 6157c478bd9Sstevel@tonic-gate new Object[] { 6167c478bd9Sstevel@tonic-gate ex.getMessage()}, 6177c478bd9Sstevel@tonic-gate bundle)); 6187c478bd9Sstevel@tonic-gate break; 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate case ServiceLocationException.NETWORK_INIT_FAILED: 6217c478bd9Sstevel@tonic-gate System.err.println(formatMessageInternal("slpd_intnet_err", 6227c478bd9Sstevel@tonic-gate new Object[] { 6237c478bd9Sstevel@tonic-gate ex.getMessage()}, 6247c478bd9Sstevel@tonic-gate bundle)); 6257c478bd9Sstevel@tonic-gate break; 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate case ServiceLocationException.NETWORK_ERROR: 6287c478bd9Sstevel@tonic-gate System.err.println(formatMessageInternal("slpd_net_err", 6297c478bd9Sstevel@tonic-gate new Object[] { 6307c478bd9Sstevel@tonic-gate ex.getMessage()}, 6317c478bd9Sstevel@tonic-gate bundle)); 6327c478bd9Sstevel@tonic-gate break; 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate default: 6357c478bd9Sstevel@tonic-gate System.err.println(formatMessageInternal("slpd_err", 6367c478bd9Sstevel@tonic-gate new Object[] { 6377c478bd9Sstevel@tonic-gate new Integer(ex.getErrorCode()), 6387c478bd9Sstevel@tonic-gate ex.getMessage()}, 6397c478bd9Sstevel@tonic-gate bundle)); 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate 6437c478bd9Sstevel@tonic-gate ex.printStackTrace(); 6447c478bd9Sstevel@tonic-gate System.err.println(formatMessageInternal("exiting_msg", 6457c478bd9Sstevel@tonic-gate new Object[0], 6467c478bd9Sstevel@tonic-gate bundle)); 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate System.exit(1); 6497c478bd9Sstevel@tonic-gate 6507c478bd9Sstevel@tonic-gate } 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate // Make a new SLPConfig object of the right class type. 6537c478bd9Sstevel@tonic-gate initializeSLPConfig()6547c478bd9Sstevel@tonic-gate private static SLPConfig initializeSLPConfig() { 6557c478bd9Sstevel@tonic-gate 6567c478bd9Sstevel@tonic-gate // The server *always* runs as an SA. It may also run as a DA. 6577c478bd9Sstevel@tonic-gate 6587c478bd9Sstevel@tonic-gate config.isSA = true; 6597c478bd9Sstevel@tonic-gate 6607c478bd9Sstevel@tonic-gate // set default logging class for slpd to syslog 6617c478bd9Sstevel@tonic-gate 6627c478bd9Sstevel@tonic-gate if (System.getProperty("sun.net.slp.loggerClass") == null) { 6637c478bd9Sstevel@tonic-gate Properties props = System.getProperties(); 6647c478bd9Sstevel@tonic-gate props.setProperty("sun.net.slp.loggerClass", "com.sun.slp.Syslog"); 6657c478bd9Sstevel@tonic-gate System.setProperties(props); 6667c478bd9Sstevel@tonic-gate 6677c478bd9Sstevel@tonic-gate } 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate // slpd is the server side config. 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate theSLPConfig = new slpd(); 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate return theSLPConfig; 6747c478bd9Sstevel@tonic-gate 6757c478bd9Sstevel@tonic-gate } 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate // 6787c478bd9Sstevel@tonic-gate // Extensions to sldp for server side only. 6797c478bd9Sstevel@tonic-gate // 6807c478bd9Sstevel@tonic-gate isDA()6817c478bd9Sstevel@tonic-gate boolean isDA() { 6827c478bd9Sstevel@tonic-gate return Boolean.getBoolean("net.slp.isDA"); 6837c478bd9Sstevel@tonic-gate } 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate // Determine whether V1 is supported. Default is no. 6867c478bd9Sstevel@tonic-gate isV1Supported()6877c478bd9Sstevel@tonic-gate boolean isV1Supported() { 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate if (!isDA() || super.getSLPv1NotSupported()) { 6907c478bd9Sstevel@tonic-gate return false; 6917c478bd9Sstevel@tonic-gate 6927c478bd9Sstevel@tonic-gate } 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate boolean v1Supported = false; 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate try { 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate Class.forName("com.sun.slp.SLPV1Manager"); 6997c478bd9Sstevel@tonic-gate v1Supported = true; 7007c478bd9Sstevel@tonic-gate 7017c478bd9Sstevel@tonic-gate } catch (ClassNotFoundException ex) { 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate // Not there. 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate } 7067c478bd9Sstevel@tonic-gate 7077c478bd9Sstevel@tonic-gate return v1Supported; 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate } 7107c478bd9Sstevel@tonic-gate 7117c478bd9Sstevel@tonic-gate // Load server message bundle. 7127c478bd9Sstevel@tonic-gate 7137c478bd9Sstevel@tonic-gate private static final String serverMsgBundle = "Server"; 7147c478bd9Sstevel@tonic-gate getMessageBundle(Locale locale)7157c478bd9Sstevel@tonic-gate ResourceBundle getMessageBundle(Locale locale) { 7167c478bd9Sstevel@tonic-gate 7177c478bd9Sstevel@tonic-gate // Get the parent bundle first. 7187c478bd9Sstevel@tonic-gate 7197c478bd9Sstevel@tonic-gate ResourceBundle parentBundle = super.getMessageBundle(locale); 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate return getMessageBundleInternal(locale, parentBundle); 7227c478bd9Sstevel@tonic-gate 7237c478bd9Sstevel@tonic-gate } 7247c478bd9Sstevel@tonic-gate 7257c478bd9Sstevel@tonic-gate // We need this in case we get an error before the config object is 7267c478bd9Sstevel@tonic-gate // created. 7277c478bd9Sstevel@tonic-gate getMessageBundleInternal( Locale locale, ResourceBundle parentBundle)7287c478bd9Sstevel@tonic-gate static private ResourceBundle getMessageBundleInternal( 7297c478bd9Sstevel@tonic-gate Locale locale, 7307c478bd9Sstevel@tonic-gate ResourceBundle parentBundle) { 7317c478bd9Sstevel@tonic-gate 7327c478bd9Sstevel@tonic-gate // Now create a server subclass. 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate ResourceBundle msgBundle = null; 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate try { 7377c478bd9Sstevel@tonic-gate msgBundle = ServerBundle.getBundle(parentBundle, locale); 7387c478bd9Sstevel@tonic-gate 7397c478bd9Sstevel@tonic-gate } catch (MissingResourceException ex) { // can't localize this one! 7407c478bd9Sstevel@tonic-gate 7417c478bd9Sstevel@tonic-gate // We can't print out to the log, because we may be in the 7427c478bd9Sstevel@tonic-gate // process of trying to. 7437c478bd9Sstevel@tonic-gate 7447c478bd9Sstevel@tonic-gate System.out.println("Missing resource bundle ``"+ 7457c478bd9Sstevel@tonic-gate SERVER_BUNDLE_NAME+ 7467c478bd9Sstevel@tonic-gate "'' for locale ``"+ 7477c478bd9Sstevel@tonic-gate locale+ 7487c478bd9Sstevel@tonic-gate "''"); 7497c478bd9Sstevel@tonic-gate // Hosed if the default locale is missing. 7507c478bd9Sstevel@tonic-gate 7517c478bd9Sstevel@tonic-gate if (locale.equals(Defaults.locale)) { 7527c478bd9Sstevel@tonic-gate 7537c478bd9Sstevel@tonic-gate System.out.println("Exiting..."); 7547c478bd9Sstevel@tonic-gate System.exit(1); 7557c478bd9Sstevel@tonic-gate } 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate // Otherwise, return the default locale. 7587c478bd9Sstevel@tonic-gate 7597c478bd9Sstevel@tonic-gate System.out.println("Using SLP default locale ``" + 7607c478bd9Sstevel@tonic-gate Defaults.locale+"''"); 7617c478bd9Sstevel@tonic-gate 7627c478bd9Sstevel@tonic-gate msgBundle = 7637c478bd9Sstevel@tonic-gate getMessageBundleInternal(Defaults.locale, parentBundle); 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate } 7667c478bd9Sstevel@tonic-gate 7677c478bd9Sstevel@tonic-gate return msgBundle; 7687c478bd9Sstevel@tonic-gate } 7697c478bd9Sstevel@tonic-gate 7707c478bd9Sstevel@tonic-gate } 771