org.apache.tools.ant.taskdefs.optional.jmx
Class AbstractMBeanTask

java.lang.Object
  |
  +--org.apache.tools.ant.ProjectComponent
        |
        +--org.apache.tools.ant.Task
              |
              +--org.apache.tools.ant.taskdefs.optional.jmx.AbstractManagementTask
                    |
                    +--org.apache.tools.ant.taskdefs.optional.jmx.AbstractMBeanTask
Direct Known Subclasses:
ConfigureMBeanTask, CopyMBeanTask, InvokeMBeanTask, RemoveMBeanTask, ShowMBeanTask

public abstract class AbstractMBeanTask
extends AbstractManagementTask

This is the abstract base class for Ant JMX mbean tasks. Implementations of AbstractMBean inherit its attributes (see below) for connecting to the JMX MBean server.

Refer to the user documentation for more information and examples on how to use this task.

Version:
$Id: AbstractMBeanTask.java,v 1.5 2003/05/26 15:15:09 bdueck Exp $
Author:
Brian Dueck

Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
AbstractMBeanTask()
           
 
Method Summary
 void execute()
          Execute the MBean task.
protected abstract  void execute(javax.management.MBeanServer mbserver)
          Execute the JMX MBean task against the specified MBeanServer.
protected  javax.management.MBeanAttributeInfo findAttributeInfo(javax.management.MBeanInfo beanInfo, java.lang.String attributeName)
          Helper function to find the MBeanAttributeInfo for the indicated attribute name.
 java.lang.String getActiveDomain()
           
protected  java.util.Map getAttributes(javax.management.MBeanInfo beanInfo)
          Helper function to return MBeanAttributeInfo[] as a Map.
protected  java.util.Map getAttributes(javax.management.MBeanInfo beanInfo, java.util.Set attributeNames)
          Helper function to return MBeanAttributeInfo[] as a Map.
protected  java.lang.String[] getFeatureNames(javax.management.MBeanFeatureInfo[] features)
          Helper function to extract attribute names from an MBeanFeatureInfo[] as a String[].
 JMXConnector getJMXServer()
           
protected  java.lang.String getName()
          The name of the JMX MBean.
protected  javax.management.ObjectName getObjectName()
          Returns an ObjectName for this nested Ant MBean element.
protected  void removeMBeanIfExists(javax.management.MBeanServer mbserver, javax.management.ObjectName mbean, java.lang.String ifExists)
          Removes a given mbean from an mbean server if required by the IfExists flag.
 void setMBeanRef(org.apache.tools.ant.types.Reference ref)
           
 void setName(java.lang.String name)
          Sets the name attribute.
 java.lang.String toString()
          Return stringified version of the MBean.
 
Methods inherited from class org.apache.tools.ant.taskdefs.optional.jmx.AbstractManagementTask
getContext, getFailOnError, getJndiName, getPassword, getProviderUrl, getUser, setContext, setContextRef, setFailOnError, setJndiName, setPassword, setProviderUrl, setServerType, setUser
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, handleErrorOutput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractMBeanTask

public AbstractMBeanTask()
Method Detail

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Execute the MBean task.
Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - If an error occurs.

execute

protected abstract void execute(javax.management.MBeanServer mbserver)
                         throws org.apache.tools.ant.BuildException
Execute the JMX MBean task against the specified MBeanServer.
Parameters:
mbserver - The target MBeanServer.
Throws:
org.apache.tools.ant.BuildException - If an error occurs.

toString

public java.lang.String toString()
Return stringified version of the MBean.
Overrides:
toString in class java.lang.Object
Returns:
Stringified information about this object.

getObjectName

protected javax.management.ObjectName getObjectName()
                                             throws javax.management.MalformedObjectNameException
Returns an ObjectName for this nested Ant MBean element. Lazily caches the result in a private instance.
Returns:
Returns the target ObjectName for this task.
Throws:
javax.management.MalformedObjectNameException - If there is an error creating a valid ObjectName based on the parameters specified for this task (jndiName, server, name, type).

setName

public void setName(java.lang.String name)
Sets the name attribute.
Parameters:
name - The name of the mbean.

getName

protected java.lang.String getName()
The name of the JMX MBean.
Returns:
The name of the MBean.

getActiveDomain

public java.lang.String getActiveDomain()

getJMXServer

public JMXConnector getJMXServer()

setMBeanRef

public void setMBeanRef(org.apache.tools.ant.types.Reference ref)

findAttributeInfo

protected javax.management.MBeanAttributeInfo findAttributeInfo(javax.management.MBeanInfo beanInfo,
                                                                java.lang.String attributeName)
Helper function to find the MBeanAttributeInfo for the indicated attribute name.

getAttributes

protected java.util.Map getAttributes(javax.management.MBeanInfo beanInfo)
Helper function to return MBeanAttributeInfo[] as a Map.

getAttributes

protected java.util.Map getAttributes(javax.management.MBeanInfo beanInfo,
                                      java.util.Set attributeNames)
Helper function to return MBeanAttributeInfo[] as a Map. Returned attributes can be filtered by passing in a set of attribute names (ignored if null).

getFeatureNames

protected java.lang.String[] getFeatureNames(javax.management.MBeanFeatureInfo[] features)
Helper function to extract attribute names from an MBeanFeatureInfo[] as a String[].
Parameters:
features - The feature information.
Returns:
An array of strings with the feature names.

removeMBeanIfExists

protected void removeMBeanIfExists(javax.management.MBeanServer mbserver,
                                   javax.management.ObjectName mbean,
                                   java.lang.String ifExists)
                            throws org.apache.tools.ant.BuildException
Removes a given mbean from an mbean server if required by the IfExists flag. If the mbean does not exist in the target mbean server, this is a null op. If the mbean exists, the action taken is determined by the ifExists paramter.

mbean exists && ifExists = skip : The mbean is left in place.

mbean exists && ifExists = warn : A warning is given and the mbean is left in place.

mbean exists && ifExists = fail : BuildException is thrown.

mbean exists && ifExists = replace : A warning is given and the mbean is removed.

mbean exists && ifExists = replaceAttributes : A warning is given but the mbean is left in place.

Parameters:
mbserver - The MBeanServer that hosts the mbean.

mbean - The mbean to remove.
ifExists - One of IfExists.getValues().
Throws:
org.apache.tools.ant.BuildException -  
See Also:
IfExists