KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > WebJPADataSourceSupport


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.web.project;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import javax.swing.JComboBox JavaDoc;
25 import org.netbeans.modules.j2ee.common.DatasourceUIHelper;
26 import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
27 import org.netbeans.modules.j2ee.persistence.spi.datasource.JPADataSource;
28 import org.netbeans.modules.j2ee.persistence.spi.datasource.JPADataSourcePopulator;
29 import org.netbeans.modules.j2ee.persistence.spi.datasource.JPADataSourceProvider;
30
31 /**
32  * Provides support for dealing with data sources in the JSR 220 support module.
33  *
34  * @author Erno Mononen
35  */

36 public class WebJPADataSourceSupport implements JPADataSourcePopulator, JPADataSourceProvider{
37     
38     private final WebProject project;
39     
40     /** Creates a new instance of WebJPADataSourceSupport */
41     public WebJPADataSourceSupport(WebProject project) {
42         this.project = project;
43     }
44     
45     public void connect(JComboBox JavaDoc comboBox) {
46         DatasourceUIHelper.connect(project.getWebModule(), comboBox);
47         // see the comment in EjbJarJPASupport regarding the code below
48
int size = comboBox.getItemCount();
49         for (int i = 0; i < size; i++){
50             Object JavaDoc item = comboBox.getItemAt(i);
51             if (item instanceof Datasource){
52                 comboBox.insertItemAt(new DatasourceWrapper((Datasource)item), i);
53             }
54         }
55     }
56
57     public List JavaDoc<JPADataSource> getDataSources() {
58         List JavaDoc<Datasource> datasources = new ArrayList JavaDoc<Datasource>();
59         datasources.addAll(project.getWebModule().getModuleDatasources());
60         datasources.addAll(project.getWebModule().getServerDatasources());
61
62         List JavaDoc<JPADataSource> result = new ArrayList JavaDoc<JPADataSource>(datasources.size());
63         for(Datasource each : datasources){
64             result.add(new DatasourceWrapper(each));
65         }
66         return result;
67     }
68
69 /**
70  * Provides <code>JPADataSource</code> interface for <code>Datasource</code>s.
71  */

72 // TODO: this class is duplicated in the EjbJarJPASupport
73
private static class DatasourceWrapper implements Datasource, JPADataSource{
74     
75     private Datasource delegate;
76     
77     DatasourceWrapper(Datasource datasource){
78         this.delegate = datasource;
79     }
80     
81     public String JavaDoc getJndiName() {
82         return delegate.getJndiName();
83     }
84     
85     public String JavaDoc getUrl() {
86         return delegate.getUrl();
87     }
88     
89     public String JavaDoc getUsername() {
90         return delegate.getUsername();
91     }
92     
93     public String JavaDoc getPassword() {
94         return delegate.getPassword();
95     }
96     
97     public String JavaDoc getDriverClassName() {
98         return delegate.getDriverClassName();
99     }
100     
101     public String JavaDoc getDisplayName() {
102         return delegate.getDisplayName();
103     }
104     
105     public String JavaDoc toString(){
106         return delegate.toString();
107     }
108 }
109
110 }
111
Popular Tags