# KKW00401SF02DBean

## Purpose

`KKW00401SF02DBean` is the central data model (form bean) for a set of web pages in the system. It acts as a comprehensive container that aggregates dozens of business fields — each carrying value, enabled-state, update-flag, and display-state sub-properties — along with five list-based collections of nested beans. It is used by the X33 web framework to mediate data between JSP views and the application logic, providing generic key/subkey-based accessors that eliminate the need for the view layer to know field names at compile time.

## Design

This class follows a **data-driven form bean** pattern typical of Java EE web applications built on a field-based presentation framework. It implements three interfaces:

- **`X33VDataTypeBeanInterface`** — requires `loadModelData(String key, String subkey)` and `typeModelData(String key, String subkey)`. These enable generic, key-based data access, meaning the JSP layer can read/write any field by name at runtime without compile-time coupling.
- **`X33VListedBeanInterface`** — requires `addListDataInstance(String key)`, `removeElementFromListData(String key, int index)`, and `clearListDataInstance(String key)`. These manage the five collection fields that hold lists of nested bean instances.
- **`Serializable`** — enables HTTP session storage or other serialization pathways.

The class does not extend any other class, so it is a leaf in the inheritance hierarchy.

### Field Organization

Every business property in the class follows a consistent four-field quadruplet:

| Field | Purpose | Type |
|---|---|---|
| `<name>_update` | Flags whether this field was updated by the user | `String` |
| `<name>_value` | The actual data value | `String` or `Boolean` |
| `<name>_enabled` | Whether the field is editable on the page | `Boolean` |
| `<name>_state` | UI state or validation message | `String` |

Boolean fields (`r`, `old_r`, `r_hidden`) store their primary value as `Boolean` rather than `String`.

The class also defines five collection fields:

| List Field | Purpose |
|---|---|
| `stb_ido_div_list` | List of STB operation division items |
| `sel_type_number_list` | List of selection type number items |
| `stb_div_list` | List of STB division items |
| `hdd_capa_list` | List of HDD capacity items |
| `tv_course_list` | List of TV course items |

Each element in these lists is a `KKW00401SF01DBean`, which itself implements `X33VDataTypeBeanInterface`. This means the nested beans expose the same key/subkey load/store/type introspection API.

### Constructor

The default constructor initializes all five list fields to empty `X33VDataTypeList` instances:

```java
stb_ido_div_list = new X33VDataTypeList();
sel_type_number_list = new X33VDataTypeList();
stb_div_list = new X33VDataTypeList();
hdd_capa_list = new X33VDataTypeList();
tv_course_list = new X33VDataTypeList();
```

The `index` field (an `int`) is not initialized in the constructor and defaults to `0`.

## Key Methods

### `loadModelData(String key, String subkey) → Object`

The primary read accessor. Given a field key (e.g., `"STB"`) and a subkey (e.g., `"value"`, `"enable"`, `"state"`), it delegates to the appropriate getter.

```
key = "STB", subkey = "value"  →  getStb_value()
key = "STB", subkey = "enable" →  getStb_enabled()
key = "STB", subkey = "state"  →  getStb_state()
```

For list-type fields, the key is expected to contain a path with an index. For example, `"STB異動区分/0/STB"` instructs the method to:

1. Parse out `"STB異動区分"` as the list field name.
2. Extract `"0"` as the index.
3. Cast `stb_ido_div_list.get(0)` to `X33VDataTypeBeanInterface`.
4. Recursively call `loadModelData("STB", "value")` on the nested bean.

If the key is `"STB異動区分/*"`, the method returns the list's element count as an `Integer`.

The method handles **38 distinct top-level keys**, spanning STB configuration, maker info, device specs, timestamps, hidden fields, and ID fields. See the "Supported Keys" section below for the full inventory.

### `storeModelData(...)` → void

The write counterpart to `loadModelData`. There are three overloaded variants:

| Signature | Description |
|---|---|
| `storeModelData(String key, String subkey, Object in_value, boolean isSetAsString)` | Full form. The `isSetAsString` parameter (passed as `false` by default) is a reserved flag for long-type properties that need string casting. |
| `storeModelData(String key, String subkey, Object in_value)` | Convenience overload; delegates to the three-argument version with `isSetAsString = false`. |
| `storeModelData(String gamenId, String key, String subkey, Object in_value)` | Overrides a parent class method from `X31CBaseBean`; ignores `gamenId` and delegates to the two-arg key form. |

For `key = "STB"` and `subkey = "value"`, the implementation casts `in_value` to `String` and calls `setStb_value()`. The same pattern applies for `"enable"` (casts to `Boolean`) and `"state"` (casts to `String`). List-type keys use the same path-based delegation as `loadModelData`, calling `storeModelData` on the nested bean.

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

Returns the Java type for a given key/subkey pair. Used by the framework for type checking and data binding validation.

