# KKW02301SF01DBean

## Purpose

`KKW02301SF01DBean` is a **display bean** (data transfer object) for the service change/screen that handles modification, reservation, and cancellation of telecommunications services. It acts as the data carrier between a JSP view layer (`KKW023010PJP.jsp`) and the business logic layer, holding field values, UI state (enabled/disabled, validation state), and update flags for roughly 30 screen items related to service contracts, pricing, dates, and options. It implements framework interfaces (`X33VDataTypeBeanInterface`, `X33VListedBeanInterface`) that enable reflective, key-driven data binding -- the JSP and framework can read and write any field by Japanese-string key and sub-key without needing to call specific getters/setters.

## Design

This class follows the **Bean / Data Transfer Object (DTO)** pattern commonly used in the X33/X31 web framework. Its responsibilities are:

1. **Hold field state** -- Each screen item has a canonical value field (`_*_value`), an update flag (`_*_update`), a state flag (`_*_state`), and some have an `_*_enabled` boolean (controls UI read-only vs. editable).
2. **Provide reflective data binding** via three methods: `loadModelData()` (get), `storeModelData()` (set), and `typeModelData()` (type info). These methods map a Japanese display-key + sub-key (`"value"`, `"state"`, `"enable"`) to the corresponding getter/setter pair -- enabling the framework to bind form submissions and initial page loads without knowing field names at compile time.
3. **Provide an item list** via `listKoumokuIds()` -- returns all supported item keys as a static method, enabling the framework to enumerate and iterate over displayable fields.
4. **Carry an `index`** field -- likely used to identify a particular row in a repeated/scrolling table.

### Naming conventions in fields

All 30+ fields follow a consistent pattern:

| Suffix | Type | Purpose |
|--------|------|---------|
| `_*_value` | `String` (or `Boolean` for `enabled`) | The actual data value |
| `_*_update` | `String` | Update flag, set by the framework after a form submission to indicate whether this field was submitted by the user |
| `_*_state` | `String` | Validation/state flag (e.g., OK, error, required) |
| `_*_enabled` | `Boolean` | Whether the field is UI-enabled (default `false`) |

This pattern enables the framework to:
- Check `_update` flags to decide which fields to process during form submission.
- Check `_state` for per-field validation messages.
- Use `enabled` to control read-only vs. editable UI.

### Interfaces

- **`X33VDataTypeBeanInterface`** -- Requires `loadModelData(String key, String subkey)`, `storeModelData(...)`, and `typeModelData(String key, String subkey)`. This is the core reflective binding contract.
- **`X33VListedBeanInterface`** -- Requires `listKoumokuIds()`. Provides the list of item keys.
- **`Serializable`** -- Enables the bean to be passed across sessions or between tiers.

## Key Methods

### Constructor

```java
public KKW02301SF01DBean()
```

Default no-arg constructor. Performs no special initialization; `value` fields default to `""` at the declaration site. There is an empty constant block generation comment, suggesting a framework code generator produced this skeleton.

### Reflective Data Binding (the most important methods)

These three methods form the core of the framework's data binding protocol.

#### `loadModelData(String key, String subkey) -> Object`

Retrieves a field's value reflectively. The `key` parameter is a Japanese display label (e.g., `"オプションサービス契約番号"`) and `subkey` is one of `"value"`, `"state"`, or `"enable"`.

- Returns the appropriate getter's result based on the key/subkey combination.
- Returns `null` if key or subkey is `null`, or if no matching field exists.
- For boolean-enabled fields, returns a `Boolean`; for all others, returns a `String`.

This is used by the framework to **populate the bean** from database results or initial data before rendering the page.

#### `storeModelData(...)` (4 overloads)

Sets a field's value reflectively. There are four overloaded variants:

