Object getAttribute()

in src/main/java/org/apache/log4j/jmx/AppenderDynamicMBean.java [224:272]


  Object getAttribute(String attributeName) throws AttributeNotFoundException,
                                                   MBeanException,
                                                   ReflectionException {

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

    cat.debug("getAttribute called with ["+attributeName+"].");
    if(attributeName.startsWith("appender="+appender.getName()+",layout")) {
      try {
	    return new ObjectName("log4j:"+attributeName );
      } catch(MalformedObjectNameException e) {
	    cat.error("attributeName", e);
      } catch(RuntimeException e) {
	    cat.error("attributeName", e);
      }
    }

    MethodUnion mu = (MethodUnion) dynamicProps.get(attributeName);

    //cat.debug("----name="+attributeName+", b="+b);

    if(mu != null && mu.readMethod != null) {
      try {
	return mu.readMethod.invoke(appender, null);
      } catch(IllegalAccessException e) {
	    return null;
      } catch(InvocationTargetException e) {
          if (e.getTargetException() instanceof InterruptedException
                  || e.getTargetException() instanceof InterruptedIOException) {
              Thread.currentThread().interrupt();
          }
	    return null;
      } catch(RuntimeException e) {
	    return null;
      }
    }



    // If attributeName has not been recognized throw an AttributeNotFoundException
    throw(new AttributeNotFoundException("Cannot find " + attributeName +
					 " attribute in " + dClassName));

  }