org.apache.xbean.kernel
Class StaticServiceFactory

java.lang.Object
  extended by org.apache.xbean.kernel.AbstractServiceFactory
      extended by org.apache.xbean.kernel.StaticServiceFactory
All Implemented Interfaces:
ServiceFactory

public class StaticServiceFactory
extends AbstractServiceFactory

A basic service factory that always creates the supplied object.

Since:
2.0
Author:
Dain Sundstrom

Constructor Summary
StaticServiceFactory(Object service)
          Creates a non-restartable service factory which will simply returns the specified service from the createService method.
StaticServiceFactory(Object service, ClassLoader classLoader)
          Creates a non-restartable service factory which will simply returns the specified service from the createService method.
 
Method Summary
 Object createService(ServiceContext serviceContext)
          Returns the static service instance.
 void destroyService(ServiceContext serviceContext)
          This method is a noop.
 ClassLoader getClassLoader()
          Gets the class loader associated with this service.
 Set getOwnedServices()
          Gets the names of services owned by this service.
 Class[] getTypes()
          Gets the types of the service this service factory will create.
 boolean isRestartable()
          A restartable service can be started and stopped repeatedly in the kernel.
 
Methods inherited from class org.apache.xbean.kernel.AbstractServiceFactory
addStartCondition, addStopCondition, getStartConditions, getStopConditions, isEnabled, removeStartCondition, removeStopCondition, setEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StaticServiceFactory

public StaticServiceFactory(Object service)
                     throws NullPointerException
Creates a non-restartable service factory which will simply returns the specified service from the createService method.

Parameters:
service - the static to which this factory "creates"
Throws:
NullPointerException - if service is null

StaticServiceFactory

public StaticServiceFactory(Object service,
                            ClassLoader classLoader)
                     throws NullPointerException
Creates a non-restartable service factory which will simply returns the specified service from the createService method.

Parameters:
service - the static to which this factory "creates"
classLoader - the classLoader used to load the service class
Throws:
NullPointerException - if service or classLoader is null
Method Detail

getTypes

public Class[] getTypes()
Description copied from interface: ServiceFactory
Gets the types of the service this service factory will create. These types is used to index the service within the kernel. It is a start error to return an object from create service that is not an instance of every type. This is the only type used to index the service, so if the service factory returns a subclass of this type from createService, the subtypes will now be reflected in the index.

Returns:
the type of the service this service factory will create

isRestartable

public boolean isRestartable()
A restartable service can be started and stopped repeatedly in the kernel. A service that is not restartable immediately enters the RUNNING state when registered with the kernel, and can not be started or stopped.

Returns:
true if this service can be started and stopped; false otherwise

getOwnedServices

public Set getOwnedServices()
Gets the names of services owned by this service. This information is used for the startRecursive method on the kernel. When a servcie is started with startRecursive all owned services will be started with startRecursive.

Returns:
the names of the services owned by this service

createService

public Object createService(ServiceContext serviceContext)
Returns the static service instance.

Parameters:
serviceContext - ignored
Returns:
the static service instance

destroyService

public void destroyService(ServiceContext serviceContext)
This method is a noop.

Parameters:
serviceContext - ignored

getClassLoader

public ClassLoader getClassLoader()
Gets the class loader associated with this service.

Returns:
the class loader associated with the service


Copyright © 2005-2009 Apache Software Foundation. All Rights Reserved.