001 /* 002 * Copyright © 2008, 2012 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 Lesser 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 Lesser General Public License for more details. 018 * 019 * You should have received a copy of the GNU Lesser 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 static final long serialVersionUID = -3426947847986039782L; 036 037 private ApiConfigurationException( String message ) { 038 super(message); 039 040 assert !StringUtils.isEmpty(message); 041 } 042 043 /* 044 public static ApiConfigurationException forClassAlreadyRegisteredAsAction( Class<?> actionClass ) { 045 assert actionClass != null; 046 047 return new ApiConfigurationException( "Class '" + actionClass.getName() + "' already registered. It is not possible to register the same class twice" ); 048 } 049 */ 050 051 public static ApiConfigurationException forActionAlreadyRegistered(String newActionName, Class<?> newActionClass, Class<?> registeredActionClass ) { 052 assert !StringUtils.isEmpty(newActionName); 053 assert newActionClass != null; 054 assert registeredActionClass != null; 055 056 return new ApiConfigurationException("Action '" + newActionName + "' is already registered for class '" + 057 registeredActionClass.getName() + "', but you are attempting to register it for class '" + 058 newActionClass.getName() + "'. It is not possible to register two classes with the same action name." ); 059 } 060 061 public static ApiConfigurationException forMethodAlreadyRegisteredInAction(String registeredMethodName, String actionName ) { 062 assert !StringUtils.isEmpty(registeredMethodName); 063 assert !StringUtils.isEmpty(actionName); 064 065 return new ApiConfigurationException("Method '" + registeredMethodName + "' is already registered for action '" + 066 actionName + "'"); 067 } 068 069 public static ApiConfigurationException forMethodHasWrongParametersForAFormHandler(String actionName, String methodName) { 070 assert !StringUtils.isEmpty(actionName); 071 assert !StringUtils.isEmpty(methodName); 072 073 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>)'" ); 074 } 075 076 public static ApiConfigurationException forMethodCantBeStandardAndFormPostMethodAtTheSameTime( 077 RegisteredAction action, Method method) { 078 assert action != null; 079 assert method != null; 080 081 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." ); 082 } 083 084 public static ApiConfigurationException forPollMethodCantBeStandardOrFormPostMethodAtTheSameTime( 085 RegisteredAction action, Method method) { 086 assert action != null; 087 assert method != null; 088 089 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." ); 090 } 091 092 public static ApiConfigurationException forMethodHasWrongParametersForAPollHandler( 093 Method method) { 094 assert method != null; 095 096 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>)'" ); 097 } 098 099 public static ApiConfigurationException forPollEventAlreadyRegistered(String eventName) { 100 assert !StringUtils.isEmpty(eventName); 101 102 return new ApiConfigurationException( "Poll event '" + eventName + "' already registered . It is not possible to register the same event twice" ); 103 } 104 105 public static ApiConfigurationException forApiAlreadyRegistered(String name) { 106 assert !StringUtils.isEmpty(name); 107 108 return new ApiConfigurationException( "Api '" + name + "' already registered. It is not possible to register the same api twice"); 109 } 110 }