001package org.andromda.cartridges.jsf.metafacades;
002
003import java.util.ArrayList;
004import java.util.Iterator;
005import java.util.List;
006import org.andromda.cartridges.jsf.JSFGlobals;
007import org.andromda.cartridges.jsf.JSFUtils;
008import org.andromda.metafacades.uml.DependencyFacade;
009import org.andromda.metafacades.uml.FrontEndAction;
010import org.andromda.metafacades.uml.ModelElementFacade;
011import org.andromda.utils.StringUtilsHelper;
012import org.apache.commons.lang.ObjectUtils;
013import org.apache.commons.lang.StringUtils;
014
015/**
016 * MetafacadeLogic implementation for org.andromda.cartridges.jsf.metafacades.JSFController.
017 *
018 * @see org.andromda.cartridges.jsf.metafacades.JSFController
019 */
020public class JSFControllerLogicImpl
021    extends JSFControllerLogic
022{
023    private static final long serialVersionUID = 34L;
024    /**
025     * @param metaObject
026     * @param context
027     */
028    public JSFControllerLogicImpl(Object metaObject, String context)
029    {
030        super(metaObject, context);
031    }
032
033    /**
034     * @return implementationName
035     * @see org.andromda.cartridges.jsf.metafacades.JSFController#getImplementationName()
036     */
037    protected String handleGetImplementationName()
038    {
039        final String pattern = ObjectUtils.toString(
040            this.getConfiguredProperty(JSFGlobals.CONTROLLER_IMPLEMENTATION_PATTERN));
041        return pattern.replaceFirst("\\{0\\}", StringUtils.capitalize(this.getName()));
042    }
043
044    /**
045     * @return fullyQualifiedImplementationName
046     * @see org.andromda.cartridges.jsf.metafacades.JSFController#getFullyQualifiedImplementationName()
047     */
048    protected String handleGetFullyQualifiedImplementationName()
049    {
050        final StringBuilder fullyQualifiedName = new StringBuilder();
051        final String packageName = this.getPackageName();
052        if (StringUtils.isNotBlank(packageName))
053        {
054            fullyQualifiedName.append(packageName + '.');
055        }
056        return fullyQualifiedName.append(this.getImplementationName()).toString();
057    }
058
059    /**
060     * @return getFullyQualifiedImplementationName().replace('.', '/')
061     * @see org.andromda.cartridges.jsf.metafacades.JSFController#getFullyQualifiedImplementationPath()
062     */
063    protected String handleGetFullyQualifiedImplementationPath()
064    {
065        return this.getFullyQualifiedImplementationName().replace('.', '/');
066    }
067
068    /**
069     * @return StringUtilsHelper.lowerCamelCaseName(this.getName())
070     * @see org.andromda.cartridges.jsf.metafacades.JSFController#getBeanName()
071     */
072    protected String handleGetBeanName()
073    {
074        return StringUtilsHelper.lowerCamelCaseName(this.getName());
075    }
076
077    /**
078     * @return references
079     * @see org.andromda.cartridges.jsf.metafacades.JSFController#getSessionObjectReferences()
080     */
081    protected List<DependencyFacade> handleGetSessionObjectReferences()
082    {
083        final List<DependencyFacade> references = new ArrayList<DependencyFacade>(this.getSourceDependencies());
084        for (final Iterator<DependencyFacade> iterator = references.iterator(); iterator.hasNext();)
085        {
086            final ModelElementFacade targetElement = (iterator.next()).getTargetElement();
087            if (!(targetElement instanceof JSFSessionObject))
088            {
089                iterator.remove();
090            }
091        }
092        return references;
093    }
094
095    /**
096     * @return controllerSerialVersionUID
097     * @see org.andromda.cartridges.jsf.metafacades.JSFController#getControllerSerialVersionUID()
098     */
099    protected String handleGetControllerSerialVersionUID()
100    {
101       final StringBuilder buffer = new StringBuilder();
102       buffer.append(this.getFullyQualifiedImplementationName());
103       addSerialUIDData(buffer);
104       return JSFUtils.calcSerialVersionUID(buffer);
105    }
106
107    private void addSerialUIDData(StringBuilder buffer)
108    {
109        for (final FrontEndAction action : this.getUseCase().getActions())
110        {
111            buffer.append(action.getName());
112        }
113    }
114}