001package org.andromda.cartridges.spring.metafacades;
002
003import java.util.ArrayList;
004import java.util.Collection;
005
006import org.andromda.metafacades.uml.ParameterFacade;
007import org.apache.commons.lang.StringUtils;
008
009import org.andromda.cartridges.spring.SpringProfile;
010
011/**
012 * MetafacadeLogic implementation for org.andromda.cartridges.spring.metafacades.SpringEntityOperation.
013 *
014 * @see org.andromda.cartridges.spring.metafacades.SpringEntityOperation
015 */
016public class SpringEntityOperationLogicImpl
017        extends SpringEntityOperationLogic
018{
019    private static final long serialVersionUID = 34L;
020    /**
021     * Public constructor for SpringEntityOperationLogicImpl
022     * @param metaObject
023     * @param context
024     * @see org.andromda.cartridges.spring.metafacades.SpringEntityOperation
025     */
026    public SpringEntityOperationLogicImpl(Object metaObject, String context)
027    {
028        super(metaObject, context);
029    }
030
031    /**
032     * @return getImplementationOperationName(StringUtils.capitalize(this.getName()))
033     * @see org.andromda.cartridges.spring.metafacades.SpringEntityOperation#getImplementationName()
034     */
035    protected String handleGetImplementationName()
036    {
037        return this.getImplementationOperationName(StringUtils.capitalize(this.getName()));
038    }
039
040    /**
041     * @return getImplementationOperationName(StringUtils.capitalize(this.getCall()))
042     * @see org.andromda.cartridges.spring.metafacades.SpringEntityOperation#getImplementationCall()
043     */
044    protected String handleGetImplementationCall()
045    {
046        return this.getImplementationOperationName(StringUtils.capitalize(this.getCall()));
047    }
048
049    /**
050     * @return getImplementationOperationName(StringUtils.capitalize(this.getSignature()))
051     * @see org.andromda.cartridges.spring.metafacades.SpringEntityOperation#getImplementationSignature()
052     */
053    protected String handleGetImplementationSignature()
054    {
055        return this.getImplementationOperationName(StringUtils.capitalize(this.getSignature()));
056    }
057
058    /**
059     * Retrieves the implementationOperatName by replacing the <code>replacement</code> in the {@link
060     * SpringGlobals#IMPLEMENTATION_OPERATION_NAME_PATTERN}
061     *
062     * @param replacement the replacement string for the pattern.
063     * @return the operation name
064     */
065    private String getImplementationOperationName(String replacement)
066    {
067        return StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(
068                SpringGlobals.IMPLEMENTATION_OPERATION_NAME_PATTERN))).replaceAll("\\{0\\}", replacement);
069    }
070
071    /**
072     * @return getArguments().getType()
073     * @see org.andromda.cartridges.spring.metafacades.SpringEntityOperation#getImplementationCall()
074     */
075    protected Collection<SpringCriteriaAttributeLogic> handleGetArguments()
076    {
077        Collection<SpringCriteriaAttributeLogic> arguments = new ArrayList<SpringCriteriaAttributeLogic>();
078        for (ParameterFacade parameter : this.getArguments())
079        {
080            arguments.add((SpringCriteriaAttributeLogic)parameter.getType());
081        }
082        return arguments;
083    }
084
085    /**
086     * @see org.andromda.cartridges.spring.metafacades.SpringEntityOperation#isPrePersist()
087     */
088    @Override
089    protected boolean handleIsPrePersist()
090    {
091        return this.hasStereotype(SpringProfile.STEREOTYPE_PRE_PERSIST);
092    }
093
094    /**
095     * @see org.andromda.cartridges.spring.metafacades.SpringEntityOperation#isPostPersist()
096     */
097    @Override
098    protected boolean handleIsPostPersist()
099    {
100        return this.hasStereotype(SpringProfile.STEREOTYPE_POST_PERSIST);
101    }
102
103    /**
104     * @see org.andromda.cartridges.spring.metafacades.SpringEntityOperation#isPreRemove()
105     */
106    @Override
107    protected boolean handleIsPreRemove()
108    {
109        return this.hasStereotype(SpringProfile.STEREOTYPE_PRE_REMOVE);
110    }
111
112    /**
113     * @see org.andromda.cartridges.spring.metafacades.SpringEntityOperation#isPostRemove()
114     */
115    @Override
116    protected boolean handleIsPostRemove()
117    {
118        return this.hasStereotype(SpringProfile.STEREOTYPE_POST_REMOVE);
119    }
120
121    /**
122     * @see org.andromda.cartridges.spring.metafacades.SpringEntityOperation#isPreUpdate()
123     */
124    @Override
125    protected boolean handleIsPreUpdate()
126    {
127        return this.hasStereotype(SpringProfile.STEREOTYPE_PRE_UPDATE);
128    }
129
130    /**
131     * @see org.andromda.cartridges.spring.metafacades.SpringEntityOperation#isPostUpdate()
132     */
133    @Override
134    protected boolean handleIsPostUpdate()
135    {
136        return this.hasStereotype(SpringProfile.STEREOTYPE_POST_UPDATE);
137    }
138}