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

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKA15001SF.KKW01027SF02DBean` |
| Layer | Webview / DBean (Data Binding / View Support) |
| Module | `KKA15001SF` (Package: `eo.web.webview.KKA15001SF`) |

## 1. Role

### KKW01027SF02DBean.addListDataInstance()

This method is a **polymorphic factory** that creates and appends new typed data binding instances into one of two internal `X33VDataTypeList` collections, based on a string key. It serves as a shared data-binding utility used throughout the webview layer (DBean hierarchy) to dynamically grow list-based form fields without hardcoding list initialization in screen controllers.

The method implements a **routing/dispatch pattern** over two service-type categories: **Code List** (コードリスト) and **Code Name List** (コード名リスト). When the key matches "コードリスト", a new `X33VDataTypeStringBean` instance is appended to `cd_div_list_list`, which holds raw code values for dropdown or radio group display. When the key matches "コード名リスト", a new `X33VDataTypeStringBean` is appended to `cd_div_nm_list_list`, which holds human-readable code descriptions.

Its **role in the larger system** is foundational: every screen within the `KKA15001SF` module (and its parent DBean class) uses this method to support dynamically growing table rows or repeating form sections — for example, adding a new discount code row to a service contract summary. The method is also inherited and overridden by dozens of subclasses across the webview layer (`FUW009xxSF*`, `KKW01027SF*`), making it a core component of the framework's dynamic list data binding mechanism.

If `key` is null or matches neither branch, the method returns `-1` to signal that no recognized list type was requested.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addListDataInstance(String key)"])
    COND_NULL{"key == null"}
    COND_CODELIST{"key equals \"コードリスト\""}
    COND_CODENAME{"key equals \"コード名リスト\""}
    INIT_CODELIST["cd_div_list_list = new X33VDataTypeList()"]
    CREATE_CODELIST["tmpBean = new X33VDataTypeStringBean()"]
    ADD_CODELIST["cd_div_list_list.add(tmpBean)"]
    RETURN_CODELIST["return cd_div_list_list.size() - 1"]
    INIT_CODENAME["cd_div_nm_list_list = new X33VDataTypeList()"]
    CREATE_CODENAME["tmpBean = new X33VDataTypeStringBean()"]
    ADD_CODENAME["cd_div_nm_list_list.add(tmpBean)"]
    RETURN_CODENAME["return cd_div_nm_list_list.size() - 1"]
    RETURN_DEFAULT["return -1"]
    END(["Return / Next"])

    START --> COND_NULL
    COND_NULL -->|true| RETURN_DEFAULT
    COND_NULL -->|false| COND_CODELIST
    COND_CODELIST -->|true| INIT_CODELIST
    INIT_CODELIST --> CREATE_CODELIST
    CREATE_CODELIST --> ADD_CODELIST
    ADD_CODELIST --> RETURN_CODELIST
    RETURN_CODELIST --> END
    COND_CODELIST -->|false| COND_CODENAME
    COND_CODENAME -->|true| INIT_CODENAME
    INIT_CODENAME --> CREATE_CODENAME
    CREATE_CODENAME --> ADD_CODENAME
    ADD_CODENAME --> RETURN_CODENAME
    RETURN_CODENAME --> END
    COND_CODENAME -->|false| RETURN_DEFAULT
    RETURN_DEFAULT --> END
```

**Branch Summary:**

| Branch | Condition | Business Action |
|--------|-----------|-----------------|
| Null Guard | `key == null` | Returns `-1` immediately; no state mutation |
| Code List | `key == "コードリスト"` | Creates `X33VDataTypeStringBean`, appends to `cd_div_list_list`, returns new index |
| Code Name List | `key == "コード名リスト"` | Creates `X33VDataTypeStringBean`, appends to `cd_div_nm_list_list`, returns new index |
| Default | Neither matched | Returns `-1`; no state mutation |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `key` | `String` | A discriminant string that determines which internal list collection receives a new element. It corresponds to a specific form field category on the web screen. Value must be one of: `"コードリスト"` (Code List — holds raw code values for display components) or `"コード名リスト"` (Code Name List — holds human-readable code descriptions). Any other value or `null` results in a `-1` return with no side effects. |

**Instance Fields Read/Written:**

| Field | Access | Business Description |
|-------|--------|---------------------|
| `cd_div_list_list` | Read/Write | Internal list collection that stores code value strings for display (e.g., dropdown options). Initialized to `null` at declaration; lazily created on first add. |
| `cd_div_nm_list_list` | Read/Write | Internal list collection that stores code name strings for display (e.g., label descriptions). Initialized to `null` at declaration; lazily created on first add. |

