---

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

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW00816SF.KKW00816SF01DBean` |
| Layer | Web View Bean (View / Data Bind layer) |
| Module | `KKW00816SF` (Package: `eo.web.webview.KKW00816SF`) |

## 1. Role

### KKW00816SF01DBean.addListDataInstance()

This method is a **data instance factory** for dynamic list-bound UI components in the KKW00816SF (Service Change / Modification) screen. It generates and appends new element instances into typed data-list fields based on a string key that identifies which list item type is being created. The method follows the **Factory Method** and **Strategy Dispatch** patterns: it dispatches instantiation logic based on the business key name, and delegates to the parent class (`X33VViewBaseBean`) for generic/common information views that are identified by the `"//"` prefix convention.

This method plays the role of a **shared utility within the view bean layer**. It is inherited by subclasses across multiple webview screens (e.g., `KKW00816SFBean` delegates to it via `super.addListDataInstance(key)`). In the broader system, it bridges the UI's request to dynamically add a row or element in a repeating list section — specifically for the "異動理由コード" (Migration Reason Code) field in this implementation. The return value (`int`) is the index of the newly appended element, enabling the UI layer to immediately reference or configure the new row.

The method handles two branches: (1) the **異動理由コード (Migration Reason Code)** branch — creates a new `X33VDataTypeStringBean`, appends it to `ido_rsn_cd_list`, and returns the new element's index; (2) the **fallback / null** branch — returns `-1` to signal the key is either `null` or does not match any recognized list item type.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addListDataInstance key"])
    CHECK_NULL{key is null}
    CHECK_ISDN{key equals 異動理由コード}
    INIT_LIST["ido_rsn_cd_list = new X33VDataTypeList()"]
    CREATE_BEAN["tmpBean = new X33VDataTypeStringBean()"]
    ADD_BEAN["ido_rsn_cd_list add tmpBean"]
    RETURN_INDEX["return ido_rsn_cd_list size minus 1"]
    RETURN_INVALID["return -1"]

    START --> CHECK_NULL
    CHECK_NULL --> |true| RETURN_INVALID
    CHECK_NULL --> |false| CHECK_ISDN
    CHECK_ISDN --> |true| INIT_LIST
    CHECK_ISDN --> |false| RETURN_INVALID
    INIT_LIST --> CREATE_BEAN
    CREATE_BEAN --> ADD_BEAN
    ADD_BEAN --> RETURN_INDEX
```

**Branch descriptions:**

| Branch | Condition | Action |
|--------|-----------|--------|
| **Branch A** | `key == null` | Returns `-1` immediately — null keys are rejected to avoid `NullPointerException`. |
| **Branch B** | `key.equals("異動理由コード")` (Migration Reason Code) | Initializes `ido_rsn_cd_list` if it is `null`, creates a new `X33VDataTypeStringBean`, appends it, and returns the new element's index. |
| **Branch C** | `key` is any unrecognized value | Falls through to the end and returns `-1` — no matching list type found. |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `key` | `String` | The **item name** (項目名) that identifies which repeating list field instance should be created. It acts as a dispatch key. When its value is `"異動理由コード"` (Migration Reason Code), the method creates a new string-type bean in the migration reason code list. Otherwise, it returns `-1` to indicate no matching list type. |

**Instance fields read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `ido_rsn_cd_list` | `X33VDataTypeList` | The dynamic list holding migration reason code instances (異動理由コード). If `null`, the method initializes it before adding elements. |

## 4. CRUD Operations / Called Services

This method does **not** perform any database operations or SC/CBS calls. It operates purely in the **view bean layer**, creating data-type beans and managing in-memory list structures.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| — | (none) | — | — | This method is a pure view-layer factory. It instantiates `X33VDataTypeList` and `X33VDataTypeStringBean` objects but performs no I/O, database access, or service component calls. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Bean:KKW00816SFBean | `KKW00816SFBean.addListDataInstance(key)` -> `super.addListDataInstance(key)` -> `KKW00816SF01DBean.addListDataInstance(key)` | N/A (pure view bean, no terminal operations) |
| 2 | Bean:KKW00816SF01DBean (self) | Direct invocation — this is the defining class | N/A (pure view bean, no terminal operations) |

