WEB アプリケーション用に LOTUS DOMINO をプログラミングする


例:Web サービスデータの説明
例 1:列挙
この例では、String 型のメンバーから構成される野菜の列挙を示します。WSDL 生成で列挙を検出し、正しく表すため、実装にはすべての識別特性 (例では太字) が存在していることが必要です。

WSDL


LotusScript の列挙パターン
[Declarations]
'member value constants:
Const VegetableType_carrot$ = "Carrot"
'constant name prefix matches enum class name
Const VegetableType_lettuce$ = "Lettuce"
Const VegetableType_ketchup$ = "Ketchup"

'member instances:
Dim Carrot_VegetableType As VegetableType
'instance name suffix matches enum class name
Dim Lettuce_VegetableType As VegetableType
Dim Ketchup_VegetableType As VegetableType

'LotusScript list of members:
Dim Enum_VegetableType List As VegetableType
' prefix "Enum_" includes a trailing underscore

'enumeration class:
Class VegetableType
'class name matches list name suffix and list type
Public Value As String 'first public property;
'type matches constants type above
Sub NEW
End Sub
'initializer:
Sub Initialize (elem As String)
Let Value = elem
Set Enum_VegetableType(Cstr(Value)) = Me
End Sub
'optional helper functions
Function Equals (you As VegetableType) As Boolean_
Function ToString As String_
End Class

[global Sub's]
'initialization (called from Sub NEW of the PortType class)
Sub VegetableType_Initialize
Set Carrot_VegetableType = New VegetableType
Call Carrot_VegetableType.Initialize(VegetableType_Carrot)
Set Lettuce_VegetableType = New VegetableType
Call Lettuce_VegetableType.Initialize(VegetableType_Lettuce)
Set Ketchup_VegetableType = New VegetableType
Call Ketchup_VegetableType.Initialize(VegetableType_Ketchup)
End Sub

'optional helper functions
Function VegetableType_FromValue (value As String) As VegetableType_
Public Function VegetableType_FromString (value As String) As VegetableType_

Java 列挙パターン
public class VegetableType {
private java.lang.String _value_;
private static java.util.HashMap _table_ = new java.util.HashMap();


public boolean equals(java.lang.Object obj) {return (obj == this);}
public int hashCode() { return toString().hashCode();}
}

例 2:障害
この例は、サービスメソッドの障害処理が明示的および暗黙的障害のどちらに対しても同じように行われることを示します。

LotusScript の障害 (明示的)
Class FaultServicePortType

Function getStockQuote( tickerSymbol As String,
Fault1
As InvalidSymbolFaultMessage ) As Single


' WS_FAULT base class properties
Call Fault1.setFault(True) ' required for fault activation
Call Fault1.setFaultString("getQuote InvalidTickerFaultMessage")
' optional fault message

' fault subclass properties
Let Fault1.TickerSymbol = tickerSymbol
Let Fault1.ApplicationCode = "12345"

End Function

End Class

LotusScript の障害 (暗黙的)
Function getStockQuote( tickerSymbol As String, Fault1 As WS_FAULT ) As Single
_
' WS_FAULT base class properties
Call Fault1.setFault(True) ' required for fault activation
Call Fault1.setFaultString("getQuote InvalidTickerFaultMessage")
'optional fault message
End Function

メモ LotusScript サービス実装メソッドの障害はメソッド引数の最後に置く必要があります (WS_FAULT 基本クラスまたはそのサブクラス)。

Java の障害 (明示的)
public class FaultServicePortType {

public float getStockQuote( java.lang.String tickerSymbol )
throws
InvalidSymbolFaultMessage
{
_
throw new InvalidSymbolFaultMessage( tickerSymbol, 12345 );
}
}

Java の障害 (暗黙的)
public float getStockQuote( java.lang.String tickerSymbol ) throws lotus.domino.types.Fault {
_
java.lang.Exception e = new java.lang.Exception("Thrown exception");
throw lotus.domino.types.Fault.makFault(e); // static factory method
}

または、さらに簡単にできます。

public float getStockQuote( java.lang.String tickerSymbol ) throws java.lang.Exception {
_
throw new java.lang.Exception("Thrown exception");
}

メモ Java サービス実装メソッドの障害は、メソッドの従来の Java throws 節に現れます。

例 3:リスト
この例では、3 つの項目 Carrot、Lettuce、Ketchup (ニンジン、レタス、ケチャップ) から構成される野菜のリストを示します。

WSDL


LotusScript のリストパターン
Class ListOfVegetables As XSD_LIST 'list base class
Public value()
As String 'one public array property;
'array type maps to a SimpleType

'mandatory helper member and methods for de/serialization:
Private initialized As Boolean
Sub setListValueFromString (idx As Integer, value As String)
If idx < 0 Then Error ErrArgOutOfRange
If Not initialized Then
Redim Me.value(0 To idx)
Let initialized = True
Else
If idx > Ubound(Me.value) Then Redim Preserve Me.value(0 To idx)
End If
Let Me.value(idx) = Cstr(value)
'cast must produce a value( ) array element type
End Sub

Function getListValueAsString (idx As Integer) As String
If Not initialized Then Error ErrArgOutOfRange
getListValueAsString = Cstr(value(idx))
End Function

Function getListLength () As Integer
If Not initialized Then
getListLength = 0
Else
getListLength = Ubound(value)+1
End If
End Function

End Class

メモ 「public value( )」配列メンバー型が LotusScript の組み込み型ではなくマップされた単純型クラスである場合、それに従って一部のパターンステートメントが変化します。たとえば、配列メンバー型が XSD_NCNAME である場合、Sub setListValueFromString の最後のステートメントは

Let Me.value(idx) = Cstr(value)

から次の 2 つのステートメントに置き換えられます。

Set Me.value(idx) = New XSD_NCNAME '単純型クラスのインスタンスを作成します。

Call Me.value(idx).setValueFromString(value)

同様に、Sub getListValueAsString の最後のステートメントは次のステートメントに置き換わります。

getListValueAsString = value(idx).getValueAsString

Java のリストパターン
public class ListOfVegetabless implements lotus.domino.types.SimpleType {
// SimpleType interface
private java.lang.String[] value; // private instance member, array,
// named "value"
// array type maps to a simple type
// default constructor
public ListOfWords()
{
}
// constructor that accepts the private array member
public ListOfWords(java.lang.String[] value)
{
this.value = value;
}
// simple type String constructor
public ListOfWords(java.lang.String value)
{
StringTokenizer st = new StringTokenizer(value, "\r\n\t ");
this.value = new java.lang.String[st.countTokens()];
for(int i = 0; st.hasMoreTokens(); i++) {
this.value[i] = new java.lang.String(st.nextToken());
}
}
// simple type toString method for serializing the array value
public java.lang.String toString()
{
if (value == null)
return null;
String ret = new String();
for (int i = 0; i < value.length; i++) {
ret += value[i].toString();
if ((i+i) < value.length)
ret += " ";
}
return ret;
}
// public getter method for private array member
public java.lang.String[] getValue()
{
return value;
}
// public setter method for private array member
public void setValue(java.lang.String[] value)
{
this.value = value;
}
// optional helper methods
public synchronized boolean equals(java.lang.Object obj) {_}
public synchronized int hashCode() {_}
}