/** Set the properties of an object passed as a parameter in one go. The <code>properties</code> are parsed relative to a <code>prefix</code>. @param obj The object to configure. @param properties A java.util.Properties containing keys and values. @param prefix Only keys having the specified prefix will be set. */ public static void setProperties(Object obj, Properties properties, String prefix) { new PropertySetter(obj).setProperties(properties, prefix); }
protected void printOptions(PrintWriter out, Logger cat) { printOptions(out, (Category) cat); }
public PropertyPrinter(PrintWriter out, boolean doCapitalize) { this.out = out; this.doCapitalize = doCapitalize; print(out); out.flush(); }
PropertySetter propSetter = new PropertySetter(filter); NodeList children = element.getChildNodes(); final int length = children.getLength(); propSetter.activate(); LogLog.debug("Adding filter of type ["+filter.getClass() +"] to appender named ["+appender.getName()+"].");
if ((name = app.getName()) == null || isGenAppName(name)) { name = genAppName(); printOptions(out, app, "log4j.appender."+name); if (app.getLayout() != null) { printOptions(out, app.getLayout(), "log4j.appender."+name+".layout");
PropertyDescriptor prop = getPropertyDescriptor(name); } else { try { setProperty(prop, name, value); } catch (PropertySetterException ex) { LogLog.warn("Failed to set property [" + name +
public static void getProperties(Object obj, PropertyCallback callback, String prefix) { try { new PropertyGetter(obj).getProperties(callback, prefix); } catch (IntrospectionException ex) { LogLog.error("Failed to introspect object " + obj, ex); } }
Method setter = prop.getWriteMethod(); if (setter == null) { throw new PropertySetterException("No setter for property ["+name+"]."); throw new PropertySetterException("#params for setter != 1"); arg = convertArg(value, paramTypes[0]); } catch (Throwable t) { throw new PropertySetterException("Conversion to type ["+paramTypes[0]+ "] failed. Reason: "+t); throw new PropertySetterException( "Conversion to type ["+paramTypes[0]+"] failed."); setter.invoke(obj, new Object[] { arg }); } catch (IllegalAccessException ex) { throw new PropertySetterException(ex); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof InterruptedException Thread.currentThread().interrupt(); throw new PropertySetterException(ex); } catch (RuntimeException ex) { throw new PropertySetterException(ex);
public void getProperties(PropertyCallback callback, String prefix) { for (int i = 0; i < props.length; i++) { Method getter = props[i].getReadMethod(); if (getter == null) continue; if (!isHandledType(getter.getReturnType())) { //System.err.println("Ignoring " + props[i].getName() +" " + getter.getReturnType()); continue; } String name = props[i].getName(); try { Object result = getter.invoke(obj, NULL_ARG); //System.err.println("PROP " + name +": " + result); if (result != null) { callback.foundProperty(obj, prefix, name, result); } } catch (IllegalAccessException ex) { LogLog.warn("Failed to get value of property " + name); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof InterruptedException || ex.getTargetException() instanceof InterruptedIOException) { Thread.currentThread().interrupt(); } LogLog.warn("Failed to get value of property " + name); } catch (RuntimeException ex) { LogLog.warn("Failed to get value of property " + name); } } }
protected void setParameter(Element elem, PropertySetter propSetter) { String name = subst(elem.getAttribute(NAME_ATTR)); String value = (elem.getAttribute(VALUE_ATTR)); value = subst(OptionConverter.convertSpecialChars(value)); propSetter.setProperty(name, value); }
PropertySetter propSetter = new PropertySetter(instance); NodeList children = element.getChildNodes(); final int length = children.getLength();
public static void main(String[] args) { new PropertyPrinter(new PrintWriter(System.out)); } }
protected PropertyDescriptor getPropertyDescriptor(String name) { if (props == null) introspect(); for (int i = 0; i < props.length; i++) { if (name.equals(props[i].getName())) { return props[i]; } } return null; }
protected void printOptions(PrintWriter out, Object obj, String fullname) { out.println(fullname + "=" + obj.getClass().getName()); PropertyGetter.getProperties(obj, this, fullname + "."); }
public void foundProperty(Object obj, String prefix, String name, Object value) { // XXX: Properties encode value.toString() if (obj instanceof Appender && "name".equals(name)) { return; } if (doCapitalize) { name = capitalize(name); } out.println(prefix + name + "=" + value.toString()); }
/** Check the provided <code>Properties</code> object for a {@link org.apache.log4j.spi.LoggerFactory LoggerFactory} entry specified by {@link #LOGGER_FACTORY_KEY}. If such an entry exists, an attempt is made to create an instance using the default constructor. This instance is used for subsequent Category creations within this configurator. @see #parseCatsAndRenderers */ protected void configureLoggerFactory(Properties props) { String factoryClassName = OptionConverter.findAndSubst(LOGGER_FACTORY_KEY, props); if(factoryClassName != null) { LogLog.debug("Setting category factory to ["+factoryClassName+"]."); loggerFactory = (LoggerFactory) OptionConverter.instantiateByClassName(factoryClassName, LoggerFactory.class, loggerFactory); PropertySetter.setProperties(loggerFactory, props, FACTORY_PREFIX + "."); } }
Logger cat, boolean isRoot) { PropertySetter propSetter = new PropertySetter(cat); propSetter.activate();
/** * Sets a parameter based from configuration file content. * * @param elem param element, may not be null. * @param propSetter property setter, may not be null. * @param props properties * @since 1.2.15 */ public static void setParameter(final Element elem, final PropertySetter propSetter, final Properties props) { String name = subst(elem.getAttribute("name"), props); String value = (elem.getAttribute("value")); value = subst(OptionConverter.convertSpecialChars(value), props); propSetter.setProperty(name, value); }
LogLog.error("Category Factory class " + className + " does not implement org.apache.log4j.LoggerFactory"); PropertySetter propSetter = new PropertySetter(factory);
/** * Prints the configuration of the default log4j hierarchy as a Java * properties file on the specified Writer. * * <p>N.B. print() can be invoked only once! */ public void print(PrintWriter out) { printOptions(out, Logger.getRootLogger()); Enumeration cats = LogManager.getCurrentLoggers(); while (cats.hasMoreElements()) { printOptions(out, (Logger) cats.nextElement()); } }