1 package org.kite9.diagram.builders;
2
3 import org.kite9.framework.alias.AliasEnabled;
4
5 /***
6 * Models the relationship between a subject and an object. e.g. has, uses, etc.
7 *
8 * @author moffatr
9 *
10 */
11 public class Relationship implements AliasEnabled {
12
13 enum RelationshipType {
14 ACTIVE, PASSIVE, BIDIRECTIONAL
15 };
16
17
18 public static final Relationship RETURNS = new Relationship("returns");
19 public static final Relationship EXTENDS = new Relationship("extends");
20 public static final Relationship IMPLEMENTS = new Relationship("implements");
21 public static final Relationship CALLS = new Relationship("calls");
22
23
24 public static final Relationship RETURNED_BY = new Relationship("returned by", RETURNS);
25 public static final Relationship EXTENDED_BY = new Relationship("extended by", EXTENDS);
26 public static final Relationship IMPLEMENTED_BY = new Relationship("implemented by", IMPLEMENTS);
27 public static final Relationship CALLED_BY = new Relationship("called by", CALLS);
28
29 RelationshipType type = RelationshipType.ACTIVE;
30
31 /***
32 * Creates the active voice relationship
33 */
34 public Relationship(String name) {
35 super();
36 this.name = name;
37 this.type = RelationshipType.ACTIVE;
38 }
39
40 /***
41 * Creates a passive voice relationship. Note that when a builder comes to render
42 * the relationship on the diagram, it will be converted to the active voice.
43 */
44 public Relationship(String name, Relationship active) {
45 super();
46 this.name = name;
47 this.type = RelationshipType.PASSIVE;
48 this.activeRelationship = active;
49 }
50
51 protected Relationship activeRelationship;
52
53 private String name;
54
55 public String getName() {
56 return name;
57 }
58
59 public Object getObjectForAlias() {
60 return name;
61 }
62
63 public Relationship getActiveRelationship() {
64 if (type == RelationshipType.ACTIVE) {
65 return this;
66 }
67
68 return activeRelationship;
69 }
70
71 public RelationshipType getType() {
72 return type;
73 }
74
75 }