1

BeanIO を使用して、いくつかのカスタム フィールドを含む固定形式のファイルを作成しています。これらのフィールドは同じ基本ハンドラー クラスを使用する必要がありますが、パラメーターが若干異なります。

@Recordデータを格納するカスタムを作成しました。例:

@Record(minOccurs = 0, maxOccurs = -1)
@Fields({
    @Field(name = "recordType", ordinal = 1, length = 2, rid = true, literal = "00")})         
public class CustomField{
    @Field(ordinal = 2, length = 8, padding = '0', align = Align.RIGHT, handlerclass = AmountHandler.class)
    private BigDecimal firstAmount;

    @Field(ordinal = 3, length = 8, padding = '0', align = Align.RIGHT, handlerclass = AmountHandler.class)
    private BigDecimal secondAmount;
}

使用するフィールドに基づいて、handlerclass をカスタマイズしたいと思います。だから私はこのクラスを作成しました:

public class AmountHandler implements ConfigurableTypeHandler{
    private int fraction, length;

    public AmountHandler (int length, int fraction){
        this.length = length;
        this.fraction = fraction;
    }

    @Override
    public TypeHandler newInstance(Properties properties) throws IllegalArgumentException {
        length = Integer.parseInt(properties.getProperty("length"));
        fraction = Integer.parseInt(properties.getProperty("fraction"));
        return new CustomHandler(length, fraction);;
    }
    //parse and format are not yet implemented. 
    @Override
    public Object parse(String text) throws TypeConversionException { return null;}

    @Override
    public String format(Object value) { return null; }

    @Override
    public Class<?> getType() { return BigDecimal.class; }
}

ただし、各フィールドのプロパティを設定する方法が見つからないようです。これどうやってするの?型のプロパティを定義する方法はあります@Fieldか? カスタム パラメーターを使用してオブジェクトのハンドラー クラスを定義するより良い方法はありますか?

4

0 に答える 0