Please note that this documentation is not final and is subject to change.

Java™ Platform
Standard Ed. 7

DRAFT ea-b76

javax.management.namespace
Class JMXNamespaces

java.lang.Object
  extended by javax.management.namespace.JMXNamespaces

public class JMXNamespaces
extends Object

Static constants and utility methods to help work with JMX name spaces. There are no instances of this class.

Since:
1.7

Field Summary
Modifier and Type Field and Description
static String NAMESPACE_SEPARATOR
          The name space separator.
 
Method Summary
Modifier and Type Method and Description
static String concat(String path, String namespace)
          Appends namespace to path.
static
<T> T
deepReplaceHeadNamespace(T obj, String toRemove, String toAdd)
          Returns an object that is the same as the given object except that any ObjectName it might contain has its domain modified.
static String getContainingNamespace(ObjectName name)
          Returns the normalized name space path of the name space expected to contain ObjectName.
static ObjectName getNamespaceObjectName(String namespace)
          Return a canonical handler name for the provided namespace, The handler name returned will be normalizeNamespaceName(namespace) + "//:type=JMXNamespace".
static ObjectName getWildcardFor(String namespace)
          Returns an ObjectName pattern that can be used to query for all MBeans contained in the given name space.
static ObjectName insertPath(String path, ObjectName to)
          Returns an ObjectName that can be used to access an MBean contained in the given name space.
static MBeanServerConnection narrowToNamespace(MBeanServerConnection parent, String namespace)
          Creates a new MBeanServerConnection proxy on a sub name space of the given parent.
static MBeanServer narrowToNamespace(MBeanServer parent, String namespace)
          Creates a new MBeanServer proxy on a sub name space of the given parent.
static String normalizeNamespaceName(String namespace)
          Returns a syntactically valid name space path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAMESPACE_SEPARATOR

public static final String NAMESPACE_SEPARATOR
The name space separator. This is an alias for ObjectName.NAMESPACE_SEPARATOR.

See Also:
Constant Field Values
Method Detail

narrowToNamespace

public static MBeanServerConnection narrowToNamespace(MBeanServerConnection parent,
                                                      String namespace)
Creates a new MBeanServerConnection proxy on a sub name space of the given parent.

Parameters:
parent - The parent MBeanServerConnection that contains the name space.
namespace - The name space in which to narrow.
Returns:
A new MBeanServerConnection proxy that shows the content of that name space.
Throws:
IllegalArgumentException - if either argument is null, or the name space does not exist, or if a proxy for that name space cannot be created. The cause of this exception will be an InstanceNotFoundException if and only if the name space is found not to exist.

narrowToNamespace

public static MBeanServer narrowToNamespace(MBeanServer parent,
                                            String namespace)
Creates a new MBeanServer proxy on a sub name space of the given parent.

Parameters:
parent - The parent MBeanServer that contains the name space.
namespace - The name space in which to narrow.
Returns:
A new MBeanServer proxy that shows the content of that name space.
Throws:
IllegalArgumentException - if either argument is null, or the name space does not exist, or if a proxy for that name space cannot be created. The cause of this exception will be an InstanceNotFoundException if and only if the name space is found not to exist.

deepReplaceHeadNamespace

public static <T> T deepReplaceHeadNamespace(T obj,
                                             String toRemove,
                                             String toAdd)
Returns an object that is the same as the given object except that any ObjectName it might contain has its domain modified. The returned object might be identical to the given object if it does not contain any ObjectName values or if none of them were modified. This method will replace a prefix (toRemove) from the path of the ObjectNames contained in obj by another prefix (toAdd). Therefore, all contained ObjectNames must have a path that start with the given toRemove prefix. If one of them doesn't, an IllegalArgumentException is thrown.

For instance, if obj contains the ObjectName x//y//z//d:k=x, and toAdd is v//w, and toRemove is x//y this method will return a copy of obj that contains v//w//z//d:k=x.
On the other hand, if obj contains the ObjectName x//y//z//d:k=x, and toAdd is v//w, and toRemove is v this method will raise an exception, because x//y//z//d:k=x doesn't start with v

Note: the default implementation of this method can use the Java serialization framework to clone and replace ObjectNames in the provided obj. It will usually fail if obj is not Java serializable, or contains objects which are not Java serializable.

Parameters:
obj - The object to deep-rewrite
toRemove - a prefix already present in contained ObjectNames. If toRemove is the empty string "", nothing will be removed from the contained ObjectNames.
toAdd - the prefix that will replace (@code toRemove} in contained ObjectNames. If toAdd is the empty string "", nothing will be added to the contained ObjectNames.
Returns:
the rewritten object, or possibly obj if nothing needed to be changed.
Throws:
IllegalArgumentException - if obj couldn't be rewritten or if toRemove or toAdd is null.

concat

public static String concat(String path,
                            String namespace)
Appends namespace to path. This methods appends namespace to path to obtain a a full path, and normalizes the result thus obtained:

Parameters:
path - a name space path prefix
namespace - a name space name to append to the path
Returns:
a syntactically valid name space path, or "" if both parameters are null or empty.
Throws:
IllegalArgumentException - if either argument is null or ends with an odd number of / characters.

normalizeNamespaceName

public static String normalizeNamespaceName(String namespace)
Returns a syntactically valid name space path. If the provided namespace ends with "//", recursively strips trailing "//". Each sequence of an even number of "/" characters is also replaced by "//", for example "foo//bar////baz/////buh" will become "foo//bar//baz///buh".

Parameters:
namespace - A name space path
Returns:
"" - if the provided namespace resolves to the empty string; otherwise a syntactically valid name space string stripped of trailing and redundant "//".
Throws:
IllegalArgumentException - if namespace is null or is not syntactically valid (e.g. it contains invalid characters like ':', or it ends with an odd number of '/').

getNamespaceObjectName

public static ObjectName getNamespaceObjectName(String namespace)
Return a canonical handler name for the provided namespace, The handler name returned will be normalizeNamespaceName(namespace) + "//:type=JMXNamespace".

Parameters:
namespace - A name space path
Returns:
a canonical ObjectName for a name space handler.
Throws:
IllegalArgumentException - if the provided namespace is null or not valid.
See Also:
normalizeNamespaceName(java.lang.String)

getWildcardFor

public static ObjectName getWildcardFor(String namespace)
Returns an ObjectName pattern that can be used to query for all MBeans contained in the given name space. For instance, if namespace="foo//bar", this method will return "foo//bar//*:*"

Returns:
an ObjectName pattern that selects all MBeans in the given name space.

insertPath

public static ObjectName insertPath(String path,
                                    ObjectName to)
Returns an ObjectName that can be used to access an MBean contained in the given name space. For instance, if path="foo//bar", and to="domain:type=Thing" this method will return "foo//bar//domain:type=Thing"

Returns:
an ObjectName that can be used to invoke an MBean located in a sub name space.
Throws:
IllegalArgumentException - if path ends with an odd number of / characters.

getContainingNamespace

public static String getContainingNamespace(ObjectName name)
Returns the normalized name space path of the name space expected to contain ObjectName. For instance, for "foo//domain:type=Thing" this will be "foo". For "//foo//bar//domain:type=Thing" this will be "foo//bar". For //foo//bar//baz//domain:type=Thing this will be "foo//bar//baz". For //foo//bar//baz//:type=JMXNamespace this will be "foo//bar".

Parameters:
name - an ObjectName
Returns:
the name space path of the name space that could contain such a name. If name has no name space, returns "".
Throws:
IllegalArgumentException - if name is null.

Java™ Platform
Standard Ed. 7

DRAFT ea-b76

Submit a bug or feature

Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.