# Business Logic — KKW00130SF01DBean.addListDataInstance() [32 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW00130SF.KKW00130SF01DBean` |
| Layer | View Bean (Webview / Presentation) |
| Module | `KKW00130SF` (Package: `eo.web.webview.KKW00130SF`) |

## 1. Role

### KKW00130SF01DBean.addListDataInstance()

This method is a **list data factory** for the KKW00130SF screen's view bean. Its business purpose is to provision list containers and inject new item instances into them, enabling the screen to dynamically grow tabular or multi-row data structures during request processing. The method supports two specific item categories: **Code List** (コードリスト) and **Code Name List** (コード名リスト), which are standard drop-down or lookup reference tables rendered on the screen. Each supported category maps to a dedicated instance field (`cd_list_list` or `cd_nm_list_list`) backed by `X33VDataTypeList`, the X33 framework's dynamic-typed list type. The method follows a **routing/dispatch** pattern: it inspects the string key, branches to the appropriate list, lazily initializes the list if it has not yet been created, then appends a fresh `X33VDataTypeStringBean` instance (a string-typed data bean from the X33 framework) and returns the index of the newly added element. Its role in the larger system is that of a **shared screen utility** — it is defined in a concrete DBean subclass and overridden by its parent bean (`KKW00130SFBean`) to add further item categories (e.g., 事務手数料料 / Transaction Fee), forming an extensible chain where each bean in the hierarchy adds its own supported keys before delegating to `super.addListDataInstance(key)`.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addListDataInstance(String key)"])

    START --> CN{"key == null?"}

    CN -->|true| RN["Return -1"]
    RN --> END(["End"])

    CN -->|false| CDL{"key is code list?"}

    CDL -->|true| CNL{"cd_list_list is null?"}

    CDL -->|false| CDN{"key is code name list?"}

    CDN -->|true| CNML{"cd_nm_list_list is null?"}

    CDN -->|false| RD["Return -1"]
    RD --> END

    CNL -->|true| ICL["cd_list_list = new X33VDataTypeList()"]
    ICL --> NTB1["tmpBean = new X33VDataTypeStringBean()"]
    NTB1 --> ACL["cd_list_list.add(tmpBean)"]
    ACL --> RL["Return cd_list_list.size() - 1"]
    RL --> END

    CNL -->|false| NTB1A["tmpBean = new X33VDataTypeStringBean()"]
    NTB1A --> ACLA["cd_list_list.add(tmpBean)"]
    ACLA --> RLA["Return cd_list_list.size() - 1"]
    RLA --> END

    CNML -->|true| ICNL["cd_nm_list_list = new X33VDataTypeList()"]
    ICNL --> NTB2["tmpBean = new X33VDataTypeStringBean()"]
    NTB2 --> ACNL["cd_nm_list_list.add(tmpBean)"]
    ACNL --> RNL["Return cd_nm_list_list.size() - 1"]
    RNL --> END

    CNML -->|false| NTB2A["tmpBean = new X33VDataTypeStringBean()"]
    NTB2A --> ACNLA["cd_nm_list_list.add(tmpBean)"]
    ACNLA --> RNLA["Return cd_nm_list_list.size() - 1"]
    RNLA --> END
