現行の作業域を持つアプリケーションは、プロパティーをその作業域へ挿入したり、 その作業域からプロパティーを取り出したりすることができます。 UserWorkArea インターフェースは、 プロパティーを設定するための 2 つの set メソッドと、プロパティーを取り出すための get メソッドを 備えています。 2 つの引数を取る set メソッドは、標準のプロパティー・モードでプロパティーを挿入します。 3 つの引数を取る set メソッドは、プロパティー・モードを 3 番目の引数として受け取ります。 (このトピックで後述する 『プロパティー・モードの設定』を参照してください。)
どちらの set メソッドも、キーと値を引数として受け取ります。 キーはストリングで、値は java.io.Serializable 型のオブジェクトです。 どちらの場合も、引数はヌルであってはなりません。 ヌルの場合は、java.lang.NullPointer 例外が発生します。
例: SimpleSample アプリケーションにおける作業域の使用 では、 プロパティーの値として、SimpleSampleCompany クラスと SimpleSampleProperty クラスの 2 つのクラスのオブジェクトを使用しています。SimpleSampleCompany クラスはサイト ID に使用され、 SimpleSamplePriority クラスはプロパティーに使用されます。次のコード例には、これらのクラスが示されています。
public class SimpleSampleServlet { ... userWorkArea.begin("SimpleSampleServlet"); try { // Set the site-identifier (default is Main). userWorkArea.set("company", SimpleSampleCompany.Main, PropertyModeType.read_only); // Set the priority. userWorkArea.set("priority", SimpleSamplePriority.Silver); } catch (PropertyReadOnly e) { // The company was previously set with the read-only or // fixed read-only mode. ... } catch (NotOriginator e) { // The work area originated in another process, // so it can't be modified here. ... } catch (NoWorkArea e) { // There is no work area begun on this thread. ... } // Do application work. ... }
get メソッドはキーを引数として受け取り、Java Serializable オブジェクトを そのキーに関連付けられている値として戻します。 例えば、作業域から company キーの値を 取り出すために、上のコード例では作業域の get メソッドを使用して値を取り出しています。
作業域について詳しくは、API 文書の『com.ibm.websphere.workarea パッケージ』を参照してください。生成済み API 文書は、インフォメーション・センターの目次で、 「参照」 > 「Developer」 > 「API documentation」 > 「Application programming interfaces」の順にたどって入手できます。