01: package org.apache.ojb.broker;
02:
03: /**
04: * GraphNode and GraphEdge model oriented graph with named nodes.
05: * In this case there are two relations between two classes.
06: * @author Oleg Nitz
07: */
08: public class GraphEdge implements java.io.Serializable {
09: private int id;
10: private int sourceId;
11: private int sinkId;
12: private GraphNode source;
13: private GraphNode sink;
14:
15: public GraphEdge() {
16: }
17:
18: public GraphEdge(int id, int sourceId, int sinkId) {
19: this .id = id;
20: this .sourceId = sourceId;
21: this .sinkId = sinkId;
22: }
23:
24: public GraphEdge(GraphNode source, GraphNode sink) {
25: source.addOutgoingEdge(this );
26: sink.addIncomingEdge(this );
27:
28: // how could it ever work without this:
29: this .source = source;
30: this .sourceId = source.getId();
31: this .sink = sink;
32: this .sinkId = sink.getId();
33:
34: }
35:
36: public int getSourceId() {
37: return sourceId;
38: }
39:
40: public int getSinkId() {
41: return sinkId;
42: }
43:
44: public GraphNode getSource() {
45: return source;
46: }
47:
48: public GraphNode getSink() {
49: return sink;
50: }
51:
52: public int getId() {
53: return id;
54: }
55:
56: public void setSourceId(int sourceId) {
57: this .sourceId = sourceId;
58: }
59:
60: public void setSinkId(int sinkId) {
61: this .sinkId = sinkId;
62: }
63:
64: public void setSource(GraphNode source) {
65: this .source = source;
66: }
67:
68: public void setSink(GraphNode sink) {
69: this .sink = sink;
70: }
71:
72: public void setId(int id) {
73: this .id = id;
74: }
75:
76: public String toString() {
77: return "("
78: + (source == null ? "null" : source.getName())
79: + " -> "
80: + (sink == null ? "null" : (sink == source ? sink
81: .getName() : sink.toString())) + ")";
82: }
83: }
|