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     * DirectJNgine is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013     * GNU General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with DirectJNgine.  If not, see <http://www.gnu.org/licenses/>.
017     * 
018     * This software uses the ExtJs library (http://extjs.com), which is 
019     * distributed under the GPL v3 license (see http://extjs.com/license).
020     */
021    
022    package com.softwarementors.extjs.djn.config;
023    
024    import java.util.ArrayList;
025    import java.util.HashMap;
026    import java.util.List;
027    import java.util.Map;
028    
029    import com.softwarementors.extjs.djn.StringUtils;
030    
031    public class RegisteredAction {
032    
033      private Class<?> actionClass;
034      private String name;
035      private Map<String, RegisteredMethod> methodsByName; 
036      
037      
038      /* package */ RegisteredAction( Class<?> actionClass, String name ) { 
039        assert actionClass != null;
040        assert !StringUtils.isEmpty(name);
041        
042        this.actionClass = actionClass;
043        this.name = name;
044      }
045      
046      public Class<?> getActionClass() {
047        return this.actionClass;
048      }
049      
050      public String getName() {
051        return this.name;
052      }
053    
054      public RegisteredMethod getMethod(String methodName) {
055        assert !StringUtils.isEmpty(methodName);
056        assert isMethodsSet();
057        
058        return this.methodsByName.get( methodName );
059      }
060    
061      /* package */ boolean isMethodRegistered(String methodName) {
062        assert !StringUtils.isEmpty(methodName);
063        assert isMethodsSet();
064        
065        return this.methodsByName.containsKey(methodName);
066      }
067    
068      // Would have love to be able to set this in the constructor,
069      // but unfortunately we need to create instances of this
070      // class in two phases, calling this method being the second phase.
071      /* package */ void setMethods( Map<String, RegisteredMethod> methodsByName ) {
072        assert methodsByName != null;
073        assert !isMethodsSet();
074        
075        this.methodsByName = new HashMap<String, RegisteredMethod>(methodsByName);
076      }
077    
078      /* package */ boolean isMethodsSet() {
079        return this.methodsByName != null;
080      }
081    
082      public List<RegisteredMethod> getMethods() {
083        return new ArrayList<RegisteredMethod>( this.methodsByName.values() );
084      }
085    }