Java try command in a method

32 views
Skip to first unread message

marius_va...@yahoo.com

unread,
Nov 9, 2015, 9:36:11 AM11/9/15
to OpenRules
I'm checking whether a date is valid.


Method boolean CheckValidDate(ProductStartEnd productStartEnd)
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd");
sdf.setLenient(false);
try {
   Date date = sdf.parse (productStartEnd.startDateString);
 
{  catch (ParseException e) {
     return false;  
}
return true;

[DecisionTable${OPENRULES_MODE}Templates.xls] has been resolved to [file:/C:/EclipseWorkspace/P2V+/DecisionTableExecuteTemplates.xls]
Processing file:/C:/EclipseWorkspace/P2V+/DecisionTableExecuteTemplates.xls
IMPORT.JAVA=mypackage.*
IMPORT.JAVA=java.util.regex.*
IMPORT.JAVA=java.text.*
Exception in thread "main" org.openl.syntax.SyntaxErrorException: Error: Encountered "try" at line 3, column 1.
Was expecting one of:
    <EOF>
    "break" ...
    "continue" ...
    "do" ...
    "false" ...
    "for" ...
    "if" ...
    "new" ...
    "null" ...
    "return" ...
    "throw" ...
    "true" ...
    "while" ...
    "(" ...
    "{" ...
    ";" ...
    "!" ...
    "++" ...
    "--" ...
    "+" ...
    "-" ...
    "|" ...
    <INTEGER_LITERAL> ...
    <FLOATING_POINT_LITERAL> ...
    <CHARACTER_LITERAL> ...
    <STRING_LITERAL> ...
    <IDENTIFIER> ...
   
Invalid Code Fragment:
=========================================
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd");
sdf.setLenient(false);
                     ^
try {
   Date date = sdf.parse (productStartEnd.startDateString);
=========================================
    at file:/C:/EclipseWorkspace/P2V+/spreadsheet/xtra/Miscellaneous.xls?sheet=Method&cell=F28&start=81&end=81&openl=

Without the try command the following happens:

Execute Rules <EvaluateOneStartDate> for a collection of ProductStartEnd
Conclusion: Start Date Flag is Y
org.apache.commons.lang.exception.NestableRuntimeException: Unparseable date: "2015-07-33"
    at org.openl.util.RuntimeExceptionWrapper.wrap(RuntimeExceptionWrapper.java:27)
    at org.openl.types.java.JavaOpenMethod.invoke(JavaOpenMethod.java:65)
    at org.openl.binding.impl.MethodBoundNode.evaluateRuntime(MethodBoundNode.java:65)


OpenRules Support

unread,
Nov 9, 2015, 10:07:45 AM11/9/15
to OpenRules
Usually you do not want to keep too many technical Java details in Excel. So, you may put your method below inside your own Java class and simply call if from Excel. Do not forget to include the proper "import.java" or "import.static" line to your Environment table - see User Manual http://openrules.com/pdf/OpenRulesUserManual.pdf p.103
Reply all
Reply to author
Forward
0 new messages