01: package org.drools.repository;
02:
03: import javax.jcr.Node;
04:
05: import org.apache.log4j.Logger;
06:
07: /**
08: * The StateItem represents the status of an asset.
09: * An asset can only be in 1 state at a time. Kind of for workflow.
10: *
11: *
12: * @author btruitt
13: */
14: public class StateItem extends Item {
15:
16: private Logger log = Logger.getLogger(StateItem.class);
17:
18: /**
19: * All assets when created, or a new version saved, have a status of Draft.
20: */
21: public static String DRAFT_STATE_NAME = "Draft";
22:
23: /**
24: * The name of the state node type
25: */
26: public static final String STATE_NODE_TYPE_NAME = "drools:stateNodeType";
27:
28: /**
29: * Constructs an object of type StateItem corresponding the specified node
30: *
31: * @param rulesRepository the rulesRepository that instantiated this object
32: * @param node the node to which this object corresponds
33: * @throws RulesRepositoryException
34: */
35: public StateItem(RulesRepository rulesRepository, Node node)
36: throws RulesRepositoryException {
37: super (rulesRepository, node);
38:
39: try {
40: //make sure this node is a state node
41: if (!(this .node.getPrimaryNodeType().getName()
42: .equals(STATE_NODE_TYPE_NAME))) {
43: String message = this .node.getName()
44: + " is not a node of type "
45: + STATE_NODE_TYPE_NAME
46: + ". It is a node of type: "
47: + this .node.getPrimaryNodeType().getName();
48: log.error(message);
49: throw new RulesRepositoryException(message);
50: }
51: } catch (Exception e) {
52: log.error("Caught exception: " + e);
53: throw new RulesRepositoryException(e);
54: }
55: }
56:
57: public boolean equals(Object in) {
58: if (!(in instanceof StateItem)) {
59: return false;
60: } else if (in == this ) {
61: return true;
62: } else if (in == null) {
63: return false;
64: } else {
65: StateItem other = (StateItem) in;
66: return this .getName().equals(other.getName());
67: }
68: }
69:
70: public String toString() {
71: return "Current status: [" + getName() + "] ("
72: + super .toString() + ")";
73: }
74:
75: public int hashCode() {
76: return getName().hashCode();
77: }
78: }
|