2 * typical object information
4 * License : The MIT License
5 * Copyright(c) 2011 MikuToga Partners
8 package jp.sourceforge.mikutoga.typical;
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.util.ArrayList;
13 import java.util.Collections;
14 import java.util.Comparator;
15 import java.util.LinkedList;
16 import java.util.List;
17 import javax.xml.parsers.DocumentBuilder;
18 import javax.xml.parsers.DocumentBuilderFactory;
19 import javax.xml.parsers.ParserConfigurationException;
20 import org.w3c.dom.Document;
21 import org.w3c.dom.Element;
22 import org.xml.sax.SAXException;
26 * <p>国産モデルではプライマリ名に日本語名が収められることが多い。
27 * プライマリ名は必ず一つ以上なければならない。
28 * <p>国産モデルではグローバル名に英語名が収められることが多いが、
29 * プライマリ名と同一の日本語名が収められている場合も多い。
33 /** オーダ番号によるコンパレータ。 */
34 public static final Comparator<TypicalObject> ORDER_COMPARATOR =
35 new OrderComparator();
37 protected final List<String> primaryList;
38 protected final List<String> globalList;
40 protected final List<String> umodPrimaryList;
41 protected final List<String> umodGlobalList;
43 protected int orderNo;
48 * <p>各初期数が0以下の場合は、状況に応じて伸長する連結リストが用意される。
49 * @param primaryNo プライマリ名初期数。
50 * @param globalNo グローバル名初期数。
52 protected TypicalObject(int primaryNo, int globalNo){
56 this.primaryList = new LinkedList<String>();
58 this.primaryList = new ArrayList<String>(primaryNo);
62 this.globalList = new LinkedList<String>();
64 this.globalList = new ArrayList<String>(globalNo);
67 this.umodPrimaryList =
68 Collections.unmodifiableList(this.primaryList);
70 Collections.unmodifiableList(this.globalList);
77 * <p>プライマリ名、グローバル名共、状況に応じて伸長する連結リストが用意される。
79 protected TypicalObject(){
89 * @throws ParserConfigurationException XMLの構成が変
90 * @throws SAXException XMLの内容が変
91 * @throws IOException 入力エラー
93 protected static Element loadXml(InputStream is)
94 throws ParserConfigurationException, SAXException, IOException {
95 DocumentBuilderFactory factory;
96 factory = DocumentBuilderFactory.newInstance();
97 factory.setNamespaceAware(true);
99 DocumentBuilder builder = factory.newDocumentBuilder();
100 Document doc = builder.parse(is);
102 Element top = doc.getDocumentElement();
112 public String getTopPrimaryName(){
113 String result = this.primaryList.get(0);
119 * @return 最初のグローバル名。ひとつもなければnull
121 public String getTopGlobalName(){
123 if(this.globalList.isEmpty()) result = null;
124 else result = this.globalList.get(0);
130 * @return 全プライマリ名リスト。(不可変)
132 public List<String> getPrimaryList(){
133 return this.umodPrimaryList;
138 * @return 全グローバル名リスト。(不可変)
140 public List<String> getGlobalList(){
141 return this.umodGlobalList;
147 private static class OrderComparator
148 implements Comparator<TypicalObject> {
153 private OrderComparator(){
160 * @param o1 {@inheritDoc}
161 * @param o2 {@inheritDoc}
162 * @return {@inheritDoc}
165 public int compare(TypicalObject o1, TypicalObject o2){
166 int result = o1.orderNo - o2.orderNo;