View Javadoc
1   package org.andromda.cartridges.jsf.metafacades;
2   
3   import org.andromda.cartridges.jsf.JSFGlobals;
4   import org.andromda.metafacades.uml.ModelElementFacade;
5   import org.apache.commons.lang.ObjectUtils;
6   import org.apache.commons.lang.StringUtils;
7   
8   /**
9    * MetafacadeLogic implementation for org.andromda.cartridges.jsf.metafacades.JSFControllerOperation.
10   *
11   * @see org.andromda.cartridges.jsf.metafacades.JSFControllerOperation
12   */
13  public class JSFControllerOperationLogicImpl
14      extends JSFControllerOperationLogic
15  {
16      private static final long serialVersionUID = 34L;
17      /**
18       * @param metaObject
19       * @param context
20       */
21      public JSFControllerOperationLogicImpl(Object metaObject, String context)
22      {
23          super(metaObject, context);
24      }
25  
26      /**
27       * @return formName
28       * @see org.andromda.cartridges.jsf.metafacades.JSFControllerOperation#getFormName()
29       */
30      protected String handleGetFormName()
31      {
32          final String pattern = ObjectUtils.toString(this.getConfiguredProperty(JSFGlobals.FORM_PATTERN));
33          return pattern.replaceFirst("\\{0\\}", StringUtils.capitalize(this.getName()));
34      }
35  
36      /**
37       * @return fullyQualifiedFormName
38       * @see org.andromda.cartridges.jsf.metafacades.JSFControllerOperation#getFullyQualifiedFormName()
39       */
40      protected String handleGetFullyQualifiedFormName()
41      {
42          final StringBuilder fullyQualifiedName = new StringBuilder();
43          final String packageName = this.getPackageName();
44          if (StringUtils.isNotBlank(packageName))
45          {
46              fullyQualifiedName.append(packageName + '.');
47          }
48          return fullyQualifiedName.append(StringUtils.capitalize(this.getFormName())).toString();
49      }
50  
51      /**
52       * @return getFullyQualifiedFormName().replace('.', '/')
53       * @see org.andromda.cartridges.jsf.metafacades.JSFControllerOperation#getFullyQualifiedFormPath()
54       */
55      protected String handleGetFullyQualifiedFormPath()
56      {
57          return this.getFullyQualifiedFormName().replace('.', '/');
58      }
59  
60      /**
61       * @return formCall
62       * @see org.andromda.cartridges.jsf.metafacades.JSFControllerOperation#getFormCall()
63       */
64      protected String handleGetFormCall()
65      {
66          final StringBuilder call = new StringBuilder();
67          call.append(this.getName());
68          call.append("(");
69          if (!this.getFormFields().isEmpty())
70          {
71              call.append("form");
72          }
73          call.append(")");
74          return call.toString();
75      }
76  
77      /**
78       * @return getFormSignature(false)
79       * @see org.andromda.cartridges.jsf.metafacades.JSFControllerOperation#getImplementationFormSignature()
80       */
81      protected String handleGetImplementationFormSignature()
82      {
83          return this.getFormSignature(false);
84      }
85  
86      /**
87       * @return getFormSignature(true)
88       * @see org.andromda.cartridges.jsf.metafacades.JSFControllerOperation#getFormSignature()
89       */
90      protected String handleGetFormSignature()
91      {
92          return this.getFormSignature(true);
93      }
94  
95      /**
96       * Constructs the signature that takes the form for this operation.
97       *
98       * @param isAbstract whether or not the signature is abstract.
99       * @return the appropriate signature.
100      */
101     private String getFormSignature(boolean isAbstract)
102     {
103         final StringBuilder signature = new StringBuilder();
104         signature.append(this.getVisibility() + ' ');
105         if (isAbstract)
106         {
107             signature.append("abstract ");
108         }
109         final ModelElementFacade returnType = this.getReturnType();
110         signature.append(returnType != null ? returnType.getFullyQualifiedName() : null);
111         signature.append(" " + this.getName() + "(");
112         if (!this.getFormFields().isEmpty())
113         {
114             signature.append(this.getFormName() + " form");
115         }
116         signature.append(")");
117         return signature.toString();
118     }
119 }