View Javadoc

1   package org.andromda.cartridges.spring.metafacades;
2   
3   import org.andromda.cartridges.spring.SpringProfile;
4   import org.andromda.metafacades.uml.UMLProfile;
5   import org.apache.commons.lang.StringUtils;
6   
7   /***
8    * MetafacadeLogic implementation for org.andromda.cartridges.spring.metafacades.SpringServiceOperation.
9    *
10   * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperation
11   */
12  public class SpringServiceOperationLogicImpl
13          extends SpringServiceOperationLogic
14  {
15  
16      public SpringServiceOperationLogicImpl(Object metaObject, String context)
17      {
18          super(metaObject, context);
19      }
20  
21      /***
22       * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperation#isWebserviceExposed()
23       */
24      protected boolean handleIsWebserviceExposed()
25      {
26          return this.hasStereotype(UMLProfile.STEREOTYPE_WEBSERVICE_OPERATION);
27      }
28  
29      /***
30       * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperation#getImplementationName()
31       */
32      protected String handleGetImplementationName()
33      {
34          return this.getImplementationOperationName(StringUtils.capitalize(this.getName()));
35      }
36  
37      /***
38       * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperation#getImplementationSignature()
39       */
40      protected String handleGetImplementationSignature()
41      {
42          return this.getImplementationOperationName(StringUtils.capitalize(this.getSignature()));
43      }
44  
45      /***
46       * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperationL#getImplementationCall()
47       */
48      protected String handleGetImplementationCall()
49      {
50          return this.getImplementationOperationName(StringUtils.capitalize(this.getCall()));
51      }
52  
53      /***
54       * Retrieves the implementationOperatName by replacing the <code>replacement</code> in the {@link
55       * SpringGlobals#IMPLEMENTATION_OPERATION_NAME_PATTERN}
56       *
57       * @param replacement the replacement string for the pattern.
58       * @return the operation name
59       */
60      private String getImplementationOperationName(String replacement)
61      {
62          return StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(
63                  SpringGlobals.IMPLEMENTATION_OPERATION_NAME_PATTERN))).replaceAll("//{0//}", replacement);
64      }
65  
66      /***
67       * The transation type for Spring service operations.
68       */
69      private static final String SERVICE_OPERATION_TRANSACTION_TYPE = "serviceOperationTransactionType";
70  
71      /***
72       * @see org.andromda.metafacades.uml.ServiceOperationFacade#getTransactionType()
73       */
74      public String handleGetTransactionType()
75      {
76          String transactionType = (String)this.findTaggedValue(SpringProfile.TAGGEDVALUE_TRANSACTION_TYPE);
77          if (StringUtils.isBlank(transactionType))
78          {
79              transactionType = (String)this.getOwner().findTaggedValue(SpringProfile.TAGGEDVALUE_TRANSACTION_TYPE);
80          }
81          if (StringUtils.isBlank(transactionType))
82          {
83              transactionType = String.valueOf(this.getConfiguredProperty(SERVICE_OPERATION_TRANSACTION_TYPE));
84          }
85          return transactionType;
86      }
87  
88      /***
89       * The transaction type for EJB wrapped service operations..
90       */
91      private static final String EJB_SERVICE_OPERATION_TRANSACTION_TYPE = "ejbServiceOperationTransactionType";
92  
93      /***
94       * @see org.andromda.metafacades.uml.ServiceOperationFacade#getEjbTransactionType()
95       */
96      protected String handleGetEjbTransactionType()
97      {
98          String transactionType = (String)this.findTaggedValue(SpringProfile.TAGGEDVALUE_EJB_TRANSACTION_TYPE);
99          if (StringUtils.isBlank(transactionType))
100         {
101             transactionType = (String)this.getOwner().findTaggedValue(SpringProfile.TAGGEDVALUE_EJB_TRANSACTION_TYPE);
102         }
103         if (StringUtils.isBlank(transactionType))
104         {
105             transactionType = String.valueOf(this.getConfiguredProperty(EJB_SERVICE_OPERATION_TRANSACTION_TYPE));
106         }
107         return transactionType;
108     }
109 
110     /***
111      * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperation#getThrowsClause()
112      */
113     protected String handleGetThrowsClause()
114     {
115         StringBuffer throwsClause = null;
116         if (this.isExceptionsPresent())
117         {
118             throwsClause = new StringBuffer(this.getExceptionList());
119         }
120         if (throwsClause != null)
121         {
122             throwsClause.insert(0, "throws ");
123         }
124         return throwsClause != null ? throwsClause.toString() : null;
125     }
126 
127     /***
128      * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperation#getThrowsClause(java.lang.String)
129      */
130     protected String handleGetThrowsClause(String initialExceptions)
131     {
132         final StringBuffer throwsClause = new StringBuffer(initialExceptions);
133         if (this.getThrowsClause() != null)
134         {
135             throwsClause.insert(0, ", ");
136             throwsClause.insert(0, this.getThrowsClause());
137         }
138         else
139         {
140             throwsClause.insert(0, "throws ");
141         }
142         return throwsClause.toString();
143     }
144 }