View Javadoc
1   package org.andromda.cartridges.ejb3.metafacades;
2   
3   import org.andromda.cartridges.ejb3.EJB3Profile;
4   import org.andromda.metafacades.uml.ParameterFacade;
5   import org.andromda.metafacades.uml.UMLProfile;
6   import org.apache.commons.lang.BooleanUtils;
7   import org.apache.commons.lang.StringUtils;
8   import org.apache.log4j.Logger;
9   
10  /**
11   * MetafacadeLogic implementation for org.andromda.cartridges.ejb3.metafacades.EJB3WebServiceOperationFacade.
12   *
13   * @see EJB3WebServiceOperationFacade
14   */
15  public class EJB3WebServiceOperationFacadeLogicImpl
16      extends EJB3WebServiceOperationFacadeLogic
17  {
18      private static final long serialVersionUID = 34L;
19      /**
20       * The logger instance.
21       */
22      private static final Logger logger = Logger.getLogger(EJB3WebServiceOperationFacadeLogicImpl.class);
23  
24      /**
25       * @param metaObject
26       * @param context
27       */
28      public EJB3WebServiceOperationFacadeLogicImpl(final Object metaObject, final String context)
29      {
30          super (metaObject, context);
31      }
32  
33      /**
34       * @see EJB3WebServiceOperationFacade#isExposed()
35       */
36      @Override
37      protected boolean handleIsExposed()
38      {
39          return this.getOwner().hasStereotype(UMLProfile.STEREOTYPE_WEBSERVICE) ||
40              this.hasStereotype(UMLProfile.STEREOTYPE_WEBSERVICE_OPERATION);
41      }
42  
43      /**
44       * @see EJB3WebServiceOperationFacadeLogic#handleIsOneway()
45       */
46      @Override
47      protected boolean handleIsOneway()
48      {
49          return BooleanUtils.toBoolean(
50                  (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_WEBSERVICE_OPERATION_ONEWAY));
51      }
52  
53      /**
54       * @see EJB3WebServiceOperationFacadeLogic#getAnnotatedSignature()
55       */
56      @Override
57      protected String handleGetAnnotatedSignature()
58      {
59          final StringBuilder signature = new StringBuilder(this.getName());
60          signature.append("(");
61          signature.append(this.getAnnotatedTypedArgumentList(true, null));
62          signature.append(")");
63          return signature.toString();
64      }
65  
66      /**
67       * @param withArgumentNames
68       * @param modifier
69       * @return
70       */
71      private String getAnnotatedTypedArgumentList(final boolean withArgumentNames, final String modifier)
72      {
73          final StringBuilder buffer = new StringBuilder();
74          boolean commaNeeded = false;
75          for (ParameterFacade paramter : this.getArguments())
76          {
77              String type = null;
78              if (paramter.getType() == null)
79              {
80                  EJB3WebServiceOperationFacadeLogicImpl.logger.error(
81                          "ERROR! No type specified for parameter --> '" + paramter.getName() +
82                          "' on operation --> '" +
83                          this.getName() +
84                          "', please check your model");
85              }
86              else
87              {
88                  type = paramter.getGetterSetterTypeName();
89              }
90  
91              if (commaNeeded)
92              {
93                  buffer.append(",");
94              }
95              buffer.append('\n');
96  
97              // Add WebParam annotation
98              if (withArgumentNames)
99              {
100                 buffer.append("        @javax.jws.WebParam(name = \"");
101                 buffer.append(StringUtils.capitalize(paramter.getName())).append("\")");
102                 buffer.append(" ");
103             }
104             if (StringUtils.isNotBlank(modifier))
105             {
106                 buffer.append(modifier);
107                 buffer.append(" ");
108             }
109             buffer.append(type);
110             if (withArgumentNames)
111             {
112                 buffer.append(" ");
113                 buffer.append(paramter.getName());
114             }
115             commaNeeded = true;
116         }
117         buffer.append('\n');
118         if (commaNeeded)
119         {
120             buffer.append("    ");
121         }
122         return buffer.toString();
123     }
124 
125     /**
126      * @see EJB3WebServiceOperationFacadeLogic#handleGetMethodName()
127      */
128     @Override
129     protected String handleGetMethodName()
130     {
131         String methodName = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_WEBSERVICE_OPERATION_NAME);
132         if (StringUtils.isBlank(methodName))
133         {
134             methodName = StringUtils.capitalize(this.getName());
135         }
136         return methodName;
137     }
138 
139     /**
140      * @see EJB3WebServiceOperationFacadeLogic#handleGetResultName()
141      */
142     @Override
143     protected String handleGetResultName()
144     {
145         return (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_WEBSERVICE_OPERATION_RESULT_NAME);
146     }
147 }