# Business Logic — KKW00401SF02DBean.addListDataInstance() [65 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW00401SF.KKW00401SF02DBean` |
| Layer | Service Component (Framework Integration Layer) |
| Module | `KKW00401SF` (Package: `eo.web.webview.KKW00401SF`) |

## 1. Role

### KKW00401SF02DBean.addListDataInstance()

This method is a polymorphic factory/routing dispatcher that dynamically creates and registers data-type-specific bean instances into typed list containers within the K-Opticom service order management system. When called with a string key representing a distinct STB (Set-Top Box) configuration item, it routes to the appropriate list, ensures that list is initialized (lazy initialization), instantiates a new `KKW00401SF01DBean` data bean, appends it to the list, and returns the zero-based index of the newly added element.

The method supports five data types: STB relocation classification (`STB異動区分`), selected type number (`選択型番号`), STB type classification (`STB区分`), HDD capacity (`HDD容量`), and TV course (`TVコース`). Each data type corresponds to a configurable row in a dynamic table rendered on the service registration screen. The method implements the `X33VDataTypeBeanInterface.addListDataInstance(String)` contract defined by the Fujitsu Futurity X33 web framework, enabling the framework to lazily populate list data as the user adds rows via the UI. It follows a **dispatch/routing pattern** — a chain of `if-else if` conditional branches — with a **lazy initialization** pattern for list containers.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    StartNode["start: addListDataInstance key"] --> KeyIsNull{key is null}
    KeyIsNull -->|Yes| RetNeg1["return -1"]
    KeyIsNull -->|No| CheckStbIdoDiv{key equals STB異動区分}
    CheckStbIdoDiv -->|True| NullCheckStbIdoDiv{stb_ido_div_list is null}
    NullCheckStbIdoDiv -->|Yes| InitStbIdoList["stb_ido_div_list = new X33VDataTypeList"]
    NullCheckStbIdoDiv -->|No| CreateStbBean["tmpBean = new KKW00401SF01DBean"]
    InitStbIdoList --> CreateStbBean
    CreateStbBean --> AddStbIdo["stb_ido_div_list.add tmpBean"]
    AddStbIdo --> RetStbIdo["return stb_ido_div_list.size - 1"]
    RetStbIdo --> EndNode["end"]
    CheckStbIdoDiv -->|False| CheckSelType{key equals 選択型番号}
    CheckSelType -->|True| NullCheckSel{sel_type_number_list is null}
    NullCheckSel -->|Yes| InitSelList["sel_type_number_list = new X33VDataTypeList"]
    NullCheckSel -->|No| CreateSelBean["tmpBean = new KKW00401SF01DBean"]
    InitSelList --> CreateSelBean
    CreateSelBean --> AddSel["sel_type_number_list.add tmpBean"]
    AddSel --> RetSel["return sel_type_number_list.size - 1"]
    RetSel --> EndNode
    CheckSelType -->|False| CheckStbDiv{key equals STB区分}
    CheckStbDiv -->|True| NullCheckStbDiv{stb_div_list is null}
    NullCheckStbDiv -->|Yes| InitStbDivList["stb_div_list = new X33VDataTypeList"]
    NullCheckStbDiv -->|No| CreateStbDivBean["tmpBean = new KKW00401SF01DBean"]
    InitStbDivList --> CreateStbDivBean
    CreateStbDivBean --> AddStbDiv["stb_div_list.add tmpBean"]
    AddStbDiv --> RetStbDiv["return stb_div_list.size - 1"]
    RetStbDiv --> EndNode
    CheckStbDiv -->|False| CheckHddCapa{key equals HDD容量}
    CheckHddCapa -->|True| NullCheckHdd{hdd_capa_list is null}
    NullCheckHdd -->|Yes| InitHddList["hdd_capa_list = new X33VDataTypeList"]
    NullCheckHdd -->|No| CreateHddBean["tmpBean = new KKW00401SF01DBean"]
    InitHddList --> CreateHddBean
    CreateHddBean --> AddHdd["hdd_capa_list.add tmpBean"]
    AddHdd --> RetHdd["return hdd_capa_list.size - 1"]
    RetHdd --> EndNode
    CheckHddCapa -->|False| CheckTvCourse{key equals TVコース}
    CheckTvCourse -->|True| NullCheckTv{tv_course_list is null}
    NullCheckTv -->|Yes| InitTvList["tv_course_list = new X33VDataTypeList"]
    NullCheckTv -->|No| CreateTvBean["tmpBean = new KKW00401SF01DBean"]
    InitTvList --> CreateTvBean
    CreateTvBean --> AddTv["tv_course_list.add tmpBean"]
    AddTv --> RetTv["return tv_course_list.size - 1"]
    RetTv --> EndNode
    CheckTvCourse -->|False| RetDefault["return -1"]
    RetDefault --> EndNode
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `key` | `String` | Data type identifier that determines which list container receives a new bean instance. Accepts one of five hardcoded Japanese strings: `"STB異動区分"` (STB relocation classification), `"選択型番号"` (selected type number), `"STB区分"` (STB type classification), `"HDD容量"` (HDD capacity), or `"TVコース"` (TV course). The exact match is case-sensitive and uses raw Japanese strings — not constant references — so callers must pass the exact key values as defined in each branch. A null value causes an immediate return of -1. |

