View Javadoc

1   /*
2    * @(#) Operation.java Jan 12, 2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.dsol.interpreter.operations;
11  
12  import java.lang.reflect.AccessibleObject;
13  import java.lang.reflect.Constructor;
14  import java.lang.reflect.Method;
15  import java.lang.reflect.Modifier;
16  
17  import nl.tudelft.simulation.dsol.interpreter.Frame;
18  import nl.tudelft.simulation.dsol.interpreter.Operation;
19  
20  /***
21   * The ReturnOperation is an abstract class for all operations which do return
22   * any value.
23   * <p>
24   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
25   * University of Technology </a>, the Netherlands. <br>
26   * See for project information <a
27   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
28   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
29   * License (GPL) </a>, no warranty <br>
30   * 
31   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
32   *         Jacobs </a><a
33   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
34   *         Verbraeck </a>
35   * @version 1.3 Apr 6, 2004
36   * @since 1.4
37   */
38  public abstract class ReturnOperation extends Operation
39  {
40  	/***
41  	 * executes the operation
42  	 * 
43  	 * @param frame the current frame
44  	 * @return Object the result
45  	 */
46  	public abstract Object execute(final Frame frame);
47  
48  	/***
49  	 * is the accessibleObject synchronized?
50  	 * 
51  	 * @param object the method or constructor
52  	 * @return isSynchronized?
53  	 */
54  	public static boolean isSynchronized(final AccessibleObject object)
55  	{
56  		if (object instanceof Method)
57  		{
58  			return Modifier.isSynchronized(((Method) object).getModifiers());
59  		}
60  		return Modifier.isSynchronized(((Constructor) object).getModifiers());
61  	}
62  
63  	/***
64  	 * is the accessibleObject static?
65  	 * 
66  	 * @param object the method or constructor
67  	 * @return isStatic?
68  	 */
69  	public static boolean isStatic(final AccessibleObject object)
70  	{
71  		if (object instanceof Method)
72  		{
73  			return Modifier.isStatic(((Method) object).getModifiers());
74  		}
75  		return Modifier.isStatic(((Constructor) object).getModifiers());
76  	}
77  }