プラグ可能な名前ハンドラーの指定

デフォルトのビジネス・オブジェクト解決を使用すると、SOAP メッセージからビジネス・オブジェクトへの変換で使用されるビジネス・オブジェクトを判別するために、プラグ可能な名前ハンドラーを指定することができます。これは、MO_DataHandler_DefaultSOAPConfig 属性を変更することによって行います。

例えば、MO_DataHandler_DefaultSOAPConfig には string 型の属性が 2 つあり、以下を指定します。

SOAPNameHandler 属性に値が指定されている場合、SOAP データ・ハンドラー は、指定された名前ハンドラーを呼び出します。この値が存在しない場合、または指定された名前ハンドラーがビジネス・オブジェクト名を 入手できなかった場合には、デフォルトのビジネス・オブジェクト解決を行う ために、SOAP データ・ハンドラーがデフォルトで呼び出されます。

SOAP DataHandler は MO に指定されている SOAPNameHandler プロパティーを使用して、custom-name-handler クラスのインスタンスを生成します。次に、getBOName を呼び出して、ビジネス・オブジェクト名を解決します。SOAP DataHanlder は、コネクターから受け取った SOAPProperty オブジェクトを custom-name-handler インプリメンテーション・クラスに渡します。

この SOAPProperty オブジェクトには、解決に使用する潜在的な候補ビジネス・オブジェクトの構造化されたリストが含まれています。このリストには、BodyName、 BodyNamespace、および BOName トリプレットが含まれています。これらのトリプレットは、SOAP 構成 MO の構成情報に基づいています。デフォルトの名前ハンドラーは、このオブジェクトを使用してビジネス・オブジェクトを解決します。カスタム名前ハンドラー開発者は、自分自身の判断でこのオブジェクトを使用できます。

SOAPProperty オブジェクトの使用

SOAPPropertyUtils クラスを使用して、SOAPProperty からビジネス・オブジェクト名を取り出すことができます。このためには、次のメソッドを使用します。

/**
  * Retrieve the business object name based on the body name and the body
 * namespace
 *.
 * @param soapProp top level SOAPProperty object that is passed by the
 * connector
 * @param name body name from the SOAP message
 * @param uri body namespace from the SOAP message
 * @return business object name from the SOAPProperty object with the body
 * name and body namespace.
 */
 java.lang.String findBOName(SOAPProperty soapProp, String name, String uri);

NameHandler のサンプル

NameHandler:package のサンプルを以下に示します。

com.ibm.adapters.datahandlers.soap.namehandlers;
 // DOM and Parsers
 import javax.xml.parsers.DocumentBuilder;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.InputSource;
 // Apache SOAP
 import org.apache.soap.Envelope;
 import org.apache.soap.Header;
 import org.apache.soap.Body;
 import org.apache.soap.Constants;
 import org.apache.soap.util.xml.DOMUtils;
 import org.apache.soap.util.xml.XMLParserUtils;
 import org.apache.soap.util.xml.QName;
 import org.apache.soap.encoding.soapenc.SoapEncUtils;
 import org.apache.soap.encoding.soapenc.Base64;
 // java
 import java.util.Vector;
 // SOAP data handler
 import com.ibm.adapters.datahandlers.soap.*;
 import com.ibm.adapters.datahandlers.soap.exceptions.*;
 public class MyCustomNameHandler extends SOAPNameHandler {
   private static final String BOPREFIX = "MyCustomBOPrefix";
   private static final char UNDERSCORE = '_';
   private static final char EMPTY_STRING = "";
 
   public String getBOName(Envelope msgEnv, SOAPProperty prop)
     throws SOAPNameHandlerException
   {
     // Initialize a String Buffer
     StringBuffer boName = new StringBuffer();
     // Determine the "MyCustomBOPrefix" SOAP data handler
     // MO property. If it exists, and is populated append
     // this prefix to the front of the BOName.
     String pref = dh.getOption(BOPREFIX);
     if (pref != null) {
        boName.append(pref.equals(EMPTY_STRING)
        ? EMPTY_STRING : pref + UNDERSCORE);
   }
     // Begin parsing the SOAP msg envelope.
     Element bodyEl, requestEl;
     Body msgBody = msgEnv.getBody();
     Vector bodyEntries = msgBody.getBodyEntries();
     if((bodyEntries == null) || (bodyEntries.size() <= 0))
        throw new SOAPNameHandlerException("No Body Entries exist
         for this SOAP message. Cannot determine BOName to use.");
     // Grab the first <SOAP-ENV:Body> Element
     bodyEl = (Element) bodyEntries.elementAt(0);
     // Grab the first Child Element of the <SOAP-ENV:Body>
     // Element
     requestEl = (Element) DOMUtils.getFirstChildElement(bodyEl);
     // Read the name and namespace of this first child
     String name = bodyEl.getLocalName();
     String uri = bodyEl.getNamespaceURI();
     if (uri == null)
        uri = Constants.NS_URI_SOAP_ENV;
     // Use the SOAPPropertyUtils findBOName() method to search
     // the SOAPProperty object for this messages first element
     // name and namespace. If no match is found, a
     // SOAPDataHandlerException will be thrown. If a match is 
     // found, and it's not an empty string, append to the boname.
 String returnedBOName = SOAPPropertyUtils.findBOName(prop, name, uri);
 if (returnedBOName != null &&
        !returnedBOName.equals(EMPTY_STRING))
   boName.append(returnedBOName);
        return boName.toString()
    }
 }

Copyright IBM Corp. 2004, 2005