1 package jp.ac.aiit.xdf.core.tags;
3 import java.util.HashMap;
4 import java.util.Locale;
7 import javax.xml.bind.JAXBContext;
8 import javax.xml.bind.JAXBException;
9 import javax.xml.bind.Unmarshaller;
11 import jp.ac.aiit.xdf.core.exceptions.UnexpectedBehaviorException;
12 import jp.ac.aiit.xdf.core.tags.Tagdef.Tag;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
19 * XDFフレームワークのタブの構造定義(Tagdef)を従って定義ファイルの取り込み機能を提供する、
20 * loadメソッドを実施後、Tagdefに定義されたすべてのタグ定義(tag)をマップとして返し、
21 * そのマップのキーはタグ定義のタブ名とする。
26 * モデルクラス :<modelclass >value:モデルクラス
27 * マッパークラス:<component-mapper env:ツールキット定義 class:マッパークラス>
29 * <tag name="xdf-window">
30 * <modelclass>jp.ac.aiit.xdf.core.model.DefaultObjectModel</modelclass>
31 * <component-mapper env="common" class="jp.ac.aiit.xdf.component.common.mappers.DoNothingComponentMapper" />
36 public class TagLoader {
37 private static final Logger log = LoggerFactory.getLogger(TagLoader.class);
41 * @param file タグ定義ファイル
44 public Map<String, Tag> load(File file) {
47 JAXBContext context = JAXBContext.newInstance(Tagdef.class);
48 Unmarshaller um = context.createUnmarshaller();
50 Tagdef tagdef = (Tagdef) um.unmarshal(file);
52 Map<String, Tag> tagMap = new HashMap<String, Tag>();
54 for (Tagdef.Tag tag : tagdef.getTag()){
56 if (checkClassNameExist(tag.getModelclass())){
58 if (!tagMap.containsKey(tag.getName().toLowerCase(Locale.ENGLISH))){
59 boolean mappingclassexist = true;
61 for (Tagdef.Tag.ComponentMapper componentmapper: tag.getComponentMapper()){
62 if (!checkClassNameExist(componentmapper.getClazz())){
63 mappingclassexist = false;
64 log.warn("指定されたクラスが存在しません:"+componentmapper.getClazz());
67 if (mappingclassexist) {
68 tagMap.put(tag.getName().toLowerCase(Locale.ENGLISH), tag);
72 log.warn("タグ名の定義が重複しています:"+tag.getName());
75 log.warn("指定されたクラスが存在しません:"+tag.getModelclass());
80 } catch(JAXBException e) {
81 log.error("JAXBを使用できません");
82 throw new UnexpectedBehaviorException("JAXBを使用できません", e);
86 // タブ定義のクラス名は存在しているかどうか
87 private boolean checkClassNameExist(String clazz) {
90 } catch (ClassNotFoundException e){