001
014
015 package com.liferay.portal.template;
016
017 import com.liferay.portal.bean.BeanLocatorImpl;
018 import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
019 import com.liferay.portal.kernel.bean.PortletBeanLocatorUtil;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022
023
026 public class ServiceLocator {
027
028 public static ServiceLocator getInstance() {
029 return _instance;
030 }
031
032 public Object findService(String serviceName) {
033 Object bean = null;
034
035 try {
036 bean = PortalBeanLocatorUtil.locate(_getServiceName(serviceName));
037 }
038 catch (Exception e) {
039 _log.error(e, e);
040 }
041
042 return bean;
043 }
044
045 public Object findService(String servletContextName, String serviceName) {
046 Object bean = null;
047
048 try {
049 bean = PortletBeanLocatorUtil.locate(
050 servletContextName, _getServiceName(serviceName));
051 }
052 catch (Exception e) {
053 _log.error(e, e);
054 }
055
056 return bean;
057 }
058
059 private ServiceLocator() {
060 }
061
062 private String _getServiceName(String serviceName) {
063 if (!serviceName.endsWith(BeanLocatorImpl.VELOCITY_SUFFIX)) {
064 serviceName += BeanLocatorImpl.VELOCITY_SUFFIX;
065 }
066
067 return serviceName;
068 }
069
070 private static Log _log = LogFactoryUtil.getLog(ServiceLocator.class);
071
072 private static ServiceLocator _instance = new ServiceLocator();
073
074 }