**Notes:**
- `KKW00816SFBean` (parent bean) overrides `addListDataInstance` with broader dispatch logic (including a `"//"` prefix branch for common information views) and delegates to `super.addListDataInstance(key)` for unrecognized keys.
- No other screens or batch processes directly call `KKW00816SF01DBean.addListDataInstance` — it is invoked only through the parent bean's override chain or internally via subclassing.

## 6. Per-Branch Detail Blocks

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

> **Description:** Guard clause — rejects `null` keys immediately to prevent `NullPointerException` on the subsequent `equals()` call. This matches the Javadoc: "nullの場合、-1で返す" (If null, returns -1).

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return -1;` //  nullの場合、-1で返す (If null, return -1) |

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

> **Description:** Dispatches instantiation for the "異動理由コード" (Migration Reason Code) array field. This field is a repeating list element whose item ID is `ido_rsn_cd`. The comment states "各繰り返し項目の固定要素数指定への処理を行う" (Performs processing for fixed element count specification of each repeating item).

**Block 2.1** — [IF] `(ido_rsn_cd_list == null)` (L501)

> **Description:** If the migration reason code list has not been initialized, create a new empty `X33VDataTypeList` instance. The comment states "リストがnullの場合、新しい空のインスタンスを生成する" (If the list is null, generate a new empty instance).

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

**Block 2.2** — [Sequential] (L504)

> **Description:** Creates a new string-type data view bean instance and appends it to the migration reason code list. The comment states "データタイプビューン型で指定したデータタイプビューンのインスタンスを生成する" (Generate an instance of the data type view bean specified by the data type).

| # | Type | Code |
|---|------|------|
| 1 | SET | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean();` // データタイプビューン型で指定したデータタイプビューンのインスタンスを生成する (Generate instance of the specified data type view bean). なお、データタイプビューンの項目初期値設定は、各データビューン内で定義 (Note: initial value settings for data type view beans are defined within each data bean itself) |
| 2 | EXEC | `ido_rsn_cd_list.add(tmpBean);` // Appends the new bean to the list |
| 3 | RETURN | `return ido_rsn_cd_list.size() - 1;` // Returns the index of the newly added element |

**Block 3** — [ELSE / FALL-THROUGH] (L513)

> **Description:** The fallback path — the `key` parameter does not match any recognized list item type ("異動理由コード"). Returns `-1` to indicate no matching item exists. 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 |
|------|------|------------------|
| `ido_rsn_cd` | Field | Migration reason code — the reason code for a service change/migration event. Stored in a list (`ido_rsn_cd_list`) of `X33VDataTypeStringBean` instances. |
| 異動理由コード | Field (Japanese) | Migration Reason Code — the reason a service is being changed, migrated, or modified. Used as the dispatch key `key` value to trigger list instance creation. |
| KKW00816SF | Module | Service Change / Modification screen module — a webview module for handling service contract changes in the K-Opticom telecom ordering system. |
| DBean | Type | Data Bean (View Bean) — a view-layer data binding class implementing `X33VDataTypeBeanInterface` and `X33VListedBeanInterface` from the Fujitsu Futurity X33 framework. |
| X33VDataTypeList | Type | A generic dynamic list container in the X33 view framework, capable of holding typed bean instances. |
| X33VDataTypeStringBean | Type | A typed view bean holding a single `String` value, used as the element type for `ido_rsn_cd_list`. |
| X33SException | Type | X33 framework exception class for service-level errors thrown by view bean methods. |
| 顧客契約引継リスト | Field (Japanese) | Customer Contract Succession List — a repeating list field in the related `KKW00816SFBean` (parent bean) for handling customer contract handover entries. |
| X33VViewBaseBean | Type | Base class in the Fujitsu Futurity X33 web framework that provides common data binding and view management functionality. |
| X33VListedBeanInterface | Interface | X33 framework interface for beans that manage repeating list data (e.g., adding/removing rows in a table). |
| 繰り返し項目 | Field (Japanese) | Repeating item — a UI concept for table rows or list entries that can appear multiple times. |
| 固定要素数指定 | Field (Japanese) | Fixed element count specification — the ability to pre-allocate a list with a fixed number of initial elements (used in the parent bean for `cust_kei_hktgi_list`). |

---
