View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: ModelAction.java,v 1.6 2002/09/11 14:35:07 ludovicc Exp $ 37 */ 38 package org.scopemvc.core; 39 40 import java.lang.reflect.Method; 41 import org.scopemvc.util.Debug; 42 43 /*** 44 * <P> 45 * 46 * Actions on model objects can be invoked via {@link ActionManager}'s API, 47 * taking a ModelAction to describe the method to invoke. A ModelAction contains 48 * a method name and a Class[] to describe the parameters in the method 49 * signature. </P> <P> 50 * 51 * ModelActions are probably not used by application builders who will more 52 * likely call a model object's methods directly. </P> 53 * 54 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A> 55 * @created 05 August 2002 56 * @version $Revision: 1.6 $ $Date: 2002/09/11 14:35:07 $ 57 * @see ActionManager#doAction 58 * @see ActionManager#canDoAction 59 */ 60 public final class ModelAction { 61 62 private String methodName; 63 64 private Class[] parameterClasses; 65 66 67 /*** 68 * Constructor for the ModelAction object 69 * 70 * @param inMethodName The name of the method on the model 71 */ 72 public ModelAction(String inMethodName) { 73 this(inMethodName, (Class) null); 74 } 75 76 77 /*** 78 * Constructor for the ModelAction object 79 * 80 * @param inMethod The method on the model 81 */ 82 public ModelAction(Method inMethod) { 83 this(inMethod.getName(), inMethod.getParameterTypes()); 84 } 85 86 87 /*** 88 * Constructor for the ModelAction object 89 * 90 * @param inMethodName The name of the method on the model 91 * @param inParameterClass The class of the unique method parameter 92 */ 93 public ModelAction(String inMethodName, Class inParameterClass) { 94 if (inMethodName == null) { 95 throw new IllegalArgumentException("Can't create a ModelAction with a null method name."); 96 } 97 methodName = inMethodName; 98 99 if (inParameterClass == null) { 100 parameterClasses = new Class[0]; 101 } else { 102 parameterClasses = new Class[]{inParameterClass}; 103 } 104 if (Debug.ON) { 105 Debug.assertTrue(parameterClasses != null); 106 } 107 } 108 109 110 /*** 111 * Constructor for the ModelAction object 112 * 113 * @param inMethodName The name of the method on the model 114 * @param inParameterClasses The set of classes for the parameters of the 115 * method 116 */ 117 public ModelAction(String inMethodName, Class[] inParameterClasses) { 118 if (inMethodName == null) { 119 throw new IllegalArgumentException("Can't create a ModelAction with a null method name."); 120 } 121 methodName = inMethodName; 122 123 if (inParameterClasses == null) { 124 parameterClasses = new Class[0]; 125 } else { 126 parameterClasses = inParameterClasses; 127 } 128 if (Debug.ON) { 129 Debug.assertTrue(parameterClasses != null); 130 } 131 } 132 133 134 /*** 135 * Gets the method name 136 * 137 * @return The methodName value 138 */ 139 public String getMethodName() { 140 return methodName; 141 } 142 143 144 /*** 145 * Gets the array of <code>Class</code> objects that represent the formal 146 * parameter types, in declaration order, of the method. 147 * 148 * @return The parameter classes to describe the method signature. Never 149 * null: if no parameters returns an empty array. 150 */ 151 public Class[] getParameterClasses() { 152 return parameterClasses; 153 } 154 155 156 /*** 157 * Returns a string representation of this object 158 * 159 * @return a string representation 160 */ 161 public String toString() { 162 return "(ModelAction:" + methodName + "(" + parameterClasses + ")" + ")"; 163 } 164 } 165

This page was automatically generated by Maven