# Eo / Ejb / Wiki

## Overview

The `eo.ejb.wiki` package contains two simple utility classes that serve as foundational building blocks within the `eo.ejb` subsystem. One class (`[PlainClass](PlainClass.java:3)`) provides a straightforward data-holding model with a greeting method, while the other (`[ReflectiveClass](ReflectiveClass.java:3)`) demonstrates runtime class loading and method invocation through Java reflection. Together, these classes form a minimal package with no child submodules.

## Key Classes and Interfaces

### PlainClass

`[PlainClass](PlainClass.java:3)` is a basic data-bearing class that stores a single `name` field and provides a greeting method. It follows the standard JavaBeans convention of encapsulating state through a private field with a public constructor and a simple accessor-style method.

**Fields:**

| Field   | Type   | Description                 |
|---------|--------|-----------------------------|
| `name`  | String | The name value, set at construction. |

**Constructor:**

- `[PlainClass(String name)](PlainClass.java:6)` — lines 6-8

  Sets the internal `name` field. This is the only way to instantiate `PlainClass`.

**Methods:**

- `[greet()](PlainClass.java:10)` — returns `String`, lines 10-12

  Returns a greeting string formatted as `"Hello, "` followed by the stored `name`. This is a read-only operation with no side effects.

### ReflectiveClass

`[ReflectiveClass](ReflectiveClass.java:3)` is a reflection-based utility that loads arbitrary classes at runtime and invokes methods on them. It serves as a generic bridge for dynamic class instantiation and method dispatch, using Java's `java.lang.reflect` API under the hood.

**Fields:**

| Field          | Type   | Description                                                  |
|----------------|--------|--------------------------------------------------------------|
| `targetClass`  | String | The fully-qualified name of the class to load via reflection. |

**Constructor:**

- `[ReflectiveClass(String targetClass)](ReflectiveClass.java:6)` — lines 6-8

  Stores the fully-qualified class name that will be used by `loadByReflection()` to dynamically load and instantiate a class via `Class.forName(targetClass).newInstance()`.

**Methods:**

- `[loadByReflection()](ReflectiveClass.java:10)` — returns `Object`, lines 10-12

  Loads the class specified by the `targetClass` field using `Class.forName(targetClass)` and creates a new instance via `newInstance()`. Returns the instantiated object as type `Object`. Throws `Exception` if the class cannot be found or instantiated. This is a core reflection-dependent method — the loaded class is resolved entirely at runtime, not at compile time.

- `[invokeMethod(Class<?> cls)](ReflectiveClass.java:14)` — returns `void`, lines 14-17

  Looks up a method named `execute` (with no parameters) on the provided class `cls` using `cls.getMethod("execute")`, then invokes it as a static method (passing `null` as the instance argument to `Method.invoke`). Throws `Exception` if the method is not found or invocation fails. This enables calling a convention-based `execute()` method on any class at runtime.

## How It Works

The package demonstrates two distinct programming patterns:

### Plain data model (PlainClass)

1. A `PlainClass` is constructed with a `name` string.
2. Calling `greet()` returns a formatted greeting. This is a simple, synchronous, side-effect-free operation.

```
new PlainClass("Alice")
  -> greet()
  -> returns "Hello, Alice"
```

### Reflection-based dispatch (ReflectiveClass)

1. A `ReflectiveClass` is constructed with a fully-qualified class name (e.g., `"com.example.SomeService"`).
2. Calling `loadByReflection()` resolves that class at runtime via `Class.forName()` and instantiates it, returning the raw `Object`.
3. Calling `invokeMethod(SomeClass.class)` dynamically retrieves and executes a no-arg static method called `execute` on the given class.

```
new ReflectiveClass("com.example.MyService")
  -> loadByReflection()
  -> Class.forName("com.example.MyService").newInstance()
  -> returns Object (the new instance)

  -> invokeMethod(MyService.class)
  -> cls.getMethod("execute").invoke(null)
  -> invokes MyService.execute() statically, returns void
```

The reflection pattern means `ReflectiveClass` has no compile-time dependency on the classes it loads — everything is resolved dynamically. This makes it flexible but also introduces runtime risks: if the target class or the `execute` method is missing, an exception is thrown.

## Data Model

This package does not define entity or DTO structures. `PlainClass` holds a single `String` field and `ReflectiveClass` holds another single `String` field used as a class name. The data flow is minimal — there are no relationships between the two classes; they operate independently.

## Dependencies and Integration

- **Package dependency:** `eo.ejb.service` — this package depends on classes from the `eo.ejb.service` package, though the specific integration points are not directly visible in these two source files.
- **Reflection dependency:** `loadByReflection()` dynamically resolves a class by name (confidence: 0.6 for the reflection chain). `invokeMethod()` resolves and invokes the `execute` method via reflection (confidence: 1.0).

## Notes for Developers

- `ReflectiveClass` uses the deprecated `Class.newInstance()` — if updating for modern Java, consider using `cls.getDeclaredConstructor().newInstance()` instead, which declares the checked exception more precisely.
- `invokeMethod()` always calls the `execute` method as a static method (passing `null` to `invoke`). If you need instance-based invocation, the method would need to be modified.
- Both classes are `public` but contain no validation or error-handling beyond letting exceptions propagate. Callers are responsible for handling potential `Exception` instances, particularly from `ReflectiveClass` methods.
- This package has no child submodules and is a leaf package within the `eo.ejb` hierarchy.

## Class Relationships

```mermaid
flowchart LR
    A["PlainClass"] -->|"contains"| B["name: String"]
    A -->|"has"| C["greet(): String"]
    D["ReflectiveClass"] -->|"contains"| E["targetClass: String"]
    D -->|"has"| F["loadByReflection(): Object"]
    D -->|"has"| G["invokeMethod(Class<?>): void"]
    D -->|"reflects onto"| H["Class.forName / Method.invoke"]
    H -->|"calls"| I["targetClass"]
    H -->|"calls"| J["execute()"]
```
