Check javax.ejb.ScheduleExpression

I have a text box in which users can enter a cron expression (e.g. 0 */5 * * * * ). Then I split it and built javax.ejb.ScheduleExpression .

Now javax.ejb.ScheduleExpression accepts any string for different elements without checking. I can for example

 scheduleExpression.minute("randomText"); 

and accepted. If then I try to use ScheduleExpression, I obviously get errors (for example, when I try to create a timer with it).

I started writing code to verify input, but the rules are not so short and trivial: http://docs.oracle.com/javaee/6/api/javax/ejb/ScheduleExpression.html

Is there an easy way (in Java EE) or a library that is already doing this work?

+6
source share
2 answers

Since I ran into the same problem, I created a bean validator annotation for EJB timers.

Feel free to use it. For all those who do not want or can use bean validation, look at the regular expression in the CronField.java file to check their lines manually.

Regular expressions are for "ScheduleExpression" and not for "CronExpression", so my chosen name may seem a bit confusing.

If you have improvements or optimizations, send me a request for transfer or message.

The source is available in this repository .

Usage: public class Month {

  @CheckCronField(CronField.MONTH) public String expression; ... } 

A few more examples are available in the test folder in the same repository.

+3
source

If you are in a Java EE environment and have quartz, perhaps this question has the answer you are looking for ...

-2
source

All Articles