org.openmrs.api.context
Class ServiceContext

java.lang.Object
  extended by org.openmrs.api.context.ServiceContext
All Implemented Interfaces:
org.springframework.context.ApplicationContextAware

public class ServiceContext
extends java.lang.Object
implements org.springframework.context.ApplicationContextAware

Represents an OpenMRS Service Context, which returns the services represented throughout the system.

This class should not be access directly, but rather used through the Context class.

This class is essentially static and only one instance is kept because this is fairly heavy-weight. Spring takes care of filling in the actual service implementations via dependency injection. See the /metadata/api/spring/applicationContext-service.xml file.

Module services are also accessed through this class. See getService(Class)

See Also:
Context

Method Summary
 void addAdvice(java.lang.Class cls, org.aopalliance.aop.Advice advice)
           
 void addAdvisor(java.lang.Class cls, org.springframework.aop.Advisor advisor)
           
static void destroyInstance()
          Null out the current instance of the ServiceContext.
 void doneRefreshingContext()
          Should be called right after any spring context refresh This wakes up all calls to getService that were waiting because startRefreshingContext was called
 ActiveListService getActiveListService()
          Gets the ActiveListService used in the context.
 AdministrationService getAdministrationService()
           
 AlertService getAlertService()
           
 ArdenService getArdenService()
           
 CohortService getCohortService()
           
 ConceptService getConceptService()
           
 DataSetService getDataSetService()
          Deprecated. see reportingcompatibility module
 EncounterService getEncounterService()
           
 FormService getFormService()
           
 HL7Service getHL7Service()
           
static ServiceContext getInstance()
          There should only be one ServiceContext per openmrs (java virtual machine).
 LocationService getLocationService()
           
 LogicService getLogicService()
           
 MessageService getMessageService()
           
 MessageSourceService getMessageSourceService()
          Gets the MessageSourceService used in the context.
 ObsService getObsService()
           
 OrderService getOrderService()
           
 PatientService getPatientService()
           
 PatientSetService getPatientSetService()
           
 PersonService getPersonService()
           
 ProgramWorkflowService getProgramWorkflowService()
           
<T> java.util.List<T>
getRegisteredComponents(java.lang.Class<T> type)
          Retrieves all Beans which have been registered in the Spring ApplicationContext that match the given object type (including subclasses).
 ReportObjectService getReportObjectService()
          Deprecated. see reportingcompatibility module
 ReportService getReportService()
          Deprecated. see reportingcompatibility module
 SchedulerService getSchedulerService()
           
 SerializationService getSerializationService()
           
<T> T
getService(java.lang.Class<? extends T> cls)
          Returns the current proxy that is stored for the Class cls
 UserService getUserService()
           
 boolean isRefreshingContext()
          Returns true/false whether startRefreshingContext() has been called without a subsequent call to doneRefreshingContext() yet.
 void removeAdvice(java.lang.Class cls, org.aopalliance.aop.Advice advice)
           
 void removeAdvisor(java.lang.Class cls, org.springframework.aop.Advisor advisor)
           
 void setActiveListService(ActiveListService activeListService)
          Sets the ActiveListService used in the context
 void setAdministrationService(AdministrationService administrationService)
           
 void setAlertService(AlertService alertService)
           
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
           
 void setArdenService(ArdenService ardenService)
           
 void setCohortService(CohortService cs)
           
 void setConceptService(ConceptService conceptService)
           
 void setDataSetService(DataSetService dataSetService)
          Deprecated. see reportingcompatibility module
 void setEncounterService(EncounterService encounterService)
           
 void setFormService(FormService formService)
           
 void setHl7Service(HL7Service hl7Service)
           
 void setLocationService(LocationService locationService)
           
 void setLogicService(LogicService logicService)
           
 void setMessageService(MessageService messageService)
          Sets the message service.
 void setMessageSourceService(MessageSourceService messageSourceService)
          Sets the MessageSourceService used in the context.
 void setModuleService(java.util.List<java.lang.Object> params)
          Allow other services to be added to our service layer

Classes will be found/loaded with the ModuleClassLoader