**Instance fields read by this method:**

| No | Field Name | Type | Business Description |
|----|-----------|------|---------------------|
| 1 | `stb_ido_div_list` | `X33VDataTypeList` | List of STB relocation classification beans — holds data for STBs being moved to different physical locations |
| 2 | `sel_type_number_list` | `X33VDataTypeList` | List of selected type number beans — holds device model number selections |
| 3 | `stb_div_list` | `X33VDataTypeList` | List of STB type classification beans — categorizes STB hardware tiers |
| 4 | `hdd_capa_list` | `X33VDataTypeList` | List of HDD capacity beans — stores hard disk drive capacity specifications |
| 5 | `tv_course_list` | `X33VDataTypeList` | List of TV course beans — stores TV subscription package selections |

## 4. CRUD Operations / Called Services

This method performs only in-memory operations. It does not call any SC (Service Component), CBS (Common Business Service), or database layer. All operations are list-level creations (C) of bean instances and list elements:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| C | `X33VDataTypeList.<init>()` | — | (in-memory) | Initializes a new empty `X33VDataTypeList` when the target field is null (lazy initialization). One of 5 possible lists. |
| C | `KKW00401SF01DBean.<init>()` | — | (in-memory) | Creates a new data bean instance for the specific data type identified by the key parameter. |
| C | `X33VDataTypeList.add(...)` | — | (in-memory) | Appends the newly created bean instance to the end of the typed list, returning the list's updated size. |

## 5. Dependency Trace

This method is called by subclasses that override `addListDataInstance` and delegate to `super.addListDataInstance(key)`, as well as by the parent bean `KKW00401SFBean` through its own override chain.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Bean:KKW00401SFBean | `KKW00401SFBean.addListDataInstance(key)` → `super.addListDataInstance(key)` → `KKW00401SF02DBean.addListDataInstance(key)` | In-memory: `X33VDataTypeList.add` → list |
| 2 | Bean:KKW00401SF01DBean | `KKW00401SF01DBean.addListDataInstance(key)` → `super.addListDataInstance(key)` → `KKW00401SF02DBean.addListDataInstance(key)` | In-memory: `X33VDataTypeList.add` → list |
| 3 | Bean:KKW00401SF09DBean | `KKW00401SF09DBean.addListDataInstance(key)` → `super.addListDataInstance(key)` → `KKW00401SF02DBean.addListDataInstance(key)` | In-memory: `X33VDataTypeList.add` → list |
| 4 | Bean:KKW00401SF22DBean | `KKW00401SF22DBean.addListDataInstance(key)` → `super.addListDataInstance(key)` → `KKW00401SF02DBean.addListDataInstance(key)` | In-memory: `X33VDataTypeList.add` → list |
| 5 | Bean:KKW00401SF23DBean | `KKW00401SF23DBean.addListDataInstance(key)` → `super.addListDataInstance(key)` → `KKW00401SF02DBean.addListDataInstance(key)` | In-memory: `X33VDataTypeList.add` → list |
| 6 | Bean:KKW00401SF25DBean | `KKW00401SF25DBean.addListDataInstance(key)` → `super.addListDataInstance(key)` → `KKW00401SF02DBean.addListDataInstance(key)` | In-memory: `X33VDataTypeList.add` → list |

