UserPropertiesCompositeImpl.java 2.73 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Node
 *  javax.jcr.RepositoryException
 */
package com.adobe.granite.security.user.internal;

import com.adobe.granite.security.user.UserProperties;
import com.adobe.granite.security.user.UserPropertiesComposite;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import javax.jcr.Node;
import javax.jcr.RepositoryException;

public class UserPropertiesCompositeImpl
implements UserPropertiesComposite {
    private final List<UserProperties> userPropertiesList;
    private final String authorizableId;

    public UserPropertiesCompositeImpl(String authorizableId, Collection<UserProperties> userPropertiesCollection) {
        this.authorizableId = authorizableId;
        this.userPropertiesList = new ArrayList<UserProperties>(userPropertiesCollection);
    }

    @Override
    public Collection<String> getPropertyNames() throws RepositoryException {
        return this.getPropertyNames(null);
    }

    @Override
    public Collection<String> getPropertyNames(String relPath) throws RepositoryException {
        HashSet<String> propertyNames = new HashSet<String>();
        for (UserProperties properties : this.userPropertiesList) {
            propertyNames.addAll(Arrays.asList(properties.getPropertyNames(relPath)));
        }
        return propertyNames;
    }

    @Override
    public String getProperty(String relativePath) throws RepositoryException {
        return this.getProperty(relativePath, null, String.class);
    }

    @Override
    public <T> T getProperty(String relativePath, T defaultValue, Class<T> type) throws RepositoryException {
        ListIterator<UserProperties> iterator = this.userPropertiesList.listIterator(this.userPropertiesList.size());
        while (iterator.hasPrevious()) {
            UserProperties properties = iterator.previous();
            T value = properties.getProperty(relativePath, defaultValue, type);
            if (null == value) continue;
            return value;
        }
        return null;
    }

    @Override
    public Collection<UserProperties> getUserProperties() {
        return Collections.unmodifiableCollection(this.userPropertiesList);
    }

    @Override
    public String getAuthorizableId() {
        return this.authorizableId;
    }

    @Override
    public Collection<String> getUserPropertiesPaths() throws RepositoryException {
        ArrayList<String> paths = new ArrayList<String>(this.userPropertiesList.size());
        for (UserProperties up : this.userPropertiesList) {
            paths.add(up.getNode().getPath());
        }
        return paths;
    }
}