public XMBean(Object resource,
String resourceType) throws MBeanException, NotCompliantMBeanException {
// TODO: document STANDARD_MBEAN
ModelMBeanInfo minfo = null;
try
{
HashMap properties = new HashMap();
if (resourceType.equals(DESCRIPTOR))
{
Descriptor d = (Descriptor)resource;
// get the actual resource type from the descriptor
resourceType = (String)d.getFieldValue(RESOURCE_TYPE);
// and the resource reference
resource = d.getFieldValue(RESOURCE_REFERENCE);
// extract builder configuration fields
String[] fields = d.getFieldNames();
for (int i = 0; i < fields.length; ++i)
{
// extract all the fields starting with the METADATA_DESCRIPTOR_PREFIX
// prefix to a property map that is passed to the builder implementations
if (fields[i].startsWith(METADATA_DESCRIPTOR_PREFIX))
properties.put(fields[i], d.getFieldValue(fields[i]));
}
}
if (resourceType.equals(STANDARD_MBEAN) && resource instanceof StandardMBean)
setManagedResource(((StandardMBean)resource).getImplementation(), resourceType);
else
setManagedResource(resource, resourceType);
// automatically create management operations that the attributes
// can map to.
final boolean CREATE_ATTRIBUTE_OPERATION_MAPPING = true;
// the resource extends StandardMBean
if (resourceType.equals(STANDARD_MBEAN) &&
resource instanceof StandardMBean)
{
StandardMBean standardMBean = (StandardMBean) resource;
minfo = MBeanInfoConversion.toModelMBeanInfo(standardMBean.getMBeanInfo(),
CREATE_ATTRIBUTE_OPERATION_MAPPING);
}
// the resource implements a Standard MBean interface
else if ((resourceType.equals(STANDARD_INTERFACE)) ||
(resourceType.equals(STANDARD_MBEAN)))
{
dynamicResource = false;
// create and configure the builder
MetaDataBuilder builder = new StandardMetaData(resource);
// pass the config keys to the builder instance
for (Iterator it = properties.keySet().iterator(); it.hasNext();)
{
String key = (String)it.next();
builder.setProperty(key, properties.get(key));
}
// build the metadata
MBeanInfo standardInfo = builder.build();
// StandardMetaData is used by the MBean server to introspect
// standard MBeans. We need to now turn that Standard metadata into
// ModelMBean metadata (including operation mapping for attributes)
minfo = MBeanInfoConversion.toModelMBeanInfo(standardInfo, CREATE_ATTRIBUTE_OPERATION_MAPPING);
}
// If the resource type string ends with an '.xml' extension attempt
// to create the metadata with the aggregated XML builder.
else if (resourceType.endsWith(".xml"))
{
// Create and configure the builder. XMLMetaData builder is an
// aggregate builder that picks the correct schema specific builder
// based on schema declaration at the beginning of the XML file.
MetaDataBuilder builder = new XMLMetaData(
this.getClass().getName(), // MMBean implementation name
resource.getClass().getName(), // resource class name
resourceType
);
// pass the config keys to the builder instance
for (Iterator it = properties.keySet().iterator(); it.hasNext();)
{
String key = (String)it.next();
builder.setProperty(key, properties.get(key));
}
minfo = (ModelMBeanInfo) builder.build();
}
// Sotre the ModelMBeanInfo
this.setModelMBeanInfo(minfo);
// we must try to load this MBean (as the superclass does), even if only NullPersistence
// is used - MMM
load();
}
catch (InstanceNotFoundException e)
{
throw new MBeanException(e);
}
catch (InvalidTargetObjectTypeException e)
{
if (resourceType.endsWith(".xml"))
throw new MBeanException(e, "Malformed URL: " + resourceType);
throw new MBeanException(e, "Unsupported resource type: " + resourceType);
}
catch (MalformedURLException e)
{
throw new MBeanException(e, "Malformed URL: " + resourceType);
}
}
- OBJECT_REF
- STANDARD_INTERFACE
- DESCRIPTOR
- Any valid URL string to a *.xml file.
OBJECT_REF: resource object can be any Java object. The
management interface must be set separately via
setModelMBeanInfo
method.
STANDARD_INTERFACE: the resource object is assumed to
follow the Standard MBean naming conventions to expose its management
interface, including implementing a xxxMBean interface. A
corresponding Model MBean metadata is generated for the Model MBean
representing this resource type.
DESCRIPTOR: the resource object is wrapped as a part of
the Descriptor object passed to this
Model MBean instance. The descriptor object must contain the mandatory
fields RESOURCE_REFERENCE and
RESOURCE_TYPE that identify the
correct resource reference and type used for this Model MBean instance.
The descriptor object may also contain additional fields, such as
SAX_PARSER and
XML_VALIDATION that are passed as
configuration properties for the metadata builder instances. Any
additional descriptor fields that match the
METADATA_DESCRIPTOR_PREFIX
naming pattern will be passed to the builder implementation via its
setProperty
method.
URL String: if a resource type string contains an URL
that ends with a *.xml file name the resource object is exposed via the
XML management interface definition read from this URL. The XML parser
implementation is picked based on the schema definition in the XML
document. Parameters:
resource - resource object or descriptor
resourceType - resource type string or URL to *.xml file
|