ページの先頭行へ戻る
Interstage Business Application Server オープンJavaフレームワークユーザーズガイド
FUJITSU Software

3.1.14 Object/XMLマッピング連携

JAXBと連携してJavaオブジェクトとXMLのマッピングをすることができます。

Marshaller, Unmarshallerという2つのインタフェースを使用して変換を行います。

Javaソース
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;
・・・
public class Application {
	private static final String FILE_NAME = "settings.xml";
	private Settings settings = new Settings();
	private Marshaller marshaller;
	private Unmarshaller unmarshaller;
・・・
	public void loadSettings() throws IOException {
		FileInputStream is = null;
		try {
			is = new FileInputStream(FILE_NAME);
			this.settings = (Settings) this.unmarshaller.unmarshal(new StreamSource(is));
		} finally {
			if (is != null) {
				is.close();
			}
		}
	}
・・・
}
bean定義
<oxm:jaxb2-marshaller id="jaxb2marshaller" contextPath="foo.bar.schema"/>
<bean id="application" class="Application">
	<property name="marshaller" ref="jaxb2marshaller" />
	<property name="unmarshaller" ref="jaxb2marshaller" />
</bean>