# Business Logic — KKW22301SF03DBean.addListDataInstance() [43 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW22301SF.KKW22301SF03DBean` |
| Layer | View / Web Bean (Framework: Fujitsu Futurity X33 Web Framework) |
| Module | `KKW22301SF` (Package: `eo.web.webview.KKW22301SF`) |

## 1. Role

### KKW22301SF03DBean.addListDataInstance()

This method is a **list-item factory** within the X33 web framework's view bean architecture. Its business purpose is to dynamically create and register instances of list-data bean objects on demand, enabling screen-level UI components (such as repeat tables, dropdown lists, or data entry grids) to obtain properly typed data containers. It implements the **dispatch/routing pattern**: the `key` parameter acts as a discriminator, routing the call to one of three supported list types — code list ("コードリスト"), code name list ("コード名リスト"), or name list ("名称リスト") — each backed by a different instance field (`cd_div_list_list`, `cd_div_nm_list_list`, `nm_list_list`). Its role in the larger system is as a **shared data-provider utility**: the base class `KKW22301SFBean` delegates to this overridden method via `super.addListDataInstance(key)` for keys beginning with `"//"` (common info beans), and individual screen controllers invoke it through the view bean hierarchy to populate dropdowns and repeat sections with typed bean instances. When the requested key does not match any supported list or is null, the method returns `-1`, signaling an unsupported or invalid list type.

## 2. Processing Pattern (Detailed Business Logic)

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

    START --> COND_NULL{key == null?}
    COND_NULL -->|Yes| RET_NEG1(["Return -1"])
    COND_NULL -->|No| COND_CD{key.equals(コードリスト)?}

    COND_CD -->|Yes| CHECK_CD_NULL{cd_div_list_list == null?}
    CHECK_CD_NULL -->|Yes| INIT_CD[cd_div_list_list = new X33VDataTypeList()]
    CHECK_CD_NULL -->|No| INIT_CD_DIRECT[Proceed to bean creation]
    INIT_CD --> INIT_CD_DIRECT

    INIT_CD_DIRECT --> CREATE_CD_STR[new X33VDataTypeStringBean()]
    CREATE_CD_STR --> ADD_CD[cd_div_list_list.add(tmpBean)]
    ADD_CD --> RET_CD[Return cd_div_list_list.size() - 1]

    COND_CD -->|No| COND_CDNM{key.equals(コード名リスト)?}

    COND_CDNM -->|Yes| CHECK_CDNM_NULL{cd_div_nm_list_list == null?}
    CHECK_CDNM_NULL -->|Yes| INIT_CDNM[cd_div_nm_list_list = new X33VDataTypeList()]
    CHECK_CDNM_NULL -->|No| INIT_CDNM_DIRECT[Proceed to bean creation]
    INIT_CDNM --> INIT_CDNM_DIRECT

    INIT_CDNM_DIRECT --> CREATE_CDNM_STR[new X33VDataTypeStringBean()]
    CREATE_CDNM_STR --> ADD_CDNM[cd_div_nm_list_list.add(tmpBean)]
    ADD_CDNM --> RET_CDNM[Return cd_div_nm_list_list.size() - 1]

    COND_CDNM -->|No| COND_NM{key.equals(名称リスト)?}

    COND_NM -->|Yes| CHECK_NM_NULL{nm_list_list == null?}
    CHECK_NM_NULL -->|Yes| INIT_NM[nm_list_list = new X33VDataTypeList()]
    CHECK_NM_NULL -->|No| INIT_NM_DIRECT[Proceed to bean creation]
    INIT_NM --> INIT_NM_DIRECT

    INIT_NM_DIRECT --> CREATE_NM_STR[new X33VDataTypeStringBean()]
    CREATE_NM_STR --> ADD_NM[nm_list_list.add(tmpBean)]
    ADD_NM --> RET_NM[Return nm_list_list.size() - 1]

    COND_NM -->|No| RET_DEFAULT(["Return -1"])

    RET_NEG1 --> END(["End"])
    RET_CD --> END
    RET_CDNM --> END
    RET_NM --> END
    RET_DEFAULT --> END
```

**Processing Summary:**

| Step | Description |
|------|-------------|
| 1 | Check if `key` is `null`. If so, return `-1` immediately. |
| 2.1 | If `key` equals `"コードリスト"` (Code List), ensure `cd_div_list_list` is initialized (create new `X33VDataTypeList` if null), instantiate `X33VDataTypeStringBean`, add it, and return the new index. |
| 2.2 | If `key` equals `"コード名リスト"` (Code Name List), ensure `cd_div_nm_list_list` is initialized, instantiate `X33VDataTypeStringBean`, add it, and return the new index. |
| 2.3 | If `key` equals `"名称リスト"` (Name List), ensure `nm_list_list` is initialized, instantiate `X33VDataTypeStringBean`, add it, and return the new index. |
| 3 | If `key` does not match any supported list, return `-1`. |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `key` | `String` | The **list item identifier** that determines which type of repeat/list data structure to populate. It maps to one of three business list categories: "コードリスト" (Code List — e.g., dropdown code values), "コード名リスト" (Code Name List — human-readable labels for code values), or "名称リスト" (Name List — free-text name entries). The value directly controls which internal `X33VDataTypeList` field receives a new bean instance. |
| | **cd_div_list_list** | `X33VDataTypeList` | Instance field storing the list of code list bean instances. Created lazily if `null`. |
| | **cd_div_nm_list_list** | `X33VDataTypeList` | Instance field storing the list of code name list bean instances. Created lazily if `null`. |
| | **nm_list_list** | `X33VDataTypeList` | Instance field storing the list of name list bean instances. Created lazily if `null`. |

## 4. CRUD Operations / Called Services

This method does **not** perform any Create/Read/Update/Delete operations against a database or call any service components (SC) or CBS (Business Service). It operates purely at the **view bean level**, creating in-memory data-type instances for UI rendering. The only external objects instantiated are framework-provided beans:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| *(none)* | — | — | — | This method creates in-memory bean instances only. No database or service-tier access occurs. |

**Framework Objects Created:**

| Object | Type | Purpose |
|--------|------|---------|
| `X33VDataTypeList()` | Framework list container | Generic in-memory list for holding bean instances |
| `X33VDataTypeStringBean()` | Framework string bean | Typed string data container for each list row/item |

## 5. Dependency Trace

The only known caller of this method is the base class `KKW22301SFBean.java`, which delegates to `super.addListDataInstance(key)` for keys beginning with `"//"` (common information beans handled by the framework's base class). No external screen classes or batches were found directly calling this method.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Class: `KKW22301SFBean` | `KKW22301SFBean.addListDataInstance(key)` → `super.addListDataInstance(key)` (delegated to `KKW22301SF03DBean`) | *(in-memory only, no SC/CRUD)* |

## 6. Per-Branch Detail Blocks

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

> Early-exit guard: if the key parameter is null, the method cannot determine which list to populate and returns an error code.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return -1;` // Return -1 when key is null — no list to initialize |

