| Method from org.apache.log4j.jmx.LayoutDynamicMBean Detail: |
public Object getAttribute(String attributeName) throws ReflectionException, AttributeNotFoundException, MBeanException {
// Check attributeName is not null to avoid NullPointerException later on
if (attributeName == null) {
throw new RuntimeOperationsException(new IllegalArgumentException(
"Attribute name cannot be null"),
"Cannot invoke a getter of " + dClassName + " with null attribute name");
}
MethodUnion mu = (MethodUnion) dynamicProps.get(attributeName);
cat.debug("----name="+attributeName+", mu="+mu);
if(mu != null && mu.readMethod != null) {
try {
return mu.readMethod.invoke(layout, null);
} catch(Exception e) {
return null;
}
}
// If attributeName has not been recognized throw an AttributeNotFoundException
throw(new AttributeNotFoundException("Cannot find " + attributeName +
" attribute in " + dClassName));
}
|
protected Logger getLogger() {
return cat;
}
|
public MBeanInfo getMBeanInfo() {
cat.debug("getMBeanInfo called.");
MBeanAttributeInfo[] attribs = new MBeanAttributeInfo[dAttributes.size()];
dAttributes.toArray(attribs);
return new MBeanInfo(dClassName,
dDescription,
attribs,
dConstructors,
dOperations,
new MBeanNotificationInfo[0]);
}
|
public Object invoke(String operationName,
Object[] params,
String[] signature) throws ReflectionException, MBeanException {
if(operationName.equals("activateOptions") &&
layout instanceof OptionHandler) {
OptionHandler oh = (OptionHandler) layout;
oh.activateOptions();
return "Options activated.";
}
return null;
}
|
public void setAttribute(Attribute attribute) throws InvalidAttributeValueException, ReflectionException, AttributeNotFoundException, MBeanException {
// Check attribute is not null to avoid NullPointerException later on
if (attribute == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute cannot be null"),
"Cannot invoke a setter of " + dClassName +
" with null attribute");
}
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute name cannot be null"),
"Cannot invoke the setter of "+dClassName+
" with null attribute name");
}
MethodUnion mu = (MethodUnion) dynamicProps.get(name);
if(mu != null && mu.writeMethod != null) {
Object[] o = new Object[1];
Class[] params = mu.writeMethod.getParameterTypes();
if(params[0] == org.apache.log4j.Priority.class) {
value = OptionConverter.toLevel((String) value,
(Level) getAttribute(name));
}
o[0] = value;
try {
mu.writeMethod.invoke(layout, o);
} catch(Exception e) {
cat.error("FIXME", e);
}
} else {
throw(new AttributeNotFoundException("Attribute " + name +
" not found in " +
this.getClass().getName()));
}
}
|