/* * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.jmx.remote.util; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.Collection; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import java.util.SortedMap; import java.util.SortedSet; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.security.AccessController; import javax.management.ObjectName; import javax.management.MBeanServer; import javax.management.InstanceNotFoundException; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXConnectorServerFactory; import com.sun.jmx.mbeanserver.GetPropertyAction; import com.sun.jmx.remote.security.NotificationAccessController; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorServer; public class EnvHelp { /** * Name of the attribute that specifies a default class loader * object. * The value associated with this attribute is a ClassLoader object. */ private static final String DEFAULT_CLASS_LOADER = JMXConnectorFactory.DEFAULT_CLASS_LOADER; /** * Name of the attribute that specifies a default class loader * ObjectName. * The value associated with this attribute is an ObjectName object. */ private static final String DEFAULT_CLASS_LOADER_NAME = JMXConnectorServerFactory.DEFAULT_CLASS_LOADER_NAME; /** * Get the Connector Server default class loader. *
* Returns: *
jmx.remote.default.class.loader
, if any.
* jmx.remote.default.class.loader.name
,
* and registered in mbs if any.
* jmx.remote.default.class.loader
and
* jmx.remote.default.class.loader.name
are specified,
* jmx.remote.default.class.loader
is not
* an instance of {@link ClassLoader},
* jmx.remote.default.class.loader.name
is not
* an instance of {@link ObjectName},
* jmx.remote.default.class.loader.name
is specified
* but mbs is null.
* jmx.remote.default.class.loader.name
is specified
* and the ClassLoader MBean is not found in mbs.
*/
public static ClassLoader resolveServerClassLoader(Map* Returns: *
jmx.remote.default.class.loader
, if any.
* * Usually a Connector Client will call *
* ClassLoader dcl = EnvHelp.resolveClientClassLoader(env); ** in its
connect(Map env)
method.
*
* @return The connector client default class loader.
*
* @exception IllegalArgumentException if
* jmx.remote.default.class.loader
is specified
* and is not an instance of {@link ClassLoader}.
*/
public static ClassLoader resolveClientClassLoader(MapLong
* object. The default value is 60000 milliseconds.
*/
public static final String FETCH_TIMEOUT =
"jmx.remote.x.notification.fetch.timeout";
/**
* Returns the timeout for a client to fetch notifications.
*/
public static long getFetchTimeout(MapNotificationAccessController
object.
* The default value is null.
*
* This field is not public because of its com.sun dependency.
*/
public static final String NOTIF_ACCESS_CONTROLLER =
"com.sun.jmx.remote.notification.access.controller";
public static NotificationAccessController getNotificationAccessController(
Mapname
* from env
. If env
is null, or does
* not contain an entry for name
, return
* defaultValue
. The value may be a Number, or it
* may be a String that is parsable as a long. It must be at
* least minValue
and at mostmaxValue
.
*
* @throws IllegalArgumentException if env
contains
* an entry for name
but it does not meet the
* constraints above.
*/
public static long getIntegerAttribute(Map
*
*
* @throws IllegalArgumentException if
* {@code ((String)env.get(prop)).equalsIgnoreCase("false")} and
* {@code ((String)env.get(prop)).equalsIgnoreCase("true")} are
* {@code false}.
*/
public static boolean computeBooleanFromString(String stringBoolean) {
// returns a default value of 'false' if no property is found...
return computeBooleanFromString(stringBoolean,false);
}
/**
* Computes a boolean value from a string value retrieved from a
* property in the given map.
*
* @param stringBoolean the string value that must be converted
* into a boolean value.
* @param defaultValue a default value to return in case no property
* was defined.
*
* @return
*
*
*
* @throws IllegalArgumentException if
* {@code ((String)env.get(prop)).equalsIgnoreCase("false")} and
* {@code ((String)env.get(prop)).equalsIgnoreCase("true")} are
* {@code false}.
*/
public static boolean computeBooleanFromString( String stringBoolean, boolean defaultValue) {
if (stringBoolean == null)
return defaultValue;
else if (stringBoolean.equalsIgnoreCase("true"))
return true;
else if (stringBoolean.equalsIgnoreCase("false"))
return false;
else
throw new IllegalArgumentException(
"Property value must be \"true\" or \"false\" instead of \"" +
stringBoolean + "\"");
}
/**
* Converts a map into a valid hash table, i.e.
* it removes all the 'null' values from the map.
*/
public static