|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.vishia.mainCmd.MainCmd
public abstract class MainCmd
---|> means an inherition
<>--> means a composition or aggregation
----> means a association
+-------------+ +-------------+ +-------------+
| |------|>| MainCmd |------|>| MainCmd_Ifc |
|UserMainClass| +-------------+ +-------------+
| | ^
| | +-------------+ main |
| |<>----->| UserClasses |---------------+
+-------------+ +-------------+
in cmdlines:
class UserMainClass extends MainCmd
{ final UserClasses userClasses = new UserClasses(this); //... the user's classes
}
class UserClasses
{ final MainCmd_Ifc main; //the aggregation to Main
UserClasses(MainCmd_Ifc main)
{ this.main = main;
}
}
The UserMainClass based on MainCmd as superclass, MainCmd implements MainCmd_Ifc.
All composite classes from UserMainclass may known the MainCmd instance respective the UserMainClass instance
via the interface MainCmd_Ifc.
With this interface the user can access at all capabilities of support of command line things,
implemented cardinally in MainCmd, but overwriteable from the user in his UserMainClass.date who what 2007-03-07 JcHartmut Method getReportFileName 2007-03-07 JcHartmut callWithoutArgument do not exit but throws an exception likewise by an error of arguments. 2006-04-02 JcHartmut writeInfo__ new methods write__Directly, solution of concurrency to write to report. 2006-01-17 JcHartmut testArgument() may thrown an ParseException. 2006-01-21 JcHartmut bugfix callWithoutArguments() should be protected, not package private. 2004-06-00 JcHartmut initial revision
| Nested Class Summary | |
|---|---|
(package private) class |
MainCmd.LogMessageImplConsole
|
(package private) class |
MainCmd.LogMessageImplFile
|
private class |
MainCmd.ShowCmdOutput
Class to write any readed stream to the output, running in a separate thread. |
| Field Summary | |
|---|---|
protected java.lang.String[] |
cmdLineArgs
array of arguments from command line |
FileWrite |
fReport
The report file. |
private int |
iArgs
number of the argument is parsing |
protected static short |
kError_writeInfoDirectly
|
protected static short |
kInfo_writeInfoDirectly
Some bits to mark the kind of output |
protected static short |
kInfoln_writeInfoDirectly
|
protected static short |
kWarning_writeInfoDirectly
|
protected java.util.List<java.lang.String> |
listAboutInfo
List of strings contents about Info in form of lines. |
protected java.util.List<java.lang.String> |
listHelpInfo
List of strings contents help Info in form of lines. |
(package private) MainCmd.LogMessageImplConsole |
logMessageConsole
|
(package private) MainCmd.LogMessageImplFile |
logMessageFile
|
protected static short |
mError_writeInfoDirectly
If this bit is setted in param kind of writeDirectly an error is to be outputted |
protected static short |
mNewln_writeInfoDirectly
If this bit is setted in param kind of writeDirectly a newline should be inserted at begin of output |
protected static short |
mWarning_writeInfoDirectly
If this bit is setted in param kind of writeDirectly a warning is to be outputted |
int |
nLevelDisplayToReport
writeError(), writeWarning(), writeInfo() are also reported if the level is equal or greater than 1,2,3 |
private int |
nMaxErrorLevel
The maximum of the value given with setExitErrorLevel |
int |
nReportLevel
All reports with a level less than or equal this level will be reported. |
int |
nReportLevelDisplay
All reports with a level less than or equal this level will be written on display. |
private static java.lang.String |
report_spaces
access to some spaces via Report.spaces.substring(0,n) |
private java.lang.String |
sFileReport
|
| Fields inherited from interface org.vishia.mainCmd.Report |
|---|
anytime, debug, error, eventOrder, exitSuccessfull, exitUserAbort, exitWithArgumentError, exitWithErrors, exitWithFileProblems, exitWithNotes, exitWithWarnings, fineDebug, fineEventOrder, fineInfo, info, interested, mNeverOutputToDisplay, mReportLevel, warning |
| Constructor Summary | |
|---|---|
protected |
MainCmd()
Empty Constructor of the main class. |
protected |
MainCmd(java.lang.String[] args)
Constructor of the main class. |
| Method Summary | |
|---|---|
protected void |
addAboutInfo(java.lang.String info)
Addes a helpinfo-line to the internal list. |
protected void |
addHelpInfo(java.lang.String info)
Addes a helpinfo-line to the internal list. |
protected void |
addStandardHelpInfo()
Adds the help info for standard arguments. |
protected void |
callWithoutArguments()
Invoked from parseArguments if no argument is given. |
protected abstract boolean |
checkArguments()
Checks the arguments after parsing from command line, test of consistence. |
int |
executeCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String[] cmd,
java.lang.String input,
int nReportLevel,
java.lang.StringBuffer output,
java.lang.StringBuffer error)
Executes a command line call maybe as pipe, waiting for finishing.. |
int |
executeCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String cmd,
java.lang.String input,
int nReportLevel,
java.lang.StringBuffer output,
java.lang.StringBuffer error)
Executes a command line call maybe as pipe, waiting for finishing.. |
int |
executeCmdLine(java.lang.String[] cmd,
int nReportLevel,
java.lang.StringBuffer output,
java.lang.String input)
Execute a command invoke a cmdline call, implements MainCmd_Ifc. |
int |
executeCmdLine(java.lang.String[] cmd,
java.lang.ProcessBuilder processBuilder,
int nReportLevel,
java.lang.StringBuffer output,
java.lang.String input)
Deprecated. |
int |
executeCmdLine(java.lang.String cmd,
int nReportLevel,
java.lang.StringBuffer output,
java.lang.String input)
Execute a command invoke a cmdline call, implements MainCmd_Ifc. |
int |
executeCmdLine(java.lang.String cmd,
java.lang.ProcessBuilder processBuilder,
int nReportLevel,
java.lang.StringBuffer output,
java.lang.String input)
Deprecated. |
void |
exit()
Exits the cmdline application with the maximum of setted exit error level. |
void |
flushReport()
Writes the content in the physical medium. |
protected java.lang.String |
getArgument(int pos)
Returns the argument contents. |
int |
getExitErrorLevel()
get the maximum of errorLevel setted with setExitErrorLevel(). |
LogMessage |
getLogMessageOutputConsole()
Gets a LogMessage output. |
LogMessage |
getLogMessageOutputFile()
Gets a LogMessage output. |
java.lang.String |
getReportFileName()
Returns the name of the report file to write out as info. |
int |
getReportLevel()
Test wether the report is in the level. |
int |
getReportLevelFromIdent(int ident)
gets the associated report level to a report identifier. |
void |
openReportfile(java.lang.String sFileReport,
boolean bAppendReport)
|
void |
parseArguments()
Parses the cmdLine-arguments. |
void |
parseArguments(java.lang.String[] args)
Parses the cmdLine-arguments. |
void |
report(int nLevel,
java.lang.String ss)
report appending on exist line. |
void |
report(java.lang.String sInfo,
java.lang.Exception exception)
Reports an exception. |
private void |
report(java.lang.String sInfo,
java.lang.Exception exception,
boolean bWrittenOnDisplay)
Internal method to write an exception to report. |
void |
reportln(int nLevel,
int nLeftMargin,
java.lang.String ss)
report begins at a new a line with left margin |
void |
reportln(int nLevel,
java.lang.String ss)
report begins at a new a line |
void |
setExitErrorLevel(int level)
set the exitErrorLevel of the maximum of given level of every call. |
int |
setReportLevel(int newLevel)
Set another level inside programming. |
void |
setReportLevelToIdent(int nLevel,
int nLevelActive)
Sets a dedicated level number to the known output priorities. |
int |
startCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String cmd)
Starts a command invocation for a independent window. |
int |
startCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String[] cmd)
Starts a command invocation for a independent window. |
int |
switchToWindowOrStartCmdline(java.lang.ProcessBuilder processBuilder,
java.lang.String sCmd,
java.lang.String sWindowTitle)
Searches the window for the already running process or starts the process with command invocation for a independent window. |
protected abstract boolean |
testArgument(java.lang.String argc,
int nArg)
Tests one argument, called from parseArguments() on every argument excluding standard arguments -r and -rlevel. |
void |
writeAboutInfo()
prints the help info to the console output. |
protected void |
writeDirectly(java.lang.String sInfo,
short kind)
Writes out the Info, Warning or Error in the users way. |
void |
writeError(java.lang.String sInfo)
Writes an error line, implementation of MainCmd_Ifc. |
void |
writeError(java.lang.String sInfo,
java.lang.Exception exception)
Writes an error line with exception info, implementation of MainCmd_Ifc. |
protected void |
writeErrorDirectly(java.lang.String sInfo,
java.lang.Exception exception)
Writes an error line by console application directly to System.err.println with the String "EXCEPTION: " before and the exception message. |
void |
writeHelpInfo()
prints the help info to the console output. |
void |
writeInfo(java.lang.String sInfo)
Writes an information, implementation of MainCmd_Ifc. |
void |
writeInfoln(java.lang.String sInfo)
Writes an information line, implementation of MainCmd_Ifc. |
void |
writeStackTrace(java.lang.Exception exception)
write out the stacktrace from a exception. |
void |
writeWarning(java.lang.String sInfo)
Writes an warning line, implementation of MainCmd_Ifc. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public FileWrite fReport
public int nReportLevel
private java.lang.String sFileReport
public int nReportLevelDisplay
Report.writeInfo(String) etc. writes to display also if this attribute is 0.
public int nLevelDisplayToReport
protected java.util.List<java.lang.String> listHelpInfo
protected java.util.List<java.lang.String> listAboutInfo
private int nMaxErrorLevel
protected java.lang.String[] cmdLineArgs
private int iArgs
private static final java.lang.String report_spaces
protected static final short kInfo_writeInfoDirectly
protected static final short kInfoln_writeInfoDirectly
protected static final short kWarning_writeInfoDirectly
protected static final short kError_writeInfoDirectly
protected static final short mNewln_writeInfoDirectly
protected static final short mWarning_writeInfoDirectly
protected static final short mError_writeInfoDirectly
MainCmd.LogMessageImplConsole logMessageConsole
MainCmd.LogMessageImplFile logMessageFile
| Constructor Detail |
|---|
protected MainCmd()
protected MainCmd(java.lang.String[] args)
| Method Detail |
|---|
protected void addStandardHelpInfo()
addHelpInfo("--about show the help infos");
addHelpInfo("--help show the help infos");
addHelpInfo("--report=FILE write the report (log) into the given file, create or clear the file.");
addHelpInfo("--report+=FILE add to the end of given file or create the report file.");
addHelpInfo("--rlevel=R set the level of report, R is number from 1 to 6.");
addHelpInfo("--rlevel=DR also write reports upto level D on display, sample: ..-rlevel:24");
addHelpInfo("--rlevel=WDR write output also in report, W is nr from 1 to 3 (error, warning, info");
protected void addHelpInfo(java.lang.String info)
writeHelpInfo()
called if the argument --help is given or without arguments. .
info - String contains 1 line of a help Info.protected void addAboutInfo(java.lang.String info)
info - String contains 1 line of a help Info.public void writeHelpInfo()
public void writeAboutInfo()
public final void parseArguments()
throws java.text.ParseException
java.text.ParseExceptionparseArguments(String [] args)
public final void parseArguments(java.lang.String[] args)
throws java.text.ParseException
testArgument(String, int) inside.
That is a abstract methode, the user must overwrite it, see there. If this method returns false,
a writeError() with a matched text is called and a ParseException("", N) ist thrown, N is the
number of the argument.
Standard arguments are parsed here, see addStandardHelpInfo().
On end the methode checkArguments() is called.
If it returns false, an ParseException("", 0) is thrown.
The user should had write an output message with writeError() inside its checkArguments()>cmd -a arg1 @@file -x argx results in the followed argument array:-a arg1 arguments-from-file-lines -x argx
java.text.ParseException
public void openReportfile(java.lang.String sFileReport,
boolean bAppendReport)
throws java.io.FileNotFoundException
openReportfile in interface Reportjava.io.FileNotFoundExceptionprotected abstract boolean checkArguments()
protected void callWithoutArguments()
throws java.text.ParseException
java.text.ParseExceptionprotected java.lang.String getArgument(int pos)
pos - position of the beginning of the information in a argument. In the sample above use the value 2.
protected abstract boolean testArgument(java.lang.String argc,
int nArg)
throws java.text.ParseException
argc - The argument to testnArg - number of argument, the first argument is numbered with 1.
java.text.ParseException - The Methode may thrown this excpetion if a conversion error or such other is thrown.public void setExitErrorLevel(int level)
setExitErrorLevel in interface Reportlevel - Errorlevel how defined in Report, 0 is the lowest level (successfull), >0 is worse.public int getExitErrorLevel()
getExitErrorLevel in interface Reportpublic void exit()
public int executeCmdLine(java.lang.String cmd,
int nReportLevel,
java.lang.StringBuffer output,
java.lang.String input)
executeCmdLine in interface MainCmd_ifccmd - String represents the command with all arguments. The arguments must be separated by exactly one space.
The rest of paramter and return see executeCmdLine(String[], ...).
public int executeCmdLine(java.lang.String[] cmd,
int nReportLevel,
java.lang.StringBuffer output,
java.lang.String input)
executeCmdLine in interface MainCmd_ifccmd - String with the separeted parts of the command. cmd[0] is the command to invoke.nReportLevel - Determines the kind of writing the output. Possible values are 1..6 using Report.error to Report.fineInfo
and -1..-3 using -Report.error to -report.info (with a negativ sign!). On negativ values the
report is written to display with the write..()-methods of this interface, with the
positive value, the report is written to Report.report..()-Methods.output - If not null, than the stdout is written in this Buffer. If null, the stdout is written to report.input - If not null, this input is send to the cmdline process. If null, no input is send.
public int executeCmdLine(java.lang.String cmd,
java.lang.ProcessBuilder processBuilder,
int nReportLevel,
java.lang.StringBuffer output,
java.lang.String input)
public int executeCmdLine(java.lang.String[] cmd,
java.lang.ProcessBuilder processBuilder,
int nReportLevel,
java.lang.StringBuffer output,
java.lang.String input)
cmd - processBuilder - nReportLevel - output - input -
public int executeCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String cmd,
java.lang.String input,
int nReportLevel,
java.lang.StringBuffer output,
java.lang.StringBuffer error)
executeCmdLine in interface MainCmd_ifcprocessBuilder - The ProcessBuilder. There may be assigned environment variables and a current directory.cmd - The cmd and arguments. If it is null, the command assigened to the processBuilder is used.input - Any pipe-input. It may be null.nReportLevel - The report level which is used for output.
If it is 0, then the output isn't written TODOoutput - The output pipe.error - The error pipe. If it is null, then errors are written in the output pipe.
public int executeCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String[] cmd,
java.lang.String input,
int nReportLevel,
java.lang.StringBuffer output,
java.lang.StringBuffer error)
executeCmdLine in interface MainCmd_ifcprocessBuilder - The ProcessBuilder. There may be assigned environment variables and a current directory.cmd - The cmd and arguments. If it is null, the command assigend to the processBuilder is used.input - Any pipe-input. It may be null.nReportLevel - The report level which is used for output.
If it is 0, then the output isn't written TODOoutput - The output pipe.error - The error pipe. If it is null, then errors are written in the output pipe.
public int startCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String cmd)
startCmdLine in interface MainCmd_ifccmd - The command. Some arguments are possible, they should be separated by space.processBuilder - The processBuilder.
public int startCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String[] cmd)
startCmdLine in interface MainCmd_ifccmd - The command and some arguments.processBuilder - The processBuilder.
public int switchToWindowOrStartCmdline(java.lang.ProcessBuilder processBuilder,
java.lang.String sCmd,
java.lang.String sWindowTitle)
MainCmd_ifc
switchToWindowOrStartCmdline in interface MainCmd_ifcprocessBuilder - The processBuilder.sWindowTitle - The title or the start of the window if the process is running already.
Note: The title is depending from the application.
Sometimes the title starts with the associated file, forex calling windows-notepad.
public final void writeInfo(java.lang.String sInfo)
writeInfo in interface ReportsInfo - String to be written.public final void writeInfoln(java.lang.String sInfo)
writeInfoln in interface ReportsInfo - String to be written.public final void writeWarning(java.lang.String sInfo)
writeWarning in interface ReportsInfo - The error text, it should be without such hot spot words line "!!!WARNING!!!",
because the distinction in display should be done by the implementation of this method.
A good sample is writeErrorln("file is empty: " + sFileName);public final void writeError(java.lang.String sInfo)
writeError in interface ReportsInfo - The error text, it should be without such hot spot words line "!!!ERROR!!!",
because the distinction in display should be done by the implementation of this method.
A good sample is writeErrorln("cannot create file: " + sFileName);
public final void writeError(java.lang.String sInfo,
java.lang.Exception exception)
writeError in interface ReportsInfo - The error text, it should be without such hot spot words line "!!!ERROR!!!",
because the distinction in display should be done by the implementation of this method.
A good sample is writeErrorln("cannot create file: " + sFileName);exception - The catched Exception. The getMessage()-part of the exception is written after sError.
The stacktrace of the exception is written to report.public void writeStackTrace(java.lang.Exception exception)
protected void writeDirectly(java.lang.String sInfo,
short kind)
sInfo - The String to writekind - Ones of the kWriteOut__
protected void writeErrorDirectly(java.lang.String sInfo,
java.lang.Exception exception)
sInfo - Text to write in the new line after "EXCEPTION: ".exception - Its getMessage will be written.
public void report(int nLevel,
java.lang.String ss)
report in interface ReportnLevel - write the report only if the demand level is greater or equal.ss - String to write.
public void reportln(int nLevel,
int nLeftMargin,
java.lang.String ss)
reportln in interface ReportnLevel - write the report only if the demand level is greater or equal.nLeftMargin - determins a left margin. First a new line is outputted, followed by '*' and spaces.ss - String to write.
public void reportln(int nLevel,
java.lang.String ss)
Report
reportln in interface ReportnLevel - write the report only if the demand level is greater or equal.ss - String to write.
public void report(java.lang.String sInfo,
java.lang.Exception exception)
report in interface ReportsInfo - Text to write in the new line after "EXCEPTION: ".exception - Exception info to write
private void report(java.lang.String sInfo,
java.lang.Exception exception,
boolean bWrittenOnDisplay)
sInfo - Text to write in the new line after "EXCEPTION: "
and before the exception.getMessage is written.exception - Exception info to writebWrittenOnDisplay - true, than the writing to display is always done.public int getReportLevel()
getReportLevel in interface Reportpublic int setReportLevel(int newLevel)
newLevel - The level to be set, use one of the defines Report.info to Report.fineDebug
public void flushReport()
Report
flushReport in interface Report
public void setReportLevelToIdent(int nLevel,
int nLevelActive)
Report
setReportLevelToIdent in interface ReportnLevelActive - Ones of the known priotity levels Report.error to Report.fineDebug.
class MyModule
{ /**Define module-specific numbers to identify a level.
* The numbers should be define regarding a band of numbers in the application.
* /
static final int myReportLevel1 = 3500, myReportLevel2=3501;
void init()
{ setLevelActive(myReportLevel1, Report.info); //This reports should be outputted always
setLevelActive(myReportLevel2, Report.debug); //This reports are debug infos.
}
void processAnything()
{ report.reportln( myReportLevel1, "InfoText"); //It depends on the report level settings
report.reportln( myReportLevel2, "DebugText");//wether it is outputted or not.
}
public int getReportLevelFromIdent(int ident)
Report
getReportLevelFromIdent in interface Reportident - The identifier.
public java.lang.String getReportFileName()
MainCmd_ifc
getReportFileName in interface MainCmd_ifcpublic LogMessage getLogMessageOutputConsole()
Report
getLogMessageOutputConsole in interface Reportpublic LogMessage getLogMessageOutputFile()
Report
getLogMessageOutputFile in interface Report
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||