info = server.getMBeanInfo(objectName);
}
catch (InstanceNotFoundException e)
{
// The MBean is no longer available
throw new DeploymentException("trying to configure nonexistent mbean: " + objectName);
}
catch (Exception e)
{
throw new DeploymentException("Could not get mbeanInfo", JMXExceptionDecoder.decode(e));
} // end of catch
if (info == null)
{
throw new DeploymentException("MBeanInfo is null for mbean: " + objectName);
} // end of if ()
// Get the classloader for loading attribute classes.
ClassLoader cl = server.getClassLoader(loaderName);
// Initialize the mbean using the configuration supplied defaults
MBeanAttributeInfo[] attributes = info.getAttributes();
HashMap<String, MBeanAttributeInfo> attributeMap = new HashMap<String, MBeanAttributeInfo>();
for (int i = 0; i < attributes.length; i++)
{
MBeanAttributeInfo attr = attributes[i];
attributeMap.put(attr.getName(), attr);
}
NodeList attrs = mbeanElement.getChildNodes();
for (int j = 0; j < attrs.getLength(); j++)
{
// skip over non-element nodes
if (attrs.item(j).getNodeType() != Node.ELEMENT_NODE)
{
continue;
}
Element element = (Element) attrs.item(j);
boolean replace = true;
// Set attributes
if (element.getTagName().equals("attribute"))
{
String attributeName = element.getAttribute("name");
boolean trim = true;
String replaceAttr = element.getAttribute("replace");
if (replaceAttr.length() > 0)
replace = Boolean.valueOf(replaceAttr).booleanValue();
String trimAttr = element.getAttribute("trim");
if (trimAttr.length() > 0)
trim = Boolean.valueOf(trimAttr).booleanValue();
String serialDataType = element.getAttribute("serialDataType");
// Get the MBeanAttributeInfo
MBeanAttributeInfo attr = attributeMap.get(attributeName);
if (attr == null)
throw new DeploymentException("No Attribute found with name: " + attributeName);
if (element.hasChildNodes())
{
Object value = null;
// Unmarshall the attribute value based on the serialDataType
if (serialDataType.equals("javaBean"))
value = parseJavaBeanSerialData(attr, cl, element, replace, trim);
else if (serialDataType.equals("jbxb"))
value = parseJbxbSerialData(attr, cl, element, replace, trim);
else
value = parseTextSerialData(attr, cl, element, replace, trim);
log.debug(attributeName + " set to " + value + " in " + objectName);
setAttribute(objectName, new Attribute(attributeName, value));
}//if has children
}
//end of "attribute
else if (element.getTagName().equals("depends"))
{
if (!element.hasChildNodes())
{
throw new DeploymentException("No ObjectName supplied for depends in " + objectName);
}
String mbeanRefName = element.getAttribute("optional-attribute-name");
if ("".equals(mbeanRefName))
mbeanRefName = null;
else
mbeanRefName = StringPropertyReplacer.replaceProperties(mbeanRefName);
String proxyType = element.getAttribute("proxy-type");
if ("".equals(proxyType))
proxyType = null;
else
proxyType = StringPropertyReplacer.replaceProperties(proxyType);
// Get the mbeanRef value
ObjectName dependsObjectName = processDependency(objectName, loaderName, element, mbeans, replace);
log.debug("considering " + ((mbeanRefName == null) ? "<anonymous>" : mbeanRefName.toString()) + " with object name " + dependsObjectName);
if (mbeanRefName != null)
{
Object attribute = dependsObjectName;
if (proxyType != null)
{
if (mbeanRefName == null)
throw new DeploymentException("You cannot use a proxy-type without an optional-attribute-name");
if (proxyType.equals("attribute"))
{
MBeanAttributeInfo attr = attributeMap.get(mbeanRefName);
if (attr == null)
throw new DeploymentException("No Attribute found with name: " + mbeanRefName);
proxyType = attr.getType();
}
Class proxyClass = cl.loadClass(proxyType);
attribute = MBeanProxyExt.create(proxyClass, dependsObjectName,
server, true);
}
//if if doesn't exist or has wrong type, we'll get an exception
setAttribute(objectName, new Attribute(mbeanRefName, attribute));
} // end of if ()
}
//end of depends
else if (element.getTagName().equals("depends-list"))
{
String dependsListName = element.getAttribute("optional-attribute-name");
if ("".equals(dependsListName))
{
dependsListName = null;
} // end of if ()
NodeList dependsList = element.getChildNodes();
ArrayList<ObjectName> dependsListNames = new ArrayList<ObjectName>();
for (int l = 0; l < dependsList.getLength(); l++)
{
if (dependsList.item(l).getNodeType() != Node.ELEMENT_NODE)
{
continue;
}
Element dependsElement = (Element) dependsList.item(l);
if (dependsElement.getTagName().equals("depends-list-element"))
{
if (!dependsElement.hasChildNodes())
{
throw new DeploymentException("Empty depends-list-element!");
} // end of if ()
// Get the depends value
ObjectName dependsObjectName = processDependency(objectName, loaderName, dependsElement, mbeans, replace);
if (!dependsListNames.contains(dependsObjectName))