# KKW00401SF01DBean

## Purpose

`KKW00401SF01DBean` is a domain data bean for a screen-form (SF) in a Japanese enterprise web application framework. It provides a unified, field-based model for managing UI state — values, enabled/disabled toggles, edit/update flags, and display states — across several domain concepts (code type code, code type name, selected index, and default code). It also manages two dynamically-sized lists of code value/name entries and exposes a key/subkey-based data access API (`loadModelData`, `storeModelData`, `typeModelData`) that lets JSP pages and controllers read and write bean fields through a string-keyed dictionary, rather than calling getters/setters directly.

## Design

This class is a **data access facade / screen-model bean** that sits between JSP view pages and the underlying framework data types. It implements three interfaces:

- `X33VDataTypeBeanInterface` — marks the bean as a data-type-aware component that can load/store typed data via key/subkey lookups.
- `X33VListedBeanInterface` — marks the bean as supporting dynamic list operations (add, remove, clear list entries).
- `Serializable` — enables the bean to be serialized (e.g., placed in session scope).

The class follows a **flat-field model** pattern: each logical property has four related fields (update flag, value, enabled boolean, state string), plus two list collections for holding lists of code values and code names. Rather than exposing each field through a direct accessor, the bean also provides a **unified keyed access layer** (`loadModelData` / `storeModelData` / `typeModelData`) that accepts a Japanese-language key string and a subkey ("value", "enable", "state") to dispatch to the right getter or setter internally. This lets the framework bind UI fields generically without hard-calling specific bean methods.

The bean is not abstract and has no super-class; it is a concrete, self-contained model object. It declares no outbound dependencies beyond the framework interfaces and data types (`X33VDataTypeList`, `X33VDataTypeStringBean`, `SelectItem`).

## Fields

| Field | Type | Default | Purpose |
|---|---|---|---|
| `cd_div_cd_update` | `String` | `null` | Update/change flag for the code type code field. |
| `cd_div_cd_value` | `String` | `""` | The current value of the code type code. |
| `cd_div_cd_enabled` | `Boolean` | `false` | Whether the code type code field is enabled. |
| `cd_div_cd_state` | `String` | `""` | Display state of the code type code field. |
| `cd_div_nm_update` | `String` | `null` | Update flag for the code type name field. |
| `cd_div_nm_value` | `String` | `""` | The current value of the code type name. |
| `cd_div_nm_enabled` | `Boolean` | `false` | Whether the code type name field is enabled. |
| `cd_div_nm_state` | `String` | `""` | Display state of the code type name field. |
| `select_index_update` | `String` | `null` | Update flag for the selected index. |
| `select_index_value` | `String` | `""` | The current value of the selected index. |
| `select_index_enabled` | `Boolean` | `false` | Whether the selected index field is enabled. |
| `select_index_state` | `String` | `""` | Display state of the selected index. |
| `default_cd_update` | `String` | `null` | Update flag for the default code. |
| `default_cd_value` | `String` | `""` | The current value of the default code. |
| `default_cd_enabled` | `Boolean` | `false` | Whether the default code field is enabled. |
| `default_cd_state` | `String` | `""` | Display state of the default code. |
| `cd_div_cd_list_list` | `X33VDataTypeList` | `null` (initialized in ctor) | List of code type code values (`X33VDataTypeStringBean` items). |
| `cd_div_nm_list_list` | `X33VDataTypeList` | `null` (initialized in ctor) | List of code type name values (`X33VDataTypeStringBean` items). |
| `index` | `int` | `0` | A generic numeric index, purpose not self-evident from name alone. |

Each property group (e.g., `cd_div_cd_*`) represents a single logical UI control, split into four facets: whether it was updated, what its value is, whether it's enabled, and what its display state is. This mirrors a typical MVC screen-model where the view needs to know all four aspects to render and re-submit a form field correctly.

## Key Methods

### Constructor

```java
public KKW00401SF01DBean()
```

Instantiates the bean and initializes both list fields (`cd_div_cd_list_list` and `cd_div_nm_list_list`) to new, empty `X33VDataTypeList` instances. This means the lists are never null at construction time, simplifying downstream code that iterates over them.

### Getter/Setter Pairs (Flat Fields)

The bean exposes standard JavaBeans getters and setters for every field listed above. These follow the pattern `getXxx()` / `setXxx(param)` where `param` is `String` for value/state/update fields and `Boolean` for enabled fields. There are 20 such pairs (4 properties per logical field × 5 logical fields).

