# Eo / Ejb / Wiki

## Overview

The `eo.ejb.wiki` package provides utility classes for basic string operations and dynamic class loading via Java reflection. It contains two small classes: one for simple name-based greeting logic and another that uses reflection to instantiate arbitrary classes and invoke their `execute()` method at runtime. The package sits at the root of the `eo.ejb` hierarchy as a subpackage with no further child modules.

## Key Classes and Interfaces

### [PlainClass](PlainClass.java:3)

A simple, stateless-adjacent class that stores a string `name` and returns a greeting message. This appears to be a basic utility or example class used for straightforward string formatting.

**Fields:**

| Field  | Type   | Description            |
|--------|--------|------------------------|
| `name` | String | The name used in greetings |

**Constructors:**

| Constructor                        | Description                                |
|------------------------------------|--------------------------------------------|
| `PlainClass(String name)` | Lines 6-8 | Initializes the instance with a name.     |

**Methods:**

| Method                              | Return Type | Description | Lines |
|-------------------------------------|-------------|-------------|-------|
| `greet()`                           | `String`    | Returns a greeting string: `"Hello, "` + the stored `name`. | 10-12 |

**How it works:**

1. The constructor accepts a `String name` and stores it in the private field.
2. Calling `greet()` concatenates `"Hello, "` with the stored name and returns the result.

This class is immutable in practice — while `name` is not declared `final`, there is no setter to modify it after construction.

---

### [ReflectiveClass](ReflectiveClass.java:3)

A class that uses Java reflection to dynamically load classes by their fully qualified name and invoke their `execute()` method. This appears to be a reflection-based factory/invoker utility for runtime class discovery and method invocation.

**Fields:**

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

**Constructors:**

| Constructor                                | Description                                         |
|--------------------------------------------|-----------------------------------------------------|
| `ReflectiveClass(String targetClass)`      | Lines 6-8 | Stores the target class name for later reflection. |

**Methods:**

| Method                                          | Return Type | Description                                                                                                                                              | Lines |
|--------------------------------------------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|-------|
| `loadByReflection()`                             | `Object`    | Dynamically loads the class specified by `targetClass` using `Class.forName()` and instantiates it with the default constructor via `newInstance()`. Throws `Exception` on failure. | 10-12 |
| `invokeMethod(Class<?> cls)`                     | `void`      | Uses reflection to find the `execute()` method on the given class and invokes it as a static method (`m.invoke(null)`). Throws `Exception` on failure.          | 14-17 |

**How it works:**

`loadByReflection()`:
1. Takes the stored `targetClass` string (e.g. `"com.example.MyClass"`).
2. Calls `Class.forName(targetClass)` to load the class from the classpath.
3. Calls `newInstance()` to create an instance using the no-arg constructor.
4. Returns the resulting `Object`.

`invokeMethod(Class<?> cls)`:
1. Accepts a `Class<?>` as input.
2. Calls `cls.getMethod("execute")` to look up a public no-arg method named `execute`.
3. Calls `m.invoke(null)`, meaning `execute` is expected to be a **static** method.
4. Returns nothing.

**Reflection chain:**

The evidence indicates the following reflection-dependent patterns:

- `loadByReflection` uses `Class.forName` and `newInstance` to load a class by its name string, with a confidence of 0.6.
- `invokeMethod` calls `getMethod.invoke` to invoke the `execute` method on the provided class, with a confidence of 1.0.

## How It Works

### Typical Usage Patterns

**Pattern 1: Greeting**
```
PlainClass pc = new PlainClass("Alice");
String result = pc.greet(); // returns "Hello, Alice"
```

**Pattern 2: Dynamic class loading**
```
ReflectiveClass rc = new ReflectiveClass("com.example.TargetClass");
Object instance = rc.loadByReflection();
```

**Pattern 3: Static method invocation via reflection**
```
ReflectiveClass rc = new ReflectiveClass("");
rc.invokeMethod(MyClass.class); // calls MyClass.execute()
```

### Flow Diagram

```mermaid
flowchart TD
    wiki["eo.ejb.wiki"]
    wiki --> plain["PlainClass"]
    wiki --> refl["ReflectiveClass"]
    plain --> plainFields["fields: name"]
    plain --> plainMethods["methods: greet(), PlainClass(String)"]
    refl --> reflFields["fields: targetClass"]
    refl --> reflMethods["methods: loadByReflection(), invokeMethod(Class), ReflectiveClass(String)"]
    refl -.->|reflection| targetCls["Target Class"]
    targetCls -.->|via execute| exec["execute()"]
```

## Data Model

This module does not define any entity, DTO, or model classes. The two classes are simple data-holding utilities:

- **PlainClass**: holds a single `String name` used for formatting a greeting.
- **ReflectiveClass**: holds a single `String targetClass` that stores the fully qualified name of a class to load at runtime.

## Dependencies and Integration

| Dependency         | Direction | Notes                                                        |
|--------------------|-----------|--------------------------------------------------------------|
| `eo.ejb.service`   | Outgoing  | This module has a package-level dependency on `eo.ejb.service`. |

The module does not import any external frameworks or libraries beyond the Java standard library (`java.lang.reflect` for reflection).

## Notes for Developers

1. **Reflection is unchecked.** Both `loadByReflection()` and `invokeMethod()` declare `throws Exception` but do not catch or handle any exceptions. Callers must handle `ClassNotFoundException`, `InstantiationException`, `IllegalAccessException`, and `NoSuchMethodException`.

2. **`loadByReflection()` requires a no-arg constructor.** The use of `newInstance()` means the target class must have an accessible no-argument constructor. There is no way to pass constructor arguments.

3. **`invokeMethod()` expects a static `execute()` method.** The method lookup uses `getMethod("execute")` with no parameters, and invocation passes `null` as the instance, meaning it expects a `public static void execute()` method. This is a contract that callers must ensure is met by the provided class.

4. **Security.** Reflective class loading and method invocation can bypass compile-time type checking. Ensure that any `targetClass` strings are validated or constrained to a known whitelist in production use.

5. **No child modules.** This package has no subpackages, so all functionality is contained within these two classes.
