001
014
015 package com.liferay.portal.velocity;
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 private ServiceLocator() {
033 }
034
035 public Object findService(String serviceName) {
036 Object bean = null;
037
038 try {
039 bean = PortalBeanLocatorUtil.locate(_getServiceName(serviceName));
040 }
041 catch (Exception e) {
042 _log.error(e, e);
043 }
044
045 return bean;
046 }
047
048 public Object findService(String servletContextName, String serviceName) {
049 Object bean = null;
050
051 try {
052 bean = PortletBeanLocatorUtil.locate(
053 servletContextName, _getServiceName(serviceName));
054 }
055 catch (Exception e) {
056 _log.error(e, e);
057 }
058
059 return bean;
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 }