# KKW00130SF01DBean

## Purpose

`KKW00130SF01DBean` is a data bean that manages structured lists of code identifiers and code names within the application. It acts as a runtime container for two parallel lists (`cd_list_list` and `cd_nm_list_list`) that hold selectable option values, providing standardized access patterns for loading, storing, and querying data through a key/subkey navigation system. This class exists to decouple the JSP view layer from direct list manipulation, offering a unified API for the framework's model-data binding mechanism.

## Design

The class follows the **Data Bean / Model-View Bridge** pattern. It implements two framework-specific interfaces:

- **`X33VDataTypeBeanInterface`** — provides the `loadModelData`, `storeModelData`, and `typeModelData` methods that the framework calls to serialize and deserialize bean state.
- **`X33VListedBeanInterface`** — provides list instance management methods (`addListDataInstance`, `removeElementFromListData`, `clearListDataInstance`) for dynamic list item creation and removal.

Its role is purely as a **data carrier and dispatcher**. It does not contain business logic; instead, it delegates all actual data operations to the individual `X33VDataTypeStringBean` instances stored inside its internal `X33VDataTypeList` containers. The class uses a key-based routing pattern (similar to a hierarchical path system like `キー/サブキー`) to determine which internal property or list element a given operation targets.

### Key fields

| Field | Type | Purpose |
|---|---|---|
| `index_update` | `String` | Tracks what was last updated; initialized to `null` |
| `index_value` | `String` | Holds the current value string; defaults to `""` |
| `index_state` | `String` | Holds the current state string; defaults to `""` |
| `cd_list_list` | `X33VDataTypeList` | List of code identifiers (code IDs); initialized to empty list in constructor |
| `cd_nm_list_list` | `X33VDataTypeList` | List of code names; initialized to empty list in constructor |
| `index` | `int` | A generic integer index, not tied to any specific framework operation |

The two `X33VDataTypeList` fields are lazily initialized inside the constructor to new empty `X33VDataTypeList` instances. They each hold `X33VDataTypeStringBean` elements, as evidenced by the casts in `getJsflist_cd_list()` and `getJsflist_cd_nm_list()`.

## Key Methods

### `loadModelData(String key, String subkey) → Object`

Loads data by resolving a key/subkey path into the appropriate internal property or list element.

- If `key` or `subkey` is `null`, returns `null`.
- Routes based on key:
  - `"添え字"` (subscript/index): Dispatches to `index_value` or `index_state` based on the `subkey` (case-insensitive match on `"value"` or `"state"`).
  - `"コードリスト"` (code list): Parses the key further as `"コードリスト/{index}"`. If the sub-key is `"*"`, returns the list size as `Integer`. Otherwise, parses the index, bounds-checks it, and delegates to `((X33VDataTypeStringBean) cd_list_list.get(index)).loadModelData(subkey)`.
  - `"コード名リスト"` (code name list): Same logic as `"コードリスト"`, but operates on `cd_nm_list_list`.
- Returns `null` for unrecognized keys.

This is the primary read-side of the model-data bridge.

### `storeModelData(...)` (three overloads)

Writes data by resolving the same key/subkey routing as `loadModelData`.

1. `storeModelData(String gamenId, String key, String subkey, Object in_value)` — Takes a screen ID parameter (`gamenId`) which is currently unused (marked as `予備` / reserve in comments). Delegates to the 3-arg overload.

2. `storeModelData(String key, String subkey, Object in_value)` — Default convenience overload that calls the full version with `isSetAsString = false`.

3. `storeModelData(String key, String subkey, Object in_value, boolean isSetAsString)` — Full implementation:
   - Early-exits if `key` or `subkey` is `null`.
   - For `"添え字"`: Sets `index_value` or `index_state` via the corresponding setter.
   - For `"コードリスト"` and `"コード名リスト"`: Parses the index from the key, bounds-checks it, then delegates to `((X33VDataTypeStringBean) list.get(index)).storeModelData(subkey, in_value)`. The `isSetAsString` flag is documented as being used by `X33VDataTypeLongBean` to control string-to-Long conversion.
   - Note: Unlike `loadModelData`, this method returns `void` and silently does nothing for out-of-range indices (the condition is `tmpIndex >= 0 && tmpIndex < list.size()` but does not throw).

