/*
 * JBoss, the OpenSource J2EE webOS
 * 
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.test.jca.inflow;

import java.net.InetAddress;
import java.util.Properties;
import javax.resource.ResourceException;
import javax.resource.spi.ActivationSpec;
import javax.resource.spi.InvalidPropertyException;
import javax.resource.spi.ResourceAdapter;

/**
 * A TestActivationSpec that has non-string java bean properties.
 * 
 * @author <a href="adrian@jboss.com">Adrian Brock</a>
 * @version $Revision: 1.1.4.1 $
 */
public class TestActivationSpec implements ActivationSpec
{
   private ResourceAdapter ra;
   
   private String name;
   /** An int between 1-10 */
   private int anInt;
   /** An Integer between 50-100 */
   private Integer anInteger;
   /** The 127.0.0.1 address */
   private InetAddress localhost;
   /** Properties of the form key1=*;key2=*;... */
   private Properties props;

   /**
    * 
    * @throws InvalidPropertyException
    */ 
   public void validate() throws InvalidPropertyException
   {
      /** An int between 1-10 */
      if( anInt <= 0 || anInt > 10 )
         throw new InvalidPropertyException("anInt is not between 1-10");
      /** An int between 50-100 */
      if( anInteger.intValue() <= 49 || anInteger.intValue() > 100 )
         throw new InvalidPropertyException("anInt is not between 50-100");
      /** The 127.0.0.1 address */
      if( localhost.getHostAddress().equals("127.0.0.1") == false )
         throw new InvalidPropertyException("localhost is not 127.0.0.1");         
      /** Properties of the key1=*;key2=*;... */
      if( props.size() == 0 )
         throw new InvalidPropertyException("props has no values");         
   }

   public String getName()
   {
      return name;
   } 
   public void setName(String name)
   {
      this.name = name;
   }

   public int getAnInt()
   {
      return anInt;
   }
   public void setAnInt(int anInt)
   {
      this.anInt = anInt;
   }

   public Integer getAnInteger()
   {
      return anInteger;
   }
   public void setAnInteger(Integer anInteger)
   {
      this.anInteger = anInteger;
   }

   public InetAddress getLocalhost()
   {
      return localhost;
   }
   public void setLocalhost(InetAddress localhost)
   {
      this.localhost = localhost;
   }

   public Properties getProps()
   {
      return props;
   }
   public void setProps(Properties props)
   {
      this.props = props;
   }

   public ResourceAdapter getResourceAdapter()
   {
      return ra;
   }
   
   public void setResourceAdapter(ResourceAdapter ra) throws ResourceException
   {
      this.ra = ra;
   }
   
   public String toString()
   {
      return "TestActivationSpec with name " + name;
   }
}