[ADOS] ADOS Developer's Site - XML Stadium
ADOS Company slogan - XML Total Solution
RIGHT:[[目次>Hestia Hacks]]|[[前>RJOによるServiceContentの作成]]|[[次>RJOによる添付ファイルの送信]]

目次

#contents

*概要 [#ca4cba3c]


【PIPReceiverRJO.java】
 1 : import java.io.FileInputStream;
 2 : import java.util.Properties;
 3 : 
 4 : import com.ados.hestia.parser.rnbm.exchange.Container;
 5 : import com.ados.hestia.parser.rnbm.exchange.PayloadContainer;
 6 : import com.ados.hestia.parser.rnbm.exchange.StatusContainer;
 7 : import com.ados.hestia.sdk.Configuration;
 8 : import com.ados.hestia.sdk.Connection;
 9 : import com.ados.hestia.sdk.message.DirectMessageExchanger;
 10 : import com.ados.hestia.sdk.session.RespondSession;
 11 : import com.ados.hestia.sdk.session.Session;
 12 : 
 13 : public class PIPReceiverRJO {
 14 : 
 15 :   public static void main(String[] args) {
 16 :     try {
 17 :       Properties prop = new Properties();
 18 :       prop.load(new FileInputStream("sample.properties"));
 19 :       String HOST = prop.getProperty("HOST");
 20 :       String USER = prop.getProperty("USER");
 21 :       String PASS = prop.getProperty("PASS");
 22 :       String HANDLER_ID = prop.getProperty("HANDLER_ID");
 23 : 
 24 :       Connection connection = new Connection(HOST, USER, PASS,
 25 :           Connection.EXCHANGE_MODE_DIRECT, null, null, null,
 26 :           HANDLER_ID);
 27 :       DirectMessageExchanger exchanger = new DirectMessageExchanger(
 28 :           connection, Configuration.getInstance());
 29 : 
 30 :       int time = 0;
 31 :       boolean loop = true;
 32 :       while (loop) {
 33 :         Thread.sleep(5000);
 34 :         SampleUtils.println("loop : " + time++);
 35 :         exchanger.hit();
 36 : 
 37 :         Container container = exchanger.receiveMessage();
 38 :         if (container != null) {
 39 :           SampleUtils.printContainerInformation(container);
 40 :           PayloadContainer request = (PayloadContainer) container;
 41 :           SampleUtils.printServiceContent(request.getServiceContent());
 42 :           Session session = new RespondSession(request
 43 :               .getRemotePartner(), request.getPIPID());
 44 :           SampleUtils.printSessionState("created", session);
 45 :           session.pushMessage(request);
 46 :           SampleUtils.printSessionState("pushed", session);
 47 :           session.acceptPartnerMessage();
 48 :           SampleUtils.printSessionState("accepted", session);
 49 :           StatusContainer status = session.getStatusToSend();
 50 :           SampleUtils.printSessionState("sent status", session);
 51 :           SampleUtils.printContainerInformation(status);
 52 :           exchanger.sendMessage(status);
 53 :           exchanger.hit();
 54 :           SampleUtils.printServiceContentInformation(request
 55 :               .getServiceContent());
 56 :           loop = false;
 57 :         }
 58 :       }
 59 : 
 60 :     } catch (Exception e) {
 61 :       e.printStackTrace();
 62 :     }
 63 :   }
 64 : 
 65 : }

【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 :   }


*基本情報の参照 [#ae958192]

System.out.println("PIP          :"+sc.getPIPID());
System.out.println("Ver          :"+sc.getFullVersion());
System.out.println("Root         :"+sc.getName());
System.out.print("Production   :"); if(sc.isProduction())System.out.println("Production");else System.out.println("Test");
System.out.println("DOC ID       :"+sc.getDocumentIdentifier());
System.out.println("Date         :"+sc.getDocumentGenerationDateTime().getRNDateTime());
System.out.println("Sender DUNS  :"+sc.getFromRole().getGlobalBusinessIdentifierNorm());
System.out.println("Receiver DUNS:"+sc.getToRole().getGlobalBusinessIdentifierNorm());

*名前空間URI、接頭辞の参照 [#j37e5db7]

HashMap map = sc.getElement().getPrefixMap();
Iterator it = map.keySet().iterator();
while (it.hasNext()) {
	String uri = (String)it.next();
	System.out.println(map.get(uri)+" : "+uri);
}

トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS

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