/**
* 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.portal.language.extender.internal;
import com.liferay.osgi.felix.util.AbstractExtender;
import java.util.List;
import org.apache.felix.utils.extender.Extension;
import org.apache.felix.utils.log.Logger;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleWiring;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
/**
* @author Carlos Sierra Andrés
*/
@Component(immediate = true)
public class LanguageExtender extends AbstractExtender {
@Activate
protected void activate(BundleContext bundleContext) throws Exception {
_logger = new Logger(bundleContext);
start(bundleContext);
}
@Deactivate
protected void deactivate(BundleContext bundleContext) throws Exception {
stop(bundleContext);
}
@Override
protected void debug(Bundle bundle, String s) {
_logger.log(Logger.LOG_DEBUG, "[" + bundle + "] " + s);
}
@Override
protected Extension doCreateExtension(Bundle bundle) throws Exception {
BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
List<BundleCapability> bundleCapabilities =
bundleWiring.getCapabilities("liferay.resource.bundle");
if (bundleCapabilities == null) {
return null;
}
return new LanguageExtension(
getBundleContext(), bundle, bundleCapabilities, _logger);
}
@Override
protected void error(String s, Throwable throwable) {
_logger.log(Logger.LOG_ERROR, s, throwable);
}
@Override
protected void warn(Bundle bundle, String s, Throwable throwable) {
_logger.log(Logger.LOG_WARNING, "[" + bundle + "] " + s);
}
private Logger _logger;
}