alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Spring Framework example source code file (ObjectNameManager.java)

This example Spring Framework source code file (ObjectNameManager.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Spring Framework tags/keywords

class, hashtable, invalid, malformedobjectnameexception, malformedobjectnameexception, management, objectname, objectname, objectnamemanager, objectnamemanager, string, string, util

The Spring Framework ObjectNameManager.java source code

/*
 * Copyright 2002-2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.jmx.support;

import java.util.Hashtable;

import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

import org.springframework.util.ClassUtils;

/**
 * Helper class for the creation of {@link javax.management.ObjectName} instances.
 *
 * <p>ObjectName instances will be cached on JMX 1.2,
 * whereas they will be recreated for each request on JMX 1.0.
 *
 * @author Rob Harrop
 * @author Juergen Hoeller
 * @since 1.2
 * @see javax.management.ObjectName#getInstance(String)
 */
public class ObjectNameManager {

	// Determine whether the JMX 1.2 <code>ObjectName.getInstance method is available.
	private static final boolean getInstanceAvailable =
			ClassUtils.hasMethod(ObjectName.class, "getInstance", new Class[] {String.class});


	/**
	 * Retrieve the <code>ObjectName instance corresponding to the supplied name.
	 * @param objectName the <code>ObjectName in ObjectName or
	 * <code>String format
	 * @return the <code>ObjectName instance
	 * @throws MalformedObjectNameException in case of an invalid object name specification
	 * @see ObjectName#ObjectName(String)
	 * @see ObjectName#getInstance(String)
	 */
	public static ObjectName getInstance(Object objectName) throws MalformedObjectNameException {
		if (objectName instanceof ObjectName) {
			return (ObjectName) objectName;
		}
		if (!(objectName instanceof String)) {
			throw new MalformedObjectNameException("Invalid ObjectName value type [" +
					objectName.getClass().getName() + "]: only ObjectName and String supported.");
		}
		return getInstance((String) objectName);
	}

	/**
	 * Retrieve the <code>ObjectName instance corresponding to the supplied name.
	 * @param objectName the <code>ObjectName in String format
	 * @return the <code>ObjectName instance
	 * @throws MalformedObjectNameException in case of an invalid object name specification
	 * @see ObjectName#ObjectName(String)
	 * @see ObjectName#getInstance(String)
	 */
	public static ObjectName getInstance(String objectName) throws MalformedObjectNameException {
		if (getInstanceAvailable) {
			return ObjectName.getInstance(objectName);
		}
		else {
			return new ObjectName(objectName);
		}
	}

	/**
	 * Retrieve an <code>ObjectName instance for the specified domain and a
	 * single property with the supplied key and value.
	 * @param domainName the domain name for the <code>ObjectName
	 * @param key the key for the single property in the <code>ObjectName
	 * @param value the value for the single property in the <code>ObjectName
	 * @return the <code>ObjectName instance
	 * @throws MalformedObjectNameException in case of an invalid object name specification
	 * @see ObjectName#ObjectName(String, String, String)
	 * @see ObjectName#getInstance(String, String, String)
	 */
	public static ObjectName getInstance(String domainName, String key, String value)
			throws MalformedObjectNameException {

		if (getInstanceAvailable) {
			return ObjectName.getInstance(domainName, key, value);
		}
		else {
			return new ObjectName(domainName, key, value);
		}
	}

	/**
	 * Retrieve an <code>ObjectName instance with the specified domain name
	 * and the supplied key/name properties.
	 * @param domainName the domain name for the <code>ObjectName
	 * @param properties the properties for the <code>ObjectName
	 * @return the <code>ObjectName instance
	 * @throws MalformedObjectNameException in case of an invalid object name specification
	 * @see ObjectName#ObjectName(String, java.util.Hashtable)
	 * @see ObjectName#getInstance(String, java.util.Hashtable)
	 */
	public static ObjectName getInstance(String domainName, Hashtable properties)
			throws MalformedObjectNameException {

		if (getInstanceAvailable) {
			return ObjectName.getInstance(domainName, properties);
		}
		else {
			return new ObjectName(domainName, properties);
		}
	}

}

Other Spring Framework examples (source code examples)

Here is a short list of links related to this Spring Framework ObjectNameManager.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.