## 4. CRUD Operations / Called Services

This method performs **pure in-memory list mutation** — no database operations, no remote service calls, and no SC/CBS layer interaction. All operations are in-memory array/list modifications managed by the view data binding framework.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| — | `cd_div_list_list.add(tmpBean)` | — | — (In-memory: `X33VDataTypeList`) | Appends a new string-typed bean instance to the code list collection. |
| — | `cd_div_nm_list_list.add(tmpBean)` | — | — (In-memory: `X33VDataTypeList`) | Appends a new string-typed bean instance to the code name list collection. |

**Classification:** These are **in-memory data structure operations** (list append), not database CRUD. No SC Code, CBS Code, or Entity/DB table is involved.

## 5. Dependency Trace

The `addListDataInstance` method is called by the **DBean hierarchy itself** through inheritance — subclasses in the `FUW009xxSF` and `KKW01027SF` packages call `super.addListDataInstance(key)` to extend the base behavior with additional key branches, or override it entirely. Direct callers that invoke this method on a `KKW01027SF02DBean` instance were not found in the caller search, indicating this method is primarily invoked via polymorphic dispatch from the parent `KKW01027SFBean` or related screen mappers.

**Known Caller Classes (via inheritance / `super` calls):**

| # | Caller (Screen/Bean) | Call Chain (Full Path to this Method) | Terminal (In-Memory Operation) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `FUW00912SF01DBean` | `super.addListDataInstance(key)` | In-memory: `cd_div_list_list.add(...)` |
| 2 | `FUW00912SFBean` | `super.addListDataInstance(key)` | In-memory: `cd_div_list_list.add(...)` |
| 3 | `FUW00926SFBean` | `super.addListDataInstance(key)` | In-memory: `cd_div_list_list.add(...)` |
| 4 | `FUW00959SFBean` | `super.addListDataInstance(key)` | In-memory: `cd_div_list_list.add(...)` |
| 5 | `FUW00964SF10DBean` | `super.addListDataInstance(key)` (override) | In-memory: `cd_div_list_list.add(...)` |
| 6 | `FUW00964SFBean` | `super.addListDataInstance(key)` | In-memory: `cd_div_list_list.add(...)` |
| 7 | `FUW00964SF04DBean` | `super.addListDataInstance(key)` (override) | In-memory: `cd_div_list_list.add(...)` |
| 8 | `FUW00964SF07DBean` | `super.addListDataInstance(key)` (override) | In-memory: `cd_div_list_list.add(...)` |
| 9 | `FUW00964SF01DBean` | `super.addListDataInstance(key)` (override) | In-memory: `cd_div_list_list.add(...)` |
| 10 | `FUW00927SFBean` | `super.addListDataInstance(key)` | In-memory: `cd_div_list_list.add(...)` |
| 11 | `FUW00901SFBean` | `super.addListDataInstance(key)` | In-memory: `cd_div_list_list.add(...)` |
| 12 | `FUW00919SFBean` | `super.addListDataInstance(key)` | In-memory: `cd_div_list_list.add(...)` |
| 13 | `FUW00931SFBean` | `super.addListDataInstance(key)` | In-memory: `cd_div_list_list.add(...)` |
| 14 | `FUW00917SF01DBean` | `super.addListDataInstance(key)` (override) | In-memory: `cd_div_list_list.add(...)` |
| 15 | `FUW00917SFBean` | `super.addListDataInstance(key)` | In-memory: `cd_div_list_list.add(...)` |

**Indirect callers (instantiating the DBean):**

| # | Caller (Screen/Bean) | Call Chain | Terminal |
|---|----------------------|-----------|----------|
| 1 | `KKW01027SFBean` (koptWebA) | `KKW01027SFBean` constructs `KKW01027SF02DBean` at lines 214, 218, 2997, 3003, 3013 | Framework dispatches via inherited `addListDataInstance` |
| 2 | `KKW01027SFBean` (koptWebB) | `KKW01027SFBean` constructs `KKW01027SF02DBean` at lines 205, 209, 2936, 2942, 2952 | Framework dispatches via inherited `addListDataInstance` |
| 3 | `KKSV0236` (Screen) | `KKSV0236OPDBMapper` references `KKW01027SFConst` | Uses DBean list for data binding |
| 4 | `KKSV0238` (Screen) | `KKSV0238OPDBMapper` references `KKW01027SFConst` | Uses DBean list for data binding |

