use of org.osgi.service.component.annotations.Component in project bnd by bndtools.
the class DesignateReader method doComponent.
void doComponent(java.lang.annotation.Annotation a) {
Component component = (Component) a;
pids = component.configurationPid();
if (pids != null) {
pid = pids[0];
}
if (pids == null || "$".equals(pid)) {
pid = component.name();
if (pid == null)
pid = clazz.getClassName().getFQN();
}
}
use of org.osgi.service.component.annotations.Component 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;
}
use of org.osgi.service.component.annotations.Component in project felix by apache.
the class DSAnnotationProcessor method process.
/**
* @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#process(org.apache.felix.scrplugin.annotations.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription)
*/
@Override
public void process(final ScannedClass scannedClass, final ClassDescription describedClass) throws SCRDescriptorFailureException, SCRDescriptorException {
final List<ClassAnnotation> componentTags = scannedClass.getClassAnnotations(Component.class.getName());
scannedClass.processed(componentTags);
for (final ClassAnnotation cad : componentTags) {
this.createComponent(cad, describedClass, scannedClass);
}
// search for the component descriptions and use the first one
final List<ComponentDescription> componentDescs = describedClass.getDescriptions(ComponentDescription.class);
ComponentDescription found = null;
if (!componentDescs.isEmpty()) {
found = componentDescs.get(0);
}
if (found != null) {
final ComponentDescription cd = found;
// search for methods
final List<MethodAnnotation> methodTags = scannedClass.getMethodAnnotations(null);
for (final MethodAnnotation m : methodTags) {
if (m.getName().equals(Activate.class.getName())) {
cd.setActivate(m.getAnnotatedMethod().getName());
scannedClass.processed(m);
} else if (m.getName().equals(Deactivate.class.getName())) {
cd.setDeactivate(m.getAnnotatedMethod().getName());
scannedClass.processed(m);
} else if (m.getName().equals(Modified.class.getName())) {
cd.setModified(m.getAnnotatedMethod().getName());
scannedClass.processed(m);
} else if (m.getName().equals(Reference.class.getName())) {
this.processReference(describedClass, m);
scannedClass.processed(m);
}
}
}
}
Aggregations