RentalServiceBase.java

// license-header java merge-point
//
// Attention: Generated code! Do not modify by hand!
// Generated by: SpringServiceBase.vsl in andromda-spring-cartridge.
//
/**
 * TEMPLATE:    SpringServiceBase.vsl in andromda-spring cartridge
 * MODEL CLASS: SpringCartridge How to Model::Spring Example::org.andromda.test::RentalService
 * STEREOTYPE:  Service
 */
package org.andromda.test;

import java.security.Principal;
import java.util.Collection;
import java.util.Locale;
import org.andromda.spring.howto9.BeanLocator;
import org.andromda.spring.howto9.PrincipalStore;
import org.springframework.context.MessageSource;

/**
 * <p>
 * Spring Service base class for <code>RentalService</code>,
 * provides access to all services and entities referenced by this service.
 * </p>
 *
 * @see RentalService
 */
public abstract class RentalServiceBase
    implements RentalService
{
    /**
     * {@inheritDoc}
     */
    @Override
    public Collection<Car> getAllCars()
        throws RentalException
    {
        try
        {
            return this.handleGetAllCars();
        }
        catch (RentalException ex)
        {
            throw ex;
        }
        catch (Throwable th)
        {
            throw new RentalServiceException(
                "Error performing 'RentalService.getAllCars()' --> " + th,
                th);
        }
    }

    /**
     * Performs the core logic for {@link #getAllCars()}
     * @return Collection<Car>
     * @throws Exception
     */
    protected abstract Collection<Car> handleGetAllCars()
        throws Exception;

    /**
     * {@inheritDoc}
     */
    @Override
    public Collection<Person> getCustomersByName(final String name)
        throws RentalException
    {
        if (name == null || name.trim().length() == 0)
        {
            throw new IllegalArgumentException(
                "org.andromda.test.RentalService.getCustomersByName(String name) - 'name' can not be null or empty");
        }
        try
        {
            return this.handleGetCustomersByName(name);
        }
        catch (RentalException ex)
        {
            throw ex;
        }
        catch (Throwable th)
        {
            throw new RentalServiceException(
                "Error performing 'RentalService.getCustomersByName(String name)' --> " + th,
                th);
        }
    }

    /**
     * Performs the core logic for {@link #getCustomersByName(String)}
     * @param name String TODO: Model Documentation for RentalService.getCustomersByName(name)
     * @return Collection<Person>
     * @throws Exception
     */
    protected abstract Collection<Person> handleGetCustomersByName(String name)
        throws Exception;

    /**
     * Gets the current <code>principal</code> if one has been set,
     * otherwise returns <code>null</code>.
     *
     * @return the current principal
     */
    protected Principal getPrincipal()
    {
        return PrincipalStore.get();
    }

    /**
     * Gets the message source available to this service.
     * @return MessageSource
     */
    protected MessageSource getMessages()
    {
        return (MessageSource)
            BeanLocator.instance().getBean("messageSource");
    }

    /**
     * Gets the message having the given <code>key</code> in the underlying message bundle.
     *
     * @param key the key of the message in the messages.properties message bundle.
     * @return String
     */
    protected String getMessage(final String key)
    {
        return this.getMessages().getMessage(key, null, null);
    }

    /**
     * Gets the message having the given <code>key</code> and <code>arguments</code> in the
     * underlying message bundle.
     *
     * @param key the key of the message in the messages.properties message bundle.
     * @param arguments any arguments to substitute when resolving the message.
     * @return String
     */
    protected String getMessage(final String key, final Object[] arguments)
    {
        return this.getMessages().getMessage(key, arguments, null);
    }

    /**
     * Gets the message having the given <code>key</code> using the given <code>arguments</code>
     * for the given <code>locale</code>.
     *
     * @param key the key of the message in the messages.properties message bundle.
     * @param arguments any arguments to substitute when resolving the message.
     * @param locale the locale of the messages to retrieve.
     * @return String
     */
    protected String getMessage(
        final String key, final Object[] arguments,
        final Locale locale)
    {
        return this.getMessages().getMessage(key, arguments, locale);
    }

}