001/*
002 *  jDTAUS Banking API
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.banking;
022
023import java.util.Locale;
024import org.jdtaus.core.container.ContainerFactory;
025import org.jdtaus.core.text.Message;
026
027/**
028 * Gets thrown whenever an illegal Textschlüssel is passed to a method expecting a legal Textschlüssel.
029 * <p>Example: Catching an {@code IllegalTextschluesselException}<br/><blockquote><pre>
030 * catch(IllegalTextschluesselException e)
031 * {
032 *     if(e.getMessages().length > 0)
033 *     {
034 *         <i>Fetch messages for well-known properties first (optional).</i>
035 *         e.getMessages(Textschluessel.PROP_<i>XYZ</i>);
036 *         ...
037 *         <i>Fetch all remaining messages.</i>
038 *         e.getMessages();
039 *         ...
040 *     }
041 * }</pre></blockquote></p>
042 *
043 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
044 * @version $JDTAUS: IllegalTextschluesselException.java 8661 2012-09-27 11:29:58Z schulte $
045 */
046public abstract class IllegalTextschluesselException extends IllegalArgumentException
047{
048
049    /** Serial version UID for backwards compatibility with 1.1.x classes. */
050    private static final long serialVersionUID = 7472131429277078032L;
051
052    /** Creates a new {@code IllegalTextschluesselException} instance. */
053    public IllegalTextschluesselException()
054    {
055        super();
056    }
057
058    /**
059     * Gets all messages describing the exception.
060     *
061     * @return An array of messages describing the exception or an empty array if the instance does not hold any
062     * messages.
063     */
064    public abstract Message[] getMessages();
065
066    /**
067     * Gets messages bound to a property removing these messages from the instance.
068     *
069     * @param propertyName The name of a property to return any messages for.
070     *
071     * @return All messages bound to a property with name {@code propertyName} or an empty array if the instance does
072     * not hold messages for a property with name {@code propertyName}.
073     *
074     * @throws NullPointerException if {@code propertyName} is {@code null}.
075     */
076    public abstract Message[] getMessages( final String propertyName );
077
078    /**
079     * Gets the names of all properties for which the exception holds messages.
080     *
081     * @return An array of the names of all properties for which the exception holds messages or an empty array if the
082     * exception does not hold any message bound to a property.
083     */
084    public abstract String[] getPropertyNames();
085
086    /**
087     * Returns the message of the exception.
088     *
089     * @return The message of the exception.
090     */
091    public String getMessage()
092    {
093        return this.getIllegalTextschluesselMessage( this.getLocale() );
094    }
095
096    //--Dependencies------------------------------------------------------------
097
098// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausDependencies
099    // This section is managed by jdtaus-container-mojo.
100
101    /**
102     * Gets the configured <code>Locale</code> implementation.
103     *
104     * @return The configured <code>Locale</code> implementation.
105     */
106    private Locale getLocale()
107    {
108        return (Locale) ContainerFactory.getContainer().
109            getDependency( this, "Locale" );
110
111    }
112
113// </editor-fold>//GEN-END:jdtausDependencies
114
115    //------------------------------------------------------------Dependencies--
116    //--Messages----------------------------------------------------------------
117
118// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages
119    // This section is managed by jdtaus-container-mojo.
120
121    /**
122     * Gets the text of message <code>illegalTextschluessel</code>.
123     * <blockquote><pre>Ungültiger Textschlüssel.</pre></blockquote>
124     * <blockquote><pre>Illegal Textschlüssel.</pre></blockquote>
125     *
126     * @param locale The locale of the message instance to return.
127     *
128     * @return the text of message <code>illegalTextschluessel</code>.
129     */
130    private String getIllegalTextschluesselMessage( final Locale locale )
131    {
132        return ContainerFactory.getContainer().
133            getMessage( this, "illegalTextschluessel", locale, null );
134
135    }
136
137// </editor-fold>//GEN-END:jdtausMessages
138
139    //----------------------------------------------------------------Messages--
140}