1
2
3
4 package net.sf.bddbddb;
5
6 import org.jdom.Element;
7
8 /***
9 * An Attribute represents a single attribute of a relation.
10 * Every Attribute has a name, a domain, and an optional option string.
11 *
12 * Attribute objects are globally unique --- there is exactly one Attribute
13 * object for every distinct attribute in the program.
14 *
15 * @author jwhaley
16 * @version $Id: Attribute.java 353 2004-10-27 19:21:05Z joewhaley $
17 */
18 public class Attribute {
19
20 /***
21 * Attribute name.
22 */
23 protected String attributeName;
24
25 /***
26 * Attribute domain.
27 */
28 protected Domain attributeDomain;
29
30 /***
31 * Attribute options.
32 */
33 protected String attributeOptions;
34
35 /***
36 * Relation that this attribute is associated with.
37 */
38 protected Relation relation;
39
40 /***
41 * Constructs a new Attribute object.
42 * This should only be called internally.
43 *
44 * @param name name of attribute
45 * @param domain domain of attribute
46 * @param options options for attribute
47 */
48 Attribute(String name, Domain domain, String options) {
49 this.attributeName = name;
50 this.attributeDomain = domain;
51 this.attributeOptions = options;
52 }
53
54
55
56
57
58
59 public String toString() {
60 return attributeName;
61 }
62
63 /***
64 * Returns the domain of this attribute.
65 *
66 * @return domain
67 */
68 public Domain getDomain() {
69 return attributeDomain;
70 }
71
72 /***
73 * Returns the options for this attribute.
74 *
75 * @return options
76 */
77 public String getOptions() {
78 return attributeOptions;
79 }
80
81 /***
82 * Sets the relation that this attribute is associated with.
83 * This should only be called internally.
84 *
85 * @param r
86 */
87 void setRelation(Relation r) {
88 this.relation = r;
89 }
90
91 /***
92 * Returns the relation that this attribute is associated with.
93 *
94 * @return options
95 */
96 public Relation getRelation() {
97 return relation;
98 }
99
100 public static Attribute fromXMLElement(Element e, XMLFactory f) {
101 String relationName = e.getAttributeValue("relation");
102 Relation r = f.getRelation(relationName);
103 String attribName = e.getAttributeValue("name");
104 return r.getAttribute(attribName);
105 }
106
107 public Element toXMLElement() {
108 Element e = new Element("attribute");
109 e.setAttribute("relation", relation.name);
110 e.setAttribute("name", attributeName);
111 return e;
112 }
113 }