View Javadoc
1   package org.andromda.translation.ocl.syntax;
2   
3   import org.andromda.core.common.ExceptionUtils;
4   import org.apache.commons.lang.StringUtils;
5   
6   /**
7    * An implementation of the ocl OperationDeclaration facade.
8    *
9    * @author Chad Brandon
10   * @see org.andromda.translation.ocl.syntax.OperationDeclaration
11   */
12  public class OperationDeclarationImpl
13          implements OperationDeclaration
14  {
15      private String name;
16      private String returnType;
17      private VariableDeclaration[] arguments = new VariableDeclaration[0];
18  
19      /**
20       * Constructs a new OperationDeclarationImpl
21       *
22       * @param name       the name of the Operation
23       * @param returnType the returnType of the operation
24       * @param arguments  the arguments of the operation.
25       */
26      public OperationDeclarationImpl(String name, String returnType, VariableDeclaration[] arguments)
27      {
28          ExceptionUtils.checkEmpty("name", name);
29          this.name = StringUtils.trimToEmpty(name);
30          this.returnType = StringUtils.trimToEmpty(returnType);
31          this.arguments = arguments;
32      }
33  
34      /**
35       * @see org.andromda.translation.ocl.syntax.OperationDeclaration#getName()
36       */
37      public String getName()
38      {
39          return this.name;
40      }
41  
42      /**
43       * @see org.andromda.translation.ocl.syntax.OperationDeclaration#getReturnType()
44       */
45      public String getReturnType()
46      {
47          return this.returnType;
48      }
49  
50      /**
51       * @see org.andromda.translation.ocl.syntax.OperationDeclaration#getArguments()
52       */
53      public VariableDeclaration[] getArguments()
54      {
55          return arguments;
56      }
57  
58      /**
59       * @see Object#toString()
60       */
61      public String toString()
62      {
63          StringBuilder toString = new StringBuilder(this.getName());
64          toString.append('(');
65          if (this.getArguments().length > 0)
66          {
67              toString.append(StringUtils.join(this.getArguments(), ','));
68          }
69          toString.append(')');
70          if (StringUtils.isNotBlank(this.getReturnType()))
71          {
72              toString.append("::");
73              toString.append(this.getReturnType());
74          }
75          return toString.toString();
76      }
77  
78  }