Package net.officefloor.script
Class AbstractScriptProcedureSourceServiceFactory
- java.lang.Object
-
- net.officefloor.script.AbstractScriptProcedureSourceServiceFactory
-
- All Implemented Interfaces:
ProcedureSourceServiceFactory
,ServiceFactory<ProcedureSource>
- Direct Known Subclasses:
JavaScriptProcedureSourceServiceFactory
public abstract class AbstractScriptProcedureSourceServiceFactory extends java.lang.Object implements ProcedureSourceServiceFactory
ProcedureSourceServiceFactory
providing abstract support for Scripts.- Author:
- Daniel Sagenschneider
-
-
Constructor Summary
Constructors Constructor Description AbstractScriptProcedureSourceServiceFactory()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ProcedureSource
createService(ServiceContext context)
Creates the service.protected void
decorateScriptEngine(javax.script.ScriptEngine engine, SourceContext context)
Enables overriding to decorate theScriptEngine
.protected abstract java.lang.String
getMetaDataScriptPath(SourceContext context)
Obtains the path to the script that extracts the function meta-data.protected abstract java.lang.String
getScriptEngineName(SourceContext context)
Obtains the name of theScriptEngine
.protected ScriptExceptionTranslator
getScriptExceptionTranslator()
Obtains theScriptExceptionTranslator
.protected abstract java.lang.String[]
getScriptFileExtensions(SourceContext context)
Obtains the extensions for the script resource.protected java.lang.String
getSetupScriptPath(SourceContext context)
Obtains the path to the setup script.protected abstract java.lang.String
getSourceName()
Obtains the source name for thisProcedureSource
.protected void
listProcedures(ProcedureListContext context)
Lists theProcedure
instances.protected void
loadManagedFunction(ProcedureManagedFunctionContext context)
Loads theManagedFunction
for theProcedure
.protected java.lang.String
loadResourceScript(java.lang.String resource, SourceContext sourceContext)
Loads the source script.protected javax.script.Invocable
loadScriptEngine(javax.script.ScriptEngineManager engineManager, java.lang.String engineName, java.lang.String setupScript, java.lang.String script, java.lang.String metaDataScript, SourceContext sourceContext)
Loads theScriptEngine
.protected java.lang.String
loadSetupScript(SourceContext sourceContext)
Loads the setup script.
-
-
-
Method Detail
-
getSourceName
protected abstract java.lang.String getSourceName()
Obtains the source name for thisProcedureSource
.- Returns:
- Source name for this
ProcedureSource
.
-
getScriptFileExtensions
protected abstract java.lang.String[] getScriptFileExtensions(SourceContext context) throws java.lang.Exception
Obtains the extensions for the script resource.- Parameters:
context
-SourceContext
.- Returns:
- Extensions for the script resource.
- Throws:
java.lang.Exception
- If fails to obtain the file extensions.
-
getScriptEngineName
protected abstract java.lang.String getScriptEngineName(SourceContext context) throws java.lang.Exception
Obtains the name of theScriptEngine
.- Parameters:
context
-SourceContext
.- Returns:
- Name of the
ScriptEngine
. - Throws:
java.lang.Exception
- If fails to obtain the name of theScriptEngine
.
-
decorateScriptEngine
protected void decorateScriptEngine(javax.script.ScriptEngine engine, SourceContext context) throws java.lang.Exception
Enables overriding to decorate theScriptEngine
.- Parameters:
engine
-ScriptEngine
.context
-SourceContext
.- Throws:
java.lang.Exception
- If fails to decorate theScriptEngine
.
-
getSetupScriptPath
protected java.lang.String getSetupScriptPath(SourceContext context) throws java.lang.Exception
Obtains the path to the setup script.- Parameters:
context
-SourceContext
.- Returns:
- Path to the setup script or
null
if no setup. - Throws:
java.lang.Exception
- If fails to obtain the setup script path.
-
getMetaDataScriptPath
protected abstract java.lang.String getMetaDataScriptPath(SourceContext context) throws java.lang.Exception
Obtains the path to the script that extracts the function meta-data.- Parameters:
context
-SourceContext
.- Returns:
- Path to the script that extracts the function meta-data.
- Throws:
java.lang.Exception
- If fails to obtain the path to the function meta-data script.
-
getScriptExceptionTranslator
protected ScriptExceptionTranslator getScriptExceptionTranslator()
Obtains theScriptExceptionTranslator
.- Returns:
ScriptExceptionTranslator
.
-
loadSetupScript
protected java.lang.String loadSetupScript(SourceContext sourceContext) throws java.lang.Exception
Loads the setup script.- Parameters:
sourceContext
-SourceContext
.- Returns:
- Setup script or
null
if no setup. - Throws:
java.lang.Exception
- If fails to load setup script.
-
loadResourceScript
protected java.lang.String loadResourceScript(java.lang.String resource, SourceContext sourceContext) throws java.lang.Exception
Loads the source script.- Parameters:
resource
- Resource.sourceContext
-SourceContext
.- Returns:
- Resource script.
- Throws:
java.lang.Exception
- If fails to load resource script.
-
loadScriptEngine
protected javax.script.Invocable loadScriptEngine(javax.script.ScriptEngineManager engineManager, java.lang.String engineName, java.lang.String setupScript, java.lang.String script, java.lang.String metaDataScript, SourceContext sourceContext) throws java.lang.Exception
Loads theScriptEngine
.- Parameters:
engineManager
-ScriptEngineManager
.engineName
- Name of theScriptEngine
.setupScript
- Setup script. May benull
for no setup.script
- Script containing the function(s).metaDataScript
- Script to extract meta-data.sourceContext
-SourceContext
.- Returns:
Invocable
for theScriptEngine
.- Throws:
java.lang.Exception
- IF fails to load theScriptEngine
.
-
listProcedures
protected void listProcedures(ProcedureListContext context) throws java.lang.Exception
Lists theProcedure
instances.- Parameters:
context
-ProcedureListContext
.- Throws:
java.lang.Exception
- If fails to list theProcedure
instances.
-
loadManagedFunction
protected void loadManagedFunction(ProcedureManagedFunctionContext context) throws java.lang.Exception
Loads theManagedFunction
for theProcedure
.- Parameters:
context
-ProcedureManagedFunctionContext
.- Throws:
java.lang.Exception
- If fails to load theManagedFunction
.
-
createService
public ProcedureSource createService(ServiceContext context) throws java.lang.Throwable
Description copied from interface:ServiceFactory
Creates the service.- Specified by:
createService
in interfaceServiceFactory<ProcedureSource>
- Parameters:
context
-ServiceContext
.- Returns:
- Service.
- Throws:
java.lang.Throwable
- If fails to create the service.
-
-