001    /*
002     * Copyright © 2008, 2009 Pedro Agulló Soliveres.
003     * 
004     * This file is part of DirectJNgine.
005     *
006     * DirectJNgine is free software: you can redistribute it and/or modify
007     * it under the terms of the GNU General Public License as published by
008     * the Free Software Foundation, either version 3 of the License.
009     *
010     * Commercial use is permitted to the extent that the code/component(s)
011     * do NOT become part of another Open Source or Commercially developed
012     * licensed development library or toolkit without explicit permission.
013     *
014     * DirectJNgine is distributed in the hope that it will be useful,
015     * but WITHOUT ANY WARRANTY; without even the implied warranty of
016     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017     * GNU General Public License for more details.
018     *
019     * You should have received a copy of the GNU General Public License
020     * along with DirectJNgine.  If not, see <http://www.gnu.org/licenses/>.
021     * 
022     * This software uses the ExtJs library (http://extjs.com), which is 
023     * distributed under the GPL v3 license (see http://extjs.com/license).
024     */
025    
026    package com.softwarementors.extjs.djn.config;
027    
028    import java.lang.reflect.Method;
029    
030    import com.softwarementors.extjs.djn.DirectJNgineException;
031    import com.softwarementors.extjs.djn.StringUtils;
032    import com.softwarementors.extjs.djn.api.RegisteredAction;
033    import com.softwarementors.extjs.djn.api.RegisteredMethod;
034    import com.softwarementors.extjs.djn.api.RegisteredPollMethod;
035    
036    public class ApiConfigurationException extends DirectJNgineException {
037      private ApiConfigurationException( String message ) {
038        super(message);
039        
040        assert !StringUtils.isEmpty(message);
041      }
042    
043      public static ApiConfigurationException forClassAlreadyRegisteredAsAction( Class<?> actionClass ) {
044        assert actionClass != null;
045        
046        return new ApiConfigurationException( "Class '" + actionClass.getName() + "' already registered. It is not possible to register the same class twice" );
047      }
048    
049      public static ApiConfigurationException forActionAlreadyRegistered(RegisteredAction action, Class<?> registeredActionClass ) {
050        assert action != null;
051        assert registeredActionClass != null;
052    
053        return new ApiConfigurationException("Action '" + action.getName() + "' is already registered for class '" + 
054            registeredActionClass.getName() + "', but you are attempting to register it for class '" + 
055            action.getActionClass().getName() + "'. It is not possible to register two classes with the same action name." );
056      }
057    
058      public static ApiConfigurationException forMethodAlreadyRegisteredInAction(RegisteredMethod method ) {
059        assert method != null;
060    
061        return new ApiConfigurationException("Method '" + method.getName() + "' is already registered for action '" + 
062            method.getActionName() + "'");
063      }
064    
065      public static ApiConfigurationException forMethodHasWrongParametersForAFormHandler(RegisteredMethod method) {
066        assert method != null;
067        
068        return new ApiConfigurationException("Method '" + method.getName() + "' in action '" + method.getActionName() + "' can't be registered as a form handler because the corresponding Java method does not have the right parameter types, '(Map<String,String>, Map<String,FileItem>)'" );
069      }
070    
071      public static ApiConfigurationException forMethodCantBeStandardAndFormPostMethodAtTheSameTime(
072          RegisteredAction action, Method method) {
073        assert action != null;
074        assert method != null;
075    
076        return new ApiConfigurationException("Method '" + method.getName() + "' in class '" + action.getActionClass().getName() + "' is a standard and a form post method at the same time: please, check your annotations and method naming to remove the ambiguity." );
077      }
078    
079      public static ApiConfigurationException forPollMethodCantBeStandardOrFormPostMethodAtTheSameTime(
080          RegisteredAction action, Method method) {
081        assert action != null;
082        assert method != null;
083    
084        return new ApiConfigurationException("Method '" + method.getName() + "' in class '" + action.getActionClass().getName() + "' can't be a poll method and a standard/form post method at the same time: please, check your annotations and method naming to remove the ambiguity." );
085      }
086    
087      public static ApiConfigurationException forMethodHasWrongParametersForAPollHandler(
088          RegisteredPollMethod method) {
089        assert method != null;
090        
091        return new ApiConfigurationException("Method '" + method.getMethod().getName() + "' in class '" + method.getOwningClass().getName() + "' can't be registered as a poll handler because the corresponding Java method does not have the right parameter types, '(Map<String,String>)'" );
092      }
093    
094      public static ApiConfigurationException forPollEventAlreadyRegistered(RegisteredPollMethod poll) {
095        assert poll != null;
096        
097        return new ApiConfigurationException( "Poll event '" + poll.getName() + "' already registered . It is not possible to register the same event twice" );
098      }
099    
100      public static ApiConfigurationException forApiAlreadyRegistered(String name) {
101        assert !StringUtils.isEmpty(name);
102        
103        return new ApiConfigurationException( "Api '" + name + "' already registered. It is not possible to register the same api twice");
104      }
105    }