001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010: package org.mmbase.storage.search.implementation;
011:
012: import org.mmbase.module.corebuilders.InsRel;
013: import org.mmbase.module.core.MMObjectNode;
014: import org.mmbase.storage.search.*;
015:
016: /**
017: * Basic implementation.
018: * <p>
019: * The checkedDirectionality property defaults to false.
020: * The directionality property defaults to DIRECTIONS_BOTH.
021: *
022: * @author Rob van Maris
023: * @version $Id: BasicRelationStep.java,v 1.12 2006/10/16 12:56:57 pierre Exp $
024: * @since MMBase-1.7
025: */
026: public class BasicRelationStep extends BasicStep implements
027: RelationStep {
028:
029: /** Checked directionality property. */
030: private boolean checkedDirectionality = false;
031:
032: /** Directionality property. */
033: private int directionality = RelationStep.DIRECTIONS_BOTH;
034:
035: /** Role property. */
036: private Integer role = null;
037:
038: /** Previous step. */
039: private Step previous = null;
040:
041: /** Next step. */
042: private Step next = null;
043:
044: /**
045: * Creator.
046: *
047: * @param builder The relation builder.
048: * @param previous The previous step.
049: * @param next The next step.
050: * @throws IllegalArgumentException when an invalid argument is supplied.
051: */
052: // package visibility!
053: BasicRelationStep(InsRel builder, Step previous, Step next) {
054: super (builder);
055: if (previous == null) {
056: throw new IllegalArgumentException(
057: "Invalid previous value: " + previous);
058: }
059: this .previous = previous;
060: if (next == null) {
061: throw new IllegalArgumentException("Invalid next value: "
062: + next);
063: }
064: this .next = next;
065: }
066:
067: /**
068: * Sets checkedDirectionality property.
069: *
070: * @param checkedDirectionality The checkedDirectionality property.
071: * @return This <code>BasicRelationStep</code> instance.
072: * @see #getCheckedDirectionality
073: */
074: public BasicRelationStep setCheckedDirectionality(
075: boolean checkedDirectionality) {
076: this .checkedDirectionality = checkedDirectionality;
077: return this ;
078: }
079:
080: /**
081: * Sets directionality property.
082: *
083: * @param directionality The directionality.
084: * Must be one of the values defined in <code>
085: * {@link org.mmbase.storage.search.RelationStep RelationStep}.</code>
086: * @return This <code>BasicRelationStep</code> instance.
087: * @throws IllegalArgumentException when an invalid argument is supplied.
088: */
089: public BasicRelationStep setDirectionality(int directionality) {
090: if (directionality != RelationStep.DIRECTIONS_SOURCE
091: && directionality != RelationStep.DIRECTIONS_DESTINATION
092: && directionality != RelationStep.DIRECTIONS_BOTH
093: && directionality != RelationStep.DIRECTIONS_ALL
094: && directionality != RelationStep.DIRECTIONS_EITHER) {
095: throw new IllegalArgumentException(
096: "Invalid directionality value: " + directionality);
097: }
098: this .directionality = directionality;
099: return this ;
100: }
101:
102: /**
103: * Sets role property.
104: *
105: * @param role The role.
106: * @return This <code>BasicRelationStep</code> instance.
107: */
108: public BasicRelationStep setRole(Integer role) {
109: this .role = role;
110: return this ;
111: }
112:
113: // javadoc is inherited
114: public boolean getCheckedDirectionality() {
115: return checkedDirectionality;
116: }
117:
118: // javadoc is inherited
119: public int getDirectionality() {
120: return directionality;
121: }
122:
123: /**
124: * Returns a description of the part
125: */
126: public String getDirectionalityDescription() {
127: try {
128: return RelationStep.DIRECTIONALITY_DESCRIPTIONS[directionality];
129: } catch (IndexOutOfBoundsException ioobe) {
130: return null;
131: }
132: }
133:
134: // javadoc is inherited
135: public Integer getRole() {
136: return role;
137: }
138:
139: // javadoc is inherited
140: public String getRoleDescription() {
141: String roleName = "reldef:" + role;
142: if (role != null && getBuilder() != null) {
143: MMObjectNode node = getBuilder().getNode(role.intValue());
144: if (node != null) {
145: roleName = node.getGUIIndicator();
146: }
147: }
148: return roleName;
149: }
150:
151: // javadoc is inherited
152: public Step getPrevious() {
153: return previous;
154: }
155:
156: // javadoc is inherited
157: public Step getNext() {
158: return next;
159: }
160:
161: // javadoc is inherited
162: public boolean equals(Object obj) {
163: if (obj == this ) {
164: return true;
165: }
166: if (obj instanceof RelationStep) {
167: RelationStep step = (RelationStep) obj;
168: return getTableName().equals(step.getTableName())
169: && (alias != null ? alias.equals(step.getAlias())
170: : step.getAlias() == null)
171: && getNodes().equals(step.getNodes())
172: && step.getDirectionality() == directionality
173: && (role == null ? step.getRole() == null : role
174: .equals(step.getRole()));
175: } else {
176: return false;
177: }
178: }
179:
180: // javadoc is inherited
181: public int hashCode() {
182: return 41 * (getTableName().hashCode() + 43 * ((alias != null ? alias
183: .hashCode()
184: : 0) + 47 * (getNodes().hashCode() + 113 * (directionality + 31 * (role != null ? role
185: .intValue()
186: : 0)))));
187: }
188:
189: // javadoc is inherited
190: public String toString() {
191: StringBuilder sb = new StringBuilder("RelationStep(tablename:")
192: .append(getTableName()).append(", alias:").append(
193: getAlias()).append(", nodes:").append(
194: getNodes()).append(", dir:").append(
195: getDirectionalityDescription()).append(
196: ", role:").append(getRoleDescription()).append(
197: ")");
198: return sb.toString();
199: }
200:
201: }
|