KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > dbschema > ColumnPairElement


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.dbschema;
21
22 /** Describes a directed column pair. Because of its direction, it has
23  * the notion of belonging to a table.
24  */

25 public final class ColumnPairElement extends DBMemberElement {
26     /** the local column to which this element is associated */
27     private ColumnElement _localColumn;
28
29     /** the referenced column to which this element is associated */
30     private ColumnElement _referencedColumn;
31
32     /** Create a new column pair element represented in memory.
33      */

34     public ColumnPairElement() {
35         this(new Memory(), null, null, null);
36     }
37
38     /** Creates a new column pair element.
39      * @param localColumn local column of this column pair
40      * @param referencedColumn referenced column of this column pair
41      * @param declaringTable declaring table of this column pair, or <code>null</code>
42      */

43     public ColumnPairElement (ColumnElement localColumn, ColumnElement referencedColumn, TableElement declaringTable) {
44         this(new Memory(), localColumn, referencedColumn, declaringTable);
45     }
46
47     /** Creates a new column pair element.
48      * @param impl the pluggable implementation
49      * @param localColumn local column of this column pair
50      * @param referencedColumn referenced column of this column pair
51      * @param declaringTable declaring table of this column pair, or <code>null</code>
52      */

53     public ColumnPairElement (ColumnPairElement.Impl impl, ColumnElement localColumn, ColumnElement referencedColumn, TableElement declaringTable) {
54         super(impl, declaringTable);
55         _localColumn = localColumn;
56         _referencedColumn = referencedColumn;
57     }
58
59     /** Returns the implementation for the column pair.
60      * @return implementation for the column pair
61      */

62     final Impl getColumnPairImpl() {
63         return (Impl)getElementImpl();
64     }
65
66     /** Gets the local column.
67      * @return the local column of this column pair
68      */

69     public final ColumnElement getLocalColumn() {
70         return _localColumn;
71     }
72
73     /** Sets the local column.
74      * @param ce the local column
75      */

76     public final void setLocalColumn (ColumnElement ce) {
77         if (_localColumn == null)
78             _localColumn = ce;
79     }
80
81     /** Gets the referenced column.
82      * @return the referenced column of this column pair
83      */

84     public final ColumnElement getReferencedColumn() {
85         return _referencedColumn;
86     }
87
88     /** Sets the referenced column.
89      * @param ce the referenced column
90      */

91     public final void setReferencedColumn(ColumnElement ce) {
92         if (_referencedColumn == null)
93             _referencedColumn = ce;
94     }
95
96     /** Gets the name of this element.
97      * @return the name
98      */

99     public DBIdentifier getName() {
100         ColumnElement lce = getLocalColumn();
101         ColumnElement fce = getReferencedColumn();
102         
103         DBIdentifier name = DBIdentifier.create(lce.getName().getFullName() + ";" + fce.getName().getFullName()); //NOI18N
104

105         return name;
106     }
107
108     /** Implementation of a reference key column element.
109      * @see DBMemberElement
110      */

111     public interface Impl extends DBMemberElement.Impl {
112     }
113
114     static class Memory extends DBMemberElement.Memory implements Impl {
115         /** Default constructor.
116          */

117         Memory() {
118         }
119
120         /** Copy constructor.
121         * @param column the object from which to read values
122         */

123         Memory(ColumnPairElement column) {
124             super(column);
125         }
126     }
127 }
128
Popular Tags