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    
034    public class ApiConfigurationException extends DirectJNgineException {
035      private ApiConfigurationException( String message ) {
036        super(message);
037        
038        assert !StringUtils.isEmpty(message);
039      }
040    
041      public static ApiConfigurationException forClassAlreadyRegisteredAsAction( Class<?> actionClass ) {
042        assert actionClass != null;
043        
044        return new ApiConfigurationException( "Class '" + actionClass.getName() + "' already registered. It is not possible to register the same class twice" );
045      }
046    
047      public static ApiConfigurationException forActionAlreadyRegistered(String newActionName, Class<?> newActionClass, Class<?> registeredActionClass ) {
048        assert !StringUtils.isEmpty(newActionName);
049        assert newActionClass != null;
050        assert registeredActionClass != null;
051    
052        return new ApiConfigurationException("Action '" + newActionName + "' is already registered for class '" + 
053            registeredActionClass.getName() + "', but you are attempting to register it for class '" + 
054            newActionClass.getName() + "'. It is not possible to register two classes with the same action name." );
055      }
056    
057      public static ApiConfigurationException forMethodAlreadyRegisteredInAction(String registeredMethodName, String actionName ) {
058        assert !StringUtils.isEmpty(registeredMethodName);
059        assert !StringUtils.isEmpty(actionName);
060    
061        return new ApiConfigurationException("Method '" + registeredMethodName + "' is already registered for action '" + 
062            actionName + "'");
063      }
064    
065      public static ApiConfigurationException forMethodHasWrongParametersForAFormHandler(String actionName, String methodName) {
066        assert !StringUtils.isEmpty(actionName);
067        assert !StringUtils.isEmpty(methodName);
068        
069        return new ApiConfigurationException("Method '" + methodName + "' in action '" + actionName + "' 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>)'" );
070      }
071    
072      public static ApiConfigurationException forMethodCantBeStandardAndFormPostMethodAtTheSameTime(
073          RegisteredAction action, Method method) {
074        assert action != null;
075        assert method != null;
076    
077        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." );
078      }
079    
080      public static ApiConfigurationException forPollMethodCantBeStandardOrFormPostMethodAtTheSameTime(
081          RegisteredAction action, Method method) {
082        assert action != null;
083        assert method != null;
084    
085        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." );
086      }
087    
088      public static ApiConfigurationException forMethodHasWrongParametersForAPollHandler(
089          Method method) {
090        assert method != null;
091        
092        return new ApiConfigurationException("Method '" + method.getName() + "' in class '" + method.getDeclaringClass().getName() + "' can't be registered as a poll handler because the corresponding Java method does not have the right parameter types, '(Map<String,String>)'" );
093      }
094    
095      public static ApiConfigurationException forPollEventAlreadyRegistered(String eventName) {
096        assert !StringUtils.isEmpty(eventName);
097        
098        return new ApiConfigurationException( "Poll event '" + eventName + "' already registered . It is not possible to register the same event twice" );
099      }
100    
101      public static ApiConfigurationException forApiAlreadyRegistered(String name) {
102        assert !StringUtils.isEmpty(name);
103        
104        return new ApiConfigurationException( "Api '" + name + "' already registered. It is not possible to register the same api twice");
105      }
106    }