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 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.api; 027 028 import java.util.ArrayList; 029 import java.util.HashMap; 030 import java.util.List; 031 import java.util.Map; 032 033 import com.softwarementors.extjs.djn.StringUtils; 034 035 import edu.umd.cs.findbugs.annotations.NonNull; 036 037 public class RegisteredApi { 038 @NonNull private Map<String, RegisteredAction> actions = new HashMap<String, RegisteredAction>(); 039 @NonNull private String fullApiFileName; 040 @NonNull private String apiNamespace; 041 @NonNull private String actionsNamespace; 042 @NonNull private String name; 043 @NonNull private Registry registry; 044 @NonNull private String apiFile; 045 046 /* package */ RegisteredApi( Registry registry, String name, String apiFile, String fullApiFileName, String apiNamespace, String actionsNamespace ) { 047 assert registry != null; 048 assert !StringUtils.isEmpty(name); 049 assert !StringUtils.isEmpty(apiNamespace); 050 assert !StringUtils.isEmpty(fullApiFileName); 051 assert actionsNamespace != null; 052 053 this.registry = registry; 054 this.apiFile = apiFile; 055 this.fullApiFileName = fullApiFileName; 056 this.apiNamespace = apiNamespace; 057 this.actionsNamespace = actionsNamespace; 058 this.name = name; 059 } 060 061 public Registry getRegistry() { 062 return this.registry; 063 } 064 065 public RegisteredAction addAction( Class<?> actionClass, String name) { 066 assert actionClass != null; 067 assert !StringUtils.isEmpty(name); 068 069 RegisteredAction result = new RegisteredAction( this, actionClass, name ); 070 this.actions.put( name, result ); 071 getRegistry().registerAction(result); 072 if( Registry.logger.isDebugEnabled()) { 073 Registry.logger.debug( "Registered new Action. Name: '" + name + "', Java class: '" + actionClass.getName() + "'" ); 074 } 075 return result; 076 } 077 078 public RegisteredAction getAction(String name) { 079 assert !StringUtils.isEmpty(name); 080 081 return this.actions.get(name); 082 } 083 084 public List<RegisteredAction> getActions() { 085 return new ArrayList<RegisteredAction>(this.actions.values()); 086 } 087 088 public String getName() { 089 return this.name; 090 } 091 092 public String getApiFile() { 093 return this.apiFile; 094 } 095 096 public String getFullApiFileName() { 097 return this.fullApiFileName; 098 } 099 100 public String getApiNamespace() { 101 return this.apiNamespace; 102 } 103 104 public String getActionsNamespace() { 105 return this.actionsNamespace; 106 } 107 108 public List<RegisteredPollMethod> getPollMethods() { 109 List<RegisteredPollMethod> result = new ArrayList<RegisteredPollMethod>(); 110 for( RegisteredAction action : this.actions.values()) { 111 result.addAll( action.getPollMethods()); 112 } 113 return result; 114 } 115 }