Hi All,
Here is a solution that hides the setMaxFileSize(long) method. It basically marks
"maxFileSize" as a String property instead of a long property. This works in the sense
that setMaxFileSize(long) need not be commented out (solving the backward
compatibility problem with Velocity) and the different configurators use the right
String-based setter method.
I do not like this solution because it just a hack. It presents an essentially long
property as a string which is basically the wrong approach. As I understand it, the
fundamental issue is that a given JavaBeans property can only have one and only one
type. Consequently, the long term solution is to rename setMaxFileSize(long) and
getMaxFileSize() to different names, e.g. setMaximumFileSize() and respectively
getMaximumFileSize.
Comments welcome, Ceki
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.APL file. */
package org.apache.log4j;
import java.beans.*;
import org.apache.log4j.helpers.LogLog;
import java.lang.reflect.Method;
public class RollingFileAppenderBeanInfo extends SimpleBeanInfo {
private PropertyDescriptor[] props;
public
RollingFileAppenderBeanInfo() {
Class clazz = RollingFileAppender.class;
try {
// the magic is here
BeanInfo bi = Introspector.getBeanInfo(clazz,
Introspector.IGNORE_ALL_BEANINFO);
props = bi.getPropertyDescriptors();
if(props != null) {
for(int i = 0; i < props.length; i++) {
if(props[i].getName().equals("maxFileSize")) {
Method m = clazz.getMethod("setMaxFileSize",
new Class[] {String.class});
props[i] = new PropertyDescriptor("maxFileSize", null, m);
}
}
}
// flush the bean info because getPropertyDescriptors() will now return
// different properties
Introspector.flushFromCaches(RollingFileAppender.class);
} catch(IntrospectionException e) {
LogLog.error("Could not inspect RollingFileAppender.", e);
} catch(NoSuchMethodException e) {
LogLog.error("Could find setter method for RollingFileAppender.", e);
}
}
public
PropertyDescriptor[] getPropertyDescriptors() {
return props;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]