View Javadoc

1   package org.andromda.core.simpleuml;
2   
3   
4   import java.util.Collection;
5   import java.util.Iterator;
6   import java.util.Vector;
7   
8   import org.andromda.core.uml14.UMLStaticHelper;
9   import org.omg.uml.foundation.core.Operation;
10  import org.omg.uml.foundation.core.Parameter;
11  import org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum;
12  import org.omg.uml.foundation.datatypes.VisibilityKind;
13  import org.omg.uml.foundation.datatypes.VisibilityKindEnum;
14  
15  /***
16   * dynamic proxy for an Operation: dynamically supports the UMLOperation, 
17   * and org.omg.uml.foundation.core.Operation interfaces.
18   *
19   *@author   <A HREF="http://www.amowers.com">Anthony Mowers</A>
20   */
21  public class POperation extends PModelElement implements UMLOperation
22  {
23  	private UMLStaticHelper scriptHelper;
24  
25  	/***
26  	 *  Description of the Method
27  	 *
28  	 *@param  operation    Description of the Parameter
29  	 *@param  scriptHelper  Description of the Parameter
30  	 *@return               Description of the Return Value
31  	 */
32  	public static Operation newInstance(
33  		UMLStaticHelper scriptHelper,
34  		Operation operation)
35  	{
36  		Class[] interfaces =
37  			new Class[] { UMLOperation.class, Operation.class };
38  
39  		return (Operation) java.lang.reflect.Proxy.newProxyInstance(
40  			operation.getClass().getClassLoader(),
41  			interfaces,
42  			new POperation(operation, scriptHelper));
43  	}
44  
45  	private POperation(Operation operation, UMLStaticHelper scriptHelper)
46  	{
47  		super(operation, scriptHelper);
48  	}
49  
50  	public Object getId()
51  	{
52  		return this.modelElement;
53  	}
54  
55  	public VisibilityKind getVisibility()
56  	{
57  		VisibilityKind visibility;
58  
59  		visibility = ((Operation)modelElement).getVisibility();
60  		if (VisibilityKindEnum.VK_PRIVATE.equals(visibility))
61  		{
62  			return JavaVisibilityEnum.PRIVATE;
63  		}
64  		else if (VisibilityKindEnum.VK_PROTECTED.equals(visibility))
65  		{
66  			return JavaVisibilityEnum.PROTECTED;
67  		}
68  		else if (VisibilityKindEnum.VK_PUBLIC.equals(visibility))
69  		{
70  			return JavaVisibilityEnum.PUBLIC;
71  		}
72  
73  		return JavaVisibilityEnum.PACKAGE;
74  	}
75  
76      public Collection getParameters()
77      {
78          Collection parms = ((Operation)modelElement).getParameter();
79          Vector ret = new Vector();
80       
81          for (Iterator i = parms.iterator(); i.hasNext(); )
82          {
83              Parameter p = (Parameter) i.next();
84              if ( !ParameterDirectionKindEnum.PDK_RETURN.equals(p.getKind())) 
85              {
86                  ret.add(p);
87              }
88          }
89          
90          return ret;
91      }
92      
93      public Object getType()
94      {
95          Collection parms = ((Operation)modelElement).getParameter();
96          for (Iterator i = parms.iterator(); i.hasNext(); )
97          {
98              Parameter p = (Parameter) i.next();
99              if ( ParameterDirectionKindEnum.PDK_RETURN.equals(p.getKind())) 
100             {
101                return p.getType();
102             }
103         }
104         
105         return null;    
106     }
107     
108 }