001
014
015 package com.liferay.portal.kernel.adaptor;
016
017 import com.liferay.portal.kernel.util.ServiceLoader;
018
019 import java.util.List;
020
021
024 public class AdaptorUtil {
025
026 public static Adaptor getAdaptor() throws AdaptorException {
027 if (_adaptor != null) {
028 return _adaptor;
029 }
030
031 try {
032 List<AdaptorFactory> services = ServiceLoader.load(
033 AdaptorFactory.class);
034
035 for (AdaptorFactory adaptorFactory : services) {
036 _adaptor = adaptorFactory.newAdaptor();
037 }
038 }
039 catch (Exception e) {
040 throw new AdaptorException(e);
041 }
042
043 return _adaptor;
044 }
045
046 public static void init(Object applicationContext) throws AdaptorException {
047 if (hasAdaptor()) {
048 Adaptor adaptor = getAdaptor();
049
050 adaptor.init(applicationContext);
051 }
052 }
053
054 public static void start() throws AdaptorException {
055 if (hasAdaptor()) {
056 Adaptor adaptor = getAdaptor();
057
058 adaptor.start();
059 }
060 }
061
062 public static void stop() throws AdaptorException {
063 if (hasAdaptor()) {
064 Adaptor adaptor = getAdaptor();
065
066 adaptor.stop();
067 }
068 }
069
070 public void setAdaptor(Adaptor adaptor) {
071 _adaptor = adaptor;
072 }
073
074 protected static boolean hasAdaptor() throws AdaptorException {
075 Adaptor adaptor = getAdaptor();
076
077 if (adaptor != null) {
078 return true;
079 }
080
081 return false;
082 }
083
084 private static Adaptor _adaptor;
085
086 }