RegistrationsResource.java 1.78 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.SyntheticResource
 */
package com.adobe.cq.screens.impl.rest;

import com.adobe.cq.screens.device.registration.PendingDevice;
import com.adobe.cq.screens.device.registration.RegistrationService;
import com.adobe.cq.screens.impl.rest.RegistrationResource;
import java.util.Iterator;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.SyntheticResource;

public class RegistrationsResource
extends SyntheticResource {
    public static final String RESOURCE_TYPE = "screens/core/components/registrations";
    private final RegistrationService svc;

    public RegistrationsResource(ResourceResolver resolver, String path, RegistrationService svc) {
        super(resolver, path, "screens/core/components/registrations");
        this.svc = svc;
    }

    public Iterator<Resource> listChildren() {
        final Iterator<PendingDevice> iter = this.svc.getDevices(null);
        return new Iterator<Resource>(){

            @Override
            public boolean hasNext() {
                return iter.hasNext();
            }

            @Override
            public Resource next() {
                PendingDevice device = (PendingDevice)iter.next();
                String token = device.getToken();
                return new RegistrationResource(RegistrationsResource.this.getResourceResolver(), RegistrationsResource.this.getPath() + "/" + token, device);
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }

}