/**
 * Copyright (c) 2011 RedEngine Ltd, http://www.RedEngine.co.nz. All rights reserved.
 *
 * This program is licensed to you under the Apache License Version 2.0,
 * and you may not use this file except in compliance with the Apache License Version 2.0.
 * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the Apache License Version 2.0 is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
 */
package net.stickycode.scheduled;

import net.stickycode.coercion.CoercionTarget;
import net.stickycode.configured.ConfigurationAttribute;


public class ScheduleConfiguration
    implements ConfigurationAttribute {
  
  private Schedule schedule;
  private final String name;

  public ScheduleConfiguration(String name) {
    this.name = name;
  }

  @Override
  public Class<?> getType() {
    return PeriodicSchedule.class;
  }

  @Override
  public boolean isArray() {
    return false;
  }

  @Override
  public Class<?> getComponentType() {
    throw new UnsupportedOperationException("Scheduling has no components");
  }

  @Override
  public CoercionTarget getComponentCoercionType() {
    throw new UnsupportedOperationException("Scheduling has no component type to coerce");
  }
  
  @Override
  public CoercionTarget[] getComponentCoercionTypes() {
    throw new UnsupportedOperationException("Scheduling has no component targets");
  }

  @Override
  public boolean hasDefaultValue() {
    return false;
  }

  @Override
  public Object getDefaultValue() {
    throw new UnsupportedOperationException("Scheduling cannot have a default value");
  }

  @Override
  public void setValue(Object value) {
    this.schedule = (Schedule)value;
  }

  @Override
  public String getName() {
    return name;
  }

  public Schedule getSchedule() {
    return schedule;
  }
  
  @Override
  public String toString() {
    if (schedule == null)
      return name + " with undefined schedule";
    
    return name + " with " + schedule.toString();
  }

}

@@ -748,16 +748,114 @@
 duled;%0A%0A
+import java.lang.reflect.ParameterizedType;%0A%0Aimport net.stickycode.coercion.AbstractCoercionType;%0A
 import n
@@ -893,16 +893,16 @@
 Target;%0A
-
 import n
@@ -951,17 +951,16 @@
 ibute;%0A%0A
-%0A
 public c
@@ -986,16 +986,49 @@
 uration%0A
+    extends AbstractCoercionType%0A
     impl
@@ -1059,19 +1059,17 @@
 ibute %7B%0A
-  
 %0A
+
   privat
@@ -1089,16 +1089,17 @@
 hedule;%0A
+%0A
   privat
@@ -1485,32 +1485,40 @@
 erride%0A  public 
+Abstract
 CoercionTarget g
@@ -1510,21 +1510,19 @@
 oercionT
-arget
+ype
  getComp
@@ -1634,27 +1634,25 @@
 erce%22);%0A  %7D%0A
-  
 %0A
+
   @Override%0A
@@ -1660,16 +1660,24 @@
  public 
+Abstract
 Coercion
@@ -1677,21 +1677,19 @@
 oercionT
-arget
+ype
 %5B%5D getCo
@@ -2095,16 +2095,17 @@
 chedule)
+ 
 value;%0A 
@@ -2229,19 +2229,17 @@
 le;%0A  %7D%0A
-  
 %0A
+
   @Overr
@@ -2345,20 +2345,16 @@
 edule%22;%0A
-    
 %0A    ret
@@ -2401,10 +2401,231 @@
 );%0A  %7D%0A%0A
+  @Override%0A  public boolean isGenericType() %7B%0A    return false;%0A  %7D%0A%0A  @Override%0A  public ParameterizedType getGenericType() %7B%0A    throw new UnsupportedOperationException(%22Schedule configurations are not generic%22);%0A  %7D%0A%0A
 %7D%0A

Use the abstract coercion type so as to not be affected by api additions