2009-07-12 23:08:17 +02:00
/* *
2009-12-27 16:01:53 +01:00
* Copyright ( C ) 2009 - 2010 Scalable Solutions AB < http : //scalablesolutions.se>
2009-07-12 23:08:17 +02:00
*/
2009-09-02 09:10:21 +02:00
package se.scalablesolutions.akka.rest
2009-07-12 23:08:17 +02:00
2009-12-18 21:26:03 +01:00
import com.sun.jersey.core.spi.component.ComponentScope
2009-07-12 23:08:17 +02:00
import com.sun.jersey.core.spi.component.ioc.IoCFullyManagedComponentProvider
2009-09-02 09:10:21 +02:00
import config.Configurator
import util.Logging
2009-07-12 23:08:17 +02:00
class ActorComponentProvider ( val clazz : Class [ _ ] , val configurators : List [ Configurator ] )
extends IoCFullyManagedComponentProvider with Logging {
2009-12-18 21:26:03 +01:00
override def getScope = ComponentScope . Singleton
2009-07-12 23:08:17 +02:00
override def getInstance : AnyRef = {
val instances = for {
conf <- configurators
if conf . isDefined ( clazz )
} yield conf . getInstance ( clazz ) . asInstanceOf [ AnyRef ]
instances match {
case instance : : Nil => instance
case Nil => throw new IllegalArgumentException ( "No Actor for class [" + clazz + "] could be found. Make sure you have defined and configured the class as an Active Object or Actor in a Configurator" )
case _ => throw new IllegalArgumentException ( "Actor for class [" + clazz + "] is defined in more than one Configurator. Eliminate the redundancy." )
}
}
}