Search in sources :

Example 6 with Reference

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);
        }
    }
}
Also used : DeclarativeServicesAnnotationError(aQute.bnd.component.error.DeclarativeServicesAnnotationError) TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Reference(org.osgi.service.component.annotations.Reference) ArrayList(java.util.ArrayList) Annotation(aQute.bnd.osgi.Annotation) ArrayList(java.util.ArrayList) List(java.util.List) Clazz(aQute.bnd.osgi.Clazz)

Example 7 with Reference

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));
}
Also used : BundleContext(org.osgi.framework.BundleContext) Reference(org.osgi.service.component.annotations.Reference) ServiceReference(org.osgi.framework.ServiceReference)

Example 8 with Reference

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;
}
Also used : CacheStatsMBean(org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean) Reference(org.osgi.service.component.annotations.Reference)

Example 9 with Reference

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);
    }
}
Also used : NamedPlugin(org.bndtools.api.NamedPlugin) Reference(org.osgi.service.component.annotations.Reference)

Aggregations

Reference (org.osgi.service.component.annotations.Reference)9 ArrayList (java.util.ArrayList)3 BundleContext (org.osgi.framework.BundleContext)3 ServiceReference (org.osgi.framework.ServiceReference)3 Hashtable (java.util.Hashtable)2 AttributableResourceProvider (org.apache.sling.api.resource.AttributableResourceProvider)2 ModifyingResourceProvider (org.apache.sling.api.resource.ModifyingResourceProvider)2 RefreshableResourceProvider (org.apache.sling.api.resource.RefreshableResourceProvider)2 ResourceProvider (org.apache.sling.api.resource.ResourceProvider)2 NamedPlugin (org.bndtools.api.NamedPlugin)2 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 DeclarativeServicesAnnotationError (aQute.bnd.component.error.DeclarativeServicesAnnotationError)1 Annotation (aQute.bnd.osgi.Annotation)1 Clazz (aQute.bnd.osgi.Clazz)1 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 CacheStatsMBean (org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean)1 Adaptable (org.apache.sling.api.adapter.Adaptable)1 ResourceProviderFactory (org.apache.sling.api.resource.ResourceProviderFactory)1