1. `storeModelData(String gamenId, String key, String subkey, Object in_value)` -- Takes a screen ID parameter (unused, forwarded to #2). The `gamenId` suggests the framework supports multiple screens within one bean, though this class only handles one.
2. `storeModelData(String key, String subkey, Object in_value)` -- Delegates to #4 with `isSetAsString = false`.
3. `storeModelData(String key, String subkey, Object in_value, boolean isSetAsString)` -- The primary implementation. If `key` or `subkey` is null, returns immediately. Otherwise, dispatches to the appropriate setter based on the key/subkey match, casting `in_value` to `String` or `Boolean` as needed.

Used by the framework to **populate the bean from form submissions** after a user action. The `isSetAsString` parameter (unused in the current implementation) appears to have been planned for Long-to-String type conversion that was never implemented.

#### `typeModelData(String key, String subkey) -> Class<?>`

Returns the Java type for a given field/subkey combination. Used by the framework for type-safe binding and validation. Returns `String.class` or `Boolean.class` depending on the field; returns `null` if no match.

#### `listKoumokuIds() -> ArrayList<String>`

**Static method** that returns an `ArrayList` of all 28 Japanese display keys. Used by the framework to enumerate and iterate over all fields for tasks like validation, display generation, or serialization. The list order matches the order of field processing in `loadModelData` / `storeModelData`.

#### `getIndex() / setIndex(int)`

Gets/sets a row index. This integer is likely used to identify a particular row in a repeating table or list on the screen (e.g., when multiple service contracts are displayed).

### Getter/Setter Pairs (sample)

Every domain field has a trio or quartet of getters/setters. Here are representative examples:

| Field group | Value getter | State getter | Enabled getter | Update getter |
|-------------|-------------|-------------|----------------|---------------|
| Option Service Contract No | `getOp_svc_kei_no_value()` | `getOp_svc_kei_no_state()` | N/A | `getOp_svc_kei_no_update()` |
| Service Contract Status Name | `getOp_svc_kei_stat_nm_value()` | `getOp_svc_kei_stat_nm_state()` | `getOp_svc_kei_stat_nm_enabled()` | `getOp_svc_kei_stat_nm_update()` |
| Service Code | `getOp_svc_cd_value()` | `getOp_svc_cd_state()` | `getOp_svc_cd_enabled()` | `getOp_svc_cd_update()` |
| Option Content | `getOp_naiyo_value()` | `getOp_naiyo_state()` | `getOp_naiyo_enabled()` | `getOp_naiyo_update()` |
| Service Start Date-Time | `getSvc_sta_dtm_value()` | `getSvc_sta_dtm_state()` | N/A | `getSvc_sta_dtm_update()` |
| Service End Date-Time | `getSvc_end_dtm_value()` | `getSvc_end_dtm_state()` | `getSvc_end_dtm_enabled()` | `getSvc_end_dtm_update()` |
| Use Start Date | `getUse_sta_ymd_value()` | `getUse_sta_ymd_state()` | `getUse_sta_ymd_enabled()` | `getUse_sta_ymd_update()` |

All getters are trivial accessors (`return this.<field>`). All setters are trivial assignments (`this.<field> = param`). The `enabled` fields default to `false` at declaration and are set to `true` by the business logic before rendering.

### Complete field inventory

| Japanese key | Field prefix | Has enabled? |
|-------------|-------------|--------------|
| オプションサービス契約番号 | `op_svc_kei_no` | No |
| オプションサービス契約ステータス | `op_svc_kei_stat` | No |
| オプションサービス契約ステータス名 | `op_svc_kei_stat_nm` | Yes |
| オプションサービスコード | `op_svc_cd` | Yes |
| オプションサービスコード名 | `op_svc_cd_nm` | Yes |
| オプション内容 | `op_naiyo` | Yes |
| サービス開始年月日時分秒 | `svc_sta_dtm` | No |
| 予約適用開始希望年月日 | `rsv_tsta_kibo_ymd` | No |
| サービス利用開始希望年月日 | `svc_use_sta_kibo_ymd` | No |
| サービス終了年月日時分秒 | `svc_end_dtm` | Yes |
| 利用開始日 | `use_sta_ymd` | Yes |
| 申込番号 | `mskm_no` | No |
| 申込明細番号 | `mskm_dtl_no` | No |
| 行表示フラグ | `gyo_disp_flg` | No |
| サブオプションサービス契約番号 | `sbop_svc_kei_no` | No |
| サブオプションサービスコード | `sbop_svc_cd` | No |
| 利用終了予定日 | `opsvc_end_rsv_ymd` | No |
| 表示用サービス提供開始年月日 | `dsp_svctk_staymd` | No |
| フェムトセル事業者コード | `fmtcel_jgs_cd` | No |
| 最大オプションサービス数 | `max_op_svc_cnt` | No |
| 異動予約存在フラグ | `ido_rsv_flg` | No |
| 回復可能期間 | `kaihk_psb_prd` | No |
| サービス課金開始年月日 | `svc_chrg_staymd` | No |
| サービス課金終了年月日 | `svc_chrg_endymd` | No |
| 料金コースコード | `pcrs_cd` | No |
| 料金プランコード | `pplan_cd` | No |

## Relationships

```mermaid
flowchart TD
    JSP["KKW023010PJP.jsp"] -->|"reads/writes via| BEAN["KKW02301SF01DBean"]

    subgraph Fields["Field Groups (each with _update, _value, _state, optionally _enabled)"]
        SVC["Service Contract No<br/>op_svc_kei_no"]
        SVCSTAT["Service Contract Status<br/>op_svc_kei_stat"]
        SVCSTATNM["Service Contract Status Name<br/>op_svc_kei_stat_nm + enabled"]
        SVCCD["Service Code<br/>op_svc_cd + enabled"]
        SVCCDNM["Service Code Name<br/>op_svc_cd_nm + enabled"]
        OPNAIYO["Option Content<br/>op_naiyo + enabled"]
        SVCSTADTM["Service Start Date-Time<br/>svc_sta_dtm"]
        RSVTSTA["Reservation Application Start Pref.<br/>rsv_tsta_kibo_ymd"]
        SVCUSE["Service Use Start Pref.<br/>svc_use_sta_kibo_ymd"]
        SVCEND["Service End Date-Time<br/>svc_end_dtm + enabled"]
        USESTAYMD["Use Start Date<br/>use_sta_ymd + enabled"]
        MSKMNO["Application No<br/>mskm_no"]
        MSKMDTL["Application Detail No<br/>mskm_dtl_no"]
        GYODISP["Row Display Flag<br/>gyo_disp_flg"]
        SBOPKEI["Sub-Option Service Contract No<br/>sbop_svc_kei_no"]
        SBOPCD["Sub-Option Service Code<br/>sbop_svc_cd"]
        OPSVCEND["Use End Reservation Date<br/>opsvc_end_rsv_ymd"]
        DSPTS["Display Service Provision Start<br/>dsp_svctk_staymd"]
        FJGSCD["Femtocell Provider Code<br/>fmtcel_jgs_cd"]
        MAXOP["Max Option Service Count<br/>max_op_svc_cnt"]
        IDORSV["Displaced Reservation Flag<br/>ido_rsv_flg"]
        KAIHKPRD["Recovery Possible Period<br/>kaihk_psb_prd"]
        SVCCRG["Service Charge Start Date<br/>svc_chrg_staymd"]
        SVCCRGEND["Service Charge End Date<br/>svc_chrg_endymd"]
        PCRSCD["Cost Code<br/>pcrs_cd"]
        PPLANCd["Plan Code<br/>pplan_cd"]
    end

    BEAN --- Fields
```

### Dependency summary

- **Depends on (inbound):** `KKW023010PJP.jsp` -- a JSP page that references the bean to display and edit service change information.
- **No outbound dependencies:** The bean has no imports beyond standard Java (`Serializable`, `ArrayList`, `Class`) and the X33 framework interfaces. It contains no business logic, no database access, and no external dependencies.

## Usage Example

```java
// 1. Create the bean
KKW02301SF01DBean bean = new KKW02301SF01DBean();

// 2. Populate from initial data using direct getters/setters
bean.setOp_svc_kei_no_value("SVC-2024-001");
bean.setOp_svc_kei_no_state("OK");
bean.setOp_svc_kei_stat_nm_enabled(true);
bean.setOp_svc_kei_stat_nm_value("Active");

// 3. Set date ranges
bean.setSvc_sta_dtm_value("20240101000000");
bean.setSvc_end_dtm_value("20251231235959");
bean.setSvc_end_dtm_enabled(true);

// 4. After form submission, the framework calls storeModelData
bean.storeModelData("オプションサービス契約番号", "value", "SVC-2024-002");
bean.storeModelData("オプションサービス契約ステータス名", "value", "Inactive");

// 5. Check which fields were updated (via _update flags)
if (bean.getOp_svc_kei_no_update() != null && !bean.getOp_svc_kei_no_update().isEmpty()) {
    // Field was submitted -- process it
    String newValue = bean.getOp_svc_kei_no_value();
}

// 6. Use reflective access for generic processing
Object val = bean.loadModelData("オプションサービスコード", "value");
Class<?> type = bean.typeModelData("オプションサービスコード名", "enable"); // Boolean.class
ArrayList<String> allKeys = KKW02301SF01DBean.listKoumokuIds();
```

## Notes for Developers

1. **All keys are Japanese strings.** The `loadModelData`, `storeModelData`, and `typeModelData` methods use hardcoded Japanese literals for the `key` parameter. These must match exactly (including full-width characters) -- there is no constant or enum mapping. Any translation or localization would require changing these strings throughout.

2. **The `isSetAsString` parameter in `storeModelData` is unused.** The method signature accepts a boolean flag for `Long`-to-`String` conversion, but the implementation never checks it. This appears to be a framework placeholder from a parent class (`X31CBaseBean`).

3. **The `gamenId` (screen ID) parameter is unused.** The four-argument `storeModelData` forwards to the three-argument version, discarding `gamenId`. This suggests the framework was designed to support multiple screens in one bean, but this particular bean only handles one.

4. **`enabled` defaults are `false`.** All `Boolean`-type `enabled` fields are initialized to `false` at declaration. They must be explicitly set to `true` by the business layer before rendering, otherwise the UI will show these fields as disabled/read-only.

5. **Thread safety:** This class is **not thread-safe**. It holds mutable state with no synchronization. One instance per request/session is expected -- the bean should not be shared between threads.

6. **28 item keys.** The `listKoumokuIds()` static method lists 28 keys. Any new field added to the class must also be added to this list, otherwise reflective methods (`loadModelData`, etc.) will silently return `null` when called with that key.

7. **Two feature additions are marked with change requests:**
   - `svc_use_sta_kibo_ymd` (lines 370-384) was added per `OM-2014-0001976` for a service use start preference date.
   - `pcrs_cd` and `pplan_cd` (lines 763-808) were added per `IT1-2014-0000122` for a光電気セールクト (Kodensha Select) option pack's cost code and plan code fields.

8. **No validation logic.** The bean only stores state flags (`_state`) -- it does not contain any validation rules. Validation is performed elsewhere (likely in a corresponding *PJP* page or business delegate).

9. **No business logic.** This class is purely a data carrier. Any data transformation, validation, or persistence logic belongs in a separate service or delegate class.

10. **The `index` field** is likely used for row identification in a repeated table on the screen, where multiple service contracts or options can appear simultaneously.
