1 17 18 package org.apache.avalon.cornerstone.services.scheduler; 19 20 import org.apache.avalon.framework.configuration.Configuration; 21 import org.apache.avalon.framework.configuration.ConfigurationException; 22 23 28 public class TimeTriggerFactory 29 { 30 35 public TimeTrigger createTimeTrigger( final Configuration conf ) 36 throws ConfigurationException 37 { 38 final String type = conf.getAttribute( "type" ); 39 40 TimeTrigger trigger; 41 if( "periodic".equals( type ) ) 42 { 43 final int offset = 44 conf.getChild( "offset", true ).getValueAsInteger( 0 ); 45 final int period = 46 conf.getChild( "period", true ).getValueAsInteger( -1 ); 47 48 trigger = new PeriodicTimeTrigger( offset, period ); 49 } 50 else if( "cron".equals( type ) ) 51 { 52 final int minute = 53 conf.getChild( "minute" ).getValueAsInteger( -1 ); 54 final int hour = 55 conf.getChild( "hour" ).getValueAsInteger( -1 ); 56 final int day = 57 conf.getChild( "day" ).getValueAsInteger( -1 ); 58 final int month = 59 conf.getChild( "month" ).getValueAsInteger( -1 ); 60 final int year = 61 conf.getChild( "year" ).getValueAsInteger( -1 ); 62 final boolean dayOfWeek = 63 conf.getChild( "day" ).getAttributeAsBoolean( "week", false ); 64 65 trigger = new CronTimeTrigger( minute, hour, day, month, year, 66 dayOfWeek ); 67 } 68 else 69 { 70 throw new ConfigurationException( "Unknown trigger type" ); 71 } 72 73 return trigger; 74 } 75 } 76 | Popular Tags |