2 * Sax 2 Xsd-types converter
4 * License : The MIT License
5 * Copyright(c) 2013 MikuToga Partners
8 package jp.sfjp.mikutoga.vmd.model.xml;
10 import javax.xml.bind.DatatypeConverter;
11 import org.xml.sax.Attributes;
14 * XSD各種型のSAX属性値をJavaプリミティブ型へ変換する。
16 final class SaxXsdUtil {
23 throw new AssertionError();
28 * xsd:string型属性値の読み込み。
31 * @return 属性値。該当する属性が無ければnull。
33 static String getStringAttr(Attributes attr, String name){
34 String attrVal = attr.getValue(name);
39 * xsd:boolean型属性値の読み込み。
43 * @throws IllegalArgumentException boolean型表記ではない
45 static boolean getBooleanAttr(Attributes attr, String name)
46 throws IllegalArgumentException{
47 String attrVal = attr.getValue(name);
49 bVal = DatatypeConverter.parseBoolean(attrVal);
54 * xsd:boolean型属性値の読み込み。
57 * @param def 属性が無い場合のデフォルト値
59 * @throws IllegalArgumentException boolean型表記ではない
61 static boolean getBooleanAttr(Attributes attr, String name, boolean def)
62 throws IllegalArgumentException{
63 String attrVal = attr.getValue(name);
64 if(attrVal == null) return def;
67 bVal = DatatypeConverter.parseBoolean(attrVal);
77 * @throws NumberFormatException byte型表記ではない
79 static byte getByteAttr(Attributes attr, String name)
80 throws NumberFormatException{
81 String attrVal = attr.getValue(name);
83 bVal = DatatypeConverter.parseByte(attrVal);
92 * @throws NumberFormatException float型表記ではない
94 static float getFloatAttr(Attributes attr, String name)
95 throws NumberFormatException {
96 String attrVal = attr.getValue(name);
98 fVal = DatatypeConverter.parseFloat(attrVal);
107 * @throws NumberFormatException int型表記ではない
109 static int getIntAttr(Attributes attr, String name)
110 throws NumberFormatException {
111 String attrVal = attr.getValue(name);
113 iVal = DatatypeConverter.parseInt(attrVal);