use of org.apache.tomcat.util.modeler.AttributeInfo in project tomcat by apache.
the class MbeansDescriptorsIntrospectionSource method createManagedBean.
/**
* XXX Find if the 'className' is the name of the MBean or
* the real class ( I suppose first )
* XXX Read (optional) descriptions from a .properties, generated
* from source
* XXX Deal with constructors
*
* @param registry The Bean registry (not used)
* @param domain The bean domain (not used)
* @param realClass The class to analyze
* @param type The bean type
* @return ManagedBean The create MBean
*/
public ManagedBean createManagedBean(Registry registry, String domain, Class<?> realClass, String type) {
ManagedBean mbean = new ManagedBean();
Method[] methods = null;
Hashtable<String, Method> attMap = new Hashtable<>();
// key: attribute val: getter method
Hashtable<String, Method> getAttMap = new Hashtable<>();
// key: attribute val: setter method
Hashtable<String, Method> setAttMap = new Hashtable<>();
// key: operation val: invoke method
Hashtable<String, Method> invokeAttMap = new Hashtable<>();
methods = realClass.getMethods();
initMethods(realClass, methods, attMap, getAttMap, setAttMap, invokeAttMap);
try {
Enumeration<String> en = attMap.keys();
while (en.hasMoreElements()) {
String name = en.nextElement();
AttributeInfo ai = new AttributeInfo();
ai.setName(name);
Method gm = getAttMap.get(name);
if (gm != null) {
//ai.setGetMethodObj( gm );
ai.setGetMethod(gm.getName());
Class<?> t = gm.getReturnType();
if (t != null)
ai.setType(t.getName());
}
Method sm = setAttMap.get(name);
if (sm != null) {
//ai.setSetMethodObj(sm);
Class<?> t = sm.getParameterTypes()[0];
if (t != null)
ai.setType(t.getName());
ai.setSetMethod(sm.getName());
}
ai.setDescription("Introspected attribute " + name);
if (log.isDebugEnabled())
log.debug("Introspected attribute " + name + " " + gm + " " + sm);
if (gm == null)
ai.setReadable(false);
if (sm == null)
ai.setWriteable(false);
if (sm != null || gm != null)
mbean.addAttribute(ai);
}
for (Entry<String, Method> entry : invokeAttMap.entrySet()) {
String name = entry.getKey();
Method m = entry.getValue();
if (m != null) {
OperationInfo op = new OperationInfo();
op.setName(name);
op.setReturnType(m.getReturnType().getName());
op.setDescription("Introspected operation " + name);
Class<?>[] parms = m.getParameterTypes();
for (int i = 0; i < parms.length; i++) {
ParameterInfo pi = new ParameterInfo();
pi.setType(parms[i].getName());
pi.setName("param" + i);
pi.setDescription("Introspected parameter param" + i);
op.addParameter(pi);
}
mbean.addOperation(op);
} else {
log.error("Null arg method for [" + name + "]");
}
}
if (log.isDebugEnabled())
log.debug("Setting name: " + type);
mbean.setName(type);
return mbean;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
Aggregations