Class RenderContext

java.lang.Object
io.mindspice.simplypages.core.RenderContext

public class RenderContext extends Object
Mutable per-render value container for SlotKey lookups.

Lifecycle: create per request/render flow, populate slot values, render components, then discard. This type is intentionally mutable to support incremental population and optional compile-on-first-hit slot caching.

Mutability/thread-safety: mutable and not thread-safe. Use per request by default. Context reuse is valid only when access is confined (no concurrent mutation), especially when using RenderContext.RenderPolicy.COMPILE_ON_FIRST_HIT.

  • Method Details

    • empty

      public static RenderContext empty()
      Returns an empty context using RenderContext.RenderPolicy.NEVER_COMPILE.
    • builder

      public static RenderContext.RenderContextBuilder builder()
      Returns a builder for explicit context construction.
    • of

      public static RenderContext of(Map<? extends SlotKey<?>, ?> values)
      Creates a context from raw slot values with default policy.

      null values remove existing entries.

    • of

      public static <T> RenderContext of(SlotKey<T> key, T value)
      Creates a context with a single raw slot value and default policy.

      null values produce an empty context for the given key.

    • get

      public <T> Optional<T> get(SlotKey<T> key)
      Resolves the value for key.

      Resolution order:

      1. live entry value

      2. key default provider (compiled entries intentionally skip cached HTML and fall back to default)

      3. empty

    • put

      public <T> RenderContext put(SlotKey<T> key, T value)
      Stores a live value for key; null removes the entry.
    • putCompiled

      public RenderContext putCompiled(SlotKey<?> key, String html)
      Stores pre-rendered trusted HTML for key; null removes the entry.
    • remove

      public RenderContext remove(SlotKey<?> key)
      Removes any entry for key.
    • clear

      public RenderContext clear()
      Removes all entries from this context.
    • withPolicy

      public RenderContext withPolicy(RenderContext.RenderPolicy policy)
      Sets render policy for subsequent template slot handling.
      Throws:
      NullPointerException - when policy is null
    • getPolicy

      public RenderContext.RenderPolicy getPolicy()
      Returns current render policy.
    • isCompiled

      public boolean isCompiled(SlotKey<?> key)
      Returns whether key currently maps to a compiled entry.
    • getCompiled

      public Optional<String> getCompiled(SlotKey<?> key)
      Returns compiled HTML for key when a compiled entry exists.
    • getEntries

      public Map<SlotKey<?>, SlotEntry> getEntries()
      Returns an immutable snapshot of stored entries.