001package org.andromda.cartridges.spring.metafacades;
002
003import java.text.MessageFormat;
004import java.util.Arrays;
005import java.util.Collection;
006import java.util.List;
007import org.andromda.cartridges.spring.SpringProfile;
008import org.andromda.metafacades.uml.ClassifierFacade;
009import org.andromda.metafacades.uml.FilteredCollection;
010import org.andromda.metafacades.uml.OperationFacade;
011import org.andromda.metafacades.uml.UMLProfile;
012import org.apache.commons.collections.Closure;
013import org.apache.commons.collections.CollectionUtils;
014import org.apache.commons.lang.BooleanUtils;
015import org.apache.commons.lang.ObjectUtils;
016import org.apache.commons.lang.StringUtils;
017
018/**
019 * MetafacadeLogic implementation for
020 * org.andromda.cartridges.spring.metafacades.SpringService.
021 *
022 * @author Chad Brandon
023 * @author Peter Friese
024 * @author Jens Vagts
025 * @see org.andromda.cartridges.spring.metafacades.SpringService
026 */
027public class SpringServiceLogicImpl
028    extends SpringServiceLogic
029{
030    private static final long serialVersionUID = 34L;
031    /**
032     * Public constructor for SpringServiceLogicImpl
033     * @param metaObject
034     * @param context
035     * @see org.andromda.cartridges.spring.metafacades.SpringService
036     */
037    public SpringServiceLogicImpl(Object metaObject, String context)
038    {
039        super(metaObject, context);
040    }
041
042    /**
043     * @return EjbJndiName
044     * @see org.andromda.cartridges.spring.metafacades.SpringService#getEjbJndiName()
045     */
046    protected String handleGetEjbJndiName()
047    {
048        StringBuilder jndiName = new StringBuilder();
049        String jndiNamePrefix = StringUtils.trimToEmpty(this.getEjbJndiNamePrefix());
050        if (StringUtils.isNotBlank(jndiNamePrefix))
051        {
052            jndiName.append(jndiNamePrefix);
053            jndiName.append('/');
054        }
055        jndiName.append("ejb/");
056        jndiName.append(this.getFullyQualifiedName());
057        return jndiName.toString();
058    }
059
060    /**
061     * @return EjbJndiName
062     * @see org.andromda.cartridges.spring.metafacades.SpringService#getEjbLocalJndiName()
063     */
064    protected String handleGetEjbLocalJndiName()
065    {
066        StringBuilder jndiName = new StringBuilder();
067        String jndiNamePrefix = StringUtils.trimToEmpty(this.getEjbJndiNamePrefix());
068        if (StringUtils.isNotBlank(jndiNamePrefix))
069        {
070            jndiName.append(jndiNamePrefix);
071            jndiName.append('/');
072        }
073        jndiName.append("ejb/");
074        jndiName.append(SpringMetafacadeUtils.getFullyQualifiedName(
075                this.getPackageName(),
076                this.getName(),
077                (EJB_BOTH_VIEW.equalsIgnoreCase(this.getEjbViewType()) ? "Local" : null)));
078        return jndiName.toString();
079    }
080
081    /**
082     * @return getName() + SpringGlobals.EJB_IMPLEMENTATION_SUFFIX
083     * @see org.andromda.cartridges.spring.metafacades.SpringService#getEjbImplementationName()
084     */
085    protected String handleGetEjbImplementationName()
086    {
087        return this.getName() + SpringGlobals.EJB_IMPLEMENTATION_SUFFIX;
088    }
089
090    /**
091     * @return getName() + SpringGlobals.IMPLEMENTATION_SUFFIX
092     * @see org.andromda.cartridges.spring.metafacades.SpringService#getImplementationName()
093     */
094    protected String handleGetImplementationName()
095    {
096        return this.getName() + SpringGlobals.IMPLEMENTATION_SUFFIX;
097    }
098
099    /**
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}