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.api; 027 028 import java.lang.reflect.Method; 029 import java.util.ArrayList; 030 import java.util.HashMap; 031 import java.util.List; 032 import java.util.Map; 033 034 import com.softwarementors.extjs.djn.StringUtils; 035 036 public class RegisteredAction { 037 038 private Class<?> actionClass; 039 private String name; 040 private Map<String, RegisteredMethod> methodsByName = new HashMap<String,RegisteredMethod>(); 041 private RegisteredApi api; 042 043 /* package */ RegisteredAction( RegisteredApi api, Class<?> actionClass, String name ) { 044 assert api != null; 045 assert actionClass != null; 046 assert !StringUtils.isEmpty(name); 047 048 this.actionClass = actionClass; 049 this.name = name; 050 051 this.api = api; 052 } 053 054 public RegisteredApi getApi() { 055 return this.api; 056 } 057 058 public RegisteredMethod addMethod( String name, Method method, boolean formHandler) { 059 assert !StringUtils.isEmpty(name); 060 assert method != null; 061 062 RegisteredMethod result = new RegisteredMethod( this, name, method, formHandler); 063 this.methodsByName.put( name, result ); 064 065 066 if( Registry.logger.isDebugEnabled() ) { 067 String type = "Standard"; 068 if( formHandler) { 069 type = "Form"; 070 } 071 072 Registry.logger.debug( " - Registered new " + type + " Method. Name: '" + result.getFullName() + "'. Java method: '" + getActionClass().getName() + "." + method.getName() + "'" ); 073 } 074 return result; 075 } 076 077 public RegisteredMethod getMethod(String methodName) { 078 assert !StringUtils.isEmpty(methodName); 079 080 return this.methodsByName.get( methodName ); 081 } 082 083 public boolean hasMethod(String method) { 084 assert !StringUtils.isEmpty(method); 085 086 return this.methodsByName.containsKey(method); 087 } 088 089 public List<RegisteredMethod> getMethods() { 090 return new ArrayList<RegisteredMethod>( this.methodsByName.values() ); 091 } 092 093 public Class<?> getActionClass() { 094 return this.actionClass; 095 } 096 097 public static final String NAME_PROPERTY = "name"; 098 099 public String getName() { 100 return this.name; 101 } 102 103 /*package*/ void addMethod(RegisteredMethod method) { 104 assert method != null; 105 assert !this.methodsByName.containsKey(method.getName()); 106 107 this.methodsByName.put( method.getName(), method ); 108 } 109 110 }