// 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);
}