/**
 * Copyright (c) 2013 SMC Treviso Srl. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package it.smc.calendar.caldav.helper.api;

import com.liferay.calendar.model.Calendar;
import com.liferay.calendar.model.CalendarResource;
import com.liferay.portal.kernel.model.User;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.util.tracker.ServiceTracker;

import java.util.Optional;

/**
 * @author Fabio Pezzutto
 */
public class CalendarHelperUtil {

	public static Optional<User> getCalendarResourceUser(
		CalendarResource calendarResource) {

		return getService().getCalendarResourceUser(calendarResource);
	}

	public static boolean isCalendarResourceUserCalendar(
		CalendarResource calendarResource) {

		return getService().isCalendarResourceUserCalendar(calendarResource);
	}

	public static boolean isCalendarUserCalendar(Calendar calendar) {

		return getService().isCalendarUserCalendar(calendar);
	}

	public static CalendarHelper getService() {
		if (_calendarHelper == null) {
			Bundle bundle = FrameworkUtil.getBundle(CalendarHelper.class);

			ServiceTracker<CalendarHelper, CalendarHelper> serviceTracker =
				new ServiceTracker<CalendarHelper, CalendarHelper>(
					bundle.getBundleContext(), CalendarHelper.class, null);

			serviceTracker.open();

			_calendarHelper = serviceTracker.getService();
		}

		return _calendarHelper;
	}

	private static CalendarHelper _calendarHelper;

}

@@ -1499,28 +1499,28 @@
 %0A%09%09if (_
-calendarHelp
+serviceTrack
 er == nu
@@ -1599,55 +1599,9 @@
 %0A%09%09%09
-ServiceTracker%3CCalendarHelper, CalendarHelper%3E 
+_
 serv
@@ -1734,16 +1734,17 @@
 l);%0A%0A%09%09%09
+_
 serviceT
@@ -1762,30 +1762,23 @@
 ();%0A
-%0A
 %09%09
-%09_calendarHelper = 
+%7D%0A%0A%09%09return _
 serv
@@ -1806,39 +1806,8 @@
 ();%0A
-%09%09%7D%0A%0A%09%09return _calendarHelper;%0A
 %09%7D%0A%0A
@@ -1814,32 +1814,47 @@
 %09private static 
+ServiceTracker%3C
 CalendarHelper _
@@ -1855,11 +1855,11 @@
 lper
- _c
+, C
 alen
@@ -1867,13 +1867,32 @@
 arHelper
+%3E%0A%09%09_serviceTracker
 ;%0A%0A%7D%0A

Make CalendarHelper service reference dynamic, isstead of use the first implementation found