KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > storage > search > implementation > BasicRelationStep


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

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 /**
17  * Basic implementation.
18  * <p>
19  * The checkedDirectionality property defaults to false.
20  * The directionality property defaults to DIRECTIONS_BOTH.
21  *
22  * @author Rob van Maris
23  * @version $Id: BasicRelationStep.java,v 1.11 2005/10/30 19:08:33 michiel Exp $
24  * @since MMBase-1.7
25  */

26 public class BasicRelationStep extends BasicStep implements RelationStep {
27
28     /** Checked directionality property. */
29     private boolean checkedDirectionality = false;
30
31     /** Directionality property. */
32     private int directionality = RelationStep.DIRECTIONS_BOTH;
33
34     /** Role property. */
35     private Integer JavaDoc role = null;
36
37     /** Previous step. */
38     private Step previous = null;
39
40     /** Next step. */
41     private Step next = null;
42
43     /**
44      * Creator.
45      *
46      * @param builder The relation builder.
47      * @param previous The previous step.
48      * @param next The next step.
49      * @throws IllegalArgumentException when an invalid argument is supplied.
50      */

51     // package visibility!
52
BasicRelationStep(InsRel builder, Step previous, Step next) {
53         super(builder);
54         if (previous == null) {
55             throw new IllegalArgumentException JavaDoc("Invalid previous value: " + previous);
56         }
57         this.previous = previous;
58         if (next == null) {
59             throw new IllegalArgumentException JavaDoc("Invalid next value: " + next);
60         }
61         this.next = next;
62     }
63
64     /**
65      * Sets checkedDirectionality property.
66      *
67      * @param checkedDirectionality The checkedDirectionality property.
68      * @return This <code>BasicRelationStep</code> instance.
69      * @see #getCheckedDirectionality
70      */

71     public BasicRelationStep setCheckedDirectionality(boolean checkedDirectionality) {
72         this.checkedDirectionality = checkedDirectionality;
73         return this;
74     }
75
76     /**
77      * Sets directionality property.
78      *
79      * @param directionality The directionality.
80      * Must be one of the values defined in <code>
81      * {@link org.mmbase.storage.search.RelationStep RelationStep}.</code>
82      * @return This <code>BasicRelationStep</code> instance.
83      * @throws IllegalArgumentException when an invalid argument is supplied.
84      */

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 JavaDoc(
92             "Invalid directionality value: " + directionality);
93         }
94         this.directionality = directionality;
95         return this;
96     }
97
98     /**
99      * Sets role property.
100      *
101      * @param role The role.
102      * @return This <code>BasicRelationStep</code> instance.
103      */

104     public BasicRelationStep setRole(Integer JavaDoc role) {
105         this.role = role;
106         return this;
107     }
108
109     // javadoc is inherited
110
public boolean getCheckedDirectionality() {
111         return checkedDirectionality;
112     }
113
114     // javadoc is inherited
115
public int getDirectionality() {
116         return directionality;
117     }
118
119     /**
120      * Returns a description of the part
121      */

122     public String JavaDoc getDirectionalityDescription() {
123         try {
124             return RelationStep.DIRECTIONALITY_DESCRIPTIONS[directionality];
125         } catch (IndexOutOfBoundsException JavaDoc ioobe) {
126             return null;
127         }
128     }
129
130     // javadoc is inherited
131
public Integer JavaDoc getRole() {
132         return role;
133     }
134
135     // javadoc is inherited
136
public String JavaDoc getRoleDescription() {
137         String JavaDoc 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     // javadoc is inherited
148
public Step getPrevious() {
149         return previous;
150     }
151
152     // javadoc is inherited
153
public Step getNext() {
154         return next;
155     }
156
157     // javadoc is inherited
158
public boolean equals(Object JavaDoc 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  // javadoc is inherited
175
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     // javadoc is inherited
184
public String JavaDoc toString() {
185         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("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