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

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW01021SF.KKW01021SF01DBean` |
| Layer | View Bean / Web Controller (Data binding bean for JSF view layer) |
| Module | `KKW01021SF` (Package: `eo.web.webview.KKW01021SF`) |

## 1. Role

### KKW01021SF01DBean.addListDataInstance()

This method is the list-item factory for the `KKW01021SF` service change/movement screen. Its business purpose is to create and add a new data instance (typed bean) to an in-memory list that backs a repeating UI section — specifically, the "Reason Code" (異動理由コード) field used when recording the reason for a service move/change event. It implements the **routing/factory design pattern**: based on the string key identifying a UI field name, it instantiates the correct typed bean (`X33VDataTypeStringBean`) and appends it to the corresponding `X33VDataTypeList`. This method serves as the shared data-binding utility called from the screen's event handlers whenever the user adds a new reason-code row to a dynamic multi-row input area. It does not interact with any database or service component — all state is held purely in the view bean's instance fields.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addListDataInstance(key)"])
    COND_NULL{"key == null"}
    COND_KEY{"key equals \"異動理由コード\""}
    INIT_LIST{"ido_rsn_cd_list == null"}
    END_RETURN(["Return index"])

    START --> COND_NULL
    COND_NULL -->|true| END_RETURN
    COND_NULL -->|false| COND_KEY
    COND_KEY -->|false| END_RETURN
    COND_KEY -->|true| INIT_LIST
    INIT_LIST -->|true| INIT_NEW["ido_rsn_cd_list = new X33VDataTypeList()"]
    INIT_LIST -->|false| CREATE_BEAN["tmpBean = new X33VDataTypeStringBean()"]
    INIT_NEW --> CREATE_BEAN
    CREATE_BEAN --> ADD_TO_LIST["ido_rsn_cd_list.add(tmpBean)"]
    ADD_TO_LIST --> END_RETURN
```

**CRITICAL — Constant Resolution:**
The condition checks the literal key `key.equals("異動理由コード")` — "異動理由コード" (ido_rsn_cd) is a Japanese field name meaning "Move/Change Reason Code". No external constant class is referenced in this method.

**Branches:**
- **Null guard**: If `key` is `null`, immediately return `-1` (no instance created).
- **Key match — "異動理由コード"**: Creates and adds a reason code bean to the list (see Block 2).
- **Unrecognized key**: Returns `-1` indicating no matching field was found.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `key` | `String` | The display name of the list-bound UI field for which a new data instance should be created. Currently, the only recognized value is `"異動理由コード"` (Move/Change Reason Code), which triggers creation of a reason code bean. Unrecognized values cause the method to return `-1` with no side effects. |

**Instance fields / external state read:**
| Field | Type | Business Description |
|-------|------|---------------------|
| `ido_rsn_cd_list` | `X33VDataTypeList` | The in-memory list holding reason code beans for the current screen view. Initially `null` and lazily initialized on the first `addListDataInstance("異動理由コード")` call. Declared with comment: 並び項目 "異動理由コード"(String型、項目ID:ido_rsn_cd) — i.e., "Repeating field 'Reason Code' (String type, field ID: ido_rsn_cd)". |

## 4. CRUD Operations / Called Services

This method performs **no database or service-component operations**. It is a pure in-memory data structure manipulation that creates view-bound bean instances for UI data binding.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| *(none)* | — | — | — | No service calls, no SQL, no entity persistence. This method operates entirely on local view-bean state. |

**Note:** The constructor of `KKW01021SF01DBean` initializes `ido_rsn_cd_list` as a new `X33VDataTypeList()`, but the field can be `null` if a subclass or another code path overrides it before this method is called — hence the null check inside the method.

## 5. Dependency Trace