**Notes:**
- This method is a leaf in the call chain — it does not invoke any downstream SC, CBS, or DAO methods.
- Callers are all beans within the KKW00401SF module that extend or wrap `KKW00401SF02DBean`'s `addListDataInstance` behavior and delegate upward via `super`.
- The method is primarily invoked by the X33 framework's data binding mechanism when the UI needs to add a new row to a dynamic list.

## 6. Per-Branch Detail Blocks

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

> Null guard. If the key is null, immediately return -1 to indicate no data type was specified. The original comment reads: nullの場合、-1で返す。(Returns -1 if null.)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return -1;` // null guard — no data type specified |

**Block 2** — ELSE-IF `(key.equals("STB異動区分"))` [STB異動区分 = "STB relocation classification"] (L3983)

> Creates a new STB relocation classification data bean instance and appends it to the `stb_ido_div_list` container. The original comments read: データタイプ項目 "STB異動区分"(項目ID:stb_ido_div) (Data type item "STB relocation classification" (item ID: stb_ido_div)) and リストがnullの場合、新しい空のインスタンスを生成する。(If the list is null, generate a new empty instance.)

| # | Type | Code |
|---|------|------|
| 1 | IF | `stb_ido_div_list == null` // list is null, create new instance |
| 2 | SET | `stb_ido_div_list = new X33VDataTypeList()` // initialize empty list [-> List initialization] |
| 3 | EXEC | (end of if block) |
| 4 | SET | `tmpBean = new KKW00401SF01DBean()` // create new data type bean instance [-> Data type bean] |
| 5 | EXEC | `stb_ido_div_list.add(tmpBean)` // append bean to list [-> List append] |
| 6 | RETURN | `return stb_ido_div_list.size() - 1;` // return zero-based index of added element |

**Block 3** — ELSE-IF `(key.equals("選択型番号"))` [選択型番号 = "Selected type number"] (L3994)

> Creates a new selected type number data bean instance and appends it to the `sel_type_number_list` container. The original comment reads: データタイプ項目 "選択型番号"(項目ID:sel_type_number) (Data type item "Selected type number" (item ID: sel_type_number)).

| # | Type | Code |
|---|------|------|
| 1 | IF | `sel_type_number_list == null` // list is null, create new instance |
| 2 | SET | `sel_type_number_list = new X33VDataTypeList()` // initialize empty list [-> List initialization] |
| 3 | EXEC | (end of if block) |
| 4 | SET | `tmpBean = new KKW00401SF01DBean()` // create new data type bean instance [-> Data type bean] |
| 5 | EXEC | `sel_type_number_list.add(tmpBean)` // append bean to list [-> List append] |
| 6 | RETURN | `return sel_type_number_list.size() - 1;` // return zero-based index of added element |

**Block 4** — ELSE-IF `(key.equals("STB区分"))` [STB区分 = "STB type classification"] (L4005)

> Creates a new STB type classification data bean instance and appends it to the `stb_div_list` container. The original comment reads: データタイプ項目 "STB区分"(項目ID:stb_div) (Data type item "STB classification" (item ID: stb_div)).

| # | Type | Code |
|---|------|------|
| 1 | IF | `stb_div_list == null` // list is null, create new instance |
| 2 | SET | `stb_div_list = new X33VDataTypeList()` // initialize empty list [-> List initialization] |
| 3 | EXEC | (end of if block) |
| 4 | SET | `tmpBean = new KKW00401SF01DBean()` // create new data type bean instance [-> Data type bean] |
| 5 | EXEC | `stb_div_list.add(tmpBean)` // append bean to list [-> List append] |
| 6 | RETURN | `return stb_div_list.size() - 1;` // return zero-based index of added element |

**Block 5** — ELSE-IF `(key.equals("HDD容量"))` [HDD容量 = "HDD capacity"] (L4016)

> Creates a new HDD capacity data bean instance and appends it to the `hdd_capa_list` container. The original comment reads: データタイプ項目 "HDD容量"(項目ID:hdd_capa) (Data type item "HDD capacity" (item ID: hdd_capa)).

| # | Type | Code |
|---|------|------|
| 1 | IF | `hdd_capa_list == null` // list is null, create new instance |
| 2 | SET | `hdd_capa_list = new X33VDataTypeList()` // initialize empty list [-> List initialization] |
| 3 | EXEC | (end of if block) |
| 4 | SET | `tmpBean = new KKW00401SF01DBean()` // create new data type bean instance [-> Data type bean] |
| 5 | EXEC | `hdd_capa_list.add(tmpBean)` // append bean to list [-> List append] |
| 6 | RETURN | `return hdd_capa_list.size() - 1;` // return zero-based index of added element |

**Block 6** — ELSE-IF `(key.equals("TVコース"))` [TVコース = "TV course"] (L4027)

> Creates a new TV course data bean instance and appends it to the `tv_course_list` container. The original comment reads: データタイプ項目 "TVコース"(項目ID:tv_course) (Data type item "TV course" (item ID: tv_course)).

| # | Type | Code |
|---|------|------|
| 1 | IF | `tv_course_list == null` // list is null, create new instance |
| 2 | SET | `tv_course_list = new X33VDataTypeList()` // initialize empty list [-> List initialization] |
| 3 | EXEC | (end of if block) |
| 4 | SET | `tmpBean = new KKW00401SF01DBean()` // create new data type bean instance [-> Data type bean] |
| 5 | EXEC | `tv_course_list.add(tmpBean)` // append bean to list [-> List append] |
| 6 | RETURN | `return tv_course_list.size() - 1;` // return zero-based index of added element |

**Block 7** — ELSE (default) (L4037)

> No matching data type key was found. Returns -1 to indicate an unrecognized key. The original comment reads: 該当する項目がない場合、-1を返す。(Returns -1 if there is no matching item.)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return -1;` // no matching item — unknown data type key [-> Default fallback] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| STB異動区分 | Japanese field | STB relocation classification — indicates whether an STB (Set-Top Box) is being relocated (異動 = transfer/relocation) to a different physical location as part of a service order |
| STB異動区分リスト | Japanese field | STB relocation classification list — the list container ID for STB relocation items (constant: `STB_IDO_DIV_LIST`) |
| 選択型番号 | Japanese field | Selected type number — the device model number chosen by the customer (選択 = selection, 型番号 = type number) |
| STB区分 | Japanese field | STB type classification — the category of STB hardware (区分 = classification/division), e.g., basic vs. premium tier |
| HDD容量 | Japanese field | HDD capacity — the storage capacity of an STB or recorder unit's internal hard disk drive (容量 = capacity) |
| TVコース | Japanese field | TV course — the television subscription plan or package selected by the customer (コース = course/package) |
| KKW00401SF01DBean | Class | Standard data transfer bean — the common bean type instantiated for each row in the dynamic lists. Implements `X33VDataTypeBeanInterface` for data serialization/deserialization |
| KKW00401SF02DBean | Class | Data type bean — the parent/factory bean that manages all typed list containers. Implements `X33VDataTypeBeanInterface` and `X33VListedBeanInterface` |
| X33VDataTypeList | Class | X33 framework list container — a typed collection that holds `X33VDataTypeBeanInterface` instances. Used for dynamic list management in the Futurity X33 web framework |
| X33VDataTypeBeanInterface | Interface | X33 framework interface for data-bearing beans — defines `loadModelData(String, String)` and `saveModelData` methods for serializing bean data |
| X33VListedBeanInterface | Interface | X33 framework interface for listed beans — provides methods for list-based bean management such as `getIndex()` and `getBean()` |
| X33SException | Exception | X33 framework runtime exception — thrown by X33 framework methods on processing errors |
| X33VDataTypeBean | Class | Generic data type bean in the X33 framework — the base class from which typed beans like `KKW00401SF01DBean` are derived |
| lazy initialization | Design pattern | Lists are initialized to `null` and only instantiated on first access, conserving memory when rows are never added for certain data types |
| dispatch/routing pattern | Design pattern | The method uses a chain of `if-else if` branches to route a string key to the appropriate processing block — equivalent to a string-based switch statement |
| KKW00401SF | Module | Service order registration screen module — handles STB and related device configuration for K-Opticom telecommunications |
| 固定要素数指定 | Japanese comment | Fixed element count specification — indicates that a list has a predetermined maximum number of elements |
| 要素数指定 | Japanese comment | Element count specification — controls the maximum number of elements allowed in a list |
