# Business Logic — Mover.setBeanMapToDataBean() [64 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW01021SF.Mover.setBeanMapToDataBean(BeanMap beanMap, X31SDataBeanAccess bean)` |
| Layer | Utility / Common Component (shared across Controller and CC layers) |
| Module | `KKW01021SF` (Package: `eo.web.webview.KKW01021SF`) |

## 1. Role

### Mover.setBeanMapToDataBean()

This method performs a **bidirectional data transfer** from a generic `BeanMap` back into a strongly-typed `X31SDataBeanAccess` data bean. It serves as the **setter counterpart** to `getBeanMapFromDataBean`, which extracts data from a data bean into a `BeanMap`. Together, these methods implement a flexible object-to-map serialization/deserialization pattern used throughout the web framework.

The method implements a **type-dispatch pattern**: it iterates over every key-value pair in the `BeanMap`, resolves the runtime type of each value using `ValueType.resolve()`, and then routes the assignment to the correct setter (`setString`, `setLong`, `setBoolean`), message array method (`sendMessageStringArray`, `sendMessageLongArray`, `sendMessageBooleanArray`), or nested data bean array method (`getDataBeanArray` / `setBeanMapListForDataBeanArray`) based on the resolved type.

Its role in the larger system is as a **cross-cutting data binding utility** used by screen mappers (e.g., `KKSV0234_KKSV0234OPDBMapper`, `KKSV0240_KKSV0240OPDBMapper`) and various screen logic classes (e.g., `KKA15001SFLogic`, `KKA15101SFLogic`, `KKW01030SFLogic`) to push processed model data back into the screen data bean before the view is rendered. It is a shared utility — called by over 20 callers across multiple screens and web modules (both koptWebA and koptWebB).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["setBeanMapToDataBean(beanMap, bean)"])
    FOR_LOOP["for (String key : beanMap.keySet())"]
    GET_VAL["Object value = beanMap.get(key)"]
    RESOLVE_TYPE["ValueType type = ValueType.resolve(value)"]
    SWITCH["switch (type)"]
    CASE_NULL["case NULL: break"]
    CASE_STRING["case STRING:"]
    CALL_SET_STRING["Mover.setString(bean, key, (String)value)"]
    CASE_LONG["case LONG:"]
    CALL_SET_LONG["Mover.setLong(bean, key, (Long)value)"]
    CASE_BOOLEAN["case BOOLEAN:"]
    CALL_SET_BOOLEAN["Mover.setBoolean(bean, key, (Boolean)value)"]
    CASE_STRINGS["case STRINGS:"]
    CREATE_VEC_S["X31CVector<String> vec = new X31CVector<String>()"]
    LOOP_STRINGS["for (String s : (String[])value) vec.add(s)"]
    CALL_SEND_SA["bean.sendMessageStringArray(key, DATABEAN_SET_DEF_VALUE, vec)"]
    CASE_LONGS["case LONGS:"]
    CREATE_VEC_L["X31CVector<Long> vec = new X31CVector<Long>()"]
    LOOP_LONGS["for (Long s : (Long[])value) vec.add(s)"]
    CALL_SEND_LA["bean.sendMessageLongArray(key, DATABEAN_SET_DEF_VALUE, vec)"]
    CASE_BOOLEANS["case BOOLEANS:"]
    CREATE_VEC_B["X31CVector<Boolean> vec = new X31CVector<Boolean>()"]
    LOOP_BOOLEANS["for (Boolean s : (Boolean[])value) vec.add(s)"]
    CALL_SEND_BA["bean.sendMessageBooleanArray(key, DATABEAN_SET_DEF_VALUE, vec)"]
    CASE_ARRAY_LIST["case ARRAY_LIST:"]
    GET_DA["subBeanArray = bean.getDataBeanArray(key)"]
    CALL_SET_LIST["setBeanMapListForDataBeanArray(subBeanArray, (ArrayList<BeanMap>)value)"]
    CASE_DEFAULT["default: throw JCCFrameworkException<br/>JCCWebCommonでサポートされていないオブジェクトの型です。"]
    NEXT_ITERATION["next key / end loop"]
    END_NODE(["Return / Next"])

    START --> FOR_LOOP
    FOR_LOOP --> GET_VAL
    GET_VAL --> RESOLVE_TYPE
    RESOLVE_TYPE --> SWITCH
    SWITCH --> CASE_NULL
    SWITCH --> CASE_STRING
    CASE_STRING --> CALL_SET_STRING
    SWITCH --> CASE_LONG
    CASE_LONG --> CALL_SET_LONG
    SWITCH --> CASE_BOOLEAN
    CASE_BOOLEAN --> CALL_SET_BOOLEAN
    SWITCH --> CASE_STRINGS
    CASE_STRINGS --> CREATE_VEC_S
    CREATE_VEC_S --> LOOP_STRINGS
    LOOP_STRINGS --> CALL_SEND_SA
    SWITCH --> CASE_LONGS
    CASE_LONGS --> CREATE_VEC_L
    CREATE_VEC_L --> LOOP_LONGS
    LOOP_LONGS --> CALL_SEND_LA
    SWITCH --> CASE_BOOLEANS
    CASE_BOOLEANS --> CREATE_VEC_B
    CREATE_VEC_B --> LOOP_BOOLEANS
    LOOP_BOOLEANS --> CALL_SEND_BA
    SWITCH --> CASE_ARRAY_LIST
    CASE_ARRAY_LIST --> GET_DA
    GET_DA --> CALL_SET_LIST
    SWITCH --> CASE_DEFAULT
    CASE_NULL --> NEXT_ITERATION
    CALL_SET_STRING --> NEXT_ITERATION
    CALL_SET_LONG --> NEXT_ITERATION
    CALL_SET_BOOLEAN --> NEXT_ITERATION
    CALL_SEND_SA --> NEXT_ITERATION
    CALL_SEND_LA --> NEXT_ITERATION
    CALL_SEND_BA --> NEXT_ITERATION
    CALL_SET_LIST --> NEXT_ITERATION
    CASE_DEFAULT --> END_NODE
    NEXT_ITERATION -->|more keys| FOR_LOOP
    NEXT_ITERATION -->|no more keys| END_NODE
