public class XmlBuilder extends Object
AnnotationMappingInfo)を組み立てるためのヘルパークラス。
// static import をすると使いやすくなります。
import static com.gh.mygreen.xlsmapper.xml.XmlBuilder.*;
public void sample() {
AnnotationMappingInfo annotationMapping = createXml()
.classInfo(createClass(SimpleSheet.class)
.annotation(createAnnotationBuilder(XlsSheet.class) // クラスに対するアノテーションの定義
.attribute("name", "単純なシート")
.buildAnnotation())
.field(createField("sheetName") // フィールドに対するアノテーションの定義
.annotation(createAnnotation(XlsSheetName.class)
.buildAnnotation())
.buildField())
.field(createField("name")
.annotation(createAnnotation(XlsLabelledCell.class)
.attribute("label", "名称")
.attribute("type", LabelledCellType.Right)
.buildAnnotation())
.annotation(createAnnotation(XlsTrim.class)
.buildAnnotation())
.annotation(createAnnotation(XlsDefaultValue.class)
.attribute("value", "ー")
.buildAnnotation())
.buildField())
.method(createMethod("setRecords") // メソッドに対するアノテーションの定義
.annotation(createAnnotation(XlsHorizontalRecords.class)
.attribute("tableLabel", "名簿一覧")
.attribute("terminal", RecordTerminal.Border)
.buildAnnotation())
.buildMethod())
.buildClass())
.buildXml();
// ファイルへの保存
XmlIO.save(annotationMapping, new File("anno_simple.xml"), "UTF-8");
// システム設定へ渡す。
XlsMapper xlsMapper = new XlsMapper();
xlsMapper.getConfiguration.setAnnotationMapping(annotaionMapping);
}
| コンストラクタと説明 |
|---|
XmlBuilder() |
| 修飾子とタイプ | メソッドと説明 |
|---|---|
static AnnotationInfo.Builder |
createAnnotation(Class<? extends Annotation> clazz)
AnnotationInfoのビルダクラスのAnnotationInfo.Builderインスタンスを作成する。 |
static ClassInfo.Builder |
createClass(Class<?> clazz)
ClassInfoのビルダクラスのClassInfo.Builderインスタンスを作成する。 |
static FieldInfo.Builder |
createField(String fieldName)
FieldInfoのビルダクラスのFieldInfo.Builderインスタンスを作成する。 |
static MethodInfo.Builder |
createMethod(String methodName)
MethodInfoのビルダクラスのMethodInfo.Builderインスタンスを作成する。 |
static AnnotationMappingInfo.Builder |
createXml()
AnnotationMappingInfoのビルダクラスのAnnotationMappingInfo.Builderインスタンスを作成する。 |
static OgnlValueFormatter |
getValueFormatter()
JavaオブジェクトをOGNL式に変換するためのクラスを取得する。
|
static void |
setValueFormatter(OgnlValueFormatter valueFormatter)
JavaオブジェクトをOGNL式に変換するためのクラスを設定する。
|
public static AnnotationMappingInfo.Builder createXml()
AnnotationMappingInfoのビルダクラスのAnnotationMappingInfo.Builderインスタンスを作成する。public static ClassInfo.Builder createClass(Class<?> clazz)
ClassInfoのビルダクラスのClassInfo.Builderインスタンスを作成する。clazz - マッピング対象のJavaのクラス情報。public static MethodInfo.Builder createMethod(String methodName)
MethodInfoのビルダクラスのMethodInfo.Builderインスタンスを作成する。methodName - メソッド名public static FieldInfo.Builder createField(String fieldName)
FieldInfoのビルダクラスのFieldInfo.Builderインスタンスを作成する。fieldName - フィールド名public static AnnotationInfo.Builder createAnnotation(Class<? extends Annotation> clazz)
AnnotationInfoのビルダクラスのAnnotationInfo.Builderインスタンスを作成する。
JavaオブジェクトをOGNL式に変換するクラスOgnlValueFormatterはデフォルトの物が使用される。
独自のものを設定したい場合は、setValueFormatter(OgnlValueFormatter)を予め呼び変更しておく必要がある。
clazz - アノテーションのクラスpublic static OgnlValueFormatter getValueFormatter()
public static void setValueFormatter(OgnlValueFormatter valueFormatter)
valueFormatter - Copyright © 2025 mygreen. All rights reserved.