For example:
```java
public String getCd_div_cd_value()
public void setCd_div_cd_value(String param)
public Boolean getCd_div_cd_enabled()
public void setCd_div_cd_enabled(Boolean param)
```

### List-to-SelectItem Conversion

```java
public ArrayList<SelectItem> getJsflist_cd_div_cd_list()
public ArrayList<SelectItem> getJsflist_cd_div_nm_list()
```

These two methods convert the internal `X33VDataTypeList` collections into `ArrayList<SelectItem>` suitable for JSF/RichFaces `<h:selectOneMenu>` or similar dropdown UI components. They iterate over the list, cast each element to `X33VDataTypeStringBean`, extract its `getValue()`, and create a `SelectItem` with the list index as the value and the bean's value as the display label. This is a convenience bridge between the framework's internal list data and the JSF UI component library.

### loadModelData (Core Read API)

```java
public Object loadModelData(String key, String subkey)
```

This is the primary read operation. It accepts a **Japanese-language key** (the logical field name) and a **subkey** ("value", "enable", or "state") and dispatches to the appropriate getter. The supported keys are:

| Key (Japanese) | English Meaning | Supported subkeys |
|---|---|---|
| `コードタイプコード` | Code Type Code | `value`, `enable`, `state` |
| `コードタイプ名称` | Code Type Name | `value`, `enable`, `state` |
| `選択インデックス` | Selected Index | `value`, `enable`, `state` |
| `初期設定コード` | Default Code | `value`, `enable`, `state` |
| `コードタイプコード値リスト` | Code Type Code Value List | `value`, `enable`, `state` (with index suffix) |
| `コードタイプ名称リスト` | Code Type Name List | `value`, `enable`, `state` (with index suffix) |

For the list keys, the key string uses a `/` separator followed by an index (e.g., `コードタイプコード値リスト/3`). Special handling:

- Passing `*` as the index part (e.g., `コードタイプコード値リスト/*`) returns the **list size** as an `Integer`.
- Passing an invalid index returns `null`.
- Passing `null` for either `key` or `subkey` returns `null` early.

The return type is `Object` — callers cast to the expected type. This is a classic **polymorphic getter** pattern that lets the framework access any field through a single method signature.

### storeModelData (Core Write API)

```java
public void storeModelData(String key, String subkey, Object in_value)
public void storeModelData(String key, String subkey, Object in_value, boolean isSetAsString)
public void storeModelData(String gamenId, String key, String subkey, Object in_value)
```

The write counterpart to `loadModelData`. The three-argument version delegates to the four-argument version with `isSetAsString = false`. The four-argument version (with `isSetAsString`) exists to support `Long` type properties where the value needs to be set as a string.

The `gamenId` (screen ID) parameter in the four-argument version is not used — it simply delegates to the three-argument version. This appears to be a pre-prepared extension point or an interface compliance requirement.

For list keys, `storeModelData` finds the element at the given index in the list and calls `storeModelData` on that element's `X33VDataTypeStringBean`, passing the subkey and value through.

### typeModelData

```java
public Class<?> typeModelData(String key, String subkey)
```

Returns the expected Java type for the given key/subkey pair, enabling the framework to perform type-safe operations. Returns:

- `String.class` for `value` and `state` subkeys across all field types.
- `Boolean.class` for `enable` subkeys.
- `Integer.class` when the list key's index part is `"*"`.
- `null` for unrecognized keys or out-of-range indices.

Like `loadModelData` and `storeModelData`, this method supports all six logical key types (four scalar fields + two list types) and dispatches based on the key.

### listKoumokuIds

```java
public static ArrayList<String> listKoumokuIds()
```

A static method that returns the complete list of six recognized key names (in Japanese). This is useful for the framework to enumerate all supported fields for introspection, debugging, or dynamic form generation.

### List Data Operations (X33VListedBeanInterface)

```java
public int addListDataInstance(String key) throws X33SException
public void removeElementFromListData(String key, int index) throws X33SException
public void clearListDataInstance(String key) throws X33SException
```

These three methods manage the dynamic list collections:

- **`addListDataInstance`**: Creates a new `X33VDataTypeStringBean`, adds it to the appropriate list (based on `key`), and returns the index of the newly added element. Returns `-1` if the key is unrecognized or null. Initializes the list if it's null.
- **`removeElementFromListData`**: Removes the element at the given `index` from the appropriate list, with bounds checking.
- **`clearListDataInstance`**: Clears all elements from the specified list.

The recognized keys for these operations are the two list-type keys: `コードタイプコード値リスト` and `コードタイプ名称リスト`.

### getIndex / setIndex

```java
public int getIndex()
public void setIndex(int index)
```

