Class GshTemplateCompiledDispatch

java.lang.Object
edu.internet2.middleware.grouper.app.gsh.template.GshTemplateCompiledDispatch

public class GshTemplateCompiledDispatch extends Object
Shared helper that turns a compiled-Java GSH template config into a ready instance of the type's framework base class. Every compiled-template dispatcher (GshTemplateExec for gsh/abac, OtherJobScript for daemons, and the change-log / report / customUi / hook / library wirings to come) funnels through here so the resolve → cast → instantiate sequence and its error reporting live in one place.

The sequence:

  1. read the template source from its configured location (GshTemplateConfig.readSource() — inline config or container file);
  2. resolve the compiled class through GshTemplateClassLoaderRegistry (compile-on-miss, source-hash cache);
  3. cast the Class to the expected framework base via asSubclass(), surfacing a clear message if the author extended the wrong base;
  4. instantiate via the public no-arg constructor.

Parse and compile failures are turned into a RuntimeException carrying the registry diagnostics so the caller's normal error path (loader log, report status, UI inline errors) reports them.

GRP-7026
  • Method Details

    • instantiate

      public static <T> T instantiate(String configId, GshTemplateConfig gshTemplateConfig, Class<T> baseClass)
      Resolve, cast, and instantiate a compiled-Java template.
      Type Parameters:
      T - the framework base class type for this templateType
      Parameters:
      configId - GSH template config id (registry cache key); must be non-empty
      gshTemplateConfig - the populated config (source location, mode)
      baseClass - the framework base the compiled class must extend/implement
      Returns:
      a new instance cast to baseClass
    • resolveClass

      public static <T> Class<? extends T> resolveClass(String configId, GshTemplateConfig gshTemplateConfig, Class<T> baseClass)
      Resolve a compiled-Java template to its loaded Class, cast to the expected framework base. Same resolve + cast as instantiate(java.lang.String, edu.internet2.middleware.grouper.app.gsh.template.GshTemplateConfig, java.lang.Class<T>) but stops short of instantiating — for callers (e.g. the hooks framework) that need the Class itself to introspect methods or create their own instances.
      Type Parameters:
      T - the framework base class type for this templateType
      Parameters:
      configId - GSH template config id (registry cache key); must be non-empty
      gshTemplateConfig - the populated config (source location, mode)
      baseClass - the framework base the compiled class must extend/implement
      Returns:
      the loaded class cast to a subclass of baseClass
    • instanceForTemplate

      public static Object instanceForTemplate(String configId)
      Resolve and instantiate a compiled library template (templateType=library) by its config id, for other templates to call. Loads the template config, reads its source, resolves the compiled class through the registry, and returns a fresh instance.

      The returned Object has no required base class — callers cast to a parent-jar interface (Option B) or invoke methods by name via GrouperUtil.callMethod (Option C). See the design doc section "Shared logic and inter-template calls". Each call returns a new instance; the compiled Class (and any statics on it) is cached in the registry and reset only when the source changes (hot-reload) or the JVM restarts.

      Library templates have no interpreted path, so the template must be templateMode=compiled; a non-compiled template raises a clear error.

      Parameters:
      configId - GSH template config id of the library template; must be non-empty
      Returns:
      a new instance of the library template's compiled class GRP-7027