org.apache.log4j.config
クラス PropertySetter

java.lang.Object
  |
  +--org.apache.log4j.config.PropertySetter

public class PropertySetter
extends Object

General purpose Object property setter. Clients repeatedly invokes setProperty(name,value) in order to invoke setters on the Object specified in the constructor. This class relies on the JavaBeans Introspector to analyze the given Object Class using reflection.

基本的な目的は、オブジェクトのプロパティのセッタとなることです。 クライアントは、コンストラクタで指定したオブジェクトに対し、セッタを起動するためには、繰り返し setProperty(name,value) を実行します。 このクラスは、指定されたオブジェクト・クラスをリフレクション機能を使って解析するという JavaBeans の Introspector を頼りにしています。

Usage:

使用方法:

PropertySetter ps = new PropertySetter(anObject);
ps.set("name", "Joe");
ps.set("age", "32");
ps.set("isMale", "true");
will cause the invocations anObject.setName("Joe"), anObject.setAge(32), and setMale(true) if such methods exist with those signatures. Otherwise an IntrospectionException are thrown.

は、anObject.setName("Joe")やanObject.setAge(32)、setMale(true)のようなシグニチャをもつメソッドがあれば、そのメソッドを起動します。 しかし、そうでなければ、IntrospectionException がスローされます。

導入されたバージョン:
1.1
作成者:
Anders Kristensen

フィールドの概要
protected  Object obj
           
protected  PropertyDescriptor[] props
           
 
コンストラクタの概要
PropertySetter(Object obj)
          Create a new PropertySetter for the specified Object.
 
メソッドの概要
 void activate()
           
protected  Object convertArg(String val, Class type)
          Convert val a String parameter to an object of a given type.
protected  PropertyDescriptor getPropertyDescriptor(String name)
           
protected  void introspect()
          Uses JavaBeans Introspector to computer setters of object to be configured.
static void setProperties(Object obj, Properties properties, String prefix)
          Set the properties of an object passed as a parameter in one go.
 void setProperties(Properties properties, String prefix)
          Set the properites for the object that match the prefix passed as parameter.
 void setProperty(PropertyDescriptor prop, String name, String value)
          Set the named property given a PropertyDescriptor.
 void setProperty(String name, String value)
          Set a property on this PropertySetter's Object.
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

obj

protected Object obj

props

protected PropertyDescriptor[] props
コンストラクタの詳細

PropertySetter

public PropertySetter(Object obj)
Create a new PropertySetter for the specified Object. This is done in prepartion for invoking setProperty(java.lang.String, java.lang.String) one or more times.

指定したオブジェクトに対する新規の PropertySetter を作成します。 このコンストラクタで1回または複数回 {link #setProperty} を実行する準備が完了します。

パラメータ:
obj - the object for which to set properties

obj プロパティの設定対象のオブジェクト

メソッドの詳細

introspect

protected void introspect()
Uses JavaBeans Introspector to computer setters of object to be configured.

指定されたオブジェクトのセッタメソッドを割り出すために JavaBeans の Introspector を使用します。


setProperties

public static void setProperties(Object obj,
                                 Properties properties,
                                 String prefix)
Set the properties of an object passed as a parameter in one go. The properties are parsed relative to a prefix.

パラメタで渡されたオブジェクトのプロパティを一挙に設定します。 properties は、prefix と比較して解析されます。

パラメータ:
obj - The object to configure.

obj 設定対象のオブジェクト

properties - A java.util.Properties containing keys and values.

properties キーと値で構成される java.util.Properties

prefix - Only keys having the specified prefix will be set.

prefix 指定した接頭辞を持つキーだけが設定される


setProperties

public void setProperties(Properties properties,
                          String prefix)
Set the properites for the object that match the prefix passed as parameter.

パラメタとして渡された prefix にマッチするオブジェクトに関するプロパティを設定します。


setProperty

public void setProperty(String name,
                        String value)
Set a property on this PropertySetter's Object. If successful, this method will invoke a setter method on the underlying Object. The setter is the one for the specified property name and the value is determined partly from the setter argument type and partly from the value specified in the call to this method.

この PropertySetter オブジェクト上でプロパティを設定します。 もし上手く行けば、このメソッドは、指定したオブジェクト上のセッタ・メソッドを呼び出します。 指定したプロパティ名と値をもつ1つのメソッドが、このメソッドを呼び出した際に指定したセッタの引数の型および値それぞれの部分から決定されます。

If the setter expects a String no conversion is necessary. If it expects an int, then an attempt is made to convert 'value' to an int using new Integer(value). If the setter expects a boolean, the conversion is by new Boolean(value).

もし、セッタが String を求める場合は、型変換の必要はありません。 もし、int が求められる場合は、'value' を new Integer(value) 使って int 型へ変換する試みが必要です。 もし、セッタが論理値を求める場合は、new Boolean(value) による変換が必要です。

パラメータ:
name - name of the property

name プロパティ名

value - String value of the property

value プロパティの String 値


setProperty

public void setProperty(PropertyDescriptor prop,
                        String name,
                        String value)
                 throws PropertySetterException
Set the named property given a PropertyDescriptor.

PropertyDescriptor を使って、名前指定したプロパティを設定します。

パラメータ:
prop - A PropertyDescriptor describing the characteristics of the property to set.

prop 設定するプロパティの特徴を記述した PropertyDescriptor

name - The named of the property to set.

name 設定するためのプロパティ名

value - The value of the property.

value プロパティの値


convertArg

protected Object convertArg(String val,
                            Class type)
Convert val a String parameter to an object of a given type.

String パラメタ val を指定した型をもつオブジェクトへ変換します。


getPropertyDescriptor

protected PropertyDescriptor getPropertyDescriptor(String name)

activate

public void activate()


Please notify me about new log4j releases.