use of org.apache.tomcat.util.modeler.ManagedBean 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;
}
}
use of org.apache.tomcat.util.modeler.ManagedBean in project tomcat by apache.
the class MbeansDescriptorsIntrospectionSource method execute.
public void execute() throws Exception {
if (registry == null)
registry = Registry.getRegistry(null, null);
try {
ManagedBean managed = createManagedBean(registry, null, (Class<?>) source, type);
if (managed == null)
return;
managed.setName(type);
registry.addManagedBean(managed);
} catch (Exception ex) {
log.error("Error reading descriptors ", ex);
}
}
use of org.apache.tomcat.util.modeler.ManagedBean in project tomcat by apache.
the class NamingResourcesMBean method addResourceLink.
/**
* Add a resource link reference for this web application.
*
* @param resourceLinkName New resource link reference name
* @param type New resource link reference type
* @return the object name of the new resource link
* @throws MalformedObjectNameException if the object name was invalid
*/
public String addResourceLink(String resourceLinkName, String type) throws MalformedObjectNameException {
NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
if (nresources == null) {
return null;
}
ContextResourceLink resourceLink = nresources.findResourceLink(resourceLinkName);
if (resourceLink != null) {
throw new IllegalArgumentException("Invalid resource link name - already exists'" + resourceLinkName + "'");
}
resourceLink = new ContextResourceLink();
resourceLink.setName(resourceLinkName);
resourceLink.setType(type);
nresources.addResourceLink(resourceLink);
// Return the corresponding MBean name
ManagedBean managed = registry.findManagedBean("ContextResourceLink");
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resourceLink);
return oname.toString();
}
use of org.apache.tomcat.util.modeler.ManagedBean in project tomcat by apache.
the class NamingResourcesMBean method addEnvironment.
// ------------------------------------------------------------- Operations
/**
* Add an environment entry for this web application.
*
* @param envName New environment entry name
* @param type The type of the new environment entry
* @param value The value of the new environment entry
* @return the object name of the new environment entry
* @throws MalformedObjectNameException if the object name was invalid
*/
public String addEnvironment(String envName, String type, String value) throws MalformedObjectNameException {
NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
if (nresources == null) {
return null;
}
ContextEnvironment env = nresources.findEnvironment(envName);
if (env != null) {
throw new IllegalArgumentException("Invalid environment name - already exists '" + envName + "'");
}
env = new ContextEnvironment();
env.setName(envName);
env.setType(type);
env.setValue(value);
nresources.addEnvironment(env);
// Return the corresponding MBean name
ManagedBean managed = registry.findManagedBean("ContextEnvironment");
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), env);
return oname.toString();
}
use of org.apache.tomcat.util.modeler.ManagedBean in project tomcat by apache.
the class NamingResourcesMBean method addResource.
/**
* Add a resource reference for this web application.
*
* @param resourceName New resource reference name
* @param type New resource reference type
* @return the object name of the new resource
* @throws MalformedObjectNameException if the object name was invalid
*/
public String addResource(String resourceName, String type) throws MalformedObjectNameException {
NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
if (nresources == null) {
return null;
}
ContextResource resource = nresources.findResource(resourceName);
if (resource != null) {
throw new IllegalArgumentException("Invalid resource name - already exists'" + resourceName + "'");
}
resource = new ContextResource();
resource.setName(resourceName);
resource.setType(type);
nresources.addResource(resource);
// Return the corresponding MBean name
ManagedBean managed = registry.findManagedBean("ContextResource");
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resource);
return oname.toString();
}
Aggregations