View Javadoc
1 package com.bonevich.erj.model; 2 3 import com.bonevich.util.dependency.Dynamic; 4 import com.bonevich.java.util.ImmutableIterator; 5 import java.util.*; 6 7 /*** A class that represents ... 8 * 9 * @see Relation 10 * @see UniqueKey 11 * @see PrimaryKey 12 * @see ForeignKey 13 * @author Jeffrey D. Bonevich <bonevich@telocity.com> 14 */ 15 public abstract class KeyConstraint extends ModelElement 16 { 17 ////////////////////////////////////////////////////////// 18 // Constants 19 public static final String EMPTY_STR = ""; 20 21 ////////////////////////////////////////////////////////// 22 // Attributes 23 { 24 _name = EMPTY_STR; 25 _description = EMPTY_STR; 26 } 27 28 ////////////////////////////////////////////////////////// 29 // Associations 30 protected Relation _relation; 31 protected List _attributes = new LinkedList(); 32 33 ////////////////////////////////////////////////////////// 34 // Constructors 35 public KeyConstraint(Relation relation, Attribute[] attributes) 36 { 37 _relation = relation; 38 for (int i = 0; i < attributes.length; i++) 39 { 40 addAttribute(attributes[i]); 41 } 42 } 43 44 ////////////////////////////////////////////////////////// 45 // Getter/Setters 46 public Relation getRelation() 47 { 48 return _relation; 49 } 50 51 ////////////////////////////////////////////////////////// 52 // Operations 53 public void addAttribute(Attribute attribute) 54 { 55 if (!_attributes.contains(attribute)) 56 { 57 _attributes.add(attribute); 58 attribute.addKey(this); 59 } 60 } 61 public Iterator getAttributeIterator() 62 { 63 return new ImmutableIterator(_attributes.iterator()); 64 } 65 66 public void dispose() 67 { 68 // inform the attributes they no longer are a member of this key 69 Iterator attrs = getAttributeIterator(); 70 while (attrs.hasNext()) 71 { 72 Attribute attr = (Attribute) attrs.next(); 73 attr.removeKey(this); 74 } 75 } 76 77 public boolean equals(Object rhs) 78 { 79 if (rhs != null && rhs instanceof KeyConstraint) 80 { 81 KeyConstraint that = (KeyConstraint)rhs; 82 if (getRelation() == that.getRelation() && 83 that.getIdentifier().equals(getIdentifier()) 84 ) 85 { 86 return true; 87 } 88 } 89 return false; 90 } 91 92 public void accept(ModelElementVisitor visitor) 93 { 94 visitor.visitKey(this); 95 } 96 97 public abstract void accept(KeyVisitor visitor); 98 99 } /* end class KeyConstraint */

This page was automatically generated by Maven