View Javadoc

1   /* This file is part of COPAL (COntext Provisioning for All).
2    *
3    * COPAL is a part of SM4All (Smart hoMes for All) project.
4    *
5    * COPAL is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU Lesser General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * COPAL is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public License
16   * along with COPAL. If not, see <http://www.gnu.org/licenses/>.
17   */
18  package at.ac.tuwien.infosys.sm4all.copal.api.util;
19  
20  import java.text.MessageFormat;
21  import at.ac.tuwien.infosys.sm4all.copal.api.ContextException;
22  
23  /**
24   * Exception when an {@link Object} is already registered with a
25   * {@link Registry}
26   * 
27   * @author sanjin
28   */
29  public class AlreadyRegisteredException extends ContextException {
30  
31      private static final long serialVersionUID = 4212693685876994920L;
32  
33      private static final int BUFFER_SIZE = 30;
34      private static final MessageFormat DETAIL_MESSAGE = new MessageFormat(
35              "{0} is already registered");
36  
37      private final String name;
38  
39      /**
40       * Create instance of already-registered exception with the specified name
41       * of already-registered {@link Object}. The cause is not initialized, and
42       * may subsequently be initialized by a call to
43       * {@link #initCause(Throwable)}.
44       * 
45       * @param name the name of already-registered {@link Object} (which is saved
46       *        for later retrieval by the {@link #getName()} method).
47       */
48      public AlreadyRegisteredException(final String name) {
49          super(DETAIL_MESSAGE.format(new Object[]{ name },
50                  new StringBuffer(BUFFER_SIZE), null).toString());
51  
52          this.name = name;
53      }
54  
55      /**
56       * Returns the name of already-registered {@link Object}.
57       * 
58       * @return the name of already-registered {@link Object}.
59       */
60      public String getName() {
61          return this.name;
62      }
63  }