1
2
3
4
5
6
7
8
9
10 package com.sri.emo.commandline.defaults;
11
12 import com.jcorporate.expresso.core.db.DBException;
13 import com.sri.emo.dbobj.Node;
14 import com.sri.emo.dbobj.WizDefinition;
15
16 /***
17 * Thrown when a wizard requires the use of a Node that has not been
18 * tagged for export.
19 * @author Michael Rimov
20 */
21 public class DependentNodesNotTaggedException extends Exception {
22
23
24 /***
25 * Serial UUID.
26 */
27 private static final long serialVersionUID = -6216247675626775425L;
28
29 private Node[] multipleNodes = null;
30
31 private WizDefinition wizardDefinition = null;
32
33 private Node singleDependentnode = null;
34
35 /***
36 * @param arg0
37 */
38 public DependentNodesNotTaggedException(final WizDefinition wizardDefinition, final Node dependentNode) {
39 super(DependentNodesNotTaggedException.constructMessage(wizardDefinition, dependentNode));
40 singleDependentnode = dependentNode;
41 }
42
43 public DependentNodesNotTaggedException(final WizDefinition wizardDefinition, final Node[] missingNodes) {
44 super();
45 this.multipleNodes = missingNodes;
46 this.wizardDefinition = wizardDefinition;
47 }
48
49
50 public Node getSingleDependentNode() {
51 return singleDependentnode;
52 }
53
54
55
56 public String getMessage() {
57 if (multipleNodes == null) {
58 return super.getMessage();
59 }
60
61 StringBuffer message = new StringBuffer();
62 for (int i = 0; i < multipleNodes.length; i++) {
63 message.append(constructMessage(this.wizardDefinition, multipleNodes[i]));
64 message.append('\n');
65 }
66
67 return message.toString();
68 }
69
70 /***
71 * Constructs a node error message.
72 * @param wizardDefinition
73 * @param dependentNode
74 * @return
75 */
76 private static String constructMessage(final WizDefinition wizardDefinition, final Node dependentNode) {
77 try {
78 return "The wizard id "
79 + ((wizardDefinition != null) ? wizardDefinition.getId() : " [error: null wizard definition]")
80 + " has a node that it depends on that has not been marked for export. "
81 + " Dependent Node ID is: "
82 + (dependentNode != null ? dependentNode.getNodeId() + "\n\t you can edit the node at /do/AddNodeAction?state=viewNode&NODE_ID="
83 + dependentNode.getNodeId() : "[error: null dependent node]"
84 );
85 } catch (DBException e) {
86 throw new RuntimeException("Fatal error, unable to get IDs for wizard definition " + wizardDefinition + " and dependent node " + dependentNode);
87 }
88 }
89
90
91
92
93 }