TokenIterator.java 2.12 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Node
 *  javax.jcr.NodeIterator
 *  javax.jcr.RepositoryException
 */
package com.day.crx.security.token.impl.helper;

import com.day.crx.security.token.impl.helper.Token;
import com.day.crx.security.token.impl.helper.TokenHelper;
import java.util.Iterator;
import java.util.NoSuchElementException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public class TokenIterator
implements Iterator<Token> {
    static final String NODE_TOKENS = ".tokens";
    private final Node userNode;
    private String userName;
    private NodeIterator tokenNodes;
    private Token nextToken;

    public TokenIterator(Node userNode) {
        this.userNode = userNode;
        try {
            if (userNode.hasNode(".tokens")) {
                Node tokensNode = userNode.getNode(".tokens");
                this.tokenNodes = tokensNode.getNodes();
                this.nextToken = this.seek();
            }
        }
        catch (RepositoryException re) {
            // empty catch block
        }
    }

    @Override
    public boolean hasNext() {
        return this.nextToken != null;
    }

    @Override
    public Token next() {
        if (!this.hasNext()) {
            throw new NoSuchElementException();
        }
        Token result = this.nextToken;
        this.nextToken = this.seek();
        return result;
    }

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

    public String getUserName() throws RepositoryException {
        if (this.userName == null) {
            this.userName = TokenHelper.getUserName(this.userNode);
        }
        return this.userName;
    }

    public String getUserIdentifier() throws RepositoryException {
        return this.userNode.getIdentifier();
    }

    private Token seek() {
        if (this.tokenNodes.hasNext()) {
            return new Token(this.tokenNodes.nextNode());
        }
        return null;
    }
}