params[0] = string representing the service interface
params[1] = service instance
 void setObsService(ObsService obsService)
           
 void setOrderService(OrderService orderService)
           
 void setPatientService(PatientService patientService)
           
 void setPatientSetService(PatientSetService patientSetService)
           
 void setPersonService(PersonService personService)
           
 void setProgramWorkflowService(ProgramWorkflowService programWorkflowService)
           
 void setReportObjectService(ReportObjectService reportObjectService)
          Deprecated. see reportingcompatibility module
 void setReportService(ReportService reportService)
          Deprecated. see reportingcompatibility module
 void setSchedulerService(SchedulerService schedulerService)
          Set the scheduler service.
 void setSerializationService(SerializationService serializationService)
           
 void setService(java.lang.Class cls, java.lang.Object classInstance)
          Allow other services to be added to our service layer
 void setUserService(UserService userService)
           
 void setUseSystemClassLoader(boolean useSystemClassLoader)
          Set this service context to use the system class loader if the useSystemClassLoader is set to true.
 void startRefreshingContext()
          Should be called right before any spring context refresh This forces all calls to getService to wait until doneRefreshingContext is called
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ServiceContext getInstance()
There should only be one ServiceContext per openmrs (java virtual machine). This method should be used when wanting to fetch the service context Note: The ServiceContext shouldn't be used independently. All calls should go through the Context

Returns:
This VM's current ServiceContext.
See Also:
Context

destroyInstance

public static void destroyInstance()
Null out the current instance of the ServiceContext. This should be used when modules are refreshing (being added/removed) and/or openmrs is shutting down


getEncounterService

public EncounterService getEncounterService()
Returns:
encounter-related services

getLocationService

public LocationService getLocationService()
Returns:
location services

getObsService

public ObsService getObsService()
Returns:
observation services

getPatientSetService

public PatientSetService getPatientSetService()
Returns:
patientset-related services

getCohortService

public CohortService getCohortService()
Returns:
cohort related service

setCohortService

public void setCohortService(CohortService cs)
Parameters:
cs - cohort related service

getOrderService

public OrderService getOrderService()
Returns:
order service

getFormService

public FormService getFormService()
Returns:
form service

getReportObjectService

@Deprecated
public ReportObjectService getReportObjectService()
Deprecated. see reportingcompatibility module

Returns:
report object service

getSerializationService

public SerializationService getSerializationService()
Returns:
serialization service

getReportService

@Deprecated
public ReportService getReportService()
Deprecated. see reportingcompatibility module

Returns:
report service

getAdministrationService

public AdministrationService getAdministrationService()
Returns:
admin-related services

getProgramWorkflowService

public ProgramWorkflowService getProgramWorkflowService()
Returns:
programWorkflowService

getArdenService

public ArdenService getArdenService()
Returns:
ardenService

getLogicService

public LogicService getLogicService()
Returns:
logicService

getSchedulerService

public SchedulerService getSchedulerService()
Returns:
scheduler service

setSchedulerService

public void setSchedulerService(SchedulerService schedulerService)
Set the scheduler service.

Parameters:
schedulerService -

getAlertService

public AlertService getAlertService()
Returns:
alert service

setAlertService

public void setAlertService(AlertService alertService)
Parameters:
alertService -

setProgramWorkflowService

public void setProgramWorkflowService(ProgramWorkflowService programWorkflowService)
Parameters:
programWorkflowService -

setArdenService

public void setArdenService(ArdenService ardenService)
Parameters:
ardenService -

setLogicService

public void setLogicService(LogicService logicService)
Parameters:
logicService -

getMessageService

public MessageService getMessageService()
Returns:
message service

setMessageService

public void setMessageService(MessageService messageService)
Sets the message service.

Parameters:
messageService -

getHL7Service

public HL7Service getHL7Service()
Returns:
the hl7Service

setHl7Service

public void setHl7Service(HL7Service hl7Service)
Parameters:
hl7Service - the hl7Service to set

setAdministrationService

public void setAdministrationService(AdministrationService administrationService)
Parameters:
administrationService - the administrationService to set

setEncounterService

public void setEncounterService(EncounterService encounterService)
Parameters:
encounterService - the encounterService to set

setLocationService

public void setLocationService(LocationService locationService)
Parameters:
locationService - the LocationService to set

setFormService

public void setFormService(FormService formService)
Parameters:
formService - the formService to set

setObsService

public void setObsService(ObsService obsService)
Parameters:
obsService - the obsService to set

setOrderService

public void setOrderService(OrderService orderService)
Parameters:
orderService - the orderService to set

setPatientSetService

public void setPatientSetService(PatientSetService patientSetService)
Parameters:
patientSetService - the patientSetService to set

setReportObjectService

@Deprecated
public void setReportObjectService(ReportObjectService reportObjectService)
Deprecated. see reportingcompatibility module

Parameters:
reportObjectService - the reportObjectService to set

setReportService

@Deprecated
public void setReportService(ReportService reportService)
Deprecated. see reportingcompatibility module

Parameters:
reportService -

setSerializationService

