001package org.andromda.cartridges.ejb.metafacades;
002
003import java.text.MessageFormat;
004import java.util.StringTokenizer;
005import org.andromda.cartridges.ejb.EJBProfile;
006import org.andromda.metafacades.uml.GeneralizableElementFacade;
007import org.apache.commons.lang.StringUtils;
008
009/**
010 * MetafacadeLogic implementation for org.andromda.cartridges.ejb.metafacades.ValueObjectFacade.
011 *
012 * @see org.andromda.cartridges.ejb.metafacades.ValueObjectFacade
013 */
014public class ValueObjectFacadeLogicImpl
015    extends ValueObjectFacadeLogic
016{
017    private static final long serialVersionUID = 34L;
018    // ---------------- constructor -------------------------------
019    /**
020     * @param metaObject
021     * @param context
022     */
023    public ValueObjectFacadeLogicImpl(
024        Object metaObject,
025        String context)
026    {
027        super(metaObject, context);
028    }
029
030    /**
031     * Using <code>/</code> in the configuredProperty <code>valueObjectPackage</code> can remove the previous package
032     * name.
033     *
034     * @see org.andromda.cartridges.ejb.metafacades.ValueObjectFacade#getPackageName()
035     */
036    public String getPackageName()
037    {
038        final String packageName =
039            MessageFormat.format(
040                this.getConfiguredProperty("valueObjectPackage").toString(),
041                StringUtils.trimToEmpty(super.getPackageName()));
042        StringBuilder buffer = new StringBuilder();
043        for (final StringTokenizer tokenizer = new StringTokenizer(packageName, "."); tokenizer.hasMoreTokens();)
044        {
045            String token = tokenizer.nextToken();
046            if (token.indexOf('/') < 0)
047            {
048                buffer.append(token).append('.');
049            }
050        }
051        final String name = buffer.toString();
052        return name.endsWith(".") ? name.substring(0, name.length() - 1) : name;
053    }
054
055    /**
056     * @see org.andromda.cartridges.ejb.metafacades.ValueObjectFacade#getName()
057     */
058    public String getName()
059    {
060        return MessageFormat.format(
061            this.getConfiguredProperty("valueObjectName").toString(),
062                StringUtils.trimToEmpty(super.getName()));
063    }
064
065    /**
066     * @see org.andromda.metafacades.uml.ModelElementFacade#getFullyQualifiedName()
067     */
068    public String getFullyQualifiedName()
069    {
070        final String name = this.getPackageName();
071        return name == null || "".equalsIgnoreCase(name) ? getName() : name + '.' + getName();
072    }
073
074    /**
075     * If we're using inheritance to build up a value object with all model elements of an entity, we're returning no
076     * superclass.
077     * @return super.getGeneralization() if generalization.hasStereotype(EJBProfile.STEREOTYPE_ENTITY)
078     */
079    public GeneralizableElementFacade getGeneralization()
080    {
081        GeneralizableElementFacade generalization = super.getGeneralization();
082        return generalization == null || generalization.hasStereotype(EJBProfile.STEREOTYPE_ENTITY) ? null
083                                                                                                    : generalization;
084    }
085}