```

**Processing flow:**
1. Iterate over every key in `beanMap` (a generic map of screen data)
2. For each entry, extract the value and resolve its runtime `ValueType` via `ValueType.resolve()`
3. **Dispatch by type** — eight branches handle each possible data type:
   - **NULL**: Skip the key (no assignment)
   - **STRING**: Set a single string value via `Mover.setString()`
   - **LONG**: Set a single long value via `Mover.setLong()`
   - **BOOLEAN**: Set a single boolean value via `Mover.setBoolean()`
   - **STRINGS**: Convert a `String[]` into `X31CVector<String>`, then write via `sendMessageStringArray` with `DATABEAN_SET_DEF_VALUE`
   - **LONGS**: Convert a `Long[]` into `X31CVector<Long>`, then write via `sendMessageLongArray` with `DATABEAN_SET_DEF_VALUE`
   - **BOOLEANS**: Convert a `Boolean[]` into `X31CVector<Boolean>`, then write via `sendMessageBooleanArray` with `DATABEAN_SET_DEF_VALUE`
   - **ARRAY_LIST**: Recursively handle nested bean arrays by fetching the sub-bean-array and delegating to `setBeanMapListForDataBeanArray()`
   - **default**: Throw a `JCCFrameworkException` with the message "JCCWebCommonでサポートされていないオブジェクトの型です。" (An object type not supported by JCCWebCommon.)

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `beanMap` | `BeanMap` | A generic key-value map representing processed screen model data. Each key corresponds to a field name in the target data bean, and each value carries the value to be written. This is the source of truth for what data should be pushed back into the screen bean — typically populated by business processing logic or mapper methods before the view layer renders the response. |
| 2 | `bean` | `X31SDataBeanAccess` | The strongly-typed screen data bean (SF Bean) that holds all data for a specific web screen (e.g., discount service contract, cancellation screen). This is the target where the method writes all data. The bean is populated field by field based on the keys present in `beanMap`. |

**External state read by the method:**

| No | Source | Description |
|----|--------|-------------|
| 1 | `X31CWebConst.DATABEAN_SET_DEF_VALUE` | Constant defining the default value mode for data bean message-based array writes. Used as the message type code when pushing string/long/boolean arrays to the bean. |
| 2 | `ValueType.resolve(Object)` | Utility method that inspects the runtime type of the value and classifies it into one of the `ValueType` enum members (NULL, STRING, LONG, BOOLEAN, STRINGS, LONGS, BOOLEANS, ARRAY_LIST). |

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `BeanMap.keySet` | BeanMap | - | Iterates over all keys in the source bean map |
| - | `BeanMap.get` | BeanMap | - | Retrieves the value for each key |
| - | `ValueType.resolve` | ValueType | - | Resolves the runtime Java type of the value |
| R | `X31SDataBeanAccess.getDataBeanArray` | OneStopDataBeanAccess | - | Fetches the sub-data-bean array at the given key (for nested ARRAY_LIST values) |
| - | `Mover.setBeanMapListForDataBeanArray` | Mover | - | Recursively writes a list of BeanMaps into a data bean array |
| - | `Mover.setString` | Mover | - | Sets a string value on the data bean for the given key |
| - | `Mover.setLong` | Mover | - | Sets a long value on the data bean for the given key |
| - | `Mover.setBoolean` | Mover | - | Sets a boolean value on the data bean for the given key |
| - | `X31CVector.<init>` | X31CVector | - | Creates a new typed vector container for array elements |
| - | `X31CVector.add` | X31CVector | - | Adds individual elements to the vector |
| - | `X31SDataBeanAccess.sendMessageStringArray` | OneStopDataBeanAccess | - | Writes a string array to the data bean via message-based API with DATABEAN_SET_DEF_VALUE |
| - | `X31SDataBeanAccess.sendMessageLongArray` | OneStopDataBeanAccess | - | Writes a long array to the data bean via message-based API with DATABEAN_SET_DEF_VALUE |
| - | `X31SDataBeanAccess.sendMessageBooleanArray` | OneStopDataBeanAccess | - | Writes a boolean array to the data bean via message-based API with DATABEAN_SET_DEF_VALUE |

This method performs **no direct database or SC (Service Component) operations**. It is a pure data-transformation utility that moves data between in-memory objects. No SC Codes or database tables are accessed.

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

No screen/batch entry points found within 8 hops. Direct callers found: 10 methods.
Terminal operations from this method: `setBeanMapListForDataBeanArray` [-], `getDataBeanArray` [R], `setBoolean` [-], `setLong` [-], `setString` [-], `keySet` [-], `keySet` [-]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Mapper:KKSV0234 | `getKKSV023402CC` -> `Mover.setBeanMapToDataBean` | No terminal SC/DB — in-memory data binding only |
| 2 | Mapper:KKSV0240 | `getKKSV024002CC` -> `Mover.setBeanMapToDataBean` | No terminal SC/DB — in-memory data binding only |
| 3 | Common:KKW01021SFLogic | `editWribCampaignList` -> `Mover.setBeanMapToDataBean` | No terminal SC/DB — in-memory data binding only |
| 4 | Utility:Mover | `addBeanMapForDataBeanArray` -> `Mover.setBeanMapToDataBean` | No terminal SC/DB — internal utility chain |
| 5 | Utility:Mover | `setBeanMapListForDataBeanArray` -> `Mover.setBeanMapToDataBean` | No terminal SC/DB — recursive data binding |
| 6 | Mapper:KKA15001SFLogic | `editCampaignList` (or similar) -> `Mover.setBeanMapToDataBean` | No terminal SC/DB — in-memory data binding only |
| 7 | Mapper:KKA15201SFLogic | `processCampaign` (various entry points) -> `Mover.setBeanMapToDataBean` | No terminal SC/DB — in-memory data binding only |
| 8 | Mapper:KKA15101SFLogic | `processCampaign` (various entry points) -> `Mover.setBeanMapToDataBean` | No terminal SC/DB — in-memory data binding only |
| 9 | Controller:KKW01001SFLogic | `processRequest` (entry point) -> `Mover.setBeanMapToDataBean` | No terminal SC/DB — in-memory data binding only |
| 10 | Controller:KKW01030SFLogic | `getKKW01030xxCC` (various) -> `Mover.setBeanMapToDataBean` | No terminal SC/DB — in-memory data binding only |
| 11 | Controller:KKW01031SFLogic | `getKKW01031xxCC` (various) -> `Mover.setBeanMapToDataBean` | No terminal SC/DB — in-memory data binding only |
| 12 | Controller:KKW01033SFLogic | `getKKW01033xxCC` (various) -> `Mover.setBeanMapToDataBean` | No terminal SC/DB — in-memory data binding only |

**Notes:**
- The method is a pure in-memory data binder and does **not** reach any SC or database layer directly.
- Its terminal operations are all data-bean-level writes (setters, message-based array writes, recursive bean array writes).
- It is called from screen mappers and logic classes across multiple web modules (koptWebA, koptWebB) for discount/campaign service screens.

## 6. Per-Branch Detail Blocks

**Block 1** — [FOR] `(for each key in beanMap)` (L1395)

> Iterate over every key-value pair in the source BeanMap and write each value into the target data bean.

| # | Type | Code |
|---|------|------|
| 1 | GET | `Object value = beanMap.get(key)` // Retrieve value for the current key |
| 2 | CALL | `ValueType type = ValueType.resolve(value)` // Classify the runtime type of the value |
| 3 | EXEC | `switch (type)` // Dispatch processing based on the resolved type |

---

**Block 1.1** — [SWITCH-CASE] `NULL` (L1400)

> Null values are silently skipped — no data is written for this key.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `break` // Skip this key, continue to next iteration |

---

**Block 1.2** — [SWITCH-CASE] `STRING` (L1402)

> Write a single String value into the data bean.

| # | Type | Code |
|---|------|------|
| 1 | CAST | `value` cast to `(String)` |
| 2 | CALL | `Mover.setString(bean, key, (String)value)` // Set the string on the bean |

---

**Block 1.3** — [SWITCH-CASE] `LONG` (L1405)

> Write a single Long value into the data bean.

| # | Type | Code |
|---|------|------|
| 1 | CAST | `value` cast to `(Long)` |
| 2 | CALL | `Mover.setLong(bean, key, (Long)value)` // Set the long on the bean |

---

**Block 1.4** — [SWITCH-CASE] `BOOLEAN` (L1408)

> Write a single Boolean value into the data bean.

| # | Type | Code |
|---|------|------|
| 1 | CAST | `value` cast to `(Boolean)` |
| 2 | CALL | `Mover.setBoolean(bean, key, (Boolean)value)` // Set the boolean on the bean |

---

**Block 1.5** — [SWITCH-CASE] `STRINGS` (L1411)

> Write a String array into the data bean. Converts the Java `String[]` into a typed `X31CVector<String>` wrapper, then writes it using the message-based array API with `DATABEAN_SET_DEF_VALUE` (default value mode).

| # | Type | Code |
|---|------|------|
| 1 | SET | `X31CVector<String> vec = new X31CVector<String>()` // Create new vector container |
| 2 | FOR | `for (String s : (String[])value)` // Iterate over each element of the string array |
| 2.1 | EXEC | `vec.add(s)` // Add string element to vector |
| 3 | CALL | `bean.sendMessageStringArray(key, X31CWebConst.DATABEAN_SET_DEF_VALUE, vec)` // Write the string array to the bean |

**Block 1.5.1** — [FOR] `for (String s : (String[])value)` (L1414)

> Copy each element of the input `String[]` into the `X31CVector`.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `vec.add(s)` // Add element to vector |

---

**Block 1.6** — [SWITCH-CASE] `LONGS` (L1423)

> Write a Long array into the data bean. Converts `Long[]` into `X31CVector<Long>`, then writes via `sendMessageLongArray` with `DATABEAN_SET_DEF_VALUE`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `X31CVector<Long> vec = new X31CVector<Long>()` // Create new vector container |
| 2 | FOR | `for (Long s : (Long[])value)` // Iterate over each element |
| 2.1 | EXEC | `vec.add(s)` // Add element to vector |
| 3 | CALL | `bean.sendMessageLongArray(key, X31CWebConst.DATABEAN_SET_DEF_VALUE, vec)` // Write long array to bean |

---

**Block 1.7** — [SWITCH-CASE] `BOOLEANS` (L1432)

> Write a Boolean array into the data bean. Converts `Boolean[]` into `X31CVector<Boolean>`, then writes via `sendMessageBooleanArray` with `DATABEAN_SET_DEF_VALUE`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `X31CVector<Boolean> vec = new X31CVector<Boolean>()` // Create new vector container |
| 2 | FOR | `for (Boolean s : (Boolean[])value)` // Iterate over each element |
| 2.1 | EXEC | `vec.add(s)` // Add element to vector |
| 3 | CALL | `bean.sendMessageBooleanArray(key, X31CWebConst.DATABEAN_SET_DEF_VALUE, vec)` // Write boolean array to bean |

---

**Block 1.8** — [SWITCH-CASE] `ARRAY_LIST` (L1441)

> Handle nested data bean arrays (e.g., a list of campaign items). Fetches the sub-bean-array from the target bean at the given key, then recursively calls `setBeanMapListForDataBeanArray` to write the entire list of BeanMaps into the nested array.

| # | Type | Code |
|---|------|------|
| 1 | SET | `X31SDataBeanAccessArray subBeanArray = null` // Declare sub-bean-array variable |
| 2 | CALL | `subBeanArray = bean.getDataBeanArray(key)` // Fetch the sub-bean-array from the target bean |
| 3 | CALL | `setBeanMapListForDataBeanArray(subBeanArray, (ArrayList<BeanMap>)value)` // Recursively write the nested list |

---

**Block 1.9** — [SWITCH-CASE] `default` (L1450)

> An unsupported type was encountered in the BeanMap. This should not happen if the BeanMap was built by `getBeanMapFromDataBean`, which only produces recognized value types. Throws a runtime exception with a Japanese error message indicating the type is not supported by JCCWebCommon.

| # | Type | Code |
|---|------|------|
| 1 | THROW | `throw new JCCFrameworkException("JCCWebCommonでサポートされていないオブジェクトの型です。")` // An object type not supported by JCCWebCommon.getScreenInfo |

---

**Block 2** — [END] `(Return)` (L1455)

> After the loop completes (all keys processed) or an exception is thrown, the method returns void.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return` // Method completes, data has been written into bean |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `BeanMap` | Class | A generic map-based container (key-value pairs) used to hold screen data in a loosely-typed format. Acts as an intermediate representation between processed model objects and typed data beans. |
| `X31SDataBeanAccess` | Class | The strongly-typed screen data bean (SF Bean) that holds all data for a specific web screen. Fields are set via typed setter methods (`setString`, `setLong`, `setBoolean`) or message-based array methods (`sendMessageStringArray`, etc.). |
| `X31SDataBeanAccessArray` | Class | A typed array container for data bean instances. Used to hold nested collections of beans (e.g., a list of campaign line items). |
| `X31CVector<T>` | Class | A typed vector/collection wrapper used by the X31S framework to hold arrays of values (String, Long, Boolean) before writing them to a data bean via message-based APIs. |
| `DATABEAN_SET_DEF_VALUE` | Constant | A constant in `X31CWebConst` specifying the default value mode for data bean message-based array writes. Indicates that the array values should overwrite existing bean data. |
| `ValueType` | Enum | An enum that classifies runtime Java object types into: NULL, STRING, LONG, BOOLEAN, STRINGS, LONGS, BOOLEANS, ARRAY_LIST. Used for type dispatch in data transfer methods. |
| `Mover` | Class | A utility class in the KKW01021SF package providing shared data transfer methods (get/set BeanMap <-> DataBean conversions). Used across multiple screen modules. |
| `JCCFrameworkException` | Class | A runtime exception thrown when an unexpected or unsupported type is encountered during data binding operations. |
| `SFBean` | Abbreviation | Screen Data Bean — the data holder for a web screen, containing all data fields that the view layer reads for rendering. |
| `koptWebA` | Module | The A-series web application module (customer-facing screens such as discount service registration, cancellation). |
| `koptWebB` | Module | The B-series web application module (operational screens for campaign management and internal processing). |
| `KKSVxxxx` | Pattern | Screen class naming convention — KKSV followed by 4 digits identifies a screen mapper class (e.g., KKSV0234 for discount service contract registration, KKSV0240 for discount service cancellation). |
| `KKW01021SF` | Module | A web screen module responsible for web riba (writing) campaign list processing. |
| `sendMessageStringArray` | Method | Data bean API that writes a string array to a bean field using a message-based setter with a specified value mode. |
| `sendMessageLongArray` | Method | Data bean API that writes a long array to a bean field using a message-based setter with a specified value mode. |
| `sendMessageBooleanArray` | Method | Data bean API that writes a boolean array to a bean field using a message-based setter with a specified value mode. |
| `getBeanMapFromDataBean` | Method | The counterpart to `setBeanMapToDataBean` — extracts data from a data bean into a BeanMap for processing. |
| `setBeanMapListForDataBeanArray` | Method | Recursively writes a list of BeanMaps into a data bean array, used for nested collection handling. |
