KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > sqls > impl > ColumnReferenceImpl


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.sqls.impl;
18
19 import org.apache.ws.jaxme.sqls.Column;
20 import org.apache.ws.jaxme.sqls.ColumnReference;
21 import org.apache.ws.jaxme.sqls.TableReference;
22
23
24 /** <p>Implementation of a {@link ColumnReference}.</p>
25  *
26  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
27  */

28 public class ColumnReferenceImpl implements ColumnReference {
29     private TableReference tableReference;
30     private Column column;
31     private Column.Name alias;
32
33     protected ColumnReferenceImpl(TableReference pTableReference, Column pColumn) {
34         if (pTableReference == null) {
35             throw new NullPointerException JavaDoc("The referenced table must not be null.");
36         }
37         if (pColumn == null) {
38             throw new NullPointerException JavaDoc("The referenced column must not be null.");
39         }
40         if (!pTableReference.getTable().equals(pColumn.getTable())) {
41             throw new IllegalStateException JavaDoc("The columns table is not the referenced table.");
42         }
43         tableReference = pTableReference;
44         column = pColumn;
45     }
46
47     public TableReference getTableReference() {
48       return tableReference;
49     }
50
51     public Column getColumn() {
52       return column;
53     }
54
55     public void setAlias(String JavaDoc pName) {
56       setAlias(new ColumnImpl.NameImpl(pName));
57     }
58
59     public void setAlias(Column.Name pName) {
60       alias = pName;
61     }
62
63     public Column.Name getAlias() {
64       return alias;
65     }
66
67    public boolean equals(Object JavaDoc o) {
68       if (o == null || !(o instanceof ColumnReference)) {
69          return false;
70       }
71       ColumnReference ref = (ColumnReference) o;
72       Column c1 = ref.getColumn();
73       Column c2 = getColumn();
74       if (c1 == null || c2 == null) {
75           return super.equals(o);
76       }
77       TableReference t1 = ref.getTableReference();
78       TableReference t2 = ref.getTableReference();
79       if (t1 == null || t2 == null) {
80           return super.equals(o);
81       }
82       return t1.equals(t2) && c1.equals(c2);
83    }
84
85    public int hashCode() {
86       return getTableReference().hashCode() + getColumn().hashCode();
87    }
88 }
89
Popular Tags