1 package com.bonevich.erj.model;
2
3 import com.bonevich.util.dependency.Dynamic;
4 import java.util.*;
5
6 /*** A class that represents ...
7 *
8 * @see Attribute
9 * @author Jeffrey D. Bonevich <bonevich@telocity.com>
10 */
11 public final class Domain
12 extends ModelElement
13 implements AttributeType
14 {
15 //////////////////////////////////////////////////////////
16 // Constants
17 public static final String NEW_DOMAIN_STR = "domain_";
18 public static final String EMPTY_STR = "";
19
20 //////////////////////////////////////////////////////////
21 // Attributes
22 {
23 _name = EMPTY_STR;
24 _identifier = EMPTY_STR;
25 _description = EMPTY_STR;
26 }
27
28 //////////////////////////////////////////////////////////
29 // Associations
30 private Schema _schema;
31 private DataType _type = (DataType)DataType.SQL92_CHAR_VARYING.clone();
32 private DefaultValue _defaultValue = new DefaultValue();
33 private AttributeConstraint _defaultConstraint = AttributeConstraint.NULL;
34
35 /////////////////////////////////////////////////////////
36 // Dynamic Sentries
37 private Dynamic _dyn_type = new Dynamic();
38 private Dynamic _dyn_defaultValue = new Dynamic();
39 private Dynamic _dyn_defaultConstraint = new Dynamic();
40
41 //////////////////////////////////////////////////////////
42 // Constructors
43 public Domain(Schema schema)
44 {
45 _schema = schema;
46 setIdentifier(NEW_DOMAIN_STR + _schema.getDomainCount());
47 setName(getIdentifier());
48 }
49
50 //////////////////////////////////////////////////////////
51 // Getter/Setters
52 public Schema getSchema()
53 {
54 return _schema;
55 }
56
57 public DataType getDataType()
58 {
59 _dyn_type.onGet();
60 return _type;
61 }
62 public void setDataType(DataType type)
63 {
64 if (_type != type)
65 {
66 _dyn_type.onSet();
67 _type = type;
68 }
69 }
70
71 public DefaultValue getDefaultValue()
72 {
73 _dyn_defaultValue.onGet();
74 return _defaultValue;
75 }
76 public void setDefaultValue(DefaultValue defaultValue)
77 {
78 if (!_defaultValue.equals(defaultValue))
79 {
80 _dyn_defaultValue.onSet();
81 _defaultValue = defaultValue;
82 }
83 }
84
85 public AttributeConstraint getDefaultConstraint()
86 {
87 _dyn_defaultConstraint.onGet();
88 return _defaultConstraint;
89 }
90 public void setDefaultConstraint(AttributeConstraint defaultConstraint)
91 {
92 if (!_defaultConstraint.equals(defaultConstraint))
93 {
94 _dyn_defaultConstraint.onSet();
95 _defaultConstraint = defaultConstraint;
96 }
97 }
98
99 //////////////////////////////////////////////////////////
100 // Operations
101
102 /***
103 * Set the type of all attributes that were members of this
104 * Domain to the datatype of this domain.
105 */
106 public void dispose()
107 {
108 Iterator relations = _schema.getRelationIterator();
109 while (relations.hasNext())
110 {
111 Iterator attributes = ( (Relation)relations.next() ).getAttributeIterator();
112 while (attributes.hasNext())
113 {
114 Attribute attribute = (Attribute)attributes.next();
115 attribute.setType(getDataType());
116 }
117 }
118 }
119
120 public void accept(ModelElementVisitor visitor)
121 {
122 visitor.visitDomain(this);
123 }
124
125 } /* end class Domain */
This page was automatically generated by Maven