```

**Branch Summary:**

| Branch | Condition | Business Meaning |
|--------|-----------|------------------|
| Branch 1 | `key == null` | Null key rejected — returns index -1 |
| Branch 2 | `key.equals("コードリスト")` | Provision the **Code List** container, create a new `X33VDataTypeStringBean`, append it, return its index |
| Branch 3 | `key.equals("コード名リスト")` | Provision the **Code Name List** container, create a new `X33VDataTypeStringBean`, append it, return its index |
| Branch 4 | Unrecognized key | No matching item — returns index -1 |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `key` | `String` | The item identifier that determines which list container is targeted. Acceptable values are the Japanese strings `"コードリスト"` (Code List — a list of system codes/drop-down values) and `"コード名リスト"` (Code Name List — a list of human-readable code descriptions). Any other value or `null` results in a -1 return. |

**Instance fields read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `cd_list_list` | `X33VDataTypeList` | The code list container — stores a sequence of `X33VDataTypeStringBean` instances representing code entries |
| `cd_nm_list_list` | `X33VDataTypeList` | The code name list container — stores a sequence of `X33VDataTypeStringBean` instances representing code description entries |

## 4. CRUD Operations / Called Services

This method performs **pure in-memory list management**. It does not call any service components (SC), CBS, or data access methods. All operations are local bean field manipulations.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| *(none)* | — | — | — | No database or service calls. This is a view-layer bean method that manages local list data structures only. |

**Method calls within this method:**

| Call | Description |
|------|-------------|
| `cd_list_list = new X33VDataTypeList()` | Instantiate a new empty dynamic-typed list (lazy initialization) |
| `cd_nm_list_list = new X33VDataTypeList()` | Instantiate a new empty dynamic-typed list (lazy initialization) |
| `new X33VDataTypeStringBean()` | Instantiate a string-typed data bean (item template) |
| `cd_list_list.add(tmpBean)` | Append the new bean to the code list |
| `cd_nm_list_list.add(tmpBean)` | Append the new bean to the code name list |
| `cd_list_list.size()` | Read current list size to compute the new element's index |
| `cd_nm_list_list.size()` | Read current list size to compute the new element's index |

## 5. Dependency Trace

The `addListDataInstance` method in `KKW00130SF01DBean` is a **protected/shared utility** called by its parent bean and sibling DBean classes within the same screen module. Below are the known callers that reference this method name within the `KKW00130SF` module and related screens.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Bean: KKW00130SF02DBean | `KKW00130SF02DBean.addListDataInstance(key)` — overrides, does not call super | *(local)* |
| 2 | Bean: KKW00130SF12DBean | `KKW00130SF12DBean.addListDataInstance(key)` — overrides, does not call super | *(local)* |
| 3 | Bean: KKW00130SFBean | `KKW00130SFBean.addListDataInstance(key)` — calls `super.addListDataInstance(key)` → KKW00130SF01DBean | *(local)* |
| 4 | Screen: FUW00901SF | `FUW00901SFBean.addListDataInstance(key)` — calls `super.addListDataInstance(key)` → KKW00130SF01DBean | *(local)* |
| 5 | Screen: FUW00907SF | `FUW00907SFBean.addListDataInstance(key)` — calls `super.addListDataInstance(key)` → KKW00130SF01DBean | *(local)* |
| 6 | Screen: FUW00912SF | `FUW00912SF01DBean.addListDataInstance(key)` — overrides, does not call super | *(local)* |
| 7 | Screen: FUW00916SF | `FUW00916SFBean.addListDataInstance(key)` — calls `super.addListDataInstance(key)` → KKW00130SF01DBean | *(local)* |
| 8 | Screen: FUW00917SF | `FUW00917SFBean.addListDataInstance(key)` — calls `super.addListDataInstance(key)` → KKW00130SF01DBean | *(local)* |
| 9 | Screen: FUW00919SF | `FUW00919SFBean.addListDataInstance(key)` — calls `super.addListDataInstance(key)` → KKW00130SF01DBean | *(local)* |
| 10 | Screen: FUW00926SF | `FUW00926SFBean.addListDataInstance(key)` — calls `super.addListDataInstance(key)` → KKW00130SF01DBean | *(local)* |
| 11 | Screen: FUW00927SF | `FUW00927SFBean.addListDataInstance(key)` — calls `super.addListDataInstance(key)` → KKW00130SF01DBean | *(local)* |
| 12 | Screen: FUW00931SF | `FUW00931SFBean.addListDataInstance(key)` — calls `super.addListDataInstance(key)` → KKW00130SF01DBean | *(local)* |
| 13 | Screen: FUW00946SF | `FUW00946SFBean.addListDataInstance(key)` — calls `super.addListDataInstance(key)` → KKW00130SF01DBean | *(local)* |
| 14 | Screen: FUW00947SF | `FUW00947SFBean.addListDataInstance(key)` — calls `super.addListDataInstance(key)` → KKW00130SF01DBean | *(local)* |
| 15 | Screen: FUW00957SF | `FUW00957SFBean.addListDataInstance(key)` — calls `super.addListDataInstance(key)` → KKW00130SF01DBean | *(local)* |

**Notes on call chain:**
- Many FUW* screen beans **override** `addListDataInstance` and delegate via `return super.addListDataInstance(key)`, forming an inheritance chain that ultimately reaches this base implementation.
- Some DBean subclasses (e.g., `KKW00130SF02DBean`, `KKW00130SF12DBean`, `FUW00912SF01DBean`) provide **independent implementations** that do not call this base method.
- This method is a **leaf in the inheritance chain** — it has no further downstream service calls.

## 6. Per-Branch Detail Blocks

**Block 1** — IF `(key == null)` (L422)

> Null guard: immediately reject null keys to prevent NullPointerException. Returns -1 to signal "no item added."

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (key == null)` //  nullの場合、-1で返す — "If null, return -1" |
| 2 | RETURN | `return -1;` |

---

**Block 2** — ELSE-IF `(key.equals("コードリスト"))` [Constant: "コードリスト" = "Code List"] (L427)

> Branch for the **Code List** item. The Japanese comment states: 配列項目 "コードリスト" (String型。項目ID:cd_list) — "Array item 'Code List' (String type. Item ID: cd_list)". This provisions the list container that holds system code values for drop-down or lookup rendering on the screen.

**Block 2.1** — IF `(cd_list_list == null)` — null check (L428)

> If the list container has not yet been initialized, create a new empty `X33VDataTypeList`. The comment states: リストがnullの場合、新しい空のインスタンスを生成 — "If the list is null, generate a new empty instance."

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (cd_list_list == null)` // リストがnullの場合、新しい空のインスタンスを生成 — "If list is null, generate new empty instance" |
| 2 | SET | `cd_list_list = new X33VDataTypeList()` |

**Block 2.2** — Create new bean instance (L431)

> Creates a `X33VDataTypeStringBean` as the template for a new string-typed data item. The comment states: データタイプビューン型で指定したデータタイプのビューンのインスタンスを生成する。なお、データタイプの項目初期値設定は、各データビューン内で定義 — "Generate an instance of the specified data type bean. Note: initial value settings for data type fields are defined within each data bean."

| # | Type | Code |
|---|------|------|
| 1 | SET | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean()` // データタイプビーン型のインスタンスを生成 — "Generate instance of data type bean" |

**Block 2.3** — Add to list (L433)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `cd_list_list.add(tmpBean)` |

**Block 2.4** — Return index (L434)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return cd_list_list.size() - 1;` // 追加された要素のインデックス番号 — "Index number of the added element" |

---

**Block 3** — ELSE-IF `(key.equals("コード名リスト"))` [Constant: "コード名リスト" = "Code Name List"] (L439)

> Branch for the **Code Name List** item. The Japanese comment states: 配列項目 "コード名リスト" (String型。項目ID:cd_nm_list) — "Array item 'Code Name List' (String type. Item ID: cd_nm_list)". This provisions the list container that holds human-readable code descriptions for screen rendering.

**Block 3.1** — IF `(cd_nm_list_list == null)` — null check (L440)

> If the list container has not yet been initialized, create a new empty `X33VDataTypeList`.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (cd_nm_list_list == null)` // リストがnullの場合、新しい空のインスタンスを生成 — "If list is null, generate new empty instance" |
| 2 | SET | `cd_nm_list_list = new X33VDataTypeList()` |

**Block 3.2** — Create new bean instance (L443)

> Creates a `X33VDataTypeStringBean` identical to Block 2.2 — same template for string-typed data items.

| # | Type | Code |
|---|------|------|
| 1 | SET | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean()` // データタイプビーン型のインスタンスを生成 — "Generate instance of data type bean" |

**Block 3.3** — Add to list (L445)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `cd_nm_list_list.add(tmpBean)` |

**Block 3.4** — Return index (L446)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return cd_nm_list_list.size() - 1;` // 追加された要素のインデックス番号 — "Index number of the added element" |

---

**Block 4** — ELSE (default, unrecognized key) (L448)

> Catch-all for any key that does not match a known item. Returns -1 to signal "no matching item found." The comment states: 該当する項目がない場合、-1を返す — "If no matching item, return -1."

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return -1;` // 該当する項目がない場合、-1を返す — "If no matching item, return -1" |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `コードリスト` | Field/Key | Code List — Japanese string key that identifies the code list data item. Maps to the `cd_list_list` field. Holds system-defined code values (e.g., status codes, type codes) rendered as drop-down options on the screen. |
| `コード名リスト` | Field/Key | Code Name List — Japanese string key that identifies the code name list data item. Maps to the `cd_nm_list_list` field. Holds human-readable descriptions corresponding to the system codes in the code list. |
| `cd_list_list` | Field | Code List List — Internal instance field of type `X33VDataTypeList`. Stores a sequence of `X33VDataTypeStringBean` instances representing code entries for the current screen. |
| `cd_nm_list_list` | Field | Code Name List List — Internal instance field of type `X33VDataTypeList`. Stores a sequence of `X33VDataTypeStringBean` instances representing code name entries for the current screen. |
| `X33VDataTypeList` | Type | X33 Framework dynamic-typed list. A generic list container that can hold any data bean type. Part of the X33 web framework's view bean infrastructure. |
| `X33VDataTypeStringBean` | Type | X33 Framework string-typed data bean. A single-item container for string data. Each instance represents one row/entry in a list data item. |
| DBean | Pattern | Data Bean — A screen-level view bean that manages the data state for a single screen (D = Display). Extends base bean classes and adds screen-specific list items. |
| KKW00130SF | Module | Screen module identifier. Part of the KKW series (web screen modules). Manages a screen related to code/code-name list data processing. |
| インデックス番号 | Term | Index number — the zero-based position of the newly added element in the list. Computed as `list.size() - 1` after the `add()` call. |
| 項目名 | Term | Item name — the business name/identifier of a data field on the screen. Used as the `key` parameter to route to the correct list handler. |
| 配列項目 | Term | Array item — a multi-valued data field on the screen that can hold zero or more entries (rows). Each entry is represented by a data bean instance. |
