All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.wiki.importer.impl.WikiImporterTracker Maven / Gradle / Ivy

There is a newer version: 1.2.9
Show newest version
/**
 * Copyright (c) 2000-present Liferay, Inc. 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 com.liferay.wiki.importer.impl;

import com.liferay.wiki.importer.WikiImporter;

import java.util.Collection;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListMap;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;

/**
 * @author Iván Zaera
 */
@Component(immediate = true, service = WikiImporterTracker.class)
public class WikiImporterTracker {

	@Reference(
		cardinality = ReferenceCardinality.MULTIPLE,
		policy = ReferencePolicy.DYNAMIC,
		policyOption = ReferencePolicyOption.GREEDY,
		service = WikiImporter.class, unbind = "removedService",
		updated = "modifiedService"
	)
	public void addingService(ServiceReference serviceReference) {
		String format = (String)serviceReference.getProperty("importer");

		_serviceReferences.put(format, serviceReference);
	}

	public Collection getImporters() {
		return _serviceReferences.keySet();
	}

	public String getProperty(String importer, String key) {
		ServiceReference serviceReference =
			_serviceReferences.get(importer);

		return (String)serviceReference.getProperty(key);
	}

	public WikiImporter getWikiImporter(String importer) {
		return _bundleContext.getService(_serviceReferences.get(importer));
	}

	public void modifiedService(
		ServiceReference serviceReference) {

		removedService(serviceReference);

		addingService(serviceReference);
	}

	public void removedService(
		ServiceReference serviceReference) {

		String importer = (String)serviceReference.getProperty("importer");

		_serviceReferences.remove(importer);
	}

	@Activate
	protected void activate() {
		Bundle bundle = FrameworkUtil.getBundle(WikiImporterTracker.class);

		_bundleContext = bundle.getBundleContext();
	}

	private BundleContext _bundleContext;
	private final ConcurrentMap>
		_serviceReferences = new ConcurrentSkipListMap<>();

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy