# Business Logic — KKW00844SFBean.addListDataInstance() [48 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW00844SF.KKW00844SFBean` |
| Layer | Web/View — WebView Bean (data-type bean in the web presentation layer) |
| Module | `KKW00844SF` (Package: `eo.web.webview.KKW00844SF`) |

## 1. Role

### KKW00844SFBean.addListDataInstance()

This method is a **repeat item data instance factory** for a telecom/ISP order management screen. It generates new instances of typed data bean objects that represent repeatable (multi-row) data entries on a web view form, returning the index of the newly added element. It supports **two domain-specific repeat item categories**: the **Customer Contract Inheritance List** (顧客契約引継リスト) — used to add a new row of customer contract handover data using `KKW00844SF01DBean` instances, with a fixed initial capacity of 1 — and the **Reason for Change List** (異動理由リスト) — used to append a new row of change-reason data using `KKW00844SF02DBean` instances, with unbounded growth. The method also **delegates unknown or common-info keys** (keys starting with `"//"`) to the parent class's implementation, implementing a **routing/dispatch pattern** that centralizes bean instance creation for the view layer. Its role in the larger system is to serve as the **shared data-type bean entry point** for the screen controller to dynamically extend repeat-item data collections during form interaction, such as adding new contract lines or change reasons when a user clicks an "add row" button.