No direct callers of `KKW01021SF01DBean.addListDataInstance(String)` were found in the codebase search. This method is a **public utility method on a view bean** that is called at runtime by JSF/facelets EL expressions or backing-bean event handlers on the `KKW01021SF` screen (service change/movement screen). Other `*DBean` classes in the codebase define their own overrides of `addListDataInstance`, and some delegate to `super.addListDataInstance(key)` to reuse this base implementation (e.g., `FUW00912SFBean`, `FUW00926SFBean`, `FUW00964SFBean`, `FUW00927SFBean`, `FUW00901SFBean`, `FUW00919SFBean`, `FUW00931SFBean`, `FUW00917SFBean`, `FUW00907SFBean`, `FUW00957SFBean`).

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKW01021SF | Screen JSF handler → `KKW01021SF01DBean.addListDataInstance("異動理由コード")` | *(none — local in-memory only)* |
| 2 | FUW00912SFBean (extends base) | `super.addListDataInstance(key)` delegates to this method | *(none — local in-memory only)* |
| 3 | FUW00926SFBean (extends base) | `super.addListDataInstance(key)` delegates to this method | *(none — local in-memory only)* |
| 4 | FUW00964SFBean (extends base) | `super.addListDataInstance(key)` delegates to this method | *(none — local in-memory only)* |
| 5 | FUW00927SFBean (extends base) | `super.addListDataInstance(key)` delegates to this method | *(none — local in-memory only)* |
| 6 | FUW00901SFBean (extends base) | `super.addListDataInstance(key)` delegates to this method | *(none — local in-memory only)* |
| 7 | FUW00919SFBean (extends base) | `super.addListDataInstance(key)` delegates to this method | *(none — local in-memory only)* |
| 8 | FUW00931SFBean (extends base) | `super.addListDataInstance(key)` delegates to this method | *(none — local in-memory only)* |
| 9 | FUW00917SFBean (extends base) | `super.addListDataInstance(key)` delegates to this method | *(none — local in-memory only)* |
| 10 | FUW00907SFBean (extends base) | `super.addListDataInstance(key)` delegates to this method | *(none — local in-memory only)* |
| 11 | FUW00957SFBean (extends base) | `super.addListDataInstance(key)` delegates to this method | *(none — local in-memory only)* |

## 6. Per-Branch Detail Blocks

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

> Null guard: if the key is null, return -1 immediately. No side effects.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return -1;` // nullの場合、-1で返す — Returns -1 when key is null |

---

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

> Processes the repeating field "異動理由コード" (Move/Change Reason Code). This is a String-type repeating field whose internal ID is `ido_rsn_cd`. Ensures the backing list is initialized, creates a typed bean instance, adds it to the list, and returns the index of the newly added element.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (ido_rsn_cd_list == null)` // リストがnullの場合、新しい空のインスタンスを生成 — If list is null, generate new empty instance |
| 1.1 | SET | `ido_rsn_cd_list = new X33VDataTypeList();` // lazily initializes the list |
| 2 | NEW | `X33VDataTypeStringBean tmpBean = new X33VDataTypeStringBean();` // データタイプビーン型で指定したデータタイプビーンインスタンスを生成 — Creates instance of specified data-type bean. Data-type bean item initial values are defined within each data bean internally. |
| 3 | EXEC | `ido_rsn_cd_list.add(tmpBean);` // appends the new bean to the list |
| 4 | RETURN | `return ido_rsn_cd_list.size() - 1;` // Returns the index of the newly added element |

---

**Block 3** — [ELSE / FALLBACK] (L629)

> Unrecognized key: returns -1. There is no explicit `else` block; this is reached via fall-through after the else-if chain.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return -1;` // 該当する項目がない場合、-1を返す — Returns -1 when no matching field is found |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `ido_rsn_cd` | Field | Move/Change Reason Code — the reason code field (String type) for a service move or change operation. Item ID in the data bean: `ido_rsn_cd`. Stored in the list: `ido_rsn_cd_list`. |
| `異動理由コード` | Field (Japanese) | Move/Change Reason Code — display name of the repeating field in the UI. "異動" = service move/change, "理由" = reason, "コード" = code. |
| `KKW01021SF` | Module | Service change/movement screen module — handles UI for recording reasons for a service move/change event. |
| `X33VDataTypeList` | Type | Fujitsu Futurity X33 framework generic list container — an in-memory list of typed view beans used for repeating UI sections. |
| `X33VDataTypeStringBean` | Type | Fujitsu Futurity X33 framework string-type view bean — a typed data wrapper whose initial values are defined within the data bean internally. |
| `X33VListedBeanInterface` | Interface | X33 framework interface that marks a bean as supporting list-based (repeating row) data binding. |
| `X33SException` | Type | X33 framework exception type — thrown by view bean operations. |
| `KKSV\d{4}` | Convention | Screen class naming convention — screen classes are named with prefix `KKSV` followed by a 4-digit number. |
| `KKW01021SF01DBean` | Class | Data bean (DBean) for the `KKW01021SF` screen — holds view-state fields and their update/value/state triplets. |
| `DBean` | Abbreviation | Data Bean — a view-layer bean that binds UI components to Java data models in the X33 framework. |
| `FUW00912SFBean` | Class | Other screen's DBean that inherits from a base class and delegates `addListDataInstance` calls up via `super`. |
