1 /*
2 * Zemucan: A Syntax Assistant for DB2
3 * Copyright (C) 2009, 2010 Andres Gomez Casanova
4 *
5 * This file is part of Zemucan.
6 *
7 * Zemucan is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * Zemucan is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, see <http://www.gnu.org/licenses/>.
19 *
20 * Contact:
21 * a n g o c a at y a h o o dot c o m
22 * Cra. 45 No 61 - 31, Bogota, Colombia.
23 *
24 * Author: $LastChangedBy: angoca $:
25 * Date: $LastChangedDate: 2011-03-06 09:19:05 -0500 (dom, 06 mar 2011) $:
26 * Revision: $LastChangedRevision: 1910 $:
27 * URL: $HeadURL: https://zemucan.svn.sourceforge.net/svnroot/zemucan/branches/zemucan_v1/source-code/graph/src/main/java/name/angoca/zemucan/core/graph/model/InvalidGraphStateException.java $:
28 */
29 package name.angoca.zemucan.core.graph.model;
30
31 import name.angoca.zemucan.tools.messages.Messages;
32
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 /**
37 * Exception that represents an invalid state in the graph. This is thrown when
38 * trying to retrieve something from the graph, when the graph is still under
39 * construction or it has not been validated.
40 * <p>
41 * <b>Control Version</b>
42 * <p>
43 * <ul>
44 * <li>1.0.0 Class creation.</li>
45 * </ul>
46 *
47 * @author Andres Gomez Casanova <a
48 * href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a>
49 * @version 1.0.0 2009-11-07
50 */
51 public class InvalidGraphStateException extends AbstractGraphException {
52
53 /**
54 * Logger.
55 */
56 private static final Logger LOGGER = LoggerFactory
57 .getLogger(InvalidGraphStateException.class);
58 /**
59 * Generated ID.
60 */
61 private static final long serialVersionUID = -5012308231732620846L;
62 /**
63 * Flag to determine if the first phase of the graph has been finished.
64 */
65 private final GraphState currentGraphState;
66 /**
67 * The needed Graph State in order to execute the method.
68 */
69 private final GraphState requieredGraphState;
70
71 /**
72 * Constructor with the flag that determines the graph state.
73 *
74 * @param excepCurrentGraphState
75 * Current state of the graph.
76 * @param requiredGraphState
77 * The required graph state in order to call the method.
78 */
79 public InvalidGraphStateException(
80 final GraphState/* ! */excepCurrentGraphState,
81 final GraphState/* ! */requiredGraphState) {
82 super();
83 assert requiredGraphState != null;
84 assert excepCurrentGraphState != null;
85
86 this.currentGraphState = excepCurrentGraphState;
87 this.requieredGraphState = requiredGraphState;
88 InvalidGraphStateException.LOGGER
89 .debug(InvalidGraphStateException.class.getName() + " created."); //$NON-NLS-1$
90 }
91
92 /**
93 * Retrieves the current state of the graph.
94 *
95 * @return The current state of the graph: FirstPhase, SecondPhase of
96 * Validated
97 */
98 public final GraphState/* ! */getCurrentGraphState() {
99 return this.currentGraphState;
100 }
101
102 /*
103 * (non-Javadoc)
104 * @see java.lang.Throwable#getMessage()
105 */
106 @Override
107 public final String getMessage() {
108 return Messages
109 .getString("InvalidGraphStateException.GRPH19-CurrentState") //$NON-NLS-1$
110 + this.currentGraphState
111 + Messages
112 .getString("InvalidGraphStateException.GRPH19-NeededState") //$NON-NLS-1$
113 + this.requieredGraphState;
114 }
115
116 /**
117 * Retrieves the required state of the graph in order to execute the
118 * command.
119 *
120 * @return Required command.
121 */
122 public final GraphState getRequiredGraphState() {
123 return this.requieredGraphState;
124 }
125 }