A simple integer accessor. The field name `index` is generic and its specific purpose is not self-evident from the source — it may serve as a row or selection index used by the calling JSP pages.

## Relationships

```mermaid
flowchart TD
    JSP1["KKW004010PJP.jsp"] --> Bean["KKW00401SF01DBean"]
    JSP2["KKW004020PJP.jsp"] --> Bean
    Bean --> IF1["X33VDataTypeBeanInterface"]
    Bean --> IF2["X33VListedBeanInterface"]
    Bean --> IF3["Serializable"]
    Bean --> List1["X33VDataTypeList"]
    Bean --> Bean2["X33VDataTypeStringBean"]
    Bean --> SI["SelectItem"]
```

**Inbound connections (2 classes depend on this):**
- `KKW004010PJP.jsp` — a JSP page that uses this bean as its screen model.
- `KKW004020PJP.jsp` — another JSP page with the same dependency.

**Outbound dependencies:**
- The bean itself has no Java `import`-style code dependencies visible beyond the interfaces it implements and the types referenced in its method bodies (`X33VDataTypeList`, `X33VDataTypeStringBean`, `SelectItem`). These are all provided by the underlying framework (X33 framework, JSF library).

## Usage Example

A typical interaction follows this flow:

```java
// 1. The JSP or controller instantiates the bean
KKW00401SF01DBean bean = new KKW00401SF01DBean();

// 2. Set simple field values directly
bean.setCd_div_cd_value("001");
bean.setCd_div_cd_enabled(true);

// 3. Add entries to the dynamic lists
int idx1 = bean.addListDataInstance("コードタイプコード値リスト");
int idx2 = bean.addListDataInstance("コードタイプ名称リスト");

// 4. Use the keyed API to set/listen data on list elements
bean.storeModelData("コードタイプコード値リスト/0/value", "value", "コードA");
bean.storeModelData("コードタイプ名称リスト/0/value", "value", "コードタイプA");

// 5. Read data back through the keyed API
Object codeValue = bean.loadModelData("コードタイプコード値リスト/0/value", "value");
Object codeName = bean.loadModelData("コードタイプ名称リスト/0/value", "value");

// 6. Get list size via special "*" subkey
int listSize = (Integer) bean.loadModelData("コードタイプコード値リスト/*", "value");

// 7. Render to JSF dropdown
ArrayList<SelectItem> items = bean.getJsflist_cd_div_cd_list();
// items can now be bound to an <h:selectOneMenu> component

// 8. Remove or clear list entries as needed
bean.removeElementFromListData("コードタイプコード値リスト", 0);
bean.clearListDataInstance("コードタイプ名称リスト");
```

The framework's binding layer likely iterates over the keys returned by `listKoumokuIds()`, calling `loadModelData` and `storeModelData` for each, to populate and re-submit the form without explicit field-level code in the controller.

## Notes for Developers

- **All keys are in Japanese.** The key strings (`コードタイプコード`, `コードタイプ名称`, `選択インデックス`, etc.) are hard-coded literals, not constants. If the application needs to support localization or refactoring, these strings should be extracted to constants.
- **Case-insensitive subkey matching.** The `subkey` parameter is compared using `equalsIgnoreCase`, so `"Value"`, `"VALUE"`, and `"value"` are all equivalent for subkeys.
- **`gamenId` parameter is unused.** The `storeModelData(String gamenId, ...)` overload accepts a screen ID that is never referenced inside the method body. Do not rely on its value.
- **List initialization is lazy for lists but eager for ctor.** The constructor creates the two `X33VDataTypeList` instances, but `addListDataInstance` also guards against null by re-initializing if needed. This is defensive but suggests the lists could theoretically be null if deserialized from a stale session.
- **Type safety relies on caller discipline.** `loadModelData` returns `Object` and `storeModelData` takes `Object`. The framework is expected to enforce correct types at the call site. There is no runtime type checking in the bean itself (except for the index parsing in list operations).
- **`isSetAsString` is a boolean flag** for `Long` type properties. When `true`, the value should be set as a String even though the underlying type is `Long`. The current implementation does not use this flag — it appears to be a hook for future type-specific logic.
- **Thread safety:** This bean is not thread-safe. It has mutable state and no synchronization. As a screen-model bean typically stored per-user session in a web application, this is acceptable, but the bean should not be shared across threads.
- **`X33SException`** is thrown by the list operations. Callers must handle or declare this exception.
- **The class does not implement `equals()` or `hashCode()`.** Two instances of `KKW00401SF01DBean` are only equal if they are the same reference.
