KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
23 import java.util.WeakHashMap JavaDoc;
24 import org.netbeans.api.project.Project;
25
26 /**
27  * Describes a source for tables and can save and retrieve the source
28  * for a given project.
29  *
30  * <p>The source for tables consists of the type (data source,
31  * database connection or dbschema file) and the name of the source,
32  * whose meaning is: the JNDI name for the data source, the
33  * {@link org.netbeans.api.db.explorer.DatabaseConnection#getName() name}
34  * of the database connection or the absolute path of the dbschema file.</p>
35  *
36  * @author Andrei Badea
37  */

38 public class TableSource {
39
40     public enum Type { DATA_SOURCE, CONNECTION, SCHEMA_FILE };
41
42     private final static Map JavaDoc<Project, TableSource> PROJECT_TO_SOURCE = new WeakHashMap JavaDoc<Project, TableSource>();
43
44     private final Type type;
45     private final String JavaDoc name;
46
47     public static TableSource get(Project project) {
48         synchronized (TableSource.class) {
49             return PROJECT_TO_SOURCE.get(project);
50         }
51     }
52
53     public static void put(Project project, TableSource tableSource) {
54         synchronized (TableSource.class) {
55             PROJECT_TO_SOURCE.put(project, tableSource);
56         }
57     }
58
59     public TableSource(String JavaDoc name, Type type) {
60         assert name != null;
61         assert type != null;
62
63         this.name = name;
64         this.type = type;
65     }
66
67     public String JavaDoc getName() {
68         return name;
69     }
70
71     public Type getType() {
72         return type;
73     }
74 }
75
Popular Tags