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 not registered with a {@link Registry}.
25   * 
26   * @author sanjin
27   */
28  public class NotRegisteredException extends ContextException {
29  
30      private static final long serialVersionUID = -1201899029354899147L;
31  
32      private static final int BUFFER_SIZE = 25;
33      private static final MessageFormat DETAIL_MESSAGE = new MessageFormat(
34              "{0} is not registered");
35  
36      private final String name;
37  
38      /**
39       * Create instance of not-registered exception with the specified name of
40       * not-registered {@link Object}. The cause is not initialized, and may
41       * subsequently be initialized by a call to {@link #initCause(Throwable)}.
42       * 
43       * @param name the name of not-registered {@link Object} (which is saved for
44       *        later retrieval by the {@link #getName()} method).
45       */
46      public NotRegisteredException(final String name) {
47          super(DETAIL_MESSAGE.format(new Object[]{ name },
48                  new StringBuffer(BUFFER_SIZE), null).toString());
49  
50          this.name = name;
51      }
52  
53      /**
54       * Returns the name of not-registered {@link Object}.
55       * 
56       * @return the name of not-registered {@link Object}.
57       */
58      public String getName() {
59          return this.name;
60      }
61  }