private void registerAdapterFactory()

in src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java [213:278]


    private void registerAdapterFactory(
            final AdapterFactory factory, final ServiceReference<AdapterFactory> reference) {
        final Converter converter = Converters.standardConverter();
        final String[] adaptables =
                converter.convert(reference.getProperty(ADAPTABLE_CLASSES)).to(String[].class);
        final String[] adapters =
                converter.convert(reference.getProperty(ADAPTER_CLASSES)).to(String[].class);
        final boolean allowedInPrivatePackage = converter
                .convert(reference.getProperty(ALLOWED_IN_PRIVATE))
                .defaultValue(false)
                .to(Boolean.class);

        if (adaptables == null || adaptables.length == 0 || adapters == null || adapters.length == 0) {
            return;
        }

        for (String clazz : adaptables) {
            if (!allowedInPrivatePackage && !checkPackage(packageAdmin, clazz)) {
                log.warn(
                        "Adaptable class {} in factory service {} is not in an exported package.",
                        clazz,
                        reference.getProperty(Constants.SERVICE_ID));
            }
        }

        for (String clazz : adapters) {
            if (!allowedInPrivatePackage && !checkPackage(packageAdmin, clazz)) {
                log.warn(
                        "Adapter class {} in factory service {} is not in an exported package.",
                        clazz,
                        reference.getProperty(Constants.SERVICE_ID));
            }
        }

        final AdapterFactoryDescriptor factoryDesc = new AdapterFactoryDescriptor(factory, adapters, adaptables);

        for (final String adaptable : adaptables) {
            AdapterFactoryDescriptorMap adfMap = null;
            synchronized (this.descriptors) {
                adfMap = descriptors.computeIfAbsent(adaptable, key -> new AdapterFactoryDescriptorMap());
            }
            synchronized (adfMap) {
                adfMap.put(reference, factoryDesc);
            }
        }

        // clear the factory cache to force rebuild on next access
        this.factoryCache.clear();

        // register adaption
        final Dictionary<String, Object> props = new Hashtable<>();
        props.put(SlingConstants.PROPERTY_ADAPTABLE_CLASSES, adaptables);
        props.put(SlingConstants.PROPERTY_ADAPTER_CLASSES, adapters);

        factoryDesc.setAdaption(
                reference.getBundle().getBundleContext().registerService(Adaption.class, AdaptionImpl.INSTANCE, props));
        if (log.isDebugEnabled()) {
            log.debug("Registered service {} with {} : {} and {} : {}", new Object[] {
                Adaption.class.getName(),
                SlingConstants.PROPERTY_ADAPTABLE_CLASSES,
                Arrays.toString(adaptables),
                SlingConstants.PROPERTY_ADAPTER_CLASSES,
                Arrays.toString(adapters)
            });
        }
    }