public boolean hasTags( String... aTags ) { for( String tag : aTags ) { if( !hasTag( tag ) ) { return false; } } return true; } }
abstract class RdfQueryParserFactoryMixin implements RdfQueryParserFactory { @Structure private Qi4jSPI spi; @Service @Tagged( ValueSerialization.Formats.JSON ) private ValueSerializer valueSerializer; @Override public RdfQueryParser newQueryParser( QueryLanguage language ) { if( language.equals( QueryLanguage.SPARQL ) ) { return new RdfQueryParserImpl( spi, valueSerializer ); } throw new UnsupportedLanguageException( language ); } } }
@Override @SuppressWarnings( {"raw", "unchecked"} ) public boolean satisfiedBy( ServiceReference<?> service ) { for( Class metaInfoType : hasMetaInfo.value() ) { Object metaInfo = service.metaInfo( metaInfoType ); if( hasMetaInfo.anded() ) { if( metaInfo == null ) { return false; } } else { if( metaInfo != null ) { return true; } } } return false; } };
@Override public <T> Specification<ServiceReference<?>> qualifier( Available active ) { return ServiceQualifier.whereAvailable(); } }
@Override public <T> Specification<ServiceReference<?>> qualifier( Active active ) { return ServiceQualifier.whereActive(); } }
@Override public boolean satisfiedBy( ServiceReference<?> service ) { ServiceTags serviceTags = service.metaInfo( ServiceTags.class ); return serviceTags != null && serviceTags.hasTags( tags ); } };
@Override @SuppressWarnings( { "raw", "unchecked" } ) public T importService( ImportedServiceDescriptor serviceDescriptor ) throws ServiceImporterException { Specification<ServiceReference<?>> selector = serviceDescriptor.metaInfo( Specification.class ); Class serviceType = Iterables.first( serviceDescriptor.types() ); Iterable<ServiceReference<T>> services = locator.findServices( serviceType ); List<ServiceReference<T>> filteredServices = new ArrayList<>(); for( ServiceReference<T> service : services ) { Specification selector1 = service.metaInfo( Specification.class ); if( selector1 != null && selector1 == selector ) { continue; } filteredServices.add( service ); } T service = ServiceQualifier.firstService( selector, filteredServices ); if( service == null ) { throw new ServiceImporterException( "Could not find any service to import that matches the given specification for " + serviceDescriptor .identity() ); } return service; }
@Tagged( ValueSerialization.Formats.JSON ) private ValueSerializer valueSerializer;
private <C, V extends Identity> V readConfig( UnitOfWork uow, Class<C> compositeType, Class<V> configType, String identity, String format, String extension ) { for( ServiceReference<ValueSerialization> serializerRef : valueSerialization ) { ServiceTags serviceTags = serializerRef.metaInfo( ServiceTags.class ); if( serviceTags.hasTag( format ) ) { String resourceName = identity + extension; InputStream asStream = getResource( compositeType, resourceName ); if( asStream != null ) { V configObject = serializerRef.get().deserialize( configType, asStream ); return uow.toEntity( configType, configObject ); } } } return null; } }
@Tagged( ValueSerialization.Formats.JSON ) private ValueSerializer valueSerializer;
@Tagged( ValueSerialization.Formats.JSON ) private ValueDeserializer valueDeserializer;