# Business Logic — KKW01027SF02DBean.loadModelData() [80 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKA15001SF.KKW01027SF02DBean` |
| Layer | View Bean (UI data access layer) |
| Module | `KKA15001SF` (Package: `eo.web.webview.KKA15001SF`) |

## 1. Role

### KKW01027SF02DBean.loadModelData()

This method serves as the central data lookup and routing dispatcher for the **Discount Service Contract Registration Selection** screen (割引サービス契約登録選択 — Screen ID: `KKW01027`). It implements a **dynamic accessor pattern** where UI framework code can query bean data using a string-based key/subkey addressing scheme, similar to a Map but with domain-typed semantics.

The method handles **three categories** of data access: (1) **Index data** — scalar properties of the screen's index row selection (value, enabled state, and state type); (2) **Code list data** — a typed list of string-type beans (`X33VDataTypeStringBean`) representing service code values; and (3) **Code name list data** — a parallel typed list holding the human-readable code name labels.

Within the larger screen framework, this method enables the view layer to access complex nested data through simple key strings (e.g., `"添字/value"` for the index value, `"コードリスト/0"` for the first code list element). The **self-call mechanism** (the no-arg `loadModelData()` calls this overloaded version with `"添字"` as key) allows the bean to serve as a data source during framework-initiated data binding cycles. When no matching key is found, the method safely returns `null` rather than throwing an exception.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["loadModelData key, subkey"])

    START --> CHECK_NULL["Check: key == null or subkey == null"]
    CHECK_NULL -->|Yes| RETURN_NULL_1["Return null"]
    CHECK_NULL -->|No| FIND_SEP["Find '/' index in key"]
    FIND_SEP --> CHECK_KEY["Check: key equals '添字' (Index)"]

    CHECK_KEY -->|Yes| SUBKEY_CHECK{"subkey matches?"}
    SUBKEY_CHECK -->|"value"| CALL_IV["getIndex_value()"]
    SUBKEY_CHECK -->|"enable"| CALL_IE["getIndex_enabled()"]
    SUBKEY_CHECK -->|"state"| CALL_IS["getIndex_state()"]
    SUBKEY_CHECK -->|Other| RETURN_NULL_2["Return null"]
    CALL_IV --> RETURN_DATA_1["Return index data"]
    CALL_IE --> RETURN_DATA_1
    CALL_IS --> RETURN_DATA_1

    CHECK_KEY -->|No| CHECK_CD_LIST["Check: key equals 'コードリスト' (Code List)"]
    CHECK_CD_LIST -->|Yes| SUBSTR_CD["key = key.substring(separaterPoint + 1)"]
    SUBSTR_CD --> CHECK_WILDCARD_CD{"key equals '*'?"}
    CHECK_WILDCARD_CD -->|Yes| RETURN_SIZE_CD["Return Integer.valueOf(cd_div_list_list.size())"]
    CHECK_WILDCARD_CD -->|No| PARSE_CD_INT["Parse key as Integer -> tmpIndexInt"]
    PARSE_CD_INT --> TRY_CD{NumberFormatException?}
    TRY_CD -->|Yes| RETURN_NULL_3["Return null"]
    TRY_CD -->|No| CHECK_RANGE_CD{"tmpIndex valid? (0 <= tmpIndex < cd_div_list_list.size())"}
    CHECK_RANGE_CD -->|Yes| GET_CD_ELEM["Get cd_div_list_list.get(tmpIndex)"]
    GET_CD_ELEM --> CAST_CD["Cast to X33VDataTypeStringBean"]
    CAST_CD --> CALL_SUB_CD["X33VDataTypeStringBean.loadModelData(subkey)"]
    CALL_SUB_CD --> RETURN_DATA_2["Return element data"]
    CHECK_RANGE_CD -->|No| RETURN_NULL_4["Return null"]

    CHECK_CD_LIST -->|No| CHECK_CD_NM["Check: key equals 'コード名リスト' (Code Name List)"]
    CHECK_CD_NM -->|Yes| SUBSTR_CN["key = key.substring(separaterPoint + 1)"]
    SUBSTR_CN --> CHECK_WILDCARD_CN{"key equals '*'?"}
    CHECK_WILDCARD_CN -->|Yes| RETURN_SIZE_CN["Return Integer.valueOf(cd_div_nm_list_list.size())"]
    CHECK_WILDCARD_CN -->|No| PARSE_CN_INT["Parse key as Integer -> tmpIndexInt"]
    PARSE_CN_INT --> TRY_CN{NumberFormatException?}
    TRY_CN -->|Yes| RETURN_NULL_5["Return null"]
    TRY_CN -->|No| CHECK_RANGE_CN{"tmpIndex valid? (0 <= tmpIndex < cd_div_nm_list_list.size())"}
    CHECK_RANGE_CN -->|Yes| GET_CN_ELEM["Get cd_div_nm_list_list.get(tmpIndex)"]
    GET_CN_ELEM --> CAST_CN["Cast to X33VDataTypeStringBean"]
    CAST_CN --> CALL_SUB_CN["X33VDataTypeStringBean.loadModelData(subkey)"]
    CALL_SUB_CN --> RETURN_DATA_3["Return element data"]
    CHECK_RANGE_CN -->|No| RETURN_NULL_6["Return null"]

    CHECK_CD_NM -->|No| RETURN_NULL_7["Return null (no matching key)"]
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `key` | `String` | The **item name** (項目名) that identifies the type of data to retrieve. Can be one of: `"添字"` (Index — for screen row selection state), `"コードリスト"` (Code List — for the list of code values, with a sub-index after `/`), or `"コード名リスト"` (Code Name List — for the list of code labels, with a sub-index after `/`). When prefixed with `"/"` followed by a number (e.g., `"コードリスト/3"`), it selects a specific element from the corresponding typed list. |
| 2 | `subkey` | `String` | The **sub-key** (サブキー) that specifies which property to retrieve from the identified data item. For the index key (`"添字"`), valid subkeys are `"value"` (the index row's value), `"enable"` (whether the index is enabled), and `"state"` (the index row's state). For list keys (`"コードリスト"` / `"コード名リスト"`), the subkey is forwarded to the inner bean's `loadModelData(subkey)` method to retrieve a property of that typed data element. |

