1 10 package org.mmbase.storage.search.implementation; 11 12 import org.mmbase.module.corebuilders.InsRel; 13 import org.mmbase.module.core.MMObjectNode; 14 import org.mmbase.storage.search.*; 15 16 26 public class BasicRelationStep extends BasicStep implements RelationStep { 27 28 29 private boolean checkedDirectionality = false; 30 31 32 private int directionality = RelationStep.DIRECTIONS_BOTH; 33 34 35 private Integer role = null; 36 37 38 private Step previous = null; 39 40 41 private Step next = null; 42 43 51 BasicRelationStep(InsRel builder, Step previous, Step next) { 53 super(builder); 54 if (previous == null) { 55 throw new IllegalArgumentException ("Invalid previous value: " + previous); 56 } 57 this.previous = previous; 58 if (next == null) { 59 throw new IllegalArgumentException ("Invalid next value: " + next); 60 } 61 this.next = next; 62 } 63 64 71 public BasicRelationStep setCheckedDirectionality(boolean checkedDirectionality) { 72 this.checkedDirectionality = checkedDirectionality; 73 return this; 74 } 75 76 85 public BasicRelationStep setDirectionality(int directionality) { 86 if (directionality != RelationStep.DIRECTIONS_SOURCE 87 && directionality != RelationStep.DIRECTIONS_DESTINATION 88 && directionality != RelationStep.DIRECTIONS_BOTH 89 && directionality != RelationStep.DIRECTIONS_ALL 90 && directionality != RelationStep.DIRECTIONS_EITHER) { 91 throw new IllegalArgumentException ( 92 "Invalid directionality value: " + directionality); 93 } 94 this.directionality = directionality; 95 return this; 96 } 97 98 104 public BasicRelationStep setRole(Integer role) { 105 this.role = role; 106 return this; 107 } 108 109 public boolean getCheckedDirectionality() { 111 return checkedDirectionality; 112 } 113 114 public int getDirectionality() { 116 return directionality; 117 } 118 119 122 public String getDirectionalityDescription() { 123 try { 124 return RelationStep.DIRECTIONALITY_DESCRIPTIONS[directionality]; 125 } catch (IndexOutOfBoundsException ioobe) { 126 return null; 127 } 128 } 129 130 public Integer getRole() { 132 return role; 133 } 134 135 public String getRoleDescription() { 137 String roleName = "reldef:"+role; 138 if (role != null && getBuilder() != null) { 139 MMObjectNode node = getBuilder().getNode(role.intValue()); 140 if (node != null) { 141 roleName = node.getGUIIndicator(); 142 } 143 } 144 return roleName; 145 } 146 147 public Step getPrevious() { 149 return previous; 150 } 151 152 public Step getNext() { 154 return next; 155 } 156 157 public boolean equals(Object obj) { 159 if (obj == this) { 160 return true; 161 } 162 if (obj instanceof RelationStep) { 163 RelationStep step = (RelationStep) obj; 164 return getTableName().equals(step.getTableName()) 165 && (alias != null ? alias.equals(step.getAlias()) : step.getAlias() == null) 166 && getNodes().equals(step.getNodes()) 167 && step.getDirectionality() == directionality 168 && (role == null? step.getRole() == null: role.equals(step.getRole())); 169 } else { 170 return false; 171 } 172 } 173 174 public int hashCode() { 176 return 41 * (getTableName().hashCode() 177 + 43 * ( (alias != null ? alias.hashCode() : 0) 178 + 47 * (getNodes().hashCode() 179 + 113 * (directionality 180 + 31 * (role != null ? role.intValue() : 0))))); 181 } 182 183 public String toString() { 185 StringBuffer sb = new StringBuffer ("RelationStep(tablename:"); 186 sb.append(getTableName()). 187 append(", alias:"). 188 append(getAlias()). 189 append(", nodes:"). 190 append(getNodes()). 191 append(", dir:"). 192 append(getDirectionalityDescription()). 193 append(", role:"). 194 append(getRoleDescription()). 195 append(")"); 196 return sb.toString(); 197 } 198 199 } 200 | Popular Tags |