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

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW00127SF.KKW00127SF01DBean` |
| Layer | View / Bean (X33VFramework data binding bean — webview tier) |
| Module | `KKW00127SF` (Package: `eo.web.webview.KKW00127SF`) |

## 1. Role

### KKW00127SF01DBean.addListDataInstance()

This method is a framework-supplied dispatcher that creates and appends typed list data instances for a given key string. It implements the `X33VListedBeanInterface` contract, which governs how view beans manage dynamically-sized lists of strongly-typed data elements. In business terms, the method serves as a factory for **code list rows** and **code name list rows** — two recurring UI display structures used throughout the KKW00127SF screen to render selectable dropdown options and associated descriptive labels.

The method follows a **routing/dispatch pattern**: it inspects the incoming `key` parameter and branches to the appropriate list creation handler. For the key `"コードリスト"` (Code List), it appends a new `X33VDataTypeStringBean` into the `cd_div_list_list` field. For the key `"コード名リスト"` (Code Name List), it appends into the `cd_div_nm_list_list` field. If the key does not match either known list, or if the key is `null`, it returns `-1` to signal that no instance was created.

This method does not interact with any database, service component, or external system. It is a pure in-memory bean manipulation routine that supports the screen's dynamic row-building logic for select items displayed to end users during service contract editing operations.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addListDataInstance(String key)"])
    COND_NULL{"key == null?"}
    COND_CODE_LIST{"key equals \"コードリスト\"" }
    COND_CODE_NM{"key equals \"コード名リスト\"" }
    INIT_CD_LIST["cd_div_list_list = new X33VDataTypeList()"]
    INIT_CODE_NM["cd_div_nm_list_list = new X33VDataTypeList()"]
    CREATE_STR_BN["tmpBean = new X33VDataTypeStringBean()"]
    ADD_TO_CD_LIST["cd_div_list_list.add(tmpBean)"]
    ADD_TO_CODE_NM["cd_div_nm_list_list.add(tmpBean)"]
    RETURN_CD_LIST["return cd_div_list_list.size() - 1"]
    RETURN_CODE_NM["return cd_div_nm_list_list.size() - 1"]
    RETURN_NEG1(["return -1 : not found"])
    RETURN_NEG1_END(["return -1 : null key"])

    START --> COND_NULL
    COND_NULL -->|true| RETURN_NEG1_END
    COND_NULL -->|false| COND_CODE_LIST
    COND_CODE_LIST -->|true| COND_CD_LIST_INIT{"cd_div_list_list == null?"}
    COND_CODE_LIST -->|false| COND_CODE_NM
    COND_CD_LIST_INIT -->|true| INIT_CD_LIST
    COND_CD_LIST_INIT -->|false| CREATE_STR_BN
    INIT_CD_LIST --> CREATE_STR_BN
    CREATE_STR_BN --> ADD_TO_CD_LIST
    ADD_TO_CD_LIST --> RETURN_CD_LIST
    RETURN_CD_LIST --> END((END))
    COND_CODE_NM -->|true| COND_CODE_NM_INIT{"cd_div_nm_list_list == null?"}
    COND_CODE_NM -->|false| RETURN_NEG1
    COND_CODE_NM_INIT -->|true| INIT_CODE_NM
    COND_CODE_NM_INIT -->|false| CREATE_STR_BN2["tmpBean = new X33VDataTypeStringBean()"]
    INIT_CODE_NM --> CREATE_STR_BN2
    CREATE_STR_BN2 --> ADD_TO_CODE_NM
    ADD_TO_CODE_NM --> RETURN_CODE_NM
    RETURN_CODE_NM --> END
```

### Branch Summary

| Branch | Condition | Business Meaning | Result |
|--------|-----------|-----------------|--------|
| Branch 1 | `key == null` | Caller passed a `null` reference — no list to populate | Returns `-1` (failure) |
| Branch 2 | `key` equals `"コードリスト"` | Request to create a new row in the **Code List** (CD code values) | Initializes list if needed, creates `StringBean`, appends, returns index |
| Branch 3 | `key` equals `"コード名リスト"` | Request to create a new row in the **Code Name List** (descriptive labels) | Initializes list if needed, creates `StringBean`, appends, returns index |
| Branch 4 | No match | Key is unrecognized — no registered list handler | Returns `-1` (not found) |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `key` | `String` | The list item name that identifies which typed list to append into. Valid values are `"コードリスト"` (Code List — for CD code values displayed in dropdowns) and `"コード名リスト"` (Code Name List — for the corresponding descriptive label text). If `null`, processing is immediately aborted with `-1`. |
| — | `cd_div_list_list` | `X33VDataTypeList` (instance field) | The backing list for code list (CD code) data elements. Holds `X33VDataTypeStringBean` instances representing individual dropdown option values. Initialized to an empty list in the constructor. |
| — | `cd_div_nm_list_list` | `X33VDataTypeList` (instance field) | The backing list for code name list (CD label) data elements. Holds `X33VDataTypeStringBean` instances representing the descriptive text paired with each dropdown option. Initialized to an empty list in the constructor. |

## 4. CRUD Operations / Called Services

This method performs **no database operations**, **no service component calls**, and **no CBS invocations**. All processing is in-memory bean manipulation within the X33VFramework data binding layer.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| (N/A) | — | — | — | No external calls — pure in-memory list mutation via `X33VDataTypeList.add()` and `X33VDataTypeStringBean` instantiation. |

## 5. Dependency Trace

This method is a framework contract implementation (`X33VListedBeanInterface.addListDataInstance`). It is **not** directly called by any screen or business component. Instead, it is invoked indirectly:

