1 22 23 package org.xquark.schema; 24 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 48 public class IdentityConstraint extends SchemaComponent { 49 private static final String RCSRevision = "$Revision: 1.1 $"; 50 private static final String RCSName = "$Name: $"; 51 52 public static final int CATEGORY_KEY = 0; 54 public static final int CATEGORY_KEYREF = 1; 55 public static final int CATEGORY_UNIQUE = 2; 56 57 private int category; 59 private List selector = null; 60 private ArrayList fields = null; 61 private IdentityConstraint referencedKey = null; private ElementDeclaration contextDecl; 63 64 72 public IdentityConstraint(Schema schema, String name, int category, ElementDeclaration contextDecl) { 73 super(schema, name); 74 this.category = category; 75 this.contextDecl = contextDecl; 76 } 77 78 public IdentityConstraint(Schema schema, String name, ElementDeclaration contextDecl) { 79 this(schema, name, CATEGORY_UNIQUE, contextDecl); 80 } 81 82 public void accept(SchemaVisitor visitor) throws SchemaException { 83 visitor.visit(this); 84 } 85 86 91 public int getCategory() { 92 return this.category; 93 } 94 public void setCategory(int category) { 95 this.category = category; 96 } 97 98 103 public ElementDeclaration getContextDeclaration() { 104 return this.contextDecl; 105 } 106 107 112 public List getSelector() { 113 return this.selector; 114 } 115 public void setSelector(List selector) { 116 this.selector = selector; 117 } 118 119 124 public IdentityConstraint getReferencedKey() { 125 return referencedKey; 126 } 127 public void setReferencedKey(IdentityConstraint refer) { 128 this.referencedKey = refer; 129 } 130 131 137 public ArrayList getFields() { 138 return this.fields; 139 } 140 public void addField(List field) { 141 if (fields == null) 142 fields = new ArrayList (); 143 fields.add(field); 144 } 145 public void deleteFields() { 146 fields.clear(); 147 } 148 149 public boolean isEqualToKeyRefFields() { 150 if ( this.category == CATEGORY_KEYREF ) { 151 if ( this.fields != null && referencedKey != null && referencedKey.fields != null 152 && this.fields.size() == referencedKey.fields.size() ) 153 return true; 154 else 155 return false; 156 } 157 else 158 return true; 159 } 160 161 } 162 | Popular Tags |