### `typeModelData(String key, String subkey) → Class<?>`

Returns the Java type for a given key/subkey path. Used by the framework for type checking and serialization.

- `"添え字"` → always returns `String.class`.
- `"コードリスト/{index}"` or `"コード名リスト/{index}"` → delegates to the corresponding `X33VDataTypeStringBean.typeModelData(subkey)`.
- `"*"` as index → returns `Integer.class` (the type for list size queries).
- Returns `null` for unknown or out-of-bounds keys.

### `listKoumokuIds() → ArrayList<String>`

A static method that returns the list of all valid property keys ("項目名") this bean supports. Currently returns three entries: `"添え字"`, `"コードリスト"`, and `"コード名リスト"`. This appears to be used by the framework to enumerate which properties should be saved/restored.

### `addListDataInstance(String key) → int`

Adds a new element to the appropriate list and returns the index of the newly added element.

- If `key` is `null`, returns `-1`.
- For `"コードリスト"`: Creates a new empty `X33VDataTypeList` if needed, instantiates a new `X33VDataTypeStringBean`, appends it, and returns the new element's index.
- For `"コード名リスト"`: Same logic on `cd_nm_list_list`.
- Returns `-1` for any unrecognized key.
- Throws `X33SException` per the signature (though the method body shown does not explicitly throw it — the exception is likely thrown by the framework's `X33VDataTypeList.add()` or `X33VDataTypeStringBean` constructor internally).

### `removeElementFromListData(String key, int index) → void`

Removes an element at the given index from the specified list. Bounds-checked — silently does nothing if the index is out of range.

### `clearListDataInstance(String key) → void`

Clears all elements from the specified list. Does not nullify the list reference — the list remains an empty `X33VDataTypeList`.

### `getJsflist_cd_list() → ArrayList<SelectItem>` and `getJsflist_cd_nm_list() → ArrayList<SelectItem>`

JSF integration helpers that convert internal `X33VDataTypeList` data into `SelectItem` objects suitable for JSF UI components (e.g., `<h:selectOneMenu>`). Each element is cast to `X33VDataTypeStringBean`, its `getValue()` is extracted, and wrapped as a `SelectItem` with the list index as the value and the actual string as the label. These are the methods that bridge the bean to the JSF view layer.

## Relationships

### Class diagram

```mermaid
flowchart TD
    subgraph JSP["JSP Pages"]
        JSP1["KKW001300PJP"]
        JSP2["KKW001360PJP"]
    end

    subgraph BEAN["KKW00130SF01DBean"]
        direction TB
        F1["index_update<br/>index_value<br/>index_state"]
        F2["cd_list_list<br/>X33VDataTypeList"]
        F3["cd_nm_list_list<br/>X33VDataTypeList"]
        F4["index<br/>int"]
    end

    JSP1 -->|"getBmp_haishi_req_ctrl_cd_list"| BEAN
    JSP2 -->|"getBmp_haishi_req_ctrl_cd_list"| BEAN

    style BEAN fill:#e1f5fe,stroke:#01579b,stroke-width:2px
```

### Dependency summary

**Incoming (who uses this class):**
- **`KKW001300PJP.jsp`** — Casts from a nested bean hierarchy to access a `KKW00130SF01DBean` instance via `getBmp_haishi_req_ctrl_cd_list()`.
- **`KKW001360PJP.jsp`** — Same access pattern, indicating this bean type is a shared data structure reused across multiple screens.

**Outgoing (what this class depends on):**
- **`X33VDataTypeList`** — The container type for both lists.
- **`X33VDataTypeStringBean`** — The element type stored within each list; the bean casts to this type in every access path.
- **`X33VDataTypeBeanInterface`** — Framework interface for data model binding.
- **`X33VListedBeanInterface`** — Framework interface for list-managed beans.
- **`ArrayList<SelectItem>`** / **`SelectItem`** — JSF component data type.
- **`X33SException`** — Thrown by list manipulation methods.

### Access pattern

The JSP files access `KKW00130SF01DBean` through a nested path:

```
KKW00130SFBean
  └─ getServiceFormBeanList() → List
      └─ get(0) → KKW00130SF02DBean
          └─ getTelno_lst_list() → List
              └─ get(telnoCounter) → KKW00130SF02DBean
                  └─ getBmp_haishi_req_ctrl_cd_list() → KKW00130SF01DBean
```

This suggests the bean lives deep within a composite structure where each phone number entry (`telnoCounter`) has its own associated list of blackout request control codes.

## Usage Example

Based on the JSP usage patterns, a typical workflow looks like this:

1. **Retrieval**: The JSP retrieves the bean from a shared service form bean list, walking through nested beans to reach the specific `KKW00130SF01DBean` instance.

2. **Population**: The framework (or backing bean) populates the `cd_list_list` and `cd_nm_list_list` with `X33VDataTypeStringBean` items via `storeModelData()` calls with keys like `"コードリスト/0"` and `"コード名リスト/0"`.

3. **JSF rendering**: The JSP calls `getJsflist_cd_list()` or `getJsflist_cd_nm_list()` to convert the internal lists into `SelectItem` collections for display in dropdown menus.

4. **Dynamic management**: When items need to be added, removed, or cleared, the JSP or backing code calls `addListDataInstance()`, `removeElementFromListData()`, or `clearListDataInstance()`.

5. **State persistence**: On form submission, the framework calls `loadModelData()` and `typeModelData()` to serialize and deserialize the bean's state using the key/subkey path convention.

## Notes for Developers

- **Japanese key names**: All routing keys are in Japanese (`"添え字"`, `"コードリスト"`, `"コード名リスト"`). These are literal string comparisons — typos or localization will silently break routing since `null` is returned for unrecognized keys.

- **Silent failure on bounds**: Both `storeModelData` and `removeElementFromListData` silently do nothing (no exception, no return value) when an index is out of bounds. Callers must manage list sizes themselves or check first.

- **Type safety is manual**: The code casts list elements to `X33VDataTypeStringBean` at every access point. If a different type is added to the list (via `addListDataInstance` or direct manipulation), a `ClassCastException` will occur at runtime.

- **Constructor side effects**: The constructor eagerly initializes both `cd_list_list` and `cd_nm_list_list` to empty lists, but the constructor comment references `"コンストラクタの宣言部生成"` (declaration section generation), suggesting this may be an auto-generated file. Do not assume the constructor logic is intentional.

- **Thread safety**: The class has no synchronization. If the same `KKW00130SF01DBean` instance is accessed from multiple threads (e.g., shared across JSP requests), concurrent `addListDataInstance` / `removeElementFromListData` calls could corrupt the internal `X33VDataTypeList` instances.

- **The `gamenId` parameter is unused**: The 4-argument `storeModelData` takes a screen ID but passes it nowhere — it is explicitly marked as `予備` (reserve/future use) in comments.

- **`addListDataInstance` throws `X33SException`**: While the visible code does not throw it directly, the exception signature suggests underlying framework operations (list creation, bean instantiation) may throw checked exceptions that should be handled by callers.

- **`isSetAsString` flag**: The `isSetAsString` parameter in the 4-arg `storeModelData` is documented as controlling whether Long-type values should be set as strings. This flag is passed through to the underlying `X33VDataTypeStringBean.storeModelData()` — verify the contract of that method if you need to understand how numeric values are converted.
