All Downloads are FREE. Search and download functionalities are using the official Maven repository.

framework.annotation.Only Maven / Gradle / Ivy

package framework.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * restrict viewer
 */
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Only {
    /**
     * @return role(if empty then logged in user only)
     */
    Class[] value() default {};

    /**
     * user
     */
    public interface User {

        /**
         * @param text class name
         * @return class
         */
        @SuppressWarnings("unchecked")
        static Class fromString(String text) {
            try {
                return (Class) Class.forName(Only.class.getName() + "$" + text);
            } catch (ClassNotFoundException e) {
                try {
                    return (Class) Class.forName(text);
                } catch (ClassNotFoundException e1) {
                    return null;
                }
            }
        }
    }

    /**
     * administrator
     */
    public interface Administrator extends User {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy