[ADOS] ADOS Developer's Site - XML Stadium
ADOS Company slogan - XML Total Solution

 RIGHT:[[目次>Hestia Hacks]]|[[前>RJOによるServiceContentの作成]]|[[次>RJOによる添付ファイルの送信]]
 RIGHT:[[目次>Hestia Hacks#SDKDevDuide]]|[[前>RJOによるServiceContentの作成]]|[[次>RJOによる添付ファイルの送信]]
 
 目次
 
 #contents
 
 *概要 [#ca4cba3c]
 
 ServiceContentのノードツリーの参照方法を解説します。XMLの内容を自動的にDBへ出力する場合などに有効です。
 
 サンプルプログラムを以下に示します。
 
 【SampleUtils.java】
  32 :   public static void printServiceContentInformation(ServiceContent sc) {
  33 :     System.out.println("PIP          :" + sc.getPIPID());
  34 :     System.out.println("Ver          :" + sc.getFullVersion());
  35 :     System.out.println("Root         :" + sc.getName());
  36 :     System.out.print("Production   :");
  37 :     if (sc.isProduction())
  38 :       System.out.println("Production");
  39 :     else
  40 :       System.out.println("Test");
  41 :     System.out.println("DOC ID       :" + sc.getDocumentIdentifier());
  42 :     System.out.println("Date         :"
  43 :         + sc.getDocumentGenerationDateTime().getRNDateTime());
  44 :     System.out.println("Sender DUNS  :"
  45 :         + sc.getFromRole().getGlobalBusinessIdentifierNorm());
  46 :     System.out.println("Receiver DUNS:"
  47 :         + sc.getToRole().getGlobalBusinessIdentifierNorm());
  48 : 
  49 :     HashMap map = sc.getElement().getPrefixMap();
  50 :     Iterator it = map.keySet().iterator();
  51 :     while (it.hasNext()) {
  52 :       String uri = (String) it.next();
  53 :       System.out.println(map.get(uri) + " : " + uri);
  54 :     }
  55 : 
  56 :     printComplexElementInformation((ComplexElement) sc.getElement(), "");
  57 :   }
  58 : 
  59 :   public static void printComplexElementInformation(ComplexElement el,
  60 :       String indent) {
  61 :     System.out.println(indent + "C:" + el.getName() + ":"
  62 :         + el.getNamespace() + ":" + el.getClass().getCanonicalName());
  63 : 
  64 :     ElementContentModel model = el.getElementContentModel();
  65 : 
  66 :     printGroupDeclarationInformation(model.getRoot(), indent + INDENT);
  67 : 
  68 :     int att_size = el.getAttributeCount();
  69 :     for (int i = 0; i < att_size; i++) {
  70 :       Attribute att = el.getAttribute(i);
  71 :       System.out.println(indent + INDENT + "A:" + att.getName() + ":"
  72 :           + att.getValue() + ":" + att.getClass().getCanonicalName());
  73 :     }
  74 :     Element[] els = el.getElements();
  75 :     for (int i = 0; i < els.length; i++) {
  76 :       if (els[i] instanceof ComplexElement) {
  77 :         printComplexElementInformation((ComplexElement) els[i], indent
  78 :             + INDENT);
  79 :       } else if (els[i] instanceof SimpleElement) {
  80 :         SimpleElement sel = (SimpleElement) els[i];
  81 :         System.out.println(indent + INDENT + "S:" + sel.getName() + ":"
  82 :             + sel.getText() + ":" + sel.getNamespace() + ":"
  83 :             + sel.getClass().getCanonicalName());
  84 :         System.out.println(indent + INDENT + INDENT + "D:"
  85 :             + sel.getTextModel().toString());
  86 :       } else if (els[i] instanceof TextElement) {
  87 :         TextElement tel = (TextElement) els[i];
  88 :         System.out.println(indent + INDENT + "T:" + tel.getName() + ":"
  89 :             + tel.getText() + ":" + tel.getNamespace() + ":"
  90 :             + tel.getClass().getCanonicalName());
  91 :       }
  92 :     }
  93 :   }
  94 : 
  95 :   public static void printGroupDeclarationInformation(GroupDeclaration group,
  96 :       String indent) {
  97 :     switch (group.getType()) {
  98 :     case GroupDeclaration.GROUP_TYPE_SEQUENCE:
  99 :       System.out.println(indent + "D:SEQUENCE:" + group.getMinOccur()
  100 :           + ".." + group.getMaxOccur());
  101 :       break;
  102 :     case GroupDeclaration.GROUP_TYPE_CHOICE:
  103 :       System.out.println(indent + "D:CHOICE:" + group.getMinOccur()
  104 :           + ".." + group.getMaxOccur());
  105 :       break;
  106 :     }
  107 :     int count = group.getChildCnt();
  108 :     for (int i = 0; i < count; i++) {
  109 :       Object o = group.getChild(i);
  110 :       if (o instanceof ElementDeclaration) {
  111 :         ElementDeclaration decl = (ElementDeclaration) o;
  112 :         System.out.println(indent + INDENT + "D:" + decl.getName()
  113 :             + " : " + decl.getNamespace() + " : "
  114 :             + decl.getMinOccur() + ".." + decl.getMaxOccur());
  115 :       } else if (o instanceof GroupDeclaration) {
  116 :         printGroupDeclarationInformation((GroupDeclaration) o, indent
  117 :             + INDENT);
  118 :       }
  119 :     }
  120 :   }
 
 なお、サンプルのPIPReceiverRJO.javaにおいて、これらのメソッドを利用しています。
 
 *ServiceContentの取得 [#bdd770c0]
 
 受信したServiceContentを取得します。
 
 【PIPReceiverRJO.java】
  54 :           SampleUtils.printServiceContentInformation(request
  55 :               .getServiceContent());
 
 *ServiceContentの参照 [#ae958192]
 
 ServiceContentからPIP名等の基本情報を参照できます。
 
  33 :     System.out.println("PIP          :" + sc.getPIPID());
  34 :     System.out.println("Ver          :" + sc.getFullVersion());
  35 :     System.out.println("Root         :" + sc.getName());
  36 :     System.out.print("Production   :");
  37 :     if (sc.isProduction())
  38 :       System.out.println("Production");
  39 :     else
  40 :       System.out.println("Test");
  41 :     System.out.println("DOC ID       :" + sc.getDocumentIdentifier());
  42 :     System.out.println("Date         :"
  43 :         + sc.getDocumentGenerationDateTime().getRNDateTime());
  44 :     System.out.println("Sender DUNS  :"
  45 :         + sc.getFromRole().getGlobalBusinessIdentifierNorm());
  46 :     System.out.println("Receiver DUNS:"
  47 :         + sc.getToRole().getGlobalBusinessIdentifierNorm());
 
 |関連クラス|機能|h
 |com.ados.hestia.parser.rnbm.particle.ServiceContent|ServiceContentを表すクラス。|
 |com.ados.hestia.parser.rnbm.particle.DateTimeStamp|ServiceContent#getDocumentGenerationDateTimeで取得される、ドキュメント生成時間を表すクラス。|
 |com.ados.hestia.parser.rnbm.particle.PartnerRoleIdentification|ServiceContent#getFromRole/getToRoleで取得される、パートナー情報を表すクラス。|
 |com.ados.hestia.parser.rnbm.particle.PartnerIdentification|PartnerRoleIdentificationの上位クラス。|
 
 ServiceContentに宣言されている名前空間URIおよび接頭辞を参照できます。
 
  49 :     HashMap map = sc.getElement().getPrefixMap();
  50 :     Iterator it = map.keySet().iterator();
  51 :     while (it.hasNext()) {
  52 :       String uri = (String) it.next();
  53 :       System.out.println(map.get(uri) + " : " + uri);
  54 :     }
 
 ServiceContentのルート要素を参照できます。
 
  56 :     printComplexElementInformation((ComplexElement) sc.getElement(), "");
 
 *XMLノードクラスの継承階層 [#ha645875]
 
 RJOでは、具体的なPIPの各要素や属性ごとにクラスが定義されます。たとえば、PIP 3B2に対してはPip3B2AdvanceShipmentNotificationというルート要素のクラスが定義され、BusinessDescription要素に対してはBusinessDescriptionクラスが定義されます。それらのクラスは以下のような抽象クラスを継承しています。
 
  + Abstract(抽象クラス)
      + Element(抽象クラス)
          + ComplexElement(抽象クラス)
              + BusinessDescription
              + ContactInformation
              + ・・・
              + RootElement(抽象クラス)
                  + Pip3B2AdvanceShipmentNotification
                  + Pip4A1StrategicForecastNotification
                  + ・・・
          + SimpleElement(抽象クラス)
              + GlobalBusinessIdentifier
              + FreeFormText
              + ・・・
          + TextElement
      + Attribute(抽象クラス)
 
 |関連クラス|機能|h
 |com.ados.hestia.parser.rnbm.model.RootElement|ServiceContent#getElementで取得される、ルート要素を表す抽象クラス。|
 |com.ados.hestia.parser.rnbm.model.ComplexElement|枝の要素を表す抽象クラス。|
 |com.ados.hestia.parser.rnbm.model.SimpleElement|葉(末端)の要素を表す抽象クラス。|
 |com.ados.hestia.parser.rnbm.model.Attribute|属性を表す抽象クラス。|
 
 
 *ComplexElementの参照 [#v1d48357]
 
 ComplexElementは枝の要素を表します。
 
  61 :     System.out.println(indent + "C:" + el.getName() + ":"
  62 :         + el.getNamespace() + ":" + el.getClass().getCanonicalName());
 
 Attributeを取得することができます。なお、getAttributeはComplexElementの上位クラスであるElementから継承されたメソッドです。
 
  70 :       Attribute att = el.getAttribute(i);
 
 子のElementを取得することができます。なお、getElementsはComplexElementに定義されたメソッドです。
 
  74 :     Element[] els = el.getElements();
 
 ElementContentModel(要素の型定義)を取得することができます。
 
  64 :     ElementContentModel model = el.getElementContentModel();
 
 ElementContentModelは、GroupDeclarationとElementDeclarationが階層的に組み合わされた構造を持ちます。ElementContentModel#getRootにより、その頂点のGroupDeclarationを取得することができます。
 
  66 :     printGroupDeclarationInformation(model.getRoot(), indent + INDENT);
 
 #ref(g05.gif,center)
 
 |関連クラス|機能|h
 |com.ados.hestia.parser.rnbm.model.ElementContentModel|要素内容モデル(型定義)を表すクラス。|
 |com.ados.hestia.parser.rnbm.model.GroupDeclaration|グループ(sequence、choice)を表すクラス。型定義の頂点のグループは、ElementContentModel#getRootで取得される。|
 |com.ados.hestia.parser.rnbm.model.ElementDeclaration|要素宣言を表すクラス。|
 
 *Attributeの参照 [#nbbc07d8]
 
 Attributeは属性を表します。
 
  71 :       System.out.println(indent + INDENT + "A:" + att.getName() + ":"
  72 :           + att.getValue() + ":" + att.getClass().getCanonicalName());
 
 *SimpleElementの参照 [#ac2f8fd8]
 
  80 :         SimpleElement sel = (SimpleElement) els[i];
  81 :         System.out.println(indent + INDENT + "S:" + sel.getName() + ":"
  82 :             + sel.getText() + ":" + sel.getNamespace() + ":"
  83 :             + sel.getClass().getCanonicalName());
  84 :         System.out.println(indent + INDENT + INDENT + "D:"
  85 :             + sel.getTextModel().toString());
 
 //*TextElementの参照 [#h31ed7d6]

トップ   差分 バックアップ リロード   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS

Copyright 2005-2008. ADOS Co., Ltd. All Rights Reserved.