package com.jscape.util.event;

import com.jscape.util.Assert;

/**
 * @author Alex Usun
 */
public abstract class PermissionRequest
        extends AbstractEvent {

    /**
     * Permission exception.
     */
    private PermissionException error;

    /**
     * @param context EventContext instance
     */
    protected PermissionRequest(EventContext context) {
        super(context);
    }

    /**
     * @param error PermissionException instance
     */
    public void setDenied(PermissionException error) {
        Assert.notNull(error);
        this.error = error;

        setHandled();
    }

    /**
     * @return isDenied
     */
    protected boolean isDenied() {
        return isHandled();
    }

    /**
     * @throws PermissionException permissionException
     */
    protected void assertNotDenied()
            throws PermissionException {
        if (isDenied()) {
            throw this.error;
        }
    }
}
