Class GshTemplateCompiledDispatch
The sequence:
- read the template source from its configured location (GshTemplateConfig.readSource() — inline config or container file);
- resolve the compiled class through GshTemplateClassLoaderRegistry (compile-on-miss, source-hash cache);
- cast the Class to the expected framework base via asSubclass(), surfacing a clear message if the author extended the wrong base;
- 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 Summary
Modifier and TypeMethodDescriptionstatic ObjectinstanceForTemplate(String configId) Resolve and instantiate a compiled library template (templateType=library) by its config id, for other templates to call.static <T> Tinstantiate(String configId, GshTemplateConfig gshTemplateConfig, Class<T> baseClass) Resolve, cast, and instantiate a compiled-Java template.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.
-
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-emptygshTemplateConfig- 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 asinstantiate(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-emptygshTemplateConfig- 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
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
-