1. **By the X33VFramework** — the framework's view bean lifecycle calls `addListDataInstance()` when dynamically building list-based UI components (e.g., repeated dropdown fields).
2. **By subclasses** — `KKW00127SFBean`, `KKW00127SF02DBean`, `KKW00127SF04DBean`, `KKW00127SF07DBean`, `KKW00127SF12DBean`, and `KKW00127SF22DBean` each override this method. Most implementations delegate to `super.addListDataInstance(key)` to reuse the base logic, then potentially add their own type-specific branches.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Framework: X33VViewBaseBean | Framework bean lifecycle -> `addListDataInstance(String)` | In-memory list add (no DB) |
| 2 | Framework: X33VListedBeanInterface | Interface contract -> `addListDataInstance(String)` -> KKW00127SF01DBean | In-memory list add (no DB) |
| 3 | Class: KKW00127SFBean | Overrides and calls `super.addListDataInstance(key)` -> KKW00127SF01DBean | In-memory list add (no DB) |
| 4 | Class: KKW00127SF02DBean | Overrides and calls `super.addListDataInstance(key)` -> KKW00127SF01DBean | In-memory list add (no DB) |
| 5 | Class: KKW00127SF04DBean | Overrides and calls `super.addListDataInstance(key)` -> KKW00127SF01DBean | In-memory list add (no DB) |
| 6 | Class: KKW00127SF07DBean | Overrides and calls `super.addListDataInstance(key)` -> KKW00127SF01DBean | In-memory list add (no DB) |
| 7 | Class: KKW00127SF12DBean | Overrides and calls `super.addListDataInstance(key)` -> KKW00127SF01DBean | In-memory list add (no DB) |
| 8 | Class: KKW00127SF22DBean | Overrides and calls `super.addListDataInstance(key)` -> KKW00127SF01DBean | In-memory list add (no DB) |

## 6. Per-Branch Detail Blocks

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

> Early-exit guard: if the caller passes a null key, return immediately with -1.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if(key == null)` // null check guard |
| 2 | RETURN | `return -1;` // Return -1 if key is null (キーがnullの場合、-1で返す) |

---

**Block 2** — ELSE-IF `(key.equals("コードリスト"))` (L427)

> Creates a new row in the Code List (CD code values). This list is used for dropdown option values — the actual CD codes that appear as selectable items in UI select components.

**Block 2.1** — IF `(cd_div_list_list == null)` (L428)

> Null-safety check: if the backing list has not yet been initialized, create a new empty list. This should normally not occur because the constructor initializes `cd_div_list_list` to a new `X33VDataTypeList()`, but the null check serves as defensive programming.

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

**Block 2.2** — (no nested condition) (L431)

> Create a typed string bean instance and append it to the code list.

| # | Type | Code |
|---|------|------|
| 1 | SET | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean();` // データタイプビーン型で指定したデータタイプビーンのインスタンスを生成 (Instantiate specified data type bean type) |
| 2 | SET | `cd_div_list_list.add(tmpBean);` // Append new StringBean to code list |
| 3 | RETURN | `return cd_div_list_list.size() - 1;` // Return zero-based index of newly added element |

---

**Block 3** — ELSE-IF `(key.equals("コード名リスト"))` (L435)

> Creates a new row in the Code Name List (CD descriptive labels). This list holds the human-readable text labels that correspond one-to-one with the codes in `cd_div_list_list`.

**Block 3.1** — IF `(cd_div_nm_list_list == null)` (L436)

> Null-safety check: if the backing list has not yet been initialized, create a new empty list.

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

**Block 3.2** — (no nested condition) (L439)

> Create a typed string bean instance and append it to the code name list.

| # | Type | Code |
|---|------|------|
| 1 | SET | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean();` // データタイプビーン型で指定したデータタイプビーンのインスタンスを生成 (Instantiate specified data type bean type) |
| 2 | SET | `cd_div_nm_list_list.add(tmpBean);` // Append new StringBean to code name list |
| 3 | RETURN | `return cd_div_nm_list_list.size() - 1;` // Return zero-based index of newly added element |

---

**Block 4** — ELSE (default fall-through) (L444)

> No matching key was found. The method returns -1 to signal that the requested list does not exist.

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

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `コードリスト` | Japanese key | Code List — the list of CD (classification data) code values used as dropdown option values |
| `コード名リスト` | Japanese key | Code Name List — the list of human-readable label text corresponding one-to-one with the code list values |
| `cd_div_list_list` | Field | CD division list list — backing storage for code list (CD code) `StringBean` instances |
| `cd_div_nm_list_list` | Field | CD division name list list — backing storage for code name list (CD label) `StringBean` instances |
| `index_update` | Field | Index update flag — tracks whether index-based operations have been performed |
| `index_value` | Field | Index value — the current index value being operated on |
| `index_state` | Field | Index state — tracks the operational state of index-based operations |
| X33VFramework | Technical | Fujitsu Futurity X33 web application framework — the enterprise JSF-based MVC framework used for this application |
| X33VListedBeanInterface | Technical | Framework interface that defines list-data instance management methods (add, remove) for view beans |
| X33VDataTypeList | Technical | Framework generic list container that holds strongly-typed data bean instances |
| X33VDataTypeStringBean | Technical | Framework typed data bean wrapping a `String` value — used here as the element type for both `cd_div_list_list` and `cd_div_nm_list_list` |
| `X33SException` | Technical | X33VFramework system exception class — thrown on framework-level errors |
| CD (Classification Data) | Business term | Master data used to define dropdown option values in the application's UI forms |
| KKW00127SF | Module | Screen module identifier — the service contract edit screen module |
