001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.tynamo.shiro.extension.authz.annotations.utils.casters.method;
020
021import org.apache.shiro.authz.annotation.*;
022
023import java.lang.annotation.Annotation;
024
025
026/**
027 * Class for accepting
028 * {@link org.tynamo.shiro.extension.authz.annotations.utils.casters.method.MethodAnnotationCasterVisitor}
029 * visitors.
030 * <p/>
031 * Provides call the desired method of the visitor, depending on the annotation type.
032 *
033 * @see org.tynamo.shiro.extension.authz.annotations.utils.casters.method.MethodAnnotationCasterVisitor
034 */
035public class MethodAnnotationCaster
036{
037
038        private static final MethodAnnotationCaster instance = new MethodAnnotationCaster();
039
040        private MethodAnnotationCaster()
041        {
042        }
043
044        public void accept(MethodAnnotationCasterVisitor visitor, Annotation annotation)
045        {
046                if (annotation instanceof RequiresPermissions)
047                {
048
049                        visitor.visitRequiresPermissions((RequiresPermissions) annotation);
050
051                } else if (annotation instanceof RequiresRoles)
052                {
053
054                        visitor.visitRequiresRoles((RequiresRoles) annotation);
055
056                } else if (annotation instanceof RequiresUser)
057                {
058
059                        visitor.visitRequiresUser((RequiresUser) annotation);
060
061                } else if (annotation instanceof RequiresGuest)
062                {
063
064                        visitor.visitRequiresGuest((RequiresGuest) annotation);
065
066                } else if (annotation instanceof RequiresAuthentication)
067                {
068
069                        visitor.visitRequiresAuthentication((RequiresAuthentication) annotation);
070
071                } else
072                {
073
074                        visitor.visitNotFound();
075
076                }
077        }
078
079        public static MethodAnnotationCaster getInstance()
080        {
081                return instance;
082        }
083}