## 6. Per-Branch Detail Blocks

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

> Null guard: if the caller passes `null` for the key, return `-1` immediately without touching any state. This prevents `NullPointerException` on the subsequent `.equals()` call.

| # | Type | Code |
|---|------|------|
| 1 | COND | `if(key == null)` |
| 2 | RETURN | `return -1;` // When key is null, return -1 (該当する場合、-1で返す) |

---

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

> The key matches "コードリスト" (Code List). This branch handles creation of a new element in the code list, which stores raw code values for display components such as dropdowns, radio buttons, or checkboxes. If the list has not yet been initialized, it creates a new empty `X33VDataTypeList`. Then it instantiates a new `X33VDataTypeStringBean` (the data-typed bean wrapper for a single string element), adds it to the list, and returns the zero-based index of the newly appended element.

| # | Type | Code |
|---|------|------|
| 1 | COND | `else if( key.equals("コードリスト") )` // Check if key matches "Code List" (コードリスト) |
| 2 | IF | `if( cd_div_list_list == null )` // If the list is null (リストがnullの場合) |
| 2.1 | SET | `cd_div_list_list = new X33VDataTypeList();` // Generate a new empty instance (新しい空のインスタンスを生成する) |
| 2.2 | END-IF | |
| 3 | SET | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean();` // Generate instance of specified data-typed bean (データタイプビーン型のインスタンスを生成する) |
| 4 | EXEC | `cd_div_list_list.add(tmpBean);` // Append to list (リストに追加) |
| 5 | RETURN | `return cd_div_list_list.size() - 1;` // Return zero-based index of appended element |

---

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

> The key matches "コード名リスト" (Code Name List). This branch handles creation of a new element in the code name list, which stores human-readable code descriptions (labels) for the same display components. The logic mirrors Block 2 but operates on the `cd_div_nm_list_list` collection instead.

| # | Type | Code |
|---|------|------|
| 1 | COND | `else if( key.equals("コード名リスト") )` // Check if key matches "Code Name List" (コード名リスト) |
| 2 | IF | `if( cd_div_nm_list_list == null )` // If the list is null (リストがnullの場合) |
| 2.1 | SET | `cd_div_nm_list_list = new X33VDataTypeList();` // Generate a new empty instance (新しい空のインスタンスを生成する) |
| 2.2 | END-IF | |
| 3 | SET | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean();` // Generate instance of specified data-typed bean (データタイプビーン型のインスタンスを生成する) |
| 4 | EXEC | `cd_div_nm_list_list.add(tmpBean);` // Append to list (リストに追加) |
| 5 | RETURN | `return cd_div_nm_list_list.size() - 1;` // Return zero-based index of appended element |

---

**Block 4** — [ELSE] Default / No Match (L468)

> No branch matched — the key is neither null, nor "コードリスト", nor "コード名リスト". Return `-1` to indicate no recognized list item.

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

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `addListDataInstance` | Method | List data instance generator — creates and appends a new element to a typed list collection based on a string discriminator key |
| `コードリスト` (code risuto) | Japanese Key | "Code List" — a list of raw code values used as display component options (e.g., dropdown item values) |
| `コード名リスト` (code me risuto) | Japanese Key | "Code Name List" — a parallel list of human-readable code descriptions/labels corresponding to the code list values |
| `cd_div_list_list` | Field | Code division list — the internal `X33VDataTypeList` backing the コードリスト branch |
| `cd_div_nm_list_list` | Field | Code name division list — the internal `X33VDataTypeList` backing the コード名リスト branch |
| `X33VDataTypeList` | Framework Class | Framework-provided typed list collection used for webview data binding |
| `X33VDataTypeStringBean` | Framework Class | Framework-provided string data-typed bean wrapper; each instance represents a single string element in the typed list |
| `key` | Parameter | Discriminant string identifying which list type to grow; maps to a specific form field category on the web screen |
| DBean | Acronym | Data Bean — a view-support data binding class in the webview layer that holds form data and display-state for a screen |
| Webview | Layer | The view/presentation layer of the application; handles data binding between controllers and JSP/HTML screens |
| `KKW01027SF02DBean` | Class | Discount-related display data bean for the KKA15001SF module; manages discount code list data for service contract screens |
| `KKW01027SF` | Module | Discount code screen module — handles discount type and applicable company code list management for service contracts |
| `KKA15001SF` | Module | Parent service module — the broader service contract / order fulfillment screen module containing KKW01027SF |
| `X33SException` | Framework Exception | Framework exception thrown by data-typed bean constructors and operations |
