protected Map toSrMap()

in src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java [572:609]


    protected Map<String, RestrictionDefinition> toSrMap(Node parentNode)
            throws RepositoryException {
        // lazy initialized map for quick lookup when processing restrictions
        Map<String, RestrictionDefinition> supportedRestrictionsMap = new HashMap<>();

        RestrictionProvider compositeRestrictionProvider = null;
        Set<RestrictionProvider> restrictionProviders = new HashSet<>();

        Bundle bundle = FrameworkUtil.getBundle(getClass());
        if (bundle != null) {
            BundleContext bundleContext = bundle.getBundleContext();
            Collection<ServiceReference<RestrictionProvider>> serviceReferences = null;
            try {
                serviceReferences = bundleContext.getServiceReferences(RestrictionProvider.class, null);
                for (ServiceReference<RestrictionProvider> serviceReference : serviceReferences) {
                    RestrictionProvider service = bundleContext.getService(serviceReference);
                    restrictionProviders.add(service);
                }
                compositeRestrictionProvider = CompositeRestrictionProvider.newInstance(restrictionProviders);

                // populate the map
                Set<RestrictionDefinition> supportedRestrictions = compositeRestrictionProvider
                        .getSupportedRestrictions(parentNode.getPath());
                for (RestrictionDefinition restrictionDefinition : supportedRestrictions) {
                    supportedRestrictionsMap.put(restrictionDefinition.getName(), restrictionDefinition);
                }
            } catch (InvalidSyntaxException e) {
                throw new RepositoryException(e);
            } finally {
                if (serviceReferences != null) {
                    for (ServiceReference<RestrictionProvider> serviceReference : serviceReferences) {
                        bundleContext.ungetService(serviceReference);
                    }
                }
            }
        }
        return supportedRestrictionsMap;
    }