# Business Logic — KKW00846SF01DBean.addListDataInstance() [21 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKA18001SF.KKW00846SF01DBean` |
| Layer | Presentation (Webview / Data Bean) |
| Module | `KKA18001SF` (Package: `eo.web.webview.KKA18001SF`) |

## 1. Role

### KKW00846SF01DBean.addListDataInstance()

This method is a **factory helper** that creates and registers typed data instances within the webview data bean's dynamic list structures. It serves as the primary mechanism for building per-field list data on screen data beans used by multiple web screens in the telecom operations system. When a screen needs to manage repeatable list items (such as multiple disoperation reason codes), it calls `addListDataInstance()` with a field-key to instruct the bean to instantiate the appropriate data type bean and append it to the corresponding list. The method implements a **key-based routing/dispatch pattern** — it inspects the incoming string key and branches to the correct list-initialization and bean-creation branch based on the field name. Its **role in the larger system** is that of a shared utility embedded in every screen data bean that supports list-type fields, allowing screens to dynamically populate their model data before rendering. Currently, only the "Disoperation reason code" (動理由コード) key is handled, returning the index of the newly appended element so the caller can reference it later. The method returns -1 when the key is null, when no matching field exists, or when the key does not correspond to a recognized list item type.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addListDataInstance key"]) --> CHECK_NULL{"key == null"}
    CHECK_NULL --> |true| RET_NULL["Return -1"]
    CHECK_NULL --> |false| CHECK_KEY{"key equals '動理由コード'"}
    CHECK_KEY --> |true| CHECK_LIST{"ido_rsn_cd_list == null"}
    CHECK_KEY --> |false| RET_DEFAULT["Return -1"]
    CHECK_LIST --> |true| INIT_LIST["ido_rsn_cd_list = new X33VDataTypeList"]
    CHECK_LIST --> |false| CREATE_BEAN["tmpBean = new X33VDataTypeStringBean"]
    INIT_LIST --> CREATE_BEAN
    CREATE_BEAN --> ADD["ido_rsn_cd_list.add tmpBean"]
    ADD --> RET_INDEX["Return ido_rsn_cd_list.size minus 1"]
    RET_NULL --> END(["End"])
    RET_DEFAULT --> END
    RET_INDEX --> END
```

**Block descriptions:**

| Step | Description |
|------|-------------|
| CHECK_NULL | Null guard on the key parameter — returns -1 if no field name was provided (null check) |
| CHECK_KEY | Key dispatch — checks if the key matches "動理由コード" (Disoperation reason code) |
| CHECK_LIST | Lazy initialization — if the target list does not exist yet, creates a new X33VDataTypeList instance |
| CREATE_BEAN | Instantiates an X33VDataTypeStringBean (string data type bean) for the field |
| ADD | Appends the new bean to the target list, creating a new list element |
| RET_INDEX | Returns the 0-based index of the newly added element (size - 1) |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `key` | `String` | The field name (item name) that identifies which list data type to instantiate. Currently expects the Japanese string "動理由コード" (Disoperation reason code) to trigger creation of a disoperation reason code list entry. If the key does not match any recognized field, the method returns -1. |

**Instance fields read by this method:**

| Field | Type | Access Description |
|-------|------|-------------------|
| `ido_rsn_cd_list` | `X33VDataTypeList` | The disoperation reason code list — checked for null to determine if initialization is needed |

## 4. CRUD Operations / Called Services

This method performs **no database or service component calls**. It operates entirely within the webview data bean, creating in-memory data type beans and adding them to list collections. There are no SC (Service Component) or CBS calls.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| — | — | — | — | No database or service layer interaction. This method is purely in-memory bean instantiation within the presentation tier. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKA18001 | `KKA18001SF01DBean.addListDataInstance` → `KKW00846SF01DBean.addListDataInstance` (direct override) | No terminal CRUD |
| 2 | Screen:FUW00901 | `FUW00901SFBean.addListDataInstance` → `super.addListDataInstance(key)` | No terminal CRUD |
| 3 | Screen:FUW00907 | `FUW00907SFBean.addListDataInstance` → `super.addListDataInstance(key)` | No terminal CRUD |
| 4 | Screen:FUW00917 | `FUW00917SFBean.addListDataInstance` → `super.addListDataInstance(key)` | No terminal CRUD |
| 5 | Screen:FUW00919 | `FUW00919SFBean.addListDataInstance` → `super.addListDataInstance(key)` | No terminal CRUD |
| 6 | Screen:FUW00927 | `FUW00927SFBean.addListDataInstance` → `super.addListDataInstance(key)` | No terminal CRUD |
| 7 | Screen:FUW00931 | `FUW00931SFBean.addListDataInstance` → `super.addListDataInstance(key)` | No terminal CRUD |
| 8 | Screen:FUW00957 | `FUW00957SFBean.addListDataInstance` → `super.addListDataInstance(key)` | No terminal CRUD |
| 9 | Screen:FUW00959 | `FUW00959SFBean.addListDataInstance` → `super.addListDataInstance(key)` | No terminal CRUD |
| 10 | Screen:FUW00964 | `FUW00964SFBean.addListDataInstance` → `super.addListDataInstance(key)` | No terminal CRUD |
| 11 | Screen:FUW00912 | `FUW00912SF01DBean.addListDataInstance` (direct override) | No terminal CRUD |
| 12 | Screen:FUW00964 variants | `FUW00964SF01DBean`, `FUW00964SF04DBean`, `FUW00964SF07DBean`, `FUW00964SF10DBean` (all direct overrides) | No terminal CRUD |

**Note:** Many caller classes delegate via `super.addListDataInstance(key)`, inheriting this base implementation. Other callers override the method with their own logic. The method itself performs no downstream service or database calls — its terminal effect is purely in-memory bean creation.

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `(key == null)` (L554)

> Null check: If the key parameter is null, return -1 immediately. This prevents NullPointerException on the subsequent string comparison and signals an invalid or missing field name.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return -1;` // null check — return -1 if key is null (nullの場合、-1で返す) |

