KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > EjbJarJPASupport


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.ejbjarproject;
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  * Implements the SPI interfaces providing support for data source handling.
33  *
34  * @author Erno Mononen
35  */

36 public class EjbJarJPASupport implements JPADataSourcePopulator, JPADataSourceProvider{
37     
38     private final EjbJarProject project;
39     
40     /** Creates a new instance of EjbJarJPASupport */
41     public EjbJarJPASupport(EjbJarProject project) {
42         this.project = project;
43     }
44     
45     public void connect(JComboBox JavaDoc comboBox) {
46         DatasourceUIHelper.connect(project.getEjbModule(), comboBox);
47         // a bit of a hack. needs rethinking when j2ee/persistence doesn't
48
// have a dependency to j2ee/utilities anymore (then the DatasourceUIHelper
49
// may be changed to use JPADataSources directly).
50
int size = comboBox.getItemCount();
51         for (int i = 0; i < size; i++){
52             Object JavaDoc item = comboBox.getItemAt(i);
53             if (item instanceof Datasource){
54                 comboBox.insertItemAt(new DatasourceWrapper((Datasource)item), i);
55             }
56         }
57     }
58     
59     public List JavaDoc<JPADataSource> getDataSources() {
60         
61         List JavaDoc<Datasource> datasources = new ArrayList JavaDoc<Datasource>();
62         datasources.addAll(project.getEjbModule().getModuleDatasources());
63         datasources.addAll(project.getEjbModule().getServerDatasources());
64
65         List JavaDoc<JPADataSource> result = new ArrayList JavaDoc<JPADataSource>(datasources.size());
66         for(Datasource each : datasources){
67             result.add(new DatasourceWrapper(each));
68         }
69         return result;
70     }
71
72 /**
73  * Provides <code>JPADataSource</code> interface for <code>Datasource</code>s.
74  */

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