## 2. Processing Pattern (Detailed Business Logic)

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

    START --> CheckNull{key is null?}

    CheckNull -->|true| RET_NULL(["return -1"])
    CheckNull -->|false| CheckStart{key starts with //?}

    CheckStart -->|true| DELEGATE["super.addListDataInstance(key)"]
    DELEGATE --> RET_SUPER(["return super result"])

    CheckStart -->|false| CheckCust{key equals 顧客契約引継リスト?}

    CheckCust -->|true| CustNull{cust_kei_hktgi_list_list is null?}
    CustNull -->|true| InitCust["cust_kei_hktgi_list_list = new X33VDataTypeList(1); create KKW00844SF01DBean"]
    CustNull -->|false| CheckMax{size < maxElementCnt?}
    InitCust --> CheckMax

    CheckMax -->|true| CreateCustBean["KKW00844SF01DBean tmpBean = new KKW00844SF01DBean(); cust_kei_hktgi_list_list.add(tmpBean)"]
    CheckMax -->|false| ThrowMax["throw createExceptionForX31Method(ERRS_CANNOT_ADD_REPEATITEM)"]
    CreateCustBean --> RET_CUST["return cust_kei_hktgi_list_list.size() - 1"]

    CheckCust -->|false| CheckIdo{key equals 異動理由リスト?}

    CheckIdo -->|true| IdoNull{ido_rsn_list_list is null?}
    IdoNull -->|true| InitIdo["ido_rsn_list_list = new X33VDataTypeList()"]
    IdoNull -->|false| noInitIdo["skip initialization"]
    InitIdo --> noInitIdo

    noInitIdo --> CreateIdoBean["KKW00844SF02DBean tmpBean = new KKW00844SF02DBean(); ido_rsn_list_list.add(tmpBean)"]
    CreateIdoBean --> RET_IDO["return ido_rsn_list_list.size() - 1"]

    CheckIdo -->|false| RET_DEFAULT(["return -1"])
```

**CRITICAL — Constant Resolution:**

| Condition | Constant | Resolved Value | Business Meaning |
|-----------|----------|----------------|------------------|
| `key.equals("顧客契約引継リスト")` | Repeat item key | `"顧客契約引継リスト"` | Customer Contract Inheritance List — repeatable customer contract handover data rows |
| `key.equals("異動理由リスト")` | Repeat item key | `"異動理由リスト"` | Reason for Change List — repeatable change/reason data rows |
| `key.startsWith("//")` | Common info marker | `"//"` prefix | Common information bean — delegates to parent class for shared UI data |
| `X33VDataTypeList(1)` | Initial capacity | `1` | Fixed initial capacity of 1 for the customer contract inheritance list |
| `ERRS_CANNOT_ADD_REPEATITEM` | Error code | `ERRS_CANNOT_ADD_REPEATITEM` | Error constant indicating the repeat item has reached its maximum element count |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `key` | `String` | The repeat item name/identifier that determines which typed data list receives the new element. It acts as a **routing key** — the method dispatches to different branch logic based on its value. Can take values like `"顧客契約引継リスト"` (Customer Contract Inheritance List), `"異動理由リスト"` (Reason for Change List), or keys starting with `"//"` (common information beans). An unknown key results in a `-1` return. |

**Instance fields / external state read by this method:**

| No | Field Name | Type | Business Description |
|----|-----------|------|---------------------|
| 1 | `cust_kei_hktgi_list_list` | `X33VDataTypeList` | The data list holding customer contract inheritance bean instances (`KKW00844SF01DBean`). May be `null` (requiring lazy initialization). |
| 2 | `ido_rsn_list_list` | `X33VDataTypeList` | The data list holding reason-for-change bean instances (`KKW00844SF02DBean`). May be `null` (requiring lazy initialization). |

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `KKW00844SFBean.addListDataInstance(String key)` | - | - | Delegates to parent class `super.addListDataInstance(key)` for common info beans (keys starting with `"//"`) |

This method performs **local in-memory data instance creation** only. It does not invoke any SC (Service Component) or CBS (Common Business Service) layers, nor does it execute any database operations. All operations are local bean instantiation and list manipulation within the web view bean.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Component: `KKW00844SFBean.addListDataInstance()` (overloaded) | `KKW00844SFBean.addListDataInstance()` -> `KKW00844SFBean.addListDataInstance(key)` | Local bean instantiation (no SC/DB) |

**Note:** The only direct caller found in the codebase is the overloaded no-argument `addListDataInstance()` method within the same `KKW00844SFBean` class. No screen (KKSV*) or batch callers were found. The terminal operations are all local — this method creates bean instances in memory without reaching any SC/CBS or database layer.

## 6. Per-Branch Detail Blocks

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

> Guard clause: returns -1 immediately if the key is null, preventing null pointer exceptions and signaling "no matching repeat item."

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

**Block 2** — [ELSE-IF] `(key.startsWith("//"))` (L1480)

> Common information bean branch: delegates to the parent class implementation for keys that start with `"//"`, which represent shared/common UI data beans handled by the base class.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `key.startsWith("//")` // 共通情報ビーンの場合 (If common info bean) |
| 2 | CALL | `super.addListDataInstance(key)` // 共通情報ビーンリストは基底クラスで処理 (Common info bean list is processed by the base class) |
| 3 | RETURN | `return super.addListDataInstance(key);` |

**Block 3** — [ELSE-IF] `(key.equals("顧客契約引継リスト"))` (L1485)

> Customer Contract Inheritance List: initializes a fixed-capacity list with initial size 1 if null, then adds a new `KKW00844SF01DBean` instance subject to maximum element count constraints.

| # | Type | Code |
|---|------|------|
| 1 | SET | `cust_kei_hktgi_list_list = new X33VDataTypeList(1);` // リストがnullの場合、新しい空のインスタンスを生成 (If list is null, generate a new empty instance) |
| 2 | EXEC | `for(int i=0; i<1; i++)` // initialization loop |
| 3 | SET | `KKW00844SF01DBean tmpBean = new KKW00844SF01DBean();` // 初期インスタンス生成 (Generate initial instance) |
| 4 | EXEC | `cust_kei_hktgi_list_list.add(tmpBean);` |

**Block 3.1** — [ELSE-IF / nested] `(cust_kei_hktgi_list_list.getMaxElementCnt() == 0 || cust_kei_hktgi_list_list.size() < cust_kei_hktgi_list_list.getMaxElementCnt())` (L1494)

> Maximum element check: allows adding a new bean only if the list has no max element limit (0) or is below the max. [-> MAX_ELEMENT_CHECK: `getMaxElementCnt() == 0` means unlimited]

| # | Type | Code |
|---|------|------|
| 1 | SET | `KKW00844SF01DBean tmpBean = new KKW00844SF01DBean();` // データタイプビーン型で指定したデータタイプビーンのインスタンスを生成 (Generate instance of the data-type bean specified by the data-type bean type) |
| 2 | EXEC | `cust_kei_hktgi_list_list.add(tmpBean);` |
| 3 | RETURN | `return cust_kei_hktgi_list_list.size() - 1;` // 追加された要素のインデックス番号 (Index number of the added element) |

**Block 3.2** — [ELSE / nested inside Block 3] — MAX element exceeded (L1503)

> Error handling: throws a system exception when the repeat item has reached its maximum allowed element count.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `throw super.createExceptionForX31Method(ERRS_CANNOT_ADD_REPEATITEM);` // 異常通知 (Exception notification) |

**Block 4** — [ELSE-IF] `(key.equals("異動理由リスト"))` (L1508)

> Reason for Change List: lazily initializes a variable-size list if null, then unconditionally appends a new `KKW00844SF02DBean` instance. This repeat item type has no maximum element cap.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ido_rsn_list_list = new X33VDataTypeList();` // リストがnullの場合、新しい空のインスタンスを生成 (If list is null, generate a new empty instance) |
| 2 | SET | `KKW00844SF02DBean tmpBean = new KKW00844SF02DBean();` // データタイプビーン型で指定したデータタイプビーンのインスタンスを生成 (Generate instance of the data-type bean specified by the data-type bean type) |
| 3 | EXEC | `ido_rsn_list_list.add(tmpBean);` // データタイプビーン内の項目初期値設定は、各データビーン内部で定義 (Item initial value settings within the data-type bean are defined internally in each data bean) |
| 4 | RETURN | `return ido_rsn_list_list.size() - 1;` // 追加された要素のインデックス番号 (Index number of the added element) |

**Block 5** — [DEFAULT / fallthrough] (L1514)

> No matching repeat item: returns -1 when the key does not correspond to any known repeat item type.

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

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `顧客契約引継リスト` | Field (Japanese) | Customer Contract Inheritance List — a repeatable data section where customer contract handover details are entered row by row |
| `異動理由リスト` | Field (Japanese) | Reason for Change List — a repeatable data section where reasons for changes/modifications are listed row by row |
| `cust_kei_hktgi_list_list` | Field | Customer contract inheritance data list — holds `KKW00844SF01DBean` instances representing contract handover rows |
| `ido_rsn_list_list` | Field | Reason-for-change data list — holds `KKW00844SF02DBean` instances representing change reason rows |
| `ERRS_CANNOT_ADD_REPEATITEM` | Constant | Error code constant thrown when a repeat item's maximum element count has been reached and no more elements can be added |
| `X33VDataTypeList` | Type | Framework data type list — a generic dynamic list type used to hold typed bean instances in the web view layer |
| `X33VDataTypeBeanInterface` | Interface | Framework interface for data-type beans — defines the contract that typed bean instances (like `KKW00844SF01DBean`, `KKW00844SF02DBean`) must implement |
| `KKW00844SF01DBean` | Type | Data bean class for Customer Contract Inheritance List items — each instance represents one row of customer contract handover data |
| `KKW00844SF02DBean` | Type | Data bean class for Reason for Change List items — each instance represents one row of change reason data |
| `KKW00844SF` | Module | Screen/feature module — a web view component module handling customer contract-related operations (KKW prefix) |
| WebView Bean | Pattern | A view-layer data bean that holds form data state and provides data-type instance management for repeat items on a web screen |
| Repeat Item | Business term | A UI data structure that allows users to add multiple rows of the same data type (e.g., multiple contract lines, multiple change reasons) |
| `super.addListDataInstance(key)` | Method call | Parent class implementation for common/shared information beans (keys prefixed with `//`) — delegates bean creation to the base framework bean |
| `createExceptionForX31Method` | Method call | Framework exception factory — creates a typed runtime exception for screen-level errors |
| `maxElementCnt` | Field | Maximum element count — the configured upper bound on how many rows a repeat item may contain; a value of 0 means unlimited |
