* @param metadata the component metadata
* @param dict the instance configuration
*/
public void configure(Element metadata, Dictionary dict) {
PojoMetadata manipulation = getPojoMetadata();
m_instanceManager = getInstanceManager();
m_jmxConfigFieldMap = new JmxConfigFieldMap();
// Build the hashmap
Element[] mbeans = metadata.getElements(JMX_CONFIG_ELT, m_namespace);
if (mbeans.length != 1) {
error("A component must have at most one " + JMX_CONFIG_ELT + ".");
error("The JMX handler configuration is ignored.");
return;
}
// retrieve kind of MBeanServer to use
m_usesMOSGi = Boolean.parseBoolean(mbeans[0]
.getAttribute(JMX_USES_MOSGI_ELT));
// retrieve object name
m_completeObjNameElt = mbeans[0].getAttribute(JMX_OBJ_NAME_ELT);
m_domainElt = mbeans[0].getAttribute(JMX_OBJ_NAME_DOMAIN_ELT);
m_objNameWODomainElt = mbeans[0]
.getAttribute(JMX_OBJ_NAME_WO_DOMAIN_ELT);
// test if Pojo is interested in registration callbacks
m_registerCallbacks = manipulation
.isInterfaceImplemented(MBeanRegistration.class.getName());
if (m_registerCallbacks) {
// don't need to check that methods exist, the pojo implements
// MBeanRegistration interface
String[] preRegisterParams = { MBeanServer.class.getName(),
ObjectName.class.getName() };
m_preRegisterMeth = manipulation.getMethod(PRE_REGISTER_METH_NAME,
preRegisterParams);
String[] postRegisterParams = { Boolean.class.getName() };
m_postRegisterMeth = manipulation.getMethod(
POST_REGISTER_METH_NAME, postRegisterParams);
m_preDeregisterMeth = manipulation.getMethod(
PRE_DEREGISTER_METH_NAME, new String[0]);
m_postDeregisterMeth = manipulation.getMethod(
POST_DEREGISTER_METH_NAME, new String[0]);
}
// set property
Element[] attributes = mbeans[0].getElements(JMX_PROPERTY_ELT, m_namespace);
if (attributes == null) {
attributes = mbeans[0].getElements(JMX_PROPERTY_ELT);
if (attributes != null) {
warn("The JMX property element should use the '" + m_namespace + "' namespace.");
}
}
// String[] fields = new String[attributes.length];
if (attributes != null) {
for (int i = 0; attributes != null && i < attributes.length; i++) {
boolean notif = false;
String rights;
String name;
String field = attributes[i].getAttribute(JMX_FIELD_ELT);
if (attributes[i].containsAttribute(JMX_NAME_ELT)) {
name = attributes[i].getAttribute(JMX_NAME_ELT);
} else {
name = field;
}
if (attributes[i].containsAttribute(JMX_RIGHTS_ELT)) {
rights = attributes[i].getAttribute(JMX_RIGHTS_ELT);
} else {
rights = "r";
}
PropertyField property = new PropertyField(name, field, rights,
getTypeFromAttributeField(field, manipulation));
if (attributes[i].containsAttribute(JMX_NOTIFICATION_ELT)) {
notif = Boolean.parseBoolean(attributes[i]
.getAttribute(JMX_NOTIFICATION_ELT));
}
property.setNotifiable(notif);
if (notif) {
// add the new notifiable property in structure
NotificationField notification = new NotificationField(
name, this.getClass().getName() + "." + field, null);
m_jmxConfigFieldMap.addNotificationFromName(name,
notification);
}
m_jmxConfigFieldMap.addPropertyFromName(name, property);
getInstanceManager().register(manipulation.getField(field),
this);
info("property exposed:" + name + " " + field + ":"
+ getTypeFromAttributeField(field, manipulation) + " "
+ rights + ", Notif=" + notif);
}