1
22
23 package com.liferay.portal.velocity;
24
25 import com.liferay.portal.bean.BeanLocatorImpl;
26 import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
27 import com.liferay.portal.kernel.bean.PortletBeanLocatorUtil;
28 import com.liferay.portal.kernel.log.Log;
29 import com.liferay.portal.kernel.log.LogFactoryUtil;
30
31
36 public class ServiceLocator {
37
38 public static ServiceLocator getInstance() {
39 return _instance;
40 }
41
42 private ServiceLocator() {
43 }
44
45 public Object findService(String serviceName) {
46 Object bean = null;
47
48 try {
49 bean = PortalBeanLocatorUtil.locate(_getServiceName(serviceName));
50 }
51 catch (Exception e) {
52 _log.error(e, e);
53 }
54
55 return bean;
56 }
57
58 public Object findService(String servletContextName, String serviceName) {
59 Object bean = null;
60
61 try {
62 bean = PortletBeanLocatorUtil.locate(
63 servletContextName, _getServiceName(serviceName));
64 }
65 catch (Exception e) {
66 _log.error(e, e);
67 }
68
69 return bean;
70 }
71
72 private String _getServiceName(String serviceName) {
73 if (!serviceName.endsWith(BeanLocatorImpl.VELOCITY_SUFFIX)) {
74 serviceName += BeanLocatorImpl.VELOCITY_SUFFIX;
75 }
76
77 return serviceName;
78 }
79
80 private static Log _log = LogFactoryUtil.getLog(ServiceLocator.class);
81
82 private static ServiceLocator _instance = new ServiceLocator();
83
84 }