use of org.osgi.service.component.annotations.Reference in project sling by apache.
the class LegacyResourceProviderWhiteboard method bindResourceProvider.
@Reference(service = ResourceProvider.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
protected void bindResourceProvider(final ServiceReference<ResourceProvider> ref) {
final BundleContext bundleContext = ref.getBundle().getBundleContext();
final ResourceProvider provider = bundleContext.getService(ref);
if (provider != 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<>();
newProps.put(PROPERTY_AUTHENTICATE, AuthType.no.toString());
newProps.put(PROPERTY_MODIFIABLE, provider instanceof ModifyingResourceProvider);
newProps.put(PROPERTY_ADAPTABLE, provider instanceof Adaptable);
newProps.put(PROPERTY_ATTRIBUTABLE, provider instanceof AttributableResourceProvider);
newProps.put(PROPERTY_REFRESHABLE, provider instanceof RefreshableResourceProvider);
newProps.put(PROPERTY_NAME, provider.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 LegacyResourceProviderAdapter(provider, languages, ownsRoot), newProps);
newServices.add(reg);
}
}
registrations.put(provider, newServices);
}
}
use of org.osgi.service.component.annotations.Reference in project bnd by bndtools.
the class AnnotationReader method doComponent.
/**
* @param annotation
* @throws Exception
*/
@SuppressWarnings("deprecation")
protected void doComponent(Component comp, Annotation annotation) throws Exception {
if (!mismatchedAnnotations.isEmpty()) {
String componentName = comp.name();
componentName = (componentName == null) ? className.getFQN() : componentName;
for (Entry<String, List<DeclarativeServicesAnnotationError>> e : mismatchedAnnotations.entrySet()) {
for (DeclarativeServicesAnnotationError errorDetails : e.getValue()) {
if (errorDetails.fieldName != null) {
analyzer.error("The DS component %s uses standard annotations to declare it as a component, but also uses the bnd DS annotation: %s on field %s. It is an error to mix these two types of annotations", componentName, e.getKey(), errorDetails.fieldName).details(errorDetails);
} else if (errorDetails.methodName != null) {
analyzer.error("The DS component %s uses standard annotations to declare it as a component, but also uses the bnd DS annotation: %s on method %s with signature %s. It is an error to mix these two types of annotations", componentName, e.getKey(), errorDetails.methodName, errorDetails.methodSignature).details(errorDetails);
} else {
analyzer.error("The DS component %s uses standard annotations to declare it as a component, but also uses the bnd DS annotation: %s. It is an error to mix these two types of annotations", componentName, e.getKey()).details(errorDetails);
}
}
}
return;
}
// Check if we are doing a super class
if (component.implementation != null)
return;
component.implementation = clazz.getClassName();
component.name = comp.name();
component.factory = comp.factory();
component.configurationPolicy = comp.configurationPolicy();
if (annotation.get("enabled") != null)
component.enabled = comp.enabled();
if (annotation.get("factory") != null)
component.factory = comp.factory();
if (annotation.get("immediate") != null)
component.immediate = comp.immediate();
if (annotation.get("servicefactory") != null)
component.scope = comp.servicefactory() ? ServiceScope.BUNDLE : ServiceScope.SINGLETON;
if (annotation.get("scope") != null && comp.scope() != ServiceScope.DEFAULT) {
component.scope = comp.scope();
if (comp.scope() == ServiceScope.PROTOTYPE) {
component.updateVersion(V1_3);
}
}
if (annotation.get("configurationPid") != null) {
component.configurationPid = comp.configurationPid();
if (component.configurationPid.length > 1) {
component.updateVersion(V1_3);
} else {
component.updateVersion(V1_2);
}
}
if (annotation.get("xmlns") != null)
component.xmlns = comp.xmlns();
String[] properties = comp.properties();
if (properties != null)
for (String entry : properties) {
if (entry.contains("=")) {
analyzer.error("Found an = sign in an OSGi DS Component annotation on %s. In the bnd annotation " + "this is an actual property but in the OSGi, this element must refer to a path with Java properties. " + "However, found a path with an '=' sign which looks like a mixup (%s) with the 'property' element.", clazz, entry).details(new DeclarativeServicesAnnotationError(className.getFQN(), null, null, ErrorType.COMPONENT_PROPERTIES_ERROR));
}
component.properties.add(entry);
}
doProperty(comp.property());
Object[] x = annotation.get("service");
if (x == null) {
// fqn.
if (interfaces != null) {
List<TypeRef> result = new ArrayList<TypeRef>();
for (int i = 0; i < interfaces.length; i++) {
if (!interfaces[i].equals(analyzer.getTypeRef("scala/ScalaObject")))
result.add(interfaces[i]);
}
component.service = result.toArray(EMPTY);
}
} else {
// We have explicit interfaces set
component.service = new TypeRef[x.length];
for (int i = 0; i < x.length; i++) {
TypeRef typeRef = (TypeRef) x[i];
Clazz service = analyzer.findClass(typeRef);
if (!analyzer.assignable(clazz, service)) {
analyzer.error("Class %s is not assignable to specified service %s", clazz.getFQN(), typeRef.getFQN()).details(new DeclarativeServicesAnnotationError(className.getFQN(), null, null, ErrorType.INCOMPATIBLE_SERVICE));
}
component.service[i] = typeRef;
}
}
// make sure reference processing knows this is a Reference in Component
member = null;
Object[] refAnnotations = annotation.get("reference");
if (refAnnotations != null) {
for (Object o : refAnnotations) {
Annotation refAnnotation = (Annotation) o;
Reference ref = refAnnotation.getAnnotation();
doReference(ref, refAnnotation);
}
}
}
use of org.osgi.service.component.annotations.Reference in project sling by apache.
the class UseRuntimeExtension method bindUseProvider.
// OSGi ################################################################################################################################
@Reference(policy = ReferencePolicy.DYNAMIC, service = UseProvider.class, cardinality = ReferenceCardinality.MULTIPLE)
private void bindUseProvider(ServiceReference serviceReference) {
BundleContext bundleContext = serviceReference.getBundle().getBundleContext();
providersMap.put(serviceReference, (UseProvider) bundleContext.getService(serviceReference));
}
use of org.osgi.service.component.annotations.Reference in project jackrabbit-oak by apache.
the class CacheStatsMetrics method setMetricRegistry.
@Reference(target = "(name=oak)")
synchronized void setMetricRegistry(MetricRegistry registry) {
LOG.debug("setMetricRegistry({})", registry);
for (CacheStatsMBean stats : cacheStatsMBeans.values()) {
unregisterCacheStatsMBean(this.registry, stats);
registerCacheStatsMBean(registry, stats);
}
this.registry = registry;
}
use of org.osgi.service.component.annotations.Reference in project bndtools by bndtools.
the class HeadlessBuildManagerImpl method addPlugin.
@Reference(cardinality = ReferenceCardinality.AT_LEAST_ONE, policy = ReferencePolicy.DYNAMIC)
void addPlugin(HeadlessBuildPlugin plugin) {
if (plugin == null) {
return;
}
NamedPlugin pluginInformation = plugin.getInformation();
String name = pluginInformation.getName();
synchronized (plugins) {
plugins.put(name, plugin);
pluginsInformation.put(name, pluginInformation);
}
}
Aggregations