KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > wizard > fromdb > Table


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.j2ee.persistence.wizard.fromdb;
21
22 import java.util.Set JavaDoc;
23 import org.netbeans.modules.j2ee.persistence.wizard.Util;
24 import org.openide.util.NbBundle;
25
26 /**
27  * Represents a table and its references used and displayed in the wizard.
28  *
29  * @author Andrei Badea
30  */

31 public abstract class Table implements Comparable JavaDoc<Table> {
32
33     private final String JavaDoc name;
34     private final boolean join;
35     private final DisabledReason disabledReason;
36
37     public Table(String JavaDoc name, boolean join, DisabledReason disabledReason) {
38         this.name = name;
39         this.join = join;
40         this.disabledReason = disabledReason;
41     }
42
43     public boolean equals(Object JavaDoc that) {
44         if (that instanceof Table) {
45             return compareTo((Table)that) == 0;
46         } else {
47             return false;
48         }
49     }
50
51     public int compareTo(Table that) {
52         if (that == null) {
53             return 1;
54         }
55         return this.getName().compareTo(that.getName());
56     }
57
58     /**
59      * Returns the name of the table.
60      */

61     public String JavaDoc getName() {
62         return name;
63     }
64
65     /**
66      * Returns true if the table is a join table.
67      */

68     public boolean isJoin() {
69         return join;
70     }
71
72     /**
73      * Returns the reason why this table should be disabled when displayed
74      * in the UI.
75      */

76     public DisabledReason getDisabledReason() {
77         return disabledReason;
78     }
79
80     /**
81      * Returns true if the table is disabled. In this case {@link #getDisabledReason}
82      * will return a non-true value.
83      */

84     public boolean isDisabled() {
85         return disabledReason != null;
86     }
87
88     public String JavaDoc toString() {
89         return "TableItem[name='" + name + "']"; // NOI18N
90
}
91
92     /**
93      * Returns the tables this table references.
94      */

95     public abstract Set JavaDoc<Table> getReferencedTables();
96
97     /**
98      * Returns the table referenced by this table.
99      */

100     public abstract Set JavaDoc<Table> getReferencedByTables();
101
102     /**
103      * Returns the tables which this table joins.
104      */

105     public abstract Set JavaDoc<Table> getJoinTables();
106
107     /**
108      * A generic reason for a table to be disabled. If there is no need
109      * to specify the exact reason why the table is disabled, this class can
110      * be used, otherwise it can be subclassed, like {@link #ExistingDisabledReason}.
111      */

112     public static class DisabledReason {
113
114         private final String JavaDoc displayName;
115         private final String JavaDoc description;
116
117         public DisabledReason(String JavaDoc displayName, String JavaDoc description) {
118             this.displayName = displayName;
119             this.description = description;
120         }
121
122         public String JavaDoc getDisplayName() {
123             return displayName;
124         }
125
126         public String JavaDoc getDescription() {
127             return description;
128         }
129     }
130
131     /**
132      * This implementation of DisabledReason specifies that a table is disabled
133      * because an entity class already exists for it.
134      */

135     public static final class ExistingDisabledReason extends DisabledReason {
136
137         private String JavaDoc fqClassName;
138
139         public ExistingDisabledReason(String JavaDoc fqClassName) {
140             super(NbBundle.getMessage(Table.class, "LBL_AlreadyMapped", Util.getClassName(fqClassName)),
141                     NbBundle.getMessage(Table.class, "LBL_AlreadyMappedDescription", fqClassName));
142             this.fqClassName = fqClassName;
143         }
144
145         public String JavaDoc getFQClassName() {
146             return fqClassName;
147         }
148     }
149
150     /**
151      * This implementation of DisabledReason specifies that a table is disabled
152      * because it doesn't have a primary key.
153      */

154     public static final class NoPrimaryKeyDisabledReason extends DisabledReason {
155
156         public NoPrimaryKeyDisabledReason() {
157             super(NbBundle.getMessage(Table.class, "LBL_NoPrimaryKey"), NbBundle.getMessage(Table.class, "LBL_NoPrimaryKeyDescription"));
158         }
159     }
160 }
161
Popular Tags