**Instance fields read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `cd_div_list_list` | `X33VDataTypeList` | The typed list of code values — contains `X33VDataTypeStringBean` elements representing the service code values for the discount service selection screen. |
| `cd_div_nm_list_list` | `X33VDataTypeList` | The typed list of code names — contains `X33VDataTypeStringBean` elements representing the human-readable labels corresponding to each code value in `cd_div_list_list`. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `KKW01027SF02DBean.getIndex_value` | KKW01027SF02DBean | - | Reads the value property of the current index row (returns the selected row's data value) |
| R | `KKW01027SF02DBean.getIndex_enabled` | KKW01027SF02DBean | - | Reads the enabled state of the current index row (returns whether the row is interactive) |
| R | `KKW01027SF02DBean.getIndex_state` | KKW01027SF02DBean | - | Reads the state type of the current index row (returns the row's display/status state) |
| R | `X33VDataTypeStringBean.loadModelData` | X33VDataTypeStringBean | - | Delegates to inner bean to retrieve a named property from a code list element (value, name, etc.) |
| R | `X33VDataTypeList.get` (via `cd_div_list_list.get`) | X33VDataTypeList | - | Reads an element from the code value list by index |
| R | `X33VDataTypeList.get` (via `cd_div_nm_list_list.get`) | X33VDataTypeList | - | Reads an element from the code name list by index |
| R | `X33VDataTypeList.size` | X33VDataTypeList | - | Returns the total count of elements in a typed list |

**Classification Notes:**
- All operations are **Read** (R) — this method does not create, update, or delete any data. It is purely an accessor.
- Internal getter methods (`getIndex_*`) read the screen's index row state.
- The delegation to `X33VDataTypeStringBean.loadModelData(subkey)` forwards property access to typed data elements stored in the code lists.
- No database tables or SC/CBS codes are accessed — this is a **view-layer bean** that operates on in-memory data structures.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | KKW01027SF02DBean | `KKW01027SF02DBean.loadModelData()` (no-arg overload) -> `KKW01027SF02DBean.loadModelData(String key, String subkey)` (self-call with key="添字") | `getIndex_value [R]`, `getIndex_enabled [R]`, `getIndex_state [R]`, `X33VDataTypeStringBean.loadModelData [R]` |

**Caller Notes:**
- The **pre-computed caller** is the no-arg overload of `loadModelData()` within the same class (`KKW01027SF02DBean.loadModelData()`). This overload calls the overloaded `loadModelData(String key, String subkey)` version with `key = "添字"`, effectively delegating the index data access to this method.
- The no-arg `loadModelData()` is typically invoked by the **screen framework** during data binding cycles to populate view-layer data.
- This method is part of the `KKA15001SF` module, which supports the **Discount Service Contract Registration Selection** screen (KKW01027). The broader call chain would involve the screen's controller (e.g., `KKSV01027*`) calling the no-arg overload to initialize view data, which then delegates to this key/subkey version.

## 6. Per-Branch Detail Blocks

### Block 1 — IF (null guard check) (L153)

> If either parameter is null, return null immediately. This prevents NullPointerException and handles missing data gracefully.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `key == null` // check key is not null |
| 2 | EXEC | `subkey == null` // check subkey is not null |
| 3 | RETURN | `return null` // both parameters null -> return null (key, subkeyがnullの場合、nullを返す) |

### Block 2 — PROCESS (extract separator position) (L157)

> Find the position of the "/" delimiter in the key string. This enables parsing of composite keys like `"コードリスト/3"` by extracting the element index portion.

| # | Type | Code |
|---|------|------|
| 1 | SET | `separaterPoint = key.indexOf("/")` // find position of "/" delimiter in key (区切り文字の位置を取得) |

### Block 3 — IF (key == "添字" branch) (L160)

> The **"添字" (Index)** key handles access to the screen's current index row state. Subkey determines which property of the index row to return. The comment "(項目ID:index)" identifies this as the Index item (項目).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `key.equals("添字")` // check if key is "添字" (添字) (項目ID:index) |
| 2 | IF | `subkey.equalsIgnoreCase("value")` (L162) — subkey is case-insensitive match for "value" |
| 3 | CALL | `return getIndex_value()` // get the index row's value property (添字の値を取得) |
| 4 | IF | `subkey.equalsIgnoreCase("enable")` (L165) — subkey matches "enable" |
| 5 | CALL | `return getIndex_enabled()` // get the index row's enabled state (インデックスのgetterの戻り値を返す。subkeyが"enable"の場合、index_enableのgetterの戻り値を返す) |
| 6 | IF | `subkey.equalsIgnoreCase("state")` (L168) — subkey matches "state" |
| 7 | CALL | `return getIndex_state()` // get the index row's state (サブキーが"state"の場合、ステータスを返す) |

### Block 4 — IF (key == "コードリスト" branch) (L174)

> The **"コードリスト" (Code List)** key handles access to a typed list of `X33VDataTypeStringBean` elements. The sub-key after "/" can be `"*"` to return the list size, or a numeric index to access a specific element. The comment "(String型、項目ID:cd_div_list)" identifies this as a String-type list with item ID `cd_div_list`.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `key.equals("コードリスト")` // check if key is "コードリスト" |
| 2 | SET | `key = key.substring(separaterPoint + 1)` // extract sub-key after "/" (keyの次の要素を取得) |
| 3 | IF | `key.equals("*")` (L179) — wildcard request for list size |
| 4 | RETURN | `return Integer.valueOf(cd_div_list_list.size())` // return list size as Integer (インデックス値の代わりに"*"が指定されていたら、リストの要素数を返す) |
| 5 | TRY | Parse key as integer (L183) |
| 6 | SET | `tmpIndexInt = Integer.valueOf(key)` // attempt to parse key as index (keyの次の要素を取得) |
| 7 | CATCH | `NumberFormatException e` (L188) — key is not a valid numeric string |
| 8 | RETURN | `return null` // not a numeric value -> return null (インデックス値が数値文字列でない場合は、ここでnullを返す) |
| 9 | IF | `tmpIndexInt == null` (L192) |
| 10 | RETURN | `return null` // parsed integer is null -> return null |
| 11 | SET | `tmpIndex = tmpIndexInt.intValue()` // extract primitive int value |
| 12 | IF | `tmpIndex < 0 \|\| tmpIndex >= cd_div_list_list.size()` (L195) — index out of bounds check |
| 13 | RETURN | `return null` // index exceeds list size-1 -> return null (インデックス値がリスト個数-1を超えると、ここでnullを返す) |
| 14 | SET | `((X33VDataTypeStringBean) cd_div_list_list.get(tmpIndex))` // get element at index and cast to typed bean |
| 15 | CALL | `return ... .loadModelData(subkey)` // delegate to inner bean's loadModelData (index要素のloadModelData) |

### Block 5 — IF (key == "コード名リスト" branch) (L202)

> The **"コード名リスト" (Code Name List)** key handles access to a typed list of code name labels (parallel to the code list in Block 4). The structure is identical to Block 4 but operates on `cd_div_nm_list_list`. The comment "(String型、項目ID:cd_div_nm_list)" identifies this as a String-type list with item ID `cd_div_nm_list`.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `key.equals("コード名リスト")` // check if key is "コード名リスト" |
| 2 | SET | `key = key.substring(separaterPoint + 1)` // extract sub-key after "/" (keyの次の要素を取得) |
| 3 | IF | `key.equals("*")` (L209) — wildcard request for list size |
| 4 | RETURN | `return Integer.valueOf(cd_div_nm_list_list.size())` // return list size as Integer (インデックス値の代わりに"*"が指定されていたら、リストの要素数を返す) |
| 5 | TRY | Parse key as integer (L213) |
| 6 | SET | `tmpIndexInt = Integer.valueOf(key)` // attempt to parse key as index |
| 7 | CATCH | `NumberFormatException e` (L218) — key is not a valid numeric string |
| 8 | RETURN | `return null` // not a numeric value -> return null (インデックス値が数値文字列でない場合は、ここでnullを返す) |
| 9 | IF | `tmpIndexInt == null` (L222) |
| 10 | RETURN | `return null` // parsed integer is null -> return null |
| 11 | SET | `tmpIndex = tmpIndexInt.intValue()` // extract primitive int value |
| 12 | IF | `tmpIndex < 0 \|\| tmpIndex >= cd_div_nm_list_list.size()` (L225) — index out of bounds check |
| 13 | RETURN | `return null` // index exceeds list size-1 -> return null (インデックス値がリスト個数-1を超えると、ここでnullを返す) |
| 14 | SET | `((X33VDataTypeStringBean) cd_div_nm_list_list.get(tmpIndex))` // get element at index and cast to typed bean |
| 15 | CALL | `return ... .loadModelData(subkey)` // delegate to inner bean's loadModelData |

### Block 6 — ELSE (no match fallback) (L230)

> If no key matches any of the three known categories, return null. The comment "(条件に一致するプロパティが存在しない場合は、nullを返す)" confirms this is an intentional graceful degradation.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return null` // no matching property found, return null (条件に一致するプロパティが存在しない場合は、nullを返す) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `添字` (てんじ / tenji) | Japanese Field | **Index** — the row selection indicator on the screen; identifies which row in the code list / code name list is currently selected. |
| `コードリスト` (こーどりすと / koodo risuto) | Japanese Field | **Code List** — a typed list (`cd_div_list_list`) of `X33VDataTypeStringBean` elements holding service code values for discount services. Item ID: `cd_div_list`. |
| `コード名リスト` (こーどめいりすと / koodo mei risuto) | Japanese Field | **Code Name List** — a typed list (`cd_div_nm_list_list`) of `X33VDataTypeStringBean` elements holding human-readable labels for each code value. Item ID: `cd_div_nm_list`. |
| `value` | Subkey | The data value of the selected index row or code list element. |
| `enable` | Subkey | The enabled/interactive state of the selected index row. |
| `state` | Subkey | The status/state type of the selected index row (e.g., normal, disabled). |
| `"*"` | Wildcard | A special subkey value that requests the total count (size) of a code list rather than a specific element. |
| `X33VDataTypeStringBean` | Class | A typed data bean representing a single string-type data element. Used as the element type for `cd_div_list_list` and `cd_div_nm_list_list`. |
| `X33VDataTypeList` | Class | A typed list container holding `X33VDataTypeStringBean` elements. Supports indexed access and size queries. |
| `KKW01027` | Screen ID | **Discount Service Contract Registration Selection** (割引サービス契約登録選択) — the screen supported by this module. |
| `KKA15001SF` | Module | The service module containing the view beans for the KKW01027 screen. |
| `loadModelData` | Method | Dynamic data accessor — retrieves bean properties via string key/subkey addressing; used by the screen framework for data binding. |
| `CD` (cd_div) | Acronym | **Code Division** — a prefix used in item IDs (`cd_div_list`, `cd_div_nm_list`) indicating the field is associated with code/value pair lists. |