**Block 2** — ELSE-IF `(key.equals("コードリスト"))` — CONSTANT `"コードリスト" = "Code List"` (L548)

> Dispatches the Code List category. The method ensures the `cd_div_list_list` field is initialized (lazy initialization) and appends a new `X33VDataTypeStringBean` instance, representing a single code value row.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (cd_div_list_list == null)` // Check if list instance is null (L550) |
| 1.1 | SET | `cd_div_list_list = new X33VDataTypeList();` // Create a new empty list instance (L551) |
| 1.2 | EXEC | *(end of if block)* |
| 2 | SET | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean();` // Instantiate a typed string bean (L554) |
| 3 | EXEC | `cd_div_list_list.add(tmpBean);` // Append the bean to the code list (L556) |
| 4 | RETURN | `return cd_div_list_list.size() - 1;` // Return the zero-based index of the newly added element (L557) |

**Block 3** — ELSE-IF `(key.equals("コード名リスト"))` — CONSTANT `"コード名リスト" = "Code Name List"` (L562)

> Dispatches the Code Name List category. Similar to Block 2, but operates on the `cd_div_nm_list_list` field, which holds human-readable label entries corresponding to code values.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (cd_div_nm_list_list == null)` // Check if code name list is null (L563) |
| 1.1 | SET | `cd_div_nm_list_list = new X33VDataTypeList();` // Create a new empty code name list (L564) |
| 1.2 | EXEC | *(end of if block)* |
| 2 | SET | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean();` // Instantiate a typed string bean (L567) |
| 3 | EXEC | `cd_div_nm_list_list.add(tmpBean);` // Append the bean to the code name list (L569) |
| 4 | RETURN | `return cd_div_nm_list_list.size() - 1;` // Return the zero-based index (L570) |

**Block 4** — ELSE-IF `(key.equals("名称リスト"))` — CONSTANT `"名称リスト" = "Name List"` (L575)

> Dispatches the Name List category. Operates on `nm_list_list`, which holds free-text name entries (e.g., customer names, item names) for display in repeat sections.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (nm_list_list == null)` // Check if name list is null (L576) |
| 1.1 | SET | `nm_list_list = new X33VDataTypeList();` // Create a new empty name list (L577) |
| 1.2 | EXEC | *(end of if block)* |
| 2 | SET | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean();` // Instantiate a typed string bean (L580) |
| 3 | EXEC | `nm_list_list.add(tmpBean);` // Append the bean to the name list (L582) |
| 4 | RETURN | `return nm_list_list.size() - 1;` // Return the zero-based index (L583) |

**Block 5** — ELSE (implicit default) (L584)

> The key did not match any of the three supported list types. Return -1 to signal an unrecognized list item.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return -1;` // Return -1 when no matching list item is found (L584) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `cd_div_list_list` | Field | Code division list — in-memory list holding `X33VDataTypeStringBean` instances for code values (e.g., dropdown option codes). |
| `cd_div_nm_list_list` | Field | Code division name list — in-memory list holding `X33VDataTypeStringBean` instances for human-readable code labels. |
| `nm_list_list` | Field | Name list — in-memory list holding `X33VDataTypeStringBean` instances for free-text name entries. |
| `"コードリスト"` | Constant | Japanese: "Code List" — the dispatch key for the code value list. |
| `"コード名リスト"` | Constant | Japanese: "Code Name List" — the dispatch key for the code label list. |
| `"名称リスト"` | Constant | Japanese: "Name List" — the dispatch key for the name text list. |
| `X33VDataTypeList` | Framework | X33 framework generic list container for holding typed bean instances in view beans. |
| `X33VDataTypeStringBean` | Framework | X33 framework typed bean wrapping a `String` value, used as the row-type for list-based UI components. |
| `X33SException` | Framework | X33 framework exception class thrown for view-layer errors. |
| `X33VViewBaseBean` | Framework | Base class for X33 view beans; provides common view-layer functionality. |
| `X33VListedBeanInterface` | Framework | Interface marking a bean as supporting listed (repeat/grid) data operations. |
| `X33VDataTypeBeanInterface` | Framework | Interface marking a bean as a typed data container within the X33 view model. |
| `-1` (return) | Convention | Return code indicating failure — either the key was `null` or no matching list type was found. |
