public class JZtxtcmd extends java.lang.Object implements JZtxtcmdEngine, javax.script.Compilable
java path/to/zbnf.jar org.vishia.zcmd.JZcmd path/to/scriptFileThis class contains the translator which uses the ZBNF parser. The core executer is
JZtxtcmdExecuter.
The translated script is stored in an instance of JZtxtcmdScript which are both parts of the component
srcJava_vishiaBase.
main(String[]) is the command line start. Arguments:
smain(String[]) is the same as main(String[]) but without exit the VM.
It can be used to invoke main from inside another Java program.
translateAndSetGenCtrl(File, LogMessage): simplest form with a file as input
translateAndSetGenCtrl(String, LogMessage): The script is given as String
translateAndSetGenCtrl(StringPartScan, LogMessage, File, File): This is the core routine.
JZtxtcmdExecuter.
execute(String): for simple algorithms given as String, for example text preparation.
execute(File, LogMessage): translate and execute a given script.
execute(JZtxtcmdExecuter, File, Appendable, String, boolean, File, LogMessage): It reuses a given instance of JZcmdExecuter.
JZtxtcmdScript and an execution environment JZtxtcmdExecuter
is established, one can invoke a subroutine of the script with
JZtxtcmdExecuter.execSub(org.vishia.cmd.JZtxtcmdScript.Subroutine, Map, boolean, Appendable, File)
or run the main routine of the script with JZtxtcmdExecuter.execute(JZtxtcmdScript, boolean, boolean, Appendable, String).
See there.
JZtxtcmdScript.getEngine(), defined in CompiledScript.getEngine() returns this instance
if the JZcmdScript was created with this.
execute(File, org.vishia.cmd.JZtxtcmdExecuter.ExecuteLevel)
compiles and executes a script given with file, whereby the given ExecuteLevel is used
execSub(File, String, Map, org.vishia.cmd.JZtxtcmdExecuter.ExecuteLevel)
ScriptEngine interface
ScriptException is thrown. That exception should be caught
by the caller.
The ScriptException contains
LogMessage#writeError(String)
if the exception has a file info. Unexpected Exceptions were written with
LogMessage.writeError(String, Throwable) with the unwrapped inner exception. That exceptions
should be shown in detail.| Modifier and Type | Class and Description |
|---|---|
private static class |
JZtxtcmd.Args |
private static class |
JZtxtcmd.CmdLine
The organization class for command line invocation.
|
| Modifier and Type | Field and Description |
|---|---|
(package private) LogMessage |
log |
(package private) ZbnfParser |
parserGenCtrl
The parser knows the correct syntax already.
|
static java.lang.String |
version
Version, history and license.
|
sVersion| Constructor and Description |
|---|
JZtxtcmd()
Instantiates.
|
JZtxtcmd(LogMessage log)
Instantiates with maybe given MainCmd logging.
|
| Modifier and Type | Method and Description |
|---|---|
JZtxtcmdScript |
compile(java.io.File fileGenCtrl,
java.io.File checkXmlOut) |
javax.script.CompiledScript |
compile(java.io.Reader script)
JSR-223-conform method to compile.
|
javax.script.CompiledScript |
compile(java.lang.String script)
JSR-223-conform method to compile.
|
private JZtxtcmdScript |
compile(StringPartScan sourceScript,
java.io.File checkXmlOutput,
java.io.File fileScript)
Deprecated.
|
javax.script.Bindings |
createBindings() |
java.lang.Object |
eval(java.io.Reader reader) |
java.lang.Object |
eval(java.io.Reader reader,
javax.script.Bindings n) |
java.lang.Object |
eval(java.io.Reader reader,
javax.script.ScriptContext context) |
java.lang.Object |
eval(java.lang.String script) |
java.lang.Object |
eval(java.lang.String script,
javax.script.Bindings n) |
java.lang.Object |
eval(java.lang.String script,
javax.script.ScriptContext context) |
java.lang.Object |
evalSub(java.io.File fileScript,
java.lang.String subroutine,
java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> args,
JZtxtcmdExecuter.ExecuteLevel execLevel)
Executes a sub routine in a special script, but uses a given execution environment.
|
static java.lang.CharSequence |
execSub(java.io.File fileScript,
java.lang.String subroutine,
java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> args,
JZtxtcmdExecuter.ExecuteLevel execLevel)
Executes a sub routine in a special script, but uses a given execution environment.
|
static java.lang.CharSequence |
execSub(java.io.File fileScript,
java.lang.String subroutine,
java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> args,
JZtxtcmdExecuter.ExecuteLevel execLevel,
java.lang.Appendable output)
Executes a sub routine in a special script, but uses a given execution environment.
|
static java.lang.CharSequence |
execute(java.io.File script,
JZtxtcmdExecuter.ExecuteLevel execLevel)
Parses the script and executes it in an own environment but with usage of the given local variables,
the current directory and the log of a given JZcmd ExecuterLevel.
|
static void |
execute(java.io.File script,
LogMessage log)
Executes a JZcmd script.
|
static void |
execute(JZtxtcmdExecuter executer,
java.io.File fileScript,
java.lang.Appendable out,
java.util.List<DataAccess.Variable<java.lang.Object>> data,
java.lang.String sCurrdir,
boolean accessPrivate,
java.io.File testOut,
LogMessage log)
Translates and executes a JZcmd script.
|
static void |
execute(JZtxtcmdExecuter executer,
java.io.File fileScript,
java.lang.Appendable out,
java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> data,
java.lang.String sCurrdir,
boolean accessPrivate,
java.io.File testOut,
LogMessage log)
Translates and executes a JZcmd script.
|
static void |
execute(JZtxtcmdExecuter executer,
java.io.File fileScript,
java.lang.Appendable out,
java.lang.String sCurrdir,
boolean accessPrivate,
java.io.File testOut,
LogMessage log)
Translates and executes a JZcmd script.
|
static void |
execute(JZtxtcmdExecuter executer,
java.io.File fileScript,
StringPartScan script,
java.lang.Appendable out,
java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> data,
java.lang.String sCurrdir,
boolean accessPrivate,
java.io.File testOut,
LogMessage log)
Executes a textual given script in a existing instance of a
JZtxtcmdExecuter. |
static void |
execute(java.lang.String script)
Executes a JZcmd script.
|
java.lang.Object |
get(java.lang.String key) |
javax.script.Bindings |
getBindings(int scope) |
javax.script.ScriptContext |
getContext() |
javax.script.ScriptEngineFactory |
getFactory() |
static void |
main(java.lang.String[] sArgs)
main started from java command line.
|
void |
put(java.lang.String key,
java.lang.Object value) |
static java.lang.String |
readJZcmdCfg(JZtxtcmdScript.AddSub2List dst,
java.io.File jzScriptFile,
LogMessage log,
CmdExecuter execToInit)
Reads a scriptfile and stores the subroutines, nested in classes too, to the given CmdStore.
|
void |
setBindings(javax.script.Bindings bindings,
int scope) |
void |
setContext(javax.script.ScriptContext context) |
static int |
smain(java.lang.String[] sArgs)
Invocation from another java program without exit the JVM
|
static JZtxtcmdScript |
translateAndSetGenCtrl(java.io.File fileGenCtrl,
java.io.File checkXmlOut,
LogMessage log) |
static JZtxtcmdScript |
translateAndSetGenCtrl(java.io.File fileScript,
LogMessage log)
Translates a script into its internal form.
|
static JZtxtcmdScript |
translateAndSetGenCtrl(java.lang.String sourceScript,
LogMessage log) |
static JZtxtcmdScript |
translateAndSetGenCtrl(StringPartScan sourceScript,
LogMessage log)
Translates with a new Parser and the given script in text format.
|
static JZtxtcmdScript |
translateAndSetGenCtrl(StringPartScan sourceScript,
LogMessage log,
java.io.File checkXmlOutput,
java.io.File fileScript)
Deprecated.
this routine is given in
JZtxtcmdScript.createScriptFromString(StringPartScan, LogMessage, File, File) |
static JZtxtcmdScript |
translateScriptFromJar(java.lang.Class<?> clazz,
java.lang.String pathInJarFromClazz,
java.io.File checkXmlOut,
LogMessage log) |
public static final java.lang.String version
JZtxtcmd(LogMessage) is specific exception free. The exception was nevertheless not expected
because the used syntax does not depend from user. If there is really an error, an IllegalArgumentException is thrown.
JZtxtcmdScript.createScriptFromString(StringPartScan, LogMessage, File, File)
for includes, not twice refactored. Better remove old stuff.
execute(JZtxtcmdExecuter, File, StringPartScan, Appendable, Map, String, boolean, File, LogMessage):
Uses now JZtxtcmdScript.createScriptFromString(StringPartScan, LogMessage, File, File)
instead the deprecated #translateAndSetGenCtrl(StringPartScan, org.vishia.cmd.JZtxtcmdScript.ZbnfJZcmdScript, File, File).
Same for compile(StringPartScan, File, File).
With changes there it is possible to read an include script from an operation,
which is hence stored in the jar file. Syntay is: include %<#?backlevel>:pkg.path.Class.operation().
The backlevel is to built a reference current directory for further includes.
It should be relative in the same working tree, usual on the root of a working tree.
translateScriptFromJar(Class, String, File, LogMessage)
execSub(File, String, Map, org.vishia.cmd.JZtxtcmdExecuter.ExecuteLevel, Appendable) with Appendable as argument.
The old form without this argument is available too.
JZtxtcmdExecuter-
Now execute(JZtxtcmdExecuter, File, Appendable, List, String, boolean, File, LogMessage)
with List-given additional variables are available. Note that JZtxtcmdExecuter.setScriptVariable(String, char, Object, boolean)
is deprecated now.
readJZcmdCfg(org.vishia.cmd.JZtxtcmdScript.AddSub2List, File, LogMessage, CmdExecuter)
translateAndSetGenCtrl(File, File, LogMessage) : close() will be invoked.
#jbatch(File, org.vishia.cmd.JZtxtcmdExecuter.ExecuteLevel) is deprecated now,
instead execSub(File, String, Map, org.vishia.cmd.JZtxtcmdExecuter.ExecuteLevel) used.
The difference: No scriptlevel created for the new compiled script, with given scriptlevel
the subroutine is executed.
main(String[])
Build of script variable currdir, scriptfile, scriptdir with them in JZtxtcmdExecuter#initialize(JZtxtcmdScript, boolean, Map, String, boolean).
#jbatch(String, org.vishia.cmd.JZtxtcmdExecuter.ExecuteLevel)
org.vishia.zmake.Zmake generator, but that is special for make problems.
A generator which converts ZBNF-parsed data from an Java data context to output texts in several form, documenation, C-sources
was need.
final ZbnfParser parserGenCtrl
JZtxtcmdSyntax.syntax to set ZbnfParser#setSyntax(String). One should use an
abbreviating syntax for experience.final LogMessage log
public JZtxtcmd()
#JZcmd(LogMessage) with null as argument.javax.script.ScriptExceptionpublic JZtxtcmd(LogMessage log)
log - if null then the MainCmdLoggingStream is used with System.out.java.lang.IllegalArgumentException - only if the internal syntax has a problem.public static void main(java.lang.String[] sArgs)
INPUT pathTo JZcmd-File to execute -t:OUTEXT pathTo text-File for output -debug:TEST.xml pathTo XML output of parsed script -u:userArgs --help show the help for command line and the syntax --currdir=PATH Set the currdir variable.
public static int smain(java.lang.String[] sArgs)
throws javax.script.ScriptException
sArgs - same like main(String[])LogMessage#exitWithArgumentError etc.javax.script.ScriptExceptionpublic static java.lang.CharSequence execute(java.io.File script,
JZtxtcmdExecuter.ExecuteLevel execLevel)
throws java.lang.IllegalAccessException
script - Path to the script.execLevel - subroutine level where this is called.
All variables of this level are used as script variables for the script to execute.
Especially the currdir of the level is used as script level currdirjava.lang.IllegalAccessExceptionpublic static java.lang.CharSequence execSub(java.io.File fileScript,
java.lang.String subroutine,
java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> args,
JZtxtcmdExecuter.ExecuteLevel execLevel,
java.lang.Appendable output)
{ ## any JZcmd script
Map args;
String args.name = value;
java org.vishia.zcmd.JZcmd.execSub(File:"path/JZcmdscript.jzcmd", "class.subroutine-Name", args, jzcmdsub);
}
fileScript - The file which contains the scriptsubroutine - name of the subroutine in the script.args - Arguments for this subroutine.execLevel - Execution level where this routine from where it is called.public static java.lang.CharSequence execSub(java.io.File fileScript,
java.lang.String subroutine,
java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> args,
JZtxtcmdExecuter.ExecuteLevel execLevel)
{ ## any JZcmd script
Map args;
String args.name = value;
java org.vishia.zcmd.JZcmd.execSub(File:"path/JZcmdscript.jzcmd", "class.subroutine-Name", args, jzcmdsub);
}
fileScript - The file which contains the scriptsubroutine - name of the subroutine in the script.args - Arguments for this subroutine.execLevel - Execution level where this routine from where it is called.public java.lang.Object evalSub(java.io.File fileScript,
java.lang.String subroutine,
java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> args,
JZtxtcmdExecuter.ExecuteLevel execLevel)
throws javax.script.ScriptException
{ ## any JZcmd script
Map args;
String args.name = value;
java org.vishia.zcmd.JZcmd.execSub(File:"path/JZcmdscript.jzcmd", "class.subroutine-Name", args, jzcmdsub);
}
evalSub in interface JZtxtcmdEnginefileScript - The file which contains the scriptsubroutine - name of the subroutine in the script.args - Arguments for this subroutine.execLevel - Execution level where this routine from where it is called.javax.script.ScriptExceptionpublic static void execute(java.lang.String script)
throws javax.script.ScriptException
console script variable is written to System.out.script - the script in ASCII-format, syntax see JZtxtcmdSyntaxjavax.script.ScriptExceptionpublic static void execute(java.io.File script,
LogMessage log)
throws javax.script.ScriptException
script - the script in ASCII-format, syntax see JZtxtcmdSyntaxlog - A given log outputjavax.script.ScriptExceptionpublic static void execute(JZtxtcmdExecuter executer, java.io.File fileScript, java.lang.Appendable out, java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> data, java.lang.String sCurrdir, boolean accessPrivate, java.io.File testOut, LogMessage log) throws javax.script.ScriptException
executer - A given instance of the executer.fileScript - the script in ASCII-format, syntax see JZtxtcmdSyntaxout - Output channel for <+text>...<.+>sCurrdir - The start value for currdiraccessPrivate - if true then private data are accessed too. The accessing of private data may be helpfull
for debugging. It is not recommended for general purpose! The access mechanism is given with
AccessibleObject.setAccessible(boolean).testOut - if not null then outputs a data tree of the generate script.log - A given log outputjavax.script.ScriptExceptionpublic static void execute(JZtxtcmdExecuter executer, java.io.File fileScript, java.lang.Appendable out, java.util.List<DataAccess.Variable<java.lang.Object>> data, java.lang.String sCurrdir, boolean accessPrivate, java.io.File testOut, LogMessage log) throws javax.script.ScriptException
executer - A given instance of the executer.fileScript - the script in ASCII-format, syntax see JZtxtcmdSyntaxout - Output channel for <+text>...<.+>sCurrdir - The start value for currdiraccessPrivate - if true then private data are accessed too. The accessing of private data may be helpfull
for debugging. It is not recommended for general purpose! The access mechanism is given with
AccessibleObject.setAccessible(boolean).testOut - if not null then outputs a data tree of the generate script.log - A given log outputjavax.script.ScriptExceptionpublic static void execute(JZtxtcmdExecuter executer, java.io.File fileScript, java.lang.Appendable out, java.lang.String sCurrdir, boolean accessPrivate, java.io.File testOut, LogMessage log) throws javax.script.ScriptException
executer - A given instance of the executer.fileScript - the script in ASCII-format, syntax see JZtxtcmdSyntaxout - Output channel for <+text>...<.+>sCurrdir - The start value for currdiraccessPrivate - if true then private data are accessed too. The accessing of private data may be helpfull
for debugging. It is not recommended for general purpose! The access mechanism is given with
AccessibleObject.setAccessible(boolean).testOut - if not null then outputs a data tree of the generate script.log - A given log outputjavax.script.ScriptExceptionpublic static void execute(JZtxtcmdExecuter executer, java.io.File fileScript, StringPartScan script, java.lang.Appendable out, java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> data, java.lang.String sCurrdir, boolean accessPrivate, java.io.File testOut, LogMessage log) throws javax.script.ScriptException
JZtxtcmdExecuter.executer - fileScript - This file is used only as information to support the <&scriptdir>.script - The input which contains the JZcmd scriptout - output for the textsCurrdir - accessPrivate - if true then private data are accessed too. The accessing of private data may be helpfull
for debugging. It is not recommended for general purpose! The access mechanism is given with
AccessibleObject.setAccessible(boolean).testOut - if not null then outputs a data tree of the generate script.log - javax.script.ScriptException - on any non-caught exception in the scriptpublic static JZtxtcmdScript translateAndSetGenCtrl(java.io.File fileScript, LogMessage log) throws javax.script.ScriptException
fileScript - log - javax.script.ScriptException, {@link #translateAndSetGenCtrl(StringPartScan, LogMessage, File, File)}
, {@link #translateAndSetGenCtrl(File, File, LogMessage)}public static JZtxtcmdScript translateAndSetGenCtrl(java.io.File fileGenCtrl, java.io.File checkXmlOut, LogMessage log) throws javax.script.ScriptException
javax.script.ScriptExceptionpublic static JZtxtcmdScript translateScriptFromJar(java.lang.Class<?> clazz, java.lang.String pathInJarFromClazz, java.io.File checkXmlOut, LogMessage log) throws javax.script.ScriptException
javax.script.ScriptExceptionpublic JZtxtcmdScript compile(java.io.File fileGenCtrl, java.io.File checkXmlOut) throws javax.script.ScriptException
javax.script.ScriptExceptionpublic static JZtxtcmdScript translateAndSetGenCtrl(java.lang.String sourceScript, LogMessage log) throws javax.script.ScriptException
javax.script.ScriptExceptionpublic static JZtxtcmdScript translateAndSetGenCtrl(StringPartScan sourceScript, LogMessage log) throws javax.script.ScriptException
fileParent - The directory which is the anchor for included scripts. Maybe null if included scripts does not exists.sourceScript - The script in form of StringPartScan. User new StringPartScan.StringPartScan(CharSequence)
to create one with a String given syntax.checkXmlOutput - may be null, for output the script in XML form.log - java.text.ParseExceptionjava.lang.IllegalArgumentExceptionjava.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionjava.io.FileNotFoundExceptionjava.io.IOExceptionjavax.script.ScriptException#translateAndSetGenCtrl(String, LogMessage), {@link #translateAndSetGenCtrl(File, LogMessage)}
, {@link #translateAndSetGenCtrl(File, File, LogMessage)}public static java.lang.String readJZcmdCfg(JZtxtcmdScript.AddSub2List dst, java.io.File jzScriptFile, LogMessage log, CmdExecuter execToInit)
dst - The command store. Its content won't be cleared, this file is added. invoke CmdStore#clear() before.jzScriptFile - log - executerToInit - The executer will be initialized with the script variables of the parsed script-@Deprecated public static JZtxtcmdScript translateAndSetGenCtrl(StringPartScan sourceScript, LogMessage log, java.io.File checkXmlOutput, java.io.File fileScript) throws javax.script.ScriptException
JZtxtcmdScript.createScriptFromString(StringPartScan, LogMessage, File, File)fileScript - The file which has contained the script. It is used only to provide the variables
'scriptdir' and 'scriptfile' for execution. The file is not evaluated. It means, it does not need
to exist.sourceScript - The content of fileScript or from any other source. This is the script source.
Use new StringPartScan.StringPartScan(CharSequence) to create one with a String given syntax.log - if null then the MainCmdLoggingStream is used with System.out.checkXmlOutput - may be null, for output the script in XML form.java.text.ParseExceptionjava.lang.IllegalArgumentExceptionjava.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionjava.io.FileNotFoundExceptionjava.io.IOExceptionjavax.script.ScriptException@Deprecated private JZtxtcmdScript compile(StringPartScan sourceScript, java.io.File checkXmlOutput, java.io.File fileScript) throws javax.script.ScriptException
fileScript - The file which has contained the script. It is used only to provide the variables
'scriptdir' and 'scriptfile' for execution. The file is not evaluated. It means, it does not need
to exist.sourceScript - The content of fileScript or from any other source. This is the script source.
Use new StringPartScan.StringPartScan(CharSequence) to create one with a String given syntax.log - checkXmlOutput - may be null, for output the script in XML form.java.text.ParseExceptionjava.lang.IllegalArgumentExceptionjava.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionjava.io.FileNotFoundExceptionjava.io.IOExceptionjavax.script.ScriptExceptionpublic javax.script.CompiledScript compile(java.lang.String script)
throws javax.script.ScriptException
compile in interface javax.script.Compilablejavax.script.ScriptExceptionCompilable.compile(java.lang.String)public javax.script.CompiledScript compile(java.io.Reader script)
throws javax.script.ScriptException
compile in interface javax.script.Compilablejavax.script.ScriptExceptionCompilable.compile(java.lang.String)public javax.script.Bindings createBindings()
createBindings in interface javax.script.ScriptEnginepublic java.lang.Object eval(java.lang.String script)
throws javax.script.ScriptException
eval in interface javax.script.ScriptEnginejavax.script.ScriptExceptionpublic java.lang.Object eval(java.io.Reader reader)
throws javax.script.ScriptException
eval in interface javax.script.ScriptEnginejavax.script.ScriptExceptionpublic java.lang.Object eval(java.lang.String script,
javax.script.ScriptContext context)
throws javax.script.ScriptException
eval in interface javax.script.ScriptEnginejavax.script.ScriptExceptionpublic java.lang.Object eval(java.io.Reader reader,
javax.script.ScriptContext context)
throws javax.script.ScriptException
eval in interface javax.script.ScriptEnginejavax.script.ScriptExceptionpublic java.lang.Object eval(java.lang.String script,
javax.script.Bindings n)
throws javax.script.ScriptException
eval in interface javax.script.ScriptEnginejavax.script.ScriptExceptionpublic java.lang.Object eval(java.io.Reader reader,
javax.script.Bindings n)
throws javax.script.ScriptException
eval in interface javax.script.ScriptEnginejavax.script.ScriptExceptionpublic java.lang.Object get(java.lang.String key)
get in interface javax.script.ScriptEnginepublic javax.script.Bindings getBindings(int scope)
getBindings in interface javax.script.ScriptEnginepublic javax.script.ScriptContext getContext()
getContext in interface javax.script.ScriptEnginepublic javax.script.ScriptEngineFactory getFactory()
getFactory in interface javax.script.ScriptEnginepublic void put(java.lang.String key,
java.lang.Object value)
put in interface javax.script.ScriptEnginepublic void setBindings(javax.script.Bindings bindings,
int scope)
setBindings in interface javax.script.ScriptEnginepublic void setContext(javax.script.ScriptContext context)
setContext in interface javax.script.ScriptEngine