public void setSerializationService(SerializationService serializationService)
Parameters:
serializationService -

setDataSetService

@Deprecated
public void setDataSetService(DataSetService dataSetService)
Deprecated. see reportingcompatibility module

Parameters:
dataSetService -

getDataSetService

@Deprecated
public DataSetService getDataSetService()
Deprecated. see reportingcompatibility module

Returns:
the DataSetService

getPatientService

public PatientService getPatientService()
Returns:
patient related services

setPatientService

public void setPatientService(PatientService patientService)
Parameters:
patientService - the patientService to set

getPersonService

public PersonService getPersonService()
Returns:
person related services

setPersonService

public void setPersonService(PersonService personService)
Parameters:
personService - the personService to set

getConceptService

public ConceptService getConceptService()
Returns:
concept related services

setConceptService

public void setConceptService(ConceptService conceptService)
Parameters:
conceptService - the conceptService to set

getUserService

public UserService getUserService()
Returns:
user-related services

setUserService

public void setUserService(UserService userService)
Parameters:
userService - the userService to set

getMessageSourceService

public MessageSourceService getMessageSourceService()
Gets the MessageSourceService used in the context.

Returns:
MessageSourceService

setMessageSourceService

public void setMessageSourceService(MessageSourceService messageSourceService)
Sets the MessageSourceService used in the context.

Parameters:
messageSourceService - the MessageSourceService to use

getActiveListService

public ActiveListService getActiveListService()
Gets the ActiveListService used in the context.

Returns:
ActiveListService

setActiveListService

public void setActiveListService(ActiveListService activeListService)
Sets the ActiveListService used in the context


addAdvisor

public void addAdvisor(java.lang.Class cls,
                       org.springframework.aop.Advisor advisor)
Parameters:
cls -
advisor -

addAdvice

public void addAdvice(java.lang.Class cls,
                      org.aopalliance.aop.Advice advice)
Parameters:
cls -
advice -

removeAdvisor

public void removeAdvisor(java.lang.Class cls,
                          org.springframework.aop.Advisor advisor)
Parameters:
cls -
advisor -

removeAdvice

public void removeAdvice(java.lang.Class cls,
                         org.aopalliance.aop.Advice advice)
Parameters:
cls -
advice -

getService

public <T> T getService(java.lang.Class<? extends T> cls)
Returns the current proxy that is stored for the Class cls

Parameters:
cls -
Returns:
Object that is a proxy for the cls class

setService

public void setService(java.lang.Class cls,
                       java.lang.Object classInstance)
Allow other services to be added to our service layer

Parameters:
cls - Interface to proxy
classInstance - the actual instance of the cls interface

setModuleService

public void setModuleService(java.util.List<java.lang.Object> params)
Allow other services to be added to our service layer

Classes will be found/loaded with the ModuleClassLoader

params[0] = string representing the service interface
params[1] = service instance

Parameters:
params - list of parameters

setUseSystemClassLoader

public void setUseSystemClassLoader(boolean useSystemClassLoader)
Set this service context to use the system class loader if the useSystemClassLoader is set to true. If false, the openmrs class loader is used to load module services

Parameters:
useSystemClassLoader - true/false whether to use the system class loader

startRefreshingContext

public void startRefreshingContext()
Should be called right before any spring context refresh This forces all calls to getService to wait until doneRefreshingContext is called


doneRefreshingContext

public void doneRefreshingContext()
Should be called right after any spring context refresh This wakes up all calls to getService that were waiting because startRefreshingContext was called


isRefreshingContext

public boolean isRefreshingContext()
Returns true/false whether startRefreshingContext() has been called without a subsequent call to doneRefreshingContext() yet. All methods involved in starting/stopping a module should call this if a service method is needed -- otherwise a deadlock will occur.

Returns:
true/false whether the services are currently blocking waiting for a call to doneRefreshingContext()

getRegisteredComponents

public <T> java.util.List<T> getRegisteredComponents(java.lang.Class<T> type)
Retrieves all Beans which have been registered in the Spring ApplicationContext that match the given object type (including subclasses).

NOTE: This method introspects top-level beans only. It does not check nested beans which might match the specified type as well.

Parameters:
type - the type of Bean to retrieve from the Spring ApplicationContext
Returns:
a List of all registered Beans that are valid instances of the passed type
Since:
1.5
See Also:
ListableBeanFactory.getBeansOfType(Class)
Expected behavior:
return a list of all registered beans of the passed type, return beans registered in a module, return an empty list if no beans have been registered of the passed type

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Parameters:
applicationContext - the applicationContext to set

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change