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