Package org.springframework.jmx.export.naming

# Class MetadataNamingStrategy

java.lang.Object
org.springframework.jmx.export.naming.MetadataNamingStrategy

All Implemented Interfaces:
  `org.springframework.beans.factory.InitializingBean`, `ObjectNamingStrategy`

public class MetadataNamingStrategy extends Object implements ObjectNamingStrategy, org.springframework.beans.factory.InitializingBean
An implementation of the `ObjectNamingStrategy` interface that reads the `ObjectName` from the source-level metadata. Falls back to the bean key (bean name) if no `ObjectName` can be found in source-level metadata.

Uses the `JmxAttributeSource` strategy interface, so that metadata can be read using any supported implementation. Out of the box, `AnnotationJmxAttributeSource` introspects a well-defined set of annotations that come with Spring.

Since:
  1.2
Author:
  Rob Harrop, Juergen Hoeller
See Also:
  - `ObjectNamingStrategy`
  - `AnnotationJmxAttributeSource`

## Constructor Summary

Constructors
Constructor
Description
`MetadataNamingStrategy()`
Create a new `MetadataNamingStrategy` which needs to be configured through the `setAttributeSource(org.springframework.jmx.export.metadata.JmxAttributeSource)` method.
`MetadataNamingStrategy(JmxAttributeSource attributeSource)`
Create a new `MetadataNamingStrategy` for the given `JmxAttributeSource`.

## Method Summary

Modifier and Type
Method
Description
`void`
`afterPropertiesSet()`
`ObjectName`
`getObjectName(Object managedBean, String beanKey)`
Reads the `ObjectName` from the source-level metadata associated with the managed resource's `Class`.
`void`
`setAttributeSource(JmxAttributeSource attributeSource)`
Set the implementation of the `JmxAttributeSource` interface to use when reading the source-level metadata.
`void`
`setDefaultDomain(String defaultDomain)`
Specify the default domain to be used for generating ObjectNames when no source-level metadata has been specified.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### MetadataNamingStrategy

public MetadataNamingStrategy()
Create a new `MetadataNamingStrategy` which needs to be configured through the `setAttributeSource(org.springframework.jmx.export.metadata.JmxAttributeSource)` method.

### MetadataNamingStrategy

public MetadataNamingStrategy(JmxAttributeSource attributeSource)
Create a new `MetadataNamingStrategy` for the given `JmxAttributeSource`.

Parameters:
  `attributeSource` - the JmxAttributeSource to use

## Method Details

### setAttributeSource

public void setAttributeSource(JmxAttributeSource attributeSource)
Set the implementation of the `JmxAttributeSource` interface to use when reading the source-level metadata.

### setDefaultDomain

public void setDefaultDomain(String defaultDomain)
Specify the default domain to be used for generating ObjectNames when no source-level metadata has been specified.

The default is to use the domain specified in the bean name (if the bean name follows the JMX ObjectName syntax); else, the package name of the managed bean class.

### afterPropertiesSet

public void afterPropertiesSet()

Specified by:
  `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`

### getObjectName

public ObjectName getObjectName(Object managedBean, @Nullable String beanKey) throws MalformedObjectNameException
Reads the `ObjectName` from the source-level metadata associated with the managed resource's `Class`.

Specified by:
  `getObjectName` in interface `ObjectNamingStrategy`
Parameters:
  `managedBean` - the bean that will be exposed under the returned `ObjectName`
  `beanKey` - the key associated with this bean in the beans map passed to the `MBeanExporter`
Returns:
  the `ObjectName` instance
Throws:
  `MalformedObjectNameException` - if the resulting `ObjectName` is invalid