// cmm object name
String objectName = mapping.getCMM_ObjectName(CMM_MbeanDescriptor);
String tokenizedON =
ObjectNameHelper.tokenizeON(asON, objectName, _context.getTokens());
DefaultDelegate delegate = null;
if (!objectFactory.isObjectCreated(tokenizedON)) {
sourceMbean = objectFactory.createObject(tokenizedON);
// create delegate
delegate = (DefaultDelegate)
delegateFactory.createDelegate(mbs, sourceMbean, asON);
_delegateReg.put(tokenizedON, delegate);
} else {
sourceMbean = objectFactory.getObject(tokenizedON);
//delegate = (MfDelegate) delegateFactory.getDelegate(tokenizedON);
delegate = (DefaultDelegate) _delegateReg.get(tokenizedON);
}
if ( (sourceMbean == null) || (delegate == null) ) {
String msg = "MBean or the delegate must not be null";
throw new IllegalStateException(msg);
}
// add attribute mapping in delegate
Map attributes = mapping.getAttributeMappings(CMM_MbeanDescriptor);
Set asAttributes = attributes.keySet();
Iterator iter = asAttributes.iterator();
while (iter.hasNext()) {
String asAttr = (String) iter.next();
String mfAttr = (String) attributes.get(asAttr);
LogDomains.getLogger().finest("AS Attribute: " + asAttr);
LogDomains.getLogger().finest("MF Attribute: " + mfAttr);
LogDomains.getLogger().finest("AS Object Name: " + asON);
if ( (asAttr != null) && (mfAttr != null) ) {
// add mapping
try {
if (mapping.isAttributeHandlerDefined(CMM_MbeanDescriptor,
asAttr, mfAttr)) {
// construct the attribute handler
AttributeHandler handler = buildAttrHandler(
CMM_MbeanDescriptor, mapping, asAttr, mfAttr);
// add mapping with handler
delegate.addMappingEntry(mfAttr, asAttr, asON, handler);
} else {
// add mapping without handler
delegate.addMappingEntry(mfAttr, asAttr, asON);
}
} catch (Exception e) {
LogDomains.getLogger().log(Level.WARNING,
"Error while adding mapping entry", e);
}
}
}
// set def capabilities mappings when dealing with a capabilities mbean
if (isCapabilitiesType(tokenizedON)) {
delegate.initCapabilitiesMappings();
}
// add default attribute mappings
NodeList defAttr =
mapping.getDefaultAttributeMappings(CMM_MbeanDescriptor);
if (defAttr != null) {
int defSize = defAttr.getLength();
for (int i=0; i<defSize; i++) {
try {
Element e = (Element) defAttr.item(i);
String cmmAttr = e.getAttribute(CMM_NAME_TAG).trim();
String mappingAttr = e.getAttribute(MAPPING_TAG).trim();
String classAttr = e.getAttribute(MAPPING_CLASS_TAG);
LogDomains.getLogger().finest("CMM Attribute: " + cmmAttr);
LogDomains.getLogger().finest("Mapping: " + mappingAttr);
LogDomains.getLogger().finest("Mapping Class: "+classAttr);
if ( (cmmAttr != null) && (mappingAttr != null) ) {
// add default mapping
Object type = convertType(mappingAttr, classAttr);
delegate.addDefaultMappingEntry(cmmAttr, type);
}
} catch (Exception e) {
LogDomains.getLogger().log(Level.WARNING,
"Error while adding default mapping entry", e);
}
}
}
// sets the name of the server instance
String serverName = _context.getServerName();
delegate.setServerName(serverName);
// sets the name of the domain
String domainName = _context.getDomainName();
delegate.setDomainName(domainName);
// return the cmm mbean
return sourceMbean;
}