1 19 20 package org.netbeans.modules.j2ee.ejbjarproject; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import javax.swing.JComboBox ; 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 36 public class EjbJarJPASupport implements JPADataSourcePopulator, JPADataSourceProvider{ 37 38 private final EjbJarProject project; 39 40 41 public EjbJarJPASupport(EjbJarProject project) { 42 this.project = project; 43 } 44 45 public void connect(JComboBox comboBox) { 46 DatasourceUIHelper.connect(project.getEjbModule(), comboBox); 47 int size = comboBox.getItemCount(); 51 for (int i = 0; i < size; i++){ 52 Object item = comboBox.getItemAt(i); 53 if (item instanceof Datasource){ 54 comboBox.insertItemAt(new DatasourceWrapper((Datasource)item), i); 55 } 56 } 57 } 58 59 public List <JPADataSource> getDataSources() { 60 61 List <Datasource> datasources = new ArrayList <Datasource>(); 62 datasources.addAll(project.getEjbModule().getModuleDatasources()); 63 datasources.addAll(project.getEjbModule().getServerDatasources()); 64 65 List <JPADataSource> result = new ArrayList <JPADataSource>(datasources.size()); 66 for(Datasource each : datasources){ 67 result.add(new DatasourceWrapper(each)); 68 } 69 return result; 70 } 71 72 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 getJndiName() { 84 return delegate.getJndiName(); 85 } 86 87 public String getUrl() { 88 return delegate.getUrl(); 89 } 90 91 public String getUsername() { 92 return delegate.getUsername(); 93 } 94 95 public String getPassword() { 96 return delegate.getPassword(); 97 } 98 99 public String getDriverClassName() { 100 return delegate.getDriverClassName(); 101 } 102 103 public String getDisplayName() { 104 return delegate.getDisplayName(); 105 } 106 107 public String toString(){ 108 return delegate.toString(); 109 } 110 } 111 112 } 113 | Popular Tags |