use of org.osgi.service.component.annotations.Reference in project sling by apache.
the class LegacyResourceProviderWhiteboard method bindResourceProviderFactory.
@Reference(service = ResourceProviderFactory.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
protected void bindResourceProviderFactory(final ServiceReference<ResourceProviderFactory> ref) {
final BundleContext bundleContext = ref.getBundle().getBundleContext();
final ResourceProviderFactory factory = bundleContext.getService(ref);
if (factory != null) {
final String[] propertyNames = ref.getPropertyKeys();
final boolean ownsRoot = toBoolean(ref.getProperty(OWNS_ROOTS), false);
final List<ServiceRegistration> newServices = new ArrayList<>();
for (final String path : PropertiesUtil.toStringArray(ref.getProperty(ROOTS), new String[0])) {
if (path != null && !path.isEmpty()) {
final Dictionary<String, Object> newProps = new Hashtable<>();
if (PropertiesUtil.toBoolean(ref.getProperty(PROPERTY_REQUIRED), false)) {
newProps.put(PROPERTY_AUTHENTICATE, AuthType.required.toString());
} else {
newProps.put(PROPERTY_AUTHENTICATE, AuthType.lazy.toString());
}
newProps.put(PROPERTY_MODIFIABLE, true);
newProps.put(PROPERTY_ADAPTABLE, true);
newProps.put(PROPERTY_ATTRIBUTABLE, true);
newProps.put(PROPERTY_REFRESHABLE, true);
newProps.put(PROPERTY_NAME, factory.getClass().getName());
newProps.put(PROPERTY_ROOT, normalizePath(path));
if (ArrayUtils.contains(propertyNames, SERVICE_PID)) {
newProps.put(ORIGINAL_SERVICE_PID, ref.getProperty(SERVICE_PID));
}
if (ArrayUtils.contains(propertyNames, USE_RESOURCE_ACCESS_SECURITY)) {
newProps.put(PROPERTY_USE_RESOURCE_ACCESS_SECURITY, ref.getProperty(USE_RESOURCE_ACCESS_SECURITY));
}
if (ArrayUtils.contains(propertyNames, SERVICE_RANKING)) {
newProps.put(SERVICE_RANKING, ref.getProperty(SERVICE_RANKING));
}
String[] languages = PropertiesUtil.toStringArray(ref.getProperty(LANGUAGES), new String[0]);
ServiceRegistration reg = bundleContext.registerService(org.apache.sling.spi.resource.provider.ResourceProvider.class.getName(), new LegacyResourceProviderFactoryAdapter(factory, languages, ownsRoot), newProps);
newServices.add(reg);
}
}
registrations.put(factory, newServices);
}
}
use of org.osgi.service.component.annotations.Reference in project smarthome by eclipse.
the class BluetoothDiscoveryService method addBluetoothAdapter.
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
protected void addBluetoothAdapter(BluetoothAdapter adapter) {
this.adapters.add(adapter);
BluetoothDiscoveryListener listener = new BluetoothDiscoveryListener() {
@Override
public void deviceDiscovered(BluetoothDevice device) {
BluetoothDiscoveryService.this.deviceDiscovered(adapter, device);
}
};
adapter.addDiscoveryListener(listener);
registeredListeners.put(adapter.getUID(), listener);
}
use of org.osgi.service.component.annotations.Reference in project smarthome by eclipse.
the class ManagedItemProvider method addItemFactory.
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
protected void addItemFactory(ItemFactory itemFactory) {
itemFactories.add(itemFactory);
if (failedToCreate.size() > 0) {
// retry failed creation attempts
Iterator<Entry<String, PersistedItem>> iterator = failedToCreate.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, PersistedItem> entry = iterator.next();
String itemName = entry.getKey();
PersistedItem persistedItem = entry.getValue();
@SuppressWarnings("null") ActiveItem item = itemFactory.createItem(persistedItem.itemType, itemName);
if (item != null) {
iterator.remove();
configureItem(persistedItem, item);
notifyListenersAboutAddedElement(item);
} else {
logger.debug("The added item factory '{}' still could not instantiate item '{}'.", itemFactory, itemName);
}
}
if (failedToCreate.isEmpty()) {
logger.info("Finished loading the items which could not have been created before.");
}
}
}
use of org.osgi.service.component.annotations.Reference in project bndtools by bndtools.
the class VersionControlIgnoresManagerImpl method addPlugin.
@Reference(cardinality = ReferenceCardinality.AT_LEAST_ONE, policy = ReferencePolicy.DYNAMIC)
void addPlugin(VersionControlIgnoresPlugin plugin) {
if (plugin == null) {
return;
}
NamedPlugin pluginInformation = plugin.getInformation();
String name = pluginInformation.getName();
synchronized (plugins) {
plugins.put(name, plugin);
pluginsInformation.put(name, pluginInformation);
}
}
use of org.osgi.service.component.annotations.Reference in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class SearchResultServlet method getResults.
/**
* Gets the search results.
*
* @param request The search request.
* @param searchComponent The search component.
* @param pageManager A PageManager.
* @return List of search results.
*/
@NotNull
private List<ListItem> getResults(@NotNull final SlingHttpServletRequest request, @NotNull final Search searchComponent, @NotNull final PageManager pageManager) {
List<ListItem> results = new ArrayList<>();
String fulltext = request.getParameter(PARAM_FULLTEXT);
if (fulltext == null || fulltext.length() < searchComponent.getSearchTermMinimumLength()) {
return results;
}
long resultsOffset = Optional.ofNullable(request.getParameter(PARAM_RESULTS_OFFSET)).map(Long::parseLong).orElse(0L);
Map<String, String> predicatesMap = new HashMap<>();
predicatesMap.put(FulltextPredicateEvaluator.FULLTEXT, fulltext);
predicatesMap.put(PathPredicateEvaluator.PATH, searchComponent.getSearchRootPagePath());
predicatesMap.put(TypePredicateEvaluator.TYPE, NameConstants.NT_PAGE);
PredicateGroup predicates = PredicateConverter.createPredicates(predicatesMap);
ResourceResolver resourceResolver = request.getResource().getResourceResolver();
Query query = queryBuilder.createQuery(predicates, resourceResolver.adaptTo(Session.class));
if (searchComponent.getResultsSize() != 0) {
query.setHitsPerPage(searchComponent.getResultsSize());
}
if (resultsOffset != 0) {
query.setStart(resultsOffset);
}
SearchResult searchResult = query.getResult();
LinkHandler linkHandler = request.adaptTo(LinkHandler.class);
// Query builder has a leaking resource resolver, so the following work around is required.
ResourceResolver leakingResourceResolver = null;
try {
Iterator<Resource> resourceIterator = searchResult.getResources();
while (resourceIterator.hasNext()) {
Resource resource = resourceIterator.next();
// Get a reference to QB's leaking resource resolver
if (leakingResourceResolver == null) {
leakingResourceResolver = resource.getResourceResolver();
}
Optional.of(resource).map(res -> resourceResolver.getResource(res.getPath())).map(pageManager::getContainingPage).map(page -> new PageListItemImpl(linkHandler, page, searchComponent.getId(), null)).ifPresent(results::add);
}
} finally {
if (leakingResourceResolver != null) {
leakingResourceResolver.close();
}
}
return results;
}
Aggregations