**Block 2** — [ELSE-IF] `(key.equals("動理由コード"))` (L558)

> Key dispatch: The key matches "動理由コード" (Disoperation reason code). This is the only recognized field key. The method proceeds to create or initialize the disoperation reason code list and add a new string-type data bean to it.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (ido_rsn_cd_list == null)` // List is null — generate a new empty instance (リストがnullの場合、新しい空のインスタンスを生成する) |
| 2 | SET | `ido_rsn_cd_list = new X33VDataTypeList();` // Lazy initialization of disoperation reason code list (動理由コードリストの遅延初期化) |
| 3 | SET | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean();` // Instantiate the specified data type bean as a data type bean instance (指定したデータタイプビューンのインスタンスを生成する。データタイプビューンの項目初期値設定は、各データビューン内で定義) |
| 4 | CALL | `ido_rsn_cd_list.add(tmpBean);` // Add the new bean to the list |
| 5 | RETURN | `return ido_rsn_cd_list.size() - 1;` // Return the 0-based index of the newly added element (追加された要素のインデックス番号) |

**Block 3** — [ELSE-IF] `(key.equals("動理由コード"))` — inner [IF-ELSE] (L559)

> List null check: Within the "Disoperation reason code" branch, check if the list itself has been initialized.

**Block 3.1** — [IF] `(ido_rsn_cd_list == null)` (L559)

| # | Type | Code |
|---|------|------|
| 1 | SET | `ido_rsn_cd_list = new X33VDataTypeList();` // Create new empty list if null (リストがnullの場合、新しい空のインスタンスを生成する) |

**Block 3.2** — [implicit fall-through after Block 3.1] (L562)

> If list was just initialized (or was non-null), proceed to create the bean and add it.

| # | Type | Code |
|---|------|------|
| 1 | SET | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean();` // Generate instance of the specified data type bean (指定したデータタイプビューンのインスタンスを生成する) |
| 2 | CALL | `ido_rsn_cd_list.add(tmpBean);` // Add bean to the list |
| 3 | RETURN | `return ido_rsn_cd_list.size() - 1;` // Return index of added element (追加された要素のインデックス番号) |

**Block 4** — [IMPLICIT ELSE / FALL-THROUGH] No matching key (L571)

> If the key does not match "動理由コード" (Disoperation reason code), return -1. This is the default "no matching field" case.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return -1;` // No matching field — return -1 (該当する項目がない場合、-1を返す) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `動理由コード` (どうりゆうコード) | Field | Disoperation reason code — a Japanese field key used to identify the disoperation (service interruption/change) reason list item. When passed as `key`, triggers creation of a string-type bean in the disoperation reason code list. |
| `ido_rsn_cd` | Field | Abbreviated English name for "Disoperation reason code" — the internal field reference corresponding to the Japanese key "動理由コード". Used as the list member's item ID. |
| `ido_rsn_cd_list` | Field | Disoperation reason code list — the `X33VDataTypeList` that stores a collection of `X33VDataTypeStringBean` instances, each representing a single disoperation reason code entry. Lazy-initialized on first call. |
| `X33VDataTypeList` | Type | A dynamic list container for view-layer data type beans. Acts as the backing collection for list-type form fields. |
| `X33VDataTypeStringBean` | Type | A string data type bean — the simplest typed data container, used for single-string list elements. Its internal item initial values are defined within the bean class itself. |
| KKA18001SF | Module | A web screen module in the telecom operations system. KKA screens typically handle service contract and order management operations. |
| DBean | Type suffix | Data Bean — a view-layer data carrier that holds form input data, list data, and validation state for a specific screen. |
| Super call | Pattern | Many FUW* screen data beans extend KKA18001SF beans and call `super.addListDataInstance(key)` to delegate the base list item creation to this parent implementation. |
