View Javadoc
1   package org.andromda.cartridges.spring.metafacades;
2   
3   import java.text.MessageFormat;
4   import java.util.Arrays;
5   import java.util.Collection;
6   import java.util.List;
7   import org.andromda.cartridges.spring.SpringProfile;
8   import org.andromda.metafacades.uml.ClassifierFacade;
9   import org.andromda.metafacades.uml.FilteredCollection;
10  import org.andromda.metafacades.uml.OperationFacade;
11  import org.andromda.metafacades.uml.UMLProfile;
12  import org.apache.commons.collections.Closure;
13  import org.apache.commons.collections.CollectionUtils;
14  import org.apache.commons.lang.BooleanUtils;
15  import org.apache.commons.lang.ObjectUtils;
16  import org.apache.commons.lang.StringUtils;
17  
18  /**
19   * MetafacadeLogic implementation for
20   * org.andromda.cartridges.spring.metafacades.SpringService.
21   *
22   * @author Chad Brandon
23   * @author Peter Friese
24   * @author Jens Vagts
25   * @see org.andromda.cartridges.spring.metafacades.SpringService
26   */
27  public class SpringServiceLogicImpl
28      extends SpringServiceLogic
29  {
30      private static final long serialVersionUID = 34L;
31      /**
32       * Public constructor for SpringServiceLogicImpl
33       * @param metaObject
34       * @param context
35       * @see org.andromda.cartridges.spring.metafacades.SpringService
36       */
37      public SpringServiceLogicImpl(Object metaObject, String context)
38      {
39          super(metaObject, context);
40      }
41  
42      /**
43       * @return EjbJndiName
44       * @see org.andromda.cartridges.spring.metafacades.SpringService#getEjbJndiName()
45       */
46      protected String handleGetEjbJndiName()
47      {
48          StringBuilder jndiName = new StringBuilder();
49          String jndiNamePrefix = StringUtils.trimToEmpty(this.getEjbJndiNamePrefix());
50          if (StringUtils.isNotBlank(jndiNamePrefix))
51          {
52              jndiName.append(jndiNamePrefix);
53              jndiName.append('/');
54          }
55          jndiName.append("ejb/");
56          jndiName.append(this.getFullyQualifiedName());
57          return jndiName.toString();
58      }
59  
60      /**
61       * @return EjbJndiName
62       * @see org.andromda.cartridges.spring.metafacades.SpringService#getEjbLocalJndiName()
63       */
64      protected String handleGetEjbLocalJndiName()
65      {
66          StringBuilder jndiName = new StringBuilder();
67          String jndiNamePrefix = StringUtils.trimToEmpty(this.getEjbJndiNamePrefix());
68          if (StringUtils.isNotBlank(jndiNamePrefix))
69          {
70              jndiName.append(jndiNamePrefix);
71              jndiName.append('/');
72          }
73          jndiName.append("ejb/");
74          jndiName.append(SpringMetafacadeUtils.getFullyQualifiedName(
75                  this.getPackageName(),
76                  this.getName(),
77                  (EJB_BOTH_VIEW.equalsIgnoreCase(this.getEjbViewType()) ? "Local" : null)));
78          return jndiName.toString();
79      }
80  
81      /**
82       * @return getName() + SpringGlobals.EJB_IMPLEMENTATION_SUFFIX
83       * @see org.andromda.cartridges.spring.metafacades.SpringService#getEjbImplementationName()
84       */
85      protected String handleGetEjbImplementationName()
86      {
87          return this.getName() + SpringGlobals.EJB_IMPLEMENTATION_SUFFIX;
88      }
89  
90      /**
91       * @return getName() + SpringGlobals.IMPLEMENTATION_SUFFIX
92       * @see org.andromda.cartridges.spring.metafacades.SpringService#getImplementationName()
93       */
94      protected String handleGetImplementationName()
95      {
96          return this.getName() + SpringGlobals.IMPLEMENTATION_SUFFIX;
97      }
98  
99      /**
100      * @return FullyQualifiedEjbImplementationName
101      * @see org.andromda.cartridges.spring.metafacades.SpringService#getFullyQualifiedImplementationName()
102      */
103     protected String handleGetFullyQualifiedEjbImplementationName()
104     {
105         return SpringMetafacadeUtils.getFullyQualifiedName(
106             this.getEjbPackageName(),
107             this.getName(),
108             SpringGlobals.EJB_IMPLEMENTATION_SUFFIX);
109     }
110 
111     /**
112      * @return FullyQualifiedEjbName
113      * @see org.andromda.cartridges.spring.metafacades.SpringService#getFullyQualifiedEjbName()
114      */
115     protected String handleGetFullyQualifiedEjbName()
116     {
117         return SpringMetafacadeUtils.getFullyQualifiedName(
118             this.getEjbPackageName(),
119             this.getName(),
120             null);
121     }
122 
123     /**
124      * add "Local" to local ejb name when viewtype = "both"
125      * @return FullyQualifiedLocalEjbName
126      * @see org.andromda.cartridges.spring.metafacades.SpringService#getFullyQualifiedLocalEjbName()
127      */
128     protected String handleGetFullyQualifiedLocalEjbName()
129     {
130         //add "Local" to local ejb name when viewtype = "both",
131         //to prevent name clashing with remote interface naming
132         return SpringMetafacadeUtils.getFullyQualifiedName(
133                 this.getEjbPackageName(),
134                 this.getName(),
135                 (EJB_BOTH_VIEW.equalsIgnoreCase(this.getEjbViewType()) ? "Local" : null));
136     }
137 
138     /**
139      * @return FullyQualifiedImplementationName
140      * @see org.andromda.cartridges.spring.metafacades.SpringService#getFullyQualifiedImplementationName()
141      */
142     protected String handleGetFullyQualifiedImplementationName()
143     {
144         return SpringMetafacadeUtils.getFullyQualifiedName(
145             this.getImplementationPackageName(),
146             this.getName(),
147             SpringGlobals.IMPLEMENTATION_SUFFIX);
148     }
149 
150     /**
151      * @return ImplementationPackageName
152      * @see org.andromda.cartridges.spring.metafacades.SpringService#getImplementationPackageName()
153      */
154     protected String handleGetImplementationPackageName() {
155         String implementationPackageName =
156             MessageFormat.format(
157                 this.getImplemenationPackageNamePattern(),
158                     StringUtils.trimToEmpty(this.getPackageName()));
159         if (StringUtils.isBlank(this.getPackageName()))
160         {
161             implementationPackageName = implementationPackageName.replaceAll(
162                     "^\\.",
163                     "");
164         }
165         return implementationPackageName;
166     }
167 
168     /**
169      * @return ImplementationPackagePath
170      * @see org.andromda.cartridges.spring.metafacades.SpringService#getImplementationPackagePath()
171      */
172     protected String handleGetImplementationPackagePath()
173     {
174          return this.getImplementationPackageName().replace(
175                     '.',
176                     '/');
177     }
178 
179     /**
180      * Gets the <code>implementationPackageNamePattern</code> for this SpringService.
181      *
182      * @return the defined package pattern.
183      */
184     protected String getImplemenationPackageNamePattern()
185     {
186         return (String)this.getConfiguredProperty(SpringGlobals.IMPLEMENTATION_PACKAGE_NAME_PATTERN);
187     }
188 
189     /**
190      * @return getName() + SpringGlobals.SERVICE_BASE_SUFFIX
191      * @see org.andromda.cartridges.spring.metafacades.SpringService#getBaseName()
192      */
193     protected String handleGetBaseName()
194     {
195         return this.getName() + SpringGlobals.SERVICE_BASE_SUFFIX;
196     }
197 
198     /**
199      * @return FullyQualifiedBaseName
200      * @see org.andromda.cartridges.spring.metafacades.SpringService#getFullyQualifiedBaseName()
201      */
202     protected String handleGetFullyQualifiedBaseName()
203     {
204         return SpringMetafacadeUtils.getFullyQualifiedName(
205             this.getImplementationPackageName(),
206             this.getName(),
207             SpringGlobals.SERVICE_BASE_SUFFIX);
208     }
209 
210     /**
211      * @return EjbPackageName
212      * @see org.andromda.cartridges.spring.metafacades.SpringService#getEjbPackageName()
213      */
214     protected String handleGetEjbPackageName()
215     {
216         String ejbPackageName =
217             MessageFormat.format(
218                 this.getEjbPackageNamePattern(),
219                     StringUtils.trimToEmpty(this.getPackageName()));
220         if (StringUtils.isBlank(this.getPackageName()))
221         {
222             ejbPackageName = ejbPackageName.replaceAll(
223                     "^\\.",
224                     "");
225         }
226         return ejbPackageName;
227     }
228 
229     /**
230      * @return getEjbPackageName().replace('.', '/')
231      * @see org.andromda.cartridges.spring.metafacades.SpringService#getEjbPackageNamePath()
232      */
233     protected String handleGetEjbPackageNamePath()
234     {
235         return this.getEjbPackageName().replace(
236             '.',
237             '/');
238     }
239 
240     /**
241      * @return getBeanName(false)
242      * @see org.andromda.cartridges.spring.metafacades.SpringService#getBeanName()
243      */
244     protected String handleGetBeanName()
245     {
246         return this.getBeanName(false);
247     }
248 
249     /**
250      * @param targetSuffix
251      * @return BeanName
252      * @see org.andromda.cartridges.spring.metafacades.SpringService#getBeanName(boolean)
253      */
254     protected String handleGetBeanName(boolean targetSuffix)
255     {
256         StringBuilder beanName = new StringBuilder(String.valueOf(this.getConfiguredProperty(SpringGlobals.BEAN_NAME_PREFIX)));
257         beanName.append(StringUtils.uncapitalize(StringUtils.trimToEmpty(this.getName())));
258         if (targetSuffix)
259         {
260             beanName.append(SpringGlobals.BEAN_NAME_TARGET_SUFFIX);
261         }
262         return beanName.toString();
263     }
264 
265     /**
266      * Gets the <code>ejbPackageNamePattern</code> for this EJB.
267      *
268      * @return the defined package pattern.
269      */
270     protected String getEjbPackageNamePattern()
271     {
272         return (String)this.getConfiguredProperty(SpringGlobals.EJB_PACKAGE_NAME_PATTERN);
273     }
274 
275     /**
276      * Gets the <code>ejbJndiNamePrefix</code> for this EJB.
277      *
278      * @return the EJB Jndi name prefix.
279      */
280     protected String getEjbJndiNamePrefix()
281     {
282         return this.isConfiguredProperty(SpringGlobals.EJB_JNDI_NAME_PREFIX)
283             ? ObjectUtils.toString(this.getConfiguredProperty(SpringGlobals.EJB_JNDI_NAME_PREFIX)) : null;
284     }
285 
286     /**
287      * @return getName() + SpringGlobals.WEB_SERVICE_DELEGATOR_SUFFIX
288      * @see org.andromda.cartridges.spring.metafacades.SpringService#getWebServiceDelegatorName()
289      */
290     protected String handleGetWebServiceDelegatorName()
291     {
292         return this.getName() + SpringGlobals.WEB_SERVICE_DELEGATOR_SUFFIX;
293     }
294 
295     /**
296      * @return FullyQualifiedWebServiceDelegatorName
297      * @see org.andromda.cartridges.spring.metafacades.SpringService#getFullyQualifiedWebServiceDelegatorName()
298      */
299     protected String handleGetFullyQualifiedWebServiceDelegatorName()
300     {
301         return SpringMetafacadeUtils.getFullyQualifiedName(
302                   this.getImplementationPackageName(),
303                   this.getName(),
304                   SpringGlobals.WEB_SERVICE_DELEGATOR_SUFFIX);
305     }
306 
307     /**
308      * @return getWebServiceOperations().isEmpty()
309      * @see org.andromda.cartridges.spring.metafacades.SpringService#isWebService()
310      */
311     protected boolean handleIsWebService()
312     {
313         boolean webService = this.hasStereotype(UMLProfile.STEREOTYPE_WEBSERVICE);
314         if (!webService)
315         {
316             webService = !this.getWebServiceOperations().isEmpty();
317         }
318         return webService;
319     }
320 
321     /**
322      * @see org.andromda.cartridges.spring.metafacades.SpringServiceLogic#handleGetInterceptors()
323      */
324     protected Collection<String> handleGetInterceptors()
325     {
326         String serviceInterceptorString =
327             this.isConfiguredProperty(SpringGlobals.SERVICE_INTERCEPTORS) ? ObjectUtils.toString(this
328                 .getConfiguredProperty(SpringGlobals.SERVICE_INTERCEPTORS)) : null;
329         Collection<String> interceptors = null;
330         if (StringUtils.isNotBlank(serviceInterceptorString) && serviceInterceptorString != null)
331         {
332             interceptors = Arrays.asList(serviceInterceptorString.split(","));
333         }
334         return SpringMetafacadeUtils.getServiceInterceptors(this, interceptors);
335     }
336 
337     /**
338      * @return !this.isPrivate() && !this.isRemotingTypeNone()
339      * @see org.andromda.cartridges.spring.metafacades.SpringService#isRemotable()
340      */
341     protected boolean handleIsRemotable()
342     {
343         return !this.isPrivate() && !this.isRemotingTypeNone();
344     }
345 
346     /**
347      * Gets the remoting type for this service.
348      */
349     private String getRemotingType()
350     {
351         final String serviceRemotingType =
352             StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(SpringGlobals.SERVICE_REMOTING_TYPE)));
353         return SpringMetafacadeUtils.getServiceRemotingType(this, serviceRemotingType);
354     }
355 
356     /**
357      * @see org.andromda.cartridges.spring.metafacades.SpringServiceLogic#handleGetRemoteServer()
358      */
359     protected String handleGetRemoteServer()
360     {
361         return StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(SpringGlobals.SERVICE_REMOTE_SERVER)));
362     }
363 
364     /**
365      * @return getServiceRemotePort(this, serviceRemotePort)
366      * @see org.andromda.cartridges.spring.metafacades.SpringService#getRemotePort()
367      */
368     protected String handleGetRemotePort()
369     {
370         String serviceRemotePort =
371             StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(SpringGlobals.SERVICE_REMOTE_PORT)));
372         return SpringMetafacadeUtils.getServiceRemotePort(this, serviceRemotePort);
373     }
374 
375     /**
376      * @see org.andromda.cartridges.spring.metafacades.SpringServiceLogic#handleGetRemoteContext()
377      */
378     protected String handleGetRemoteContext()
379     {
380         return this.isConfiguredProperty(SpringGlobals.SERVICE_REMOTE_CONTEXT)
381             ? ObjectUtils.toString(this.getConfiguredProperty(SpringGlobals.SERVICE_REMOTE_CONTEXT)) : "";
382     }
383 
384     /**
385      * Checks whether this service has a remote port assigned.
386      *
387      * @return <code>true</code> if the service has a remote port, <code>false</code> otherwise.
388      */
389     private boolean hasServiceRemotePort()
390     {
391         final String serviceRemotePort = this.getRemotePort();
392         return StringUtils.isNotBlank(serviceRemotePort);
393     }
394 
395     /**
396      * Checks whether the service has a remote context assigned.
397      *
398      * @return <code>true</code> if the service has a remote context, <code>false</code> otherwise.
399      */
400     private boolean hasServiceRemoteContext()
401     {
402         final String serviceRemoteContext = this.getRemoteContext();
403         return StringUtils.isNotBlank(serviceRemoteContext);
404     }
405 
406     /**
407      * @return RemoteUrl
408      * @see org.andromda.cartridges.spring.metafacades.SpringService#getRemoteUrl()
409      */
410     protected String handleGetRemoteUrl()
411     {
412         String result = "";
413 
414         String propertyPrefix = ObjectUtils.toString(this.getConfiguredProperty(SpringGlobals.CONFIG_PROPERTY_PREFIX));
415 
416         if (this.isRemotingTypeNone())
417         {
418             // nothing
419         }
420         else if (this.isRemotingTypeHttpInvoker() || this.isRemotingTypeHessian() || this.isRemotingTypeBurlap())
421         {
422             // server
423             result = "${" + propertyPrefix + "remoteHttpScheme}://${" + propertyPrefix + "remoteServer}";
424 
425             // port
426             if (hasServiceRemotePort())
427             {
428                 result += ":${" + propertyPrefix + "remotePort}";
429             }
430 
431             // context
432             if (hasServiceRemoteContext())
433             {
434                 result += "/${" + propertyPrefix + "remoteContext}";
435             }
436 
437             // service name
438             result += '/' + getName();
439         }
440         else if (this.isRemotingTypeLingo())
441         {
442             result = "${" + propertyPrefix + "remoteTcpScheme}://${" + propertyPrefix + "remoteServer}";
443             result += "/${" + propertyPrefix + "remotePortJMS}";
444         }
445         else if (this.isRemotingTypeRmi())
446         {
447             // server
448             result = "${" + propertyPrefix + "remoteRmiScheme}://${" + propertyPrefix + "remoteServer}";
449 
450             // port
451             if (hasServiceRemotePort())
452             {
453                 result += ":${" + propertyPrefix + "remotePort}";
454             }
455 
456             // service name
457             result += '/' + getName();
458         }
459         return result;
460     }
461 
462     /**
463      * @return getOperations() instanceof SpringServiceOperation && isWebserviceExposed()
464      * @see org.andromda.cartridges.spring.metafacades.SpringService#getWebServiceOperations()
465      */
466     protected Collection handleGetWebServiceOperations()
467     {
468         Collection<OperationFacade> operations = this.getOperations();
469         if (!this.hasStereotype(UMLProfile.STEREOTYPE_WEBSERVICE))
470         {
471             operations = new FilteredCollection<OperationFacade>(operations)
472             {
473                 private static final long serialVersionUID = 34L;
474                 public boolean evaluate(Object object)
475                 {
476                     return object instanceof SpringServiceOperation && ((SpringServiceOperation)object).isWebserviceExposed();
477                 }
478             };
479         }
480         return operations;
481     }
482 
483     /**
484      * Override to retrieve any abstract operations from an abstract
485      * generalization.
486      *
487      * @see org.andromda.metafacades.uml.ClassifierFacade#getOperations()
488      */
489     public List<OperationFacade> getOperations()
490     {
491         final List<OperationFacade> operations = super.getOperations();
492         if (!this.isAbstract())
493         {
494             for (ClassifierFacade generalization = (ClassifierFacade)this.getGeneralization(); generalization != null;
495                 generalization = (ClassifierFacade)generalization.getGeneralization())
496             {
497                 if (generalization.isAbstract())
498                 {
499                     CollectionUtils.forAllDo(
500                         generalization.getOperations(),
501                         new Closure()
502                         {
503                             public void execute(Object object)
504                             {
505                                 if (((OperationFacade)object).isAbstract())
506                                 {
507                                     operations.add((OperationFacade)object);
508                                 }
509                             }
510                         });
511                 }
512             }
513         }
514         return operations;
515     }
516 
517     /**
518      * @return DefaultExceptionName
519      * @see org.andromda.cartridges.spring.metafacades.SpringService#getDefaultExceptionName()
520      */
521     protected String handleGetDefaultExceptionName()
522     {
523         String name =
524             StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(SpringGlobals.DEFAULT_SERVICE_EXCEPTION_NAME_PATTERN)));
525         return name.replaceAll("\\{0\\}", this.getName());
526     }
527 
528     /**
529      * @return FullyQualifiedDefaultExceptionName
530      * @see org.andromda.cartridges.spring.metafacades.SpringService#getFullyQualifiedDefaultExceptionName()
531      */
532     protected String handleGetFullyQualifiedDefaultExceptionName()
533     {
534         StringBuilder fullyQualifiedName = new StringBuilder("RuntimeException");
535         if (this.isAllowDefaultServiceException())
536         {
537             fullyQualifiedName = new StringBuilder();
538             if (StringUtils.isNotBlank(this.getPackageName()))
539             {
540                 fullyQualifiedName.append(this.getPackageName());
541                 fullyQualifiedName.append('.');
542             }
543             fullyQualifiedName.append(this.getDefaultExceptionName());
544         }
545         return fullyQualifiedName.toString();
546     }
547 
548     /**
549      * @return getConfiguredProperty(SpringGlobals.DEFAULT_SERVICE_EXCEPTIONS)
550      * @see org.andromda.cartridges.spring.metafacades.SpringService#isAllowDefaultServiceException()
551      */
552     protected boolean handleIsAllowDefaultServiceException()
553     {
554         return Boolean.valueOf(String.valueOf(this.getConfiguredProperty(SpringGlobals.DEFAULT_SERVICE_EXCEPTIONS))).booleanValue();
555     }
556 
557     /**
558      * @return getRemotingType().equalsIgnoreCase(SpringGlobals.REMOTING_PROTOCOL_RMI)
559      * @see org.andromda.cartridges.spring.metafacades.SpringService#isRemotingTypeRmi()
560      */
561     protected boolean handleIsRemotingTypeRmi()
562     {
563         return SpringGlobals.REMOTING_PROTOCOL_RMI.equalsIgnoreCase(this.getRemotingType());
564     }
565 
566     /**
567      * @return getRemotingType().equalsIgnoreCase(SpringGlobals.REMOTING_PROTOCOL_BURLAP)
568      * @see org.andromda.cartridges.spring.metafacades.SpringService#isRemotingTypeBurlap()
569      */
570     protected boolean handleIsRemotingTypeBurlap()
571     {
572         return SpringGlobals.REMOTING_PROTOCOL_BURLAP.equalsIgnoreCase(this.getRemotingType());
573     }
574 
575     /**
576      * @return getRemotingType().equalsIgnoreCase(SpringGlobals.REMOTING_PROTOCOL_HESSIAN)
577      * @see org.andromda.cartridges.spring.metafacades.SpringService#isRemotingTypeHessian()
578      */
579     protected boolean handleIsRemotingTypeHessian()
580     {
581         return SpringGlobals.REMOTING_PROTOCOL_HESSIAN.equalsIgnoreCase(this.getRemotingType());
582     }
583 
584     /**
585      * @return getRemotingType().equalsIgnoreCase(SpringGlobals.REMOTING_PROTOCOL_HTTPINVOKER)
586      * @see org.andromda.cartridges.spring.metafacades.SpringService#isRemotingTypeHttpInvoker()
587      */
588     protected boolean handleIsRemotingTypeHttpInvoker()
589     {
590         return SpringGlobals.REMOTING_PROTOCOL_HTTPINVOKER.equalsIgnoreCase(this.getRemotingType());
591     }
592 
593     /**
594      * @return getRemotingType().equalsIgnoreCase(SpringGlobals.REMOTING_PROTOCOL_LINGO)
595      * @see org.andromda.cartridges.spring.metafacades.SpringService#isRemotingTypeLingo()
596      */
597     protected boolean handleIsRemotingTypeLingo()
598     {
599         return SpringGlobals.REMOTING_PROTOCOL_LINGO.equalsIgnoreCase(this.getRemotingType());
600     }
601 
602     /**
603      * @return getRemotingType().equalsIgnoreCase(SpringGlobals.REMOTING_PROTOCOL_NONE)
604      * @see org.andromda.cartridges.spring.metafacades.SpringService#isRemotingTypeNone()
605      */
606     protected boolean handleIsRemotingTypeNone()
607     {
608         return SpringGlobals.REMOTING_PROTOCOL_NONE.equalsIgnoreCase(this.getRemotingType());
609     }
610 
611     /**
612      * Stores the namespace property indicating whether or not the hibernate
613      * interceptor is enabled for this service.
614      */
615     private static final String HIBERNATE_INTERCEPTOR_ENABLED = "serviceHibernateInterceptorEnabled";
616 
617     /**
618      * @return getConfiguredProperty(HIBERNATE_INTERCEPTOR_ENABLED)
619      * @see org.andromda.cartridges.spring.metafacades.SpringService#isHibernateInterceptorEnabled()
620      */
621     protected boolean handleIsHibernateInterceptorEnabled()
622     {
623         return Boolean.valueOf(String.valueOf(this.getConfiguredProperty(HIBERNATE_INTERCEPTOR_ENABLED))).booleanValue();
624     }
625 
626     /**
627      * Stores the view type for an EJB service.
628      */
629     private static final String EJB_VIEW_TYPE = "ejbViewType";
630 
631     /**
632      * Gets the view for this service (if wrapped by an EJB).
633      */
634     private String getEjbViewType()
635     {
636         Object value = this.findTaggedValue(SpringProfile.TAGGEDVALUE_EJB_VIEW_TYPE);
637         if (value == null)
638         {
639             value = this.getConfiguredProperty(EJB_VIEW_TYPE);
640         }
641         return ObjectUtils.toString(value);
642     }
643 
644     /**
645      * The three EJB view type values.
646      */
647     private static final String EJB_REMOTE_VIEW = "remote";
648     private static final String EJB_LOCAL_VIEW = "local";
649     private static final String EJB_BOTH_VIEW = "both";
650 
651     /**
652      * @return getEjbViewType().equalsIgnoreCase(EJB_REMOTE_VIEW) || EJB_BOTH_VIEW
653      * @see org.andromda.cartridges.spring.metafacades.SpringService#isEjbRemoteView()
654      */
655     protected boolean handleIsEjbRemoteView()
656     {
657         return (EJB_REMOTE_VIEW.equalsIgnoreCase(this.getEjbViewType())
658                 || EJB_BOTH_VIEW.equalsIgnoreCase(this.getEjbViewType()));
659     }
660 
661     /**
662      * @return getEjbViewType().equalsIgnoreCase(EJB_LOCAL_VIEW) || EJB_BOTH_VIEW
663      * @see org.andromda.cartridges.spring.metafacades.SpringService#isEjbLocalView()
664      */
665     protected boolean handleIsEjbLocalView()
666     {
667         return (EJB_LOCAL_VIEW.equalsIgnoreCase(this.getEjbViewType())
668                 || EJB_BOTH_VIEW.equalsIgnoreCase(this.getEjbViewType()));
669     }
670 
671     /**
672      * @return EjbTransactionType "Container" or "Bean"
673      * @see org.andromda.cartridges.spring.metafacades.SpringService#getEjbTransactionType()
674      */
675     protected String handleGetEjbTransactionType()
676     {
677         String transactionType = null;
678         final boolean ejbTransactionsEnabled =
679             BooleanUtils.toBoolean(
680                 ObjectUtils.toString(this.getConfiguredProperty(SpringGlobals.EJB_TRANSACTIONS_ENABLED)));
681         if (ejbTransactionsEnabled)
682         {
683             transactionType = "Container";
684         }
685         else
686         {
687             transactionType = "Bean";
688         }
689         return transactionType;
690     }
691 
692     /**
693      * @see org.andromda.cartridges.spring.metafacades.SpringServiceLogic#handleIsConfigonly()
694      */
695     protected boolean handleIsConfigonly()
696     {
697         String value = (String)this.findTaggedValue(SpringProfile.TAGGEDVALUE_SERVICE_CONFIG_ONLY);
698         return BooleanUtils.toBoolean(StringUtils.trimToEmpty(value));
699     }
700 
701     /**
702      * @see org.andromda.cartridges.spring.metafacades.SpringServiceLogic#handleIsPrivate()
703      */
704     protected boolean handleIsPrivate()
705     {
706         String value = (String)this.findTaggedValue(SpringProfile.TAGGEDVALUE_SERVICE_PRIVATE);
707         return BooleanUtils.toBoolean(StringUtils.trimToEmpty(value));
708     }
709 
710     /**
711      * @return getWebServiceAttachmentHandlerCall(SpringGlobals.WEBSERVICE_OUTGOING_ATTACHMENT_HANDLER_CALL_PATTERN)
712      * @see org.andromda.cartridges.spring.metafacades.SpringService#getWebServiceOutgoingAttachmentHandlerCall()
713      */
714     protected String handleGetWebServiceOutgoingAttachmentHandlerCall()
715     {
716         return this.getWebServiceAttachmentHandlerCall(SpringGlobals.WEBSERVICE_OUTGOING_ATTACHMENT_HANDLER_CALL_PATTERN);
717     }
718 
719     /**
720      * @return getWebServiceAttachmentHandlerCall(SpringGlobals.WEBSERVICE_INCOMING_ATTACHMENT_HANDLER_CALL_PATTERN)
721      * @see org.andromda.cartridges.spring.metafacades.SpringService#getWebServiceIncomingAttachmentHandlerCall()
722      */
723     protected String handleGetWebServiceIncomingAttachmentHandlerCall()
724     {
725         return this.getWebServiceAttachmentHandlerCall(SpringGlobals.WEBSERVICE_INCOMING_ATTACHMENT_HANDLER_CALL_PATTERN);
726     }
727 
728     /**
729      * Constructs the webservice attachment handler call or returns null if
730      * one isn't found or is not appropriate it for the service (i.e. it isn't
731      * a webservice).
732      *
733      * @param patternProperty the property defining the pattern type.
734      * @return the call value.
735      */
736     private String getWebServiceAttachmentHandlerCall(final String patternProperty)
737     {
738         String call = null;
739         if (this.isWebService())
740         {
741             final String value = ObjectUtils.toString(this.getConfiguredProperty(patternProperty));
742             if (StringUtils.isNotBlank(value))
743             {
744                 call = value;
745             }
746         }
747         return call;
748     }
749 
750     /**
751      * @return getConfiguredProperty(SpringGlobals.RICH_CLIENT).equalsIgnoreCase("true")
752      * @see org.andromda.cartridges.spring.metafacades.SpringService#isRichClient()
753      */
754     protected boolean handleIsRichClient()
755     {
756         final String richClient = StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(SpringGlobals.RICH_CLIENT)));
757         return "true".equalsIgnoreCase(richClient);
758     }
759 
760     /**
761      * {@inheritDoc}
762      */
763     protected String handleGetInitMethodName()
764     {
765         String result = "";
766         for (OperationFacade operation : getOperations())
767         {
768             if(((SpringServiceOperation)operation).isInitMethod())
769             {
770                 result = operation.getName();
771                 break;
772             }
773         }
774         return result;
775     }
776 
777     /**
778      * {@inheritDoc}
779      */
780     protected String handleGetDestroyMethodName()
781     {
782         String result = "";
783         for (OperationFacade operation : getOperations())
784         {
785             if(((SpringServiceOperation)operation).isDestroyMethod())
786             {
787                 result = operation.getName();
788                 break;
789             }
790         }
791         return result;
792     }
793 }