```
key = "STB", subkey = "value"  →  String.class
key = "STB", subkey = "enable" →  Boolean.class
key = "STB", subkey = "state"  →  String.class
key = "R", subkey = "value"    →  Boolean.class    (note: R is a Boolean field)
```

For list keys, the behavior mirrors `loadModelData` — if the subkey pattern targets an index position, it returns `Integer.class`; otherwise it delegates to the nested bean's `typeModelData`.

### `addListDataInstance(String key) → int`

Creates a new list element and appends it to the appropriate list. Returns the index of the newly added element.

```java
int idx = bean.addListDataInstance("STB異動区分");
// → Creates a new KKW00401SF01DBean, adds it to stb_ido_div_list, returns 0
```

The method throws `X33SException` on errors. It supports all five list keys: `"STB異動区分"`, `"選択型番コード"`, `"STB区分"`, `"HDD容量"`, `"TVコース"`. Returns `-1` if the key is unrecognized or null.

### `removeElementFromListData(String key, int index) → void`

Removes the element at the given index from the specified list. Performs bounds checking (skips silently if `index < 0 || index >= list.size()`).

### `clearListDataInstance(String key) → void`

Clears all elements from the specified list. Supports the same five list keys as `addListDataInstance`.

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

A static factory method that returns the complete list of 42 supported field keys as Japanese-language names. This is used by the framework to enumerate all form fields during page rendering or validation.

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

Accessor for the `index` field. This field is not used internally by any method in the class — it appears to be a reserved slot for external use by the framework or calling JSP pages.

### `getJsflist_typelist_*()` → `ArrayList<SelectItem>`

Five convenience methods that convert the raw `X33VDataTypeList` objects into `ArrayList<SelectItem>` for dropdown/pop-up rendering in JSF-like components:

| Method | List |
|---|---|
| `getJsflist_typelist_stb_ido_div()` | `stb_ido_div_list` |
| `getJsflist_typelist_sel_type_number()` | `sel_type_number_list` |
| `getJsflist_typelist_stb_div()` | `stb_div_list` |
| `getJsflist_typelist_hdd_capa()` | `hdd_capa_list` |
| `getJsflist_typelist_tv_course()` | `tv_course_list` |

These iterate the list and build `SelectItem` objects suitable for `<h:selectOneMenu>` or similar UI components.

## Supported Keys

The following keys are handled by `loadModelData`, `storeModelData`, and `typeModelData`:

| Key (Japanese) | Internal Field | Data Type |
|---|---|---|
| `STB` | `stb_value` | String |
| メーカーコード | `maker_cd_value` | String |
| メーカー名 | `maker_nm_value` | String |
| 保有ルーター種類コード | `hoyu_router_sbt_cd_value` | String |
| VONUパススルー可否 | `vonu_bspt_kh_value` | String |
| STBID | `stbid_value` | String |
| 宅内機器型式コード | `taknkiki_model_cd_value` | String |
| HDD有無 | `hdd_um_value` | String |
| R | `r_value` | Boolean |
| STB異動区分コード | `stb_ido_div_cd_value` | String |
| 選択型番コード | `sel_type_number_cd_value` | String |
| STB区分コード | `stb_div_cd_value` | String |
| HDD容量コード | `hdd_capa_cd_value` | String |
| TVコースコード | `tv_course_cd_value` | String |
| 変更前STB異動区分コード | `old_stb_ido_div_cd_value` | String |
| 変更前選択型番コード | `old_sel_type_number_cd_value` | String |
| 変更前STB区分コード | `old_stb_div_cd_value` | String |
| 変更前R | `old_r_value` | Boolean |
| 変更前HDD容量コード | `old_hdd_capa_cd_value` | String |
| 変更前TVコースコード | `old_tv_course_cd_value` | String |
| 変更前TVコースコード?カレント | `old_tv_course_cd_cur_value` | String |
| 機器提供サービス契約番号 | `kktk_svc_kei_no_value` | String |
| 宅内機器型式 | `taknkiki_model_value` | String |
| 宅内機器種類コード | `taknkiki_sbt_cd_value` | String |
| 機器提供種類コード | `kktk_sbt_cd_value` | String |
| 機器製造番号 | `kiki_seizo_no_value` | String |
| HDDコード | `hdd_capa_value` | String |
| サービス契約内訳番号 | `svc_kei_ucwk_no_value` | String |
| 世代登録年月日時分秒 | `gene_add_dtm_value` | String |
| 機器提供更新年月日時分秒 | `kktk_upd_dtm_value` | String |
| サービス契約内訳更新年月日時分秒 | `svc_kei_ucwk_upd_dtm_value` | String |
| 隠しSTB異動区分コード | `stb_ido_div_hidden_value` | String |
| 隠し選択型番コード | `sel_type_number_hidden_value` | String |
| 隠しSTB区分コード | `stb_div_hidden_value` | String |
| 隠しR | `r_hidden_value` | Boolean |
| 隠しHDD容量コード | `hdd_capa_hidden_value` | String |
| 隠しTVコースコード | `tv_course_hidden_value` | String |
| 一覧のスタイル制御 | `list_style_value` | String |
| BCASID | `bcas_id_value` | String |
| CCASID | `ccas_id_value` | String |
| 予約TVコースコード | `rsv_tv_course_cd_value` | String |
| 機器最低利用期間 | `kiki_min_use_prd_value` | String |
| STB異動区分 | *(list)* | — |
| 選択型番 | *(list)* | — |
| STB区分 | *(list)* | — |
| HDD容量 | *(list)* | — |
| TVコース | *(list)* | — |

## Relationships

```mermaid
flowchart TD
    A["KKW004010PJP.jsp"] --> B["KKW00401SF02DBean"]
    C["KKW004020PJP.jsp"] --> B
    B --> D["KKW00401SF01DBean"]
    B --> E["X33VDataTypeList"]
    B --> F["X33VDataTypeBeanInterface"]
    B --> G["X33VListedBeanInterface"]
    D --> F
    E --> H["Object"]
```

### Incoming (Used by)

Two JSP pages reference `KKW00401SF02DBean`:

- **`KKW004010PJP.jsp`** — The primary form page, likely the main data entry/display view.
- **`KKW004020PJP.jsp`** — A secondary or related form page, possibly a confirmation or edit view.

Both pages access the bean through the X33 framework's standard JSP tag libraries (e.g., `<x33:formBean>` or `<x33:property>` tags), which internally call `loadModelData`/`storeModelData` to bind data.

### Outgoing (Uses)

The class has no direct outbound dependencies beyond the interfaces it implements and the collection types it uses. Its nested bean type (`KKW00401SF01DBean`) is instantiated only within `addListDataInstance`.

## Usage Example

A typical JSP page accesses the bean through the X33 framework:

```jsp
<%-- Read a field value --%>
<x33:formBean name="KKW00401SF02DBean" id="bean" scope="session" />
<x33:property beanId="bean" key="STB" subkey="value" />

<%-- Read a list element at index 0 --%>
<x33:property beanId="bean" key="STB異動区分/0/STB" subkey="value" />

<%-- Add a new row to a list --%>
<x33:script>
    int idx = bean.addListDataInstance("STB異動区分");
    bean.setIndex(idx);
</x33:script>

<%-- Read list size --%>
<x33:property beanId="bean" key="STB異動区分/*" subkey="value" />
```

From a Java context, one might use it like:

```java
KKW00401SF02DBean bean = new KKW00401SF02DBean();

// Set a simple field
bean.storeModelData("STB", "value", "STB-001");
bean.storeModelData("STB", "enable", Boolean.TRUE);

// Read a field
Object value = bean.loadModelData("STB", "value");

// Type-check a field
Class<?> type = bean.typeModelData("STB", "value");  // String.class

// Manage list items
int idx = bean.addListDataInstance("STB異動区分");
// The new item at index 0 is a KKW00401SF01DBean
bean.loadModelData("STB異動区分/" + idx + "/STB", "value");

// Get dropdown options
ArrayList<SelectItem> items = bean.getJsflist_typelist_stb_ido_div();
```

## Notes for Developers

- **All key/subkey matching is case-insensitive for the subkey.** `"value"`, `"VALUE"`, and `"Value"` all resolve to the same field.
- **List keys require a specific path format:** `"LIST_KEY/index/inner_key"`. If the index segment is `"*"`, the system returns the list size. If the path is malformed (e.g., no `/` separator, non-numeric index), the method returns `null` or `-1` without throwing — failure is silently absorbed.
- **Boolean vs String:** Most fields are `String`, but three fields (`r_value`, `old_r_value`, `r_hidden_value`) are typed as `Boolean`. The `typeModelData` method reflects this correctly.
- **Thread safety:** The class is **not thread-safe**. It holds mutable state (fields, list collections) and has no synchronization. It is expected to be instantiated per-request or per-session.
- **No validation logic:** The bean only stores values and metadata. Business rule validation (e.g., "STB ID must be unique") is handled by the service layer or controller, not within this bean.
- **Interface contract completeness:** `typeModelData` is called with `(key, "*")` for list-size queries. Returning `Integer.class` (not `Integer` instance) ensures the framework knows the result type.
- **The `index` field is a leftover:** It is never read or written internally by the class itself. It exists to be set by JSP scripts or the framework for potential use in rendering or iteration.
- **Additions:** Fields added via change tickets (marked `ANK-xxxx-xx-xx` in comments) are appended to the existing structure. The `load/store/type` methods all use long `if-else` chains, so adding a new field requires editing in three places (load, store, type), which is error-prone.
- **No outbound references:** The class has zero method calls to other application classes (besides the framework interfaces). Its entire behavior is self-contained, which makes it safe to inspect and modify without worrying about ripple effects to other modules.
