Hi there,
I have a requirement as below. Can anyone share some ideas or point the direction of the solution?
I have a SchemaEntryPoint class which contains some internal DSL scripts:
class SchemaEntryPoint (implicit var ctxMeta: PayrollEngineContextMeta)
extends PySchemaDsl
{
def schema_cn28 = {
// ----------------Schema Scripts Begins Here----------
IMPORT(IT0008)
PIT(PCR1("NORM"))
IF(OFF_CYCLE){
BLOCK("Off-cycle schema block"){
PIT(PCR1("NORM"))
}
} ELSE {
IMPORT(IT0008)
}
PIT(PCR1("NORM"))
IF(TERM_MONTH){
PIT(PCR1("WFWF"))
}
// ----------------Schema Scripts Ends Here----------
}
def schema_cn29 = {
....
....
}
}
The SchemaEntryPoint.scala file will be modified by business specialist who only knows the DSL syntax.
Then in the main program, class SchemaEntryPoint will be instantiated and the schema_cnXX method will be called as the entry point of DSL script. Like this:
private def runForOnePeriod(period: PyPeriod): LogNode = {
// Prepare payroll engine meta info
implicit val pyMeta: PayrollEngineContextMeta = PayrollEngineContextMeta(pernr, period)
val schemaEntryPoint = new SchemaEntryPoint()
schemaEntryPoint.schema_cn28 <-- DSL schema script entry point here
schemaEntryPoint.outputSchmLog()
}
Since the DSL script will be changed a lot by the business specialist, every time a new entry point method “schema_cnXX” created, we have to modify the main program and rebuild the whole project.
For this reason, I want the main program to read the name string of schema entry point from conf configuration file, and call it dynamically with the name string
Can anyone shed some light?
Not sure if reflection or macros can do this? I