+ private ComponentMetadata decorateServiceType(Attr attr, ComponentMetadata component, ParserContext context) {
+ if (!(component instanceof MutableServiceMetadata)) {
+ throw new ComponentDefinitionException("Expected an instanceof MutableServiceMetadata");
+ }
+
+ MutableServiceMetadata service = (MutableServiceMetadata)component;
+
+ LOG.debug("decorateServiceType for {} - adding type property {}", service.getId(), attr.getValue());
+
+ service.addServiceProperty(createValue(context, TYPE_ATTR), createValue(context, attr.getValue()));
+ return component;
+ }
+
+ private ComponentMetadata decorateServiceReferenceType(Attr attr, ComponentMetadata component, ParserContext context) {
+ if (!(component instanceof MutableServiceReferenceMetadata)) {
+ throw new ComponentDefinitionException("Expected an instanceof MutableServiceReferenceMetadata");
+ }
+
+ // We don't actually need the ComponentProcessor for augmenting the OSGi filter here but we create it
+ // to workaround an issue in Aries where it doesn't use the extended filter unless there's a
+ // Processor or ComponentDefinitionRegistryProcessor registered. This may actually be working as
+ // designed in Aries b/c the extended filter was really added to allow the OSGi filter to be
+ // substituted by a variable via the "cm:property-placeholder" processor. If so, it's a bit funky
+ // but as long as there's at least one processor registered, it correctly uses the extended filter.
+ registerComponentProcessor(context);
+
+ MutableServiceReferenceMetadata serviceRef = (MutableServiceReferenceMetadata)component;
+ String oldFilter = serviceRef.getExtendedFilter() == null ? null :
+ serviceRef.getExtendedFilter().getStringValue();
+
+ String filter;
+ if(Strings.isNullOrEmpty(oldFilter)) {
+ filter = String.format("(type=%s)", attr.getValue());
+ } else {
+ filter = String.format("(&(%s)(type=%s))", oldFilter, attr.getValue());
+ }
+
+ LOG.debug("decorateServiceReferenceType for {} with type {}, old filter: {}, new filter: {}",
+ serviceRef.getId(), attr.getValue(), oldFilter, filter);
+
+ serviceRef.setExtendedFilter(createValue(context, filter));
+ return component;
+ }
+