Tue, 20 Mar 2007 07:00:26 +0000Backing out changes. dev_M9_new_features_root
jbaker@netbeans.org [Tue, 20 Mar 2007 07:00:26 +0000] rev 350
Backing out changes.

Tue, 20 Mar 2007 04:48:23 +0000#93216 Implement per project in-memory context
jbaker@netbeans.org [Tue, 20 Mar 2007 04:48:23 +0000] rev 349
#93216 Implement per project in-memory context

and

#88871 partial implemenatation of Cannot easily change JNDI resource name


Index: DataconnectivityModuleInstaller.java
===================================================================
RCS file: /cvs/visualweb/dataconnectivity/src/org/netbeans/modules/visualweb/dataconnectivity/DataconnectivityModuleInstaller.java,v
retrieving revision 1.3
diff -u -r1.3 DataconnectivityModuleInstaller.java
--- DataconnectivityModuleInstaller.java 8 Mar 2007 00:28:39 -0000 1.3
+++ DataconnectivityModuleInstaller.java 20 Mar 2007 04:31:13 -0000
@@ -27,13 +27,9 @@
import org.netbeans.modules.visualweb.dataconnectivity.model.XmlUtil;
import org.netbeans.modules.visualweb.dataconnectivity.project.datasource.ProjectDataSourceTracker;
import org.netbeans.modules.visualweb.dataconnectivity.explorer.ideDb.BundledDatabaseHelper;
-import org.netbeans.modules.visualweb.dataconnectivity.model.DataSourceInfoManager;
import org.netbeans.modules.visualweb.dataconnectivity.utils.DbPortUtilities;
import org.netbeans.modules.visualweb.dataconnectivity.utils.SampleDatabaseCreator;
-
-
import org.netbeans.modules.visualweb.dataconnectivity.naming.DesignTimeInitialContextFactory;
-
import java.beans.Introspector;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -45,8 +41,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.netbeans.modules.visualweb.dataconnectivity.datasource.CurrentProject;
import org.openide.modules.InstalledFileLocator;
import org.openide.modules.ModuleInstall;
+import org.openide.windows.WindowManager;

// Comment out the code that was added to create Driver entries for DataDirect drivers
// import java.net.URL;
@@ -82,7 +80,7 @@
public void restored() {

Log.err.log("Entering DataconnectivityModuleInstaller.restored()");
-// long start = System.currentTimeMillis();
+// long start = System.TimeMillis();
// long time1 = start, time2;

setBundledDBPort() ;
@@ -142,7 +140,10 @@
// time1 = time2;

// Create sample database in Shortfin
- SampleDatabaseCreator.createAll("travel", "travel", "travel", "TRAVEL", "modules/ext/travel.zip", false, "localhost", 1527);
+ SampleDatabaseCreator.createAll("travel", "travel", "travel", "TRAVEL", "modules/ext/travel.zip", false, "localhost", 1527);
+ init();
+
+
// Won't include other databases yet
// SampleDatabaseCreator.createAll("jsc", "jsc", "jsc", "JSC", "modules/ext/jsc.zip", true, "localhost", 1527);
// SampleDatabaseCreator.createAll("vir", "vir", "vir", "VIR", "modules/ext/vir.zip", true, "localhost", 1527);
@@ -156,6 +157,15 @@
BundledDatabaseHelper.save() ;
}

+ public static void init() {
+ WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
+ public void run() {
+ // code to be invoked when system UI is ready
+ System.out.println("*** CurrentProject.getInstance().setup();");
+ CurrentProject.getInstance().setup();
+ }
+ } );
+ }

// public static String compString = "jdbc:pointbase:server://localhost:9092/"; //NOI18N
public static String compString = "jdbc:derby://localhost:1527/"; //NOI18N





Index: DataSourceInfo.java
===================================================================
RCS file: /cvs/visualweb/dataconnectivity/src/org/netbeans/modules/visualweb/dataconnectivity/model/DataSourceInfo.java,v
retrieving revision 1.2
diff -u -r1.2 DataSourceInfo.java
--- DataSourceInfo.java 8 Mar 2007 00:28:42 -0000 1.2
+++ DataSourceInfo.java 20 Mar 2007 04:32:58 -0000
@@ -65,7 +65,7 @@
this.name = name;
setDataSource(dataSource);
dbmdh = null;
- setId(DataSourceInfoManager.getInstance().getUniqueDataSourceId());
+// setId(DataSourceInfoManager.getInstance().getUniqueDataSourceId());

// Used as tooltip in the Datasource node
if ( isAlias() ) {
@@ -83,14 +83,14 @@
setDataSource(new DesignTimeDataSource(null, false, driverClassName,url,
validationQuery, username, password) );
dbmdh = null;
- setId(DataSourceInfoManager.getInstance().getUniqueDataSourceId());
+// setId(DataSourceInfoManager.getInstance().getUniqueDataSourceId());
}

public DataSourceInfo(String name, String aliasName) {
this.name = name;
setDataSource(new DesignTimeDataSourceAlias(aliasName) );
dbmdh = null;
- setId(DataSourceInfoManager.getInstance().getUniqueDataSourceId());
+// setId(DataSourceInfoManager.getInstance().getUniqueDataSourceId());
}

private void setDataSource( DesignTimeDataSource dtds ) {



Index: ProjectDataSourceManager.java
===================================================================
RCS file: /cvs/visualweb/dataconnectivity/src/org/netbeans/modules/visualweb/dataconnectivity/model/ProjectDataSourceManager.java,v
retrieving revision 1.1
diff -u -r1.1 ProjectDataSourceManager.java
--- ProjectDataSourceManager.java 28 Jan 2007 18:47:40 -0000 1.1
+++ ProjectDataSourceManager.java 20 Mar 2007 04:33:30 -0000
@@ -50,9 +50,10 @@
*
* @author marcow
*/
-public class ProjectDataSourceManager {
+public class ProjectDataSourceManager {
private Project project = null;
private DesignTimeDataSourceService dataSourceService = null;
+ private static Project currentProj;

/**
* Creates a new instance of ProjectDataSourceManager
@@ -102,7 +103,8 @@


// save data source for project
- DataSourceInfoManager.getInstance().addDataSourceInfo(dsInfo);
+// DataSourceInfoManager.getInstance().addDataSourceInfo(dsInfo);
+// dsHelper.addFullNameDataSource(dsString, ds.getDataSource() ) ;

return true;
}
@@ -263,4 +265,6 @@
// Modify the datasource meta data in the project if it exists in the project
throw new UnsupportedOperationException("Missing support in web/project"); //NOI18N
}
+
+
}



Index: DatasourceTransferManager.java
===================================================================
RCS file: /cvs/visualweb/dataconnectivity/src/org/netbeans/modules/visualweb/dataconnectivity/model/DatasourceTransferManager.java,v
retrieving revision 1.1
diff -u -r1.1 DatasourceTransferManager.java
--- DatasourceTransferManager.java 28 Jan 2007 18:47:39 -0000 1.1
+++ DatasourceTransferManager.java 20 Mar 2007 04:34:14 -0000
@@ -28,7 +28,6 @@
package org.netbeans.modules.visualweb.dataconnectivity.model;

import org.netbeans.modules.visualweb.api.designerapi.DesignTimeTransferDataCreator;
-import org.netbeans.modules.visualweb.api.j2ee.common.RequestedJdbcResource;
import org.netbeans.modules.visualweb.dataconnectivity.explorer.RowSetBeanCreateInfoSet;

import org.netbeans.modules.visualweb.dataconnectivity.ui.JdbcDriverConfigUtil;
@@ -37,26 +36,28 @@
import com.sun.rave.designtime.Result;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
-import java.awt.datatransfer.UnsupportedFlavorException;
-import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.Iterator;
-import java.util.Set;
+import java.sql.SQLException;
+import java.util.logging.ErrorManager;
+import javax.naming.NamingException;
+//import javax.xml.transform.Result;
import org.netbeans.api.db.explorer.DatabaseConnection;
import org.netbeans.api.db.explorer.JDBCDriver;
import org.netbeans.modules.db.api.explorer.DatabaseMetaDataTransfer;
-import org.openide.ErrorManager;
+import org.netbeans.modules.visualweb.dataconnectivity.sql.DesignTimeDataSource;
+import org.netbeans.modules.visualweb.dataconnectivity.sql.DesignTimeDataSourceHelper;
+//import org.openide.ErrorManager;

/**
* Manages the Design Time Data sources transferables
* @author Winston Prakash
*/
public class DatasourceTransferManager implements DesignTimeTransferDataCreator{
-
+
protected static String dataProviderClassName = "com.sun.data.provider.impl.CachedRowSetDataProvider";
public static String rowSetClassName = "com.sun.sql.rowset.CachedRowSetXImpl";
-
+
public DisplayItem getDisplayItem(Transferable transferable) {
Object transferData = null;
try {
@@ -68,46 +69,52 @@
DatabaseMetaDataTransfer.Table tableInfo = (DatabaseMetaDataTransfer.Table) transferData;
String schemaName = tableInfo.getDatabaseConnection().getSchema();
String tableName =
- ((schemaName == null) || (schemaName.equals(""))) ?
- tableInfo.getTableName() :
- schemaName + "." + tableInfo.getTableName();
+ ((schemaName == null) || (schemaName.equals(""))) ?
+ tableInfo.getTableName() :
+ schemaName + "." + tableInfo.getTableName();
// String tableName = tableInfo.getTableName();
DatabaseConnection dbConnection = (DatabaseConnection)tableInfo.getDatabaseConnection();
JDBCDriver jdbcDriver = (JDBCDriver) tableInfo.getJDBCDriver();
-
+
// Create the Bean Create Infoset and return
return new DatasourceBeanCreateInfoSet(dbConnection, jdbcDriver, tableName);
}
}
}
}catch (Exception exc) {
- ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
+// ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
}
return null;
}
-
+
private static final class DatasourceBeanCreateInfoSet extends RowSetBeanCreateInfoSet{
DatabaseConnection dbConnection = null;
JDBCDriver jdbcDriver = null;
-
+
public DatasourceBeanCreateInfoSet(DatabaseConnection connection, JDBCDriver driver, String tableName ) {
super(tableName);
dbConnection = connection;
jdbcDriver = driver;
}
-
+
public Result beansCreatedSetup(DesignBean[] designBeans) {
DesignBean designBean = designBeans[0];
-
+
// Get the Database Connection information and add it to design time
// Naming Context
// Make sure duplicate datasources are not added
- String dsName = "dataSource";
+// String dsName = "dataSource";

- // I can not use the name returned by NB DatabaseConnection
- // It has some wierd format and exception is thrown from CachedRowset
- // Ex. the name look like jdbc:derby://localhost:1527/sample [travel on TRAVEL]
- //String dsName = dbConnection.getName();
+ String databaseProductName = null;
+ try {
+ databaseProductName = dbConnection.getJDBCConnection().getMetaData().getDatabaseProductName();
+ } catch (SQLException sqle) {
+ sqle.printStackTrace();
+ }
+
+ String dsName = dbConnection.getSchema() + "_" + databaseProductName;
+ if (dbConnection.getSchema() == "")
+ dsName = dbConnection.getUser() + dsName;

String driverClassName = dbConnection.getDriverClass();
String url = dbConnection.getDatabaseURL();
@@ -116,126 +123,31 @@
String password = dbConnection.getPassword();

DataSourceInfo dataSourceInfo = new DataSourceInfo(dsName, driverClassName, url, validationQuery, username, password);
- /* XXX
- DataSourceInfo dsInfo = DataSourceInfoManager.getInstance().findDataSourceInfo(dataSourceInfo);
- if(dsInfo != null){
- dataSourceInfo = dsInfo;
- }else{
- DataSourceInfoManager.getInstance().addDataSourceInfo(dataSourceInfo);
- addJdbcDriver(jdbcDriver);
+
+ // Logic to reuse the datasource exist in the project. No necessary to create new data source
+ ProjectDataSourceManager projectDataSourceManager = new ProjectDataSourceManager(designBean);
+
+ // If Datasource exists in the project use its name
+ try {
+ DesignTimeDataSourceHelper dsHelper = new DesignTimeDataSourceHelper();
+ DesignTimeDataSource dtDs = dsHelper.getDataSource(dataSourceInfo.getName());
+ } catch (NamingException ne) {
+ // XXX Swallow exception for now - clean up later
}
- */

- // Logic to reuse the datasource exist in the project. No necessary to create new data source
- // First find if the datasource exists in the project
- ProjectDataSourceManager projectDataSourceManager = new ProjectDataSourceManager(designBean);
- Set<RequestedJdbcResource> projectDataResources = projectDataSourceManager.
- findRequestedJdbcResources(dataSourceInfo);
- Set<DataSourceInfo> dsInfos = DataSourceInfoManager.getInstance().findDataSourceInfo(dataSourceInfo);
- // OK, we don't have the datasource. Add it
- if ((dsInfos == null) || (dsInfos.size() == 0)) {
- boolean found = false;
-
- // If Datasource exists in the project use its name
- if (projectDataResources != null && projectDataResources.size() > 0) {
- Iterator<RequestedJdbcResource> it = projectDataResources.iterator();
-
- while (it.hasNext() && !found) {
- RequestedJdbcResource r = it.next();
- String projectDsInfoName = r.getResourceName().replaceFirst("jdbc/", ""); // NOI18N
- // Make sure it doesn't exist in the DataSourceInfoManager
- String lastUniqueName = DataSourceInfoManager.getInstance().
- getUniqueDataSourceName(projectDsInfoName);
- dataSourceInfo.setName(lastUniqueName);
-
- if (lastUniqueName.equals(projectDsInfoName)) {
- found = true;
- }
- }
- }
-
- if (!found) {
- RequestedJdbcResource r = projectDataSourceManager.
- getDataSourceWithName(dataSourceInfo.getName());
-
- if (r != null && !projectDataSourceManager.matchDataSourceInfo(r, dataSourceInfo)) {
- // Too bad we have a different datasource in the DataSourceInfoManager
- // with same name as project datasource
- dataSourceInfo.setName(getUniqueName(dataSourceInfo.getName()));
- }
-
- if (!projectDataSourceManager.addDataSource(dataSourceInfo)) {
- return Result.FAILURE;
- }
- }
-
- DataSourceInfoManager.getInstance().addDataSourceInfo(dataSourceInfo);
- addJdbcDriver(jdbcDriver);
- } else {
- if (projectDataResources != null && projectDataResources.size() > 0) {
- Iterator<RequestedJdbcResource> it = projectDataResources.iterator();
- boolean found = false;
- String lastProjectDsInfoName = null;
-
- while (it.hasNext() && !found) {
- RequestedJdbcResource r = it.next();
- lastProjectDsInfoName = r.getResourceName().replaceFirst("jdbc/",""); // NOI18N
-
- Iterator<DataSourceInfo> it1 = dsInfos.iterator();
-
- while (it1.hasNext() && !found) {
- DataSourceInfo dsInfo = it1.next();
- if (dsInfo.getName().equals(lastProjectDsInfoName)) {
- found = true;
- dataSourceInfo = dsInfo;
- }
- }
- }
-
- if (!found) {
- // OK we have a problem, the JNDI name doesn't match, so create
- // another datasource with that of project datasource in the
- // Datasource manager
- String uniqueName = DataSourceInfoManager.getInstance().
- getUniqueDataSourceName(lastProjectDsInfoName);
-
- dataSourceInfo.setName(uniqueName);
-
- if (!uniqueName.equals(lastProjectDsInfoName)) {
- RequestedJdbcResource r = projectDataSourceManager.
- getDataSourceWithName(uniqueName);
-
- if (r != null && !projectDataSourceManager.matchDataSourceInfo(r, dataSourceInfo)) {
- dataSourceInfo.setName(getUniqueName(dataSourceInfo.getName()));
- }
-
- if (!projectDataSourceManager.addDataSource(dataSourceInfo)) {
- return Result.FAILURE;
- }
- }
-
- DataSourceInfoManager.getInstance().addDataSourceInfo(dataSourceInfo);
- }
- } else {
- dataSourceInfo = dsInfos.iterator().next();
-
- boolean needAdd = false;
-
- if (projectDataSourceManager.getDataSourceWithName(dataSourceInfo.getName()) != null) {
- dataSourceInfo.setName(getUniqueName(dataSourceInfo.getName()));
- needAdd = true;
- }
-
- if (!projectDataSourceManager.addDataSource(dataSourceInfo)) {
- return Result.FAILURE;
- }
-
- if (needAdd) {
- DataSourceInfoManager.getInstance().addDataSourceInfo(dataSourceInfo);
- }
- }
+ // Add the data sources to the project
+ projectDataSourceManager.addDataSource(dataSourceInfo);
+ try {
+ DesignTimeDataSourceHelper dsHelper = new DesignTimeDataSourceHelper();
+ dsHelper.addDataSource( dsName, driverClassName, url, null, username, password);
+ } catch (NamingException ne) {
+ ne.printStackTrace();
}

+
+ // no need to do this once the switch is made to use NetBeans connections
+ addJdbcDriver(jdbcDriver);
+
setDataSourceInfo(dataSourceInfo);
return super.beansCreatedSetup(designBeans);
}
@@ -244,7 +156,7 @@
* This is needed for design time datasource connection to work
* TODO make sure duplicate drivers are not added
* Possibly check against the driver jar names and its size
- */
+ */
private void addJdbcDriver(JDBCDriver jdbcDriver){
// Get the driver jar urls copy them and then add the jar names
URL[] driverJarUrls = jdbcDriver.getURLs();
@@ -256,18 +168,18 @@
if (urlPath != null) // test if urlPath is undefined
driverUtil.copyJarNoConfirm(urlPath);
} catch (URISyntaxException urie) {
- ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, urie);
+// ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, urie);
}
}
}
-
+
private String getUniqueName(String name){
- if(name.indexOf('_') != -1){
- String prefix = name.substring(0, name.indexOf('_'));
- return prefix + "_" + System.currentTimeMillis(); // NOI18N
- } else{
- return name + "_" + System.currentTimeMillis(); // NOI18N
- }
- }
+ if(name.indexOf('_') != -1){
+ String prefix = name.substring(0, name.indexOf('_'));
+ return prefix + "_" + System.currentTimeMillis(); // NOI18N
+ } else{
+ return name + "_" + System.currentTimeMillis(); // NOI18N
+ }
+ }
}
}



Index: DataSourceExport.java
===================================================================
RCS file: /cvs/visualweb/dataconnectivity/src/org/netbeans/modules/visualweb/dataconnectivity/sql/DataSourceExport.java,v
retrieving revision 1.1
diff -u -r1.1 DataSourceExport.java
--- DataSourceExport.java 8 Mar 2007 00:28:44 -0000 1.1
+++ DataSourceExport.java 20 Mar 2007 04:35:36 -0000
@@ -144,7 +144,7 @@
return ( validationTable == null ? "" : validationTable ) ; // NOI18N
}
public void setValidationTable(String table) {
- setValidationQuery( DesignTimeDataSource.composeValidationQuery(table) ) ;
+// setValidationQuery( DesignTimeDataSource.composeValidationQuery(table) ) ;
}

public void setAlias(String alias) {





Index: DataSourceImport.java
===================================================================
RCS file: /cvs/visualweb/dataconnectivity/src/org/netbeans/modules/visualweb/dataconnectivity/sql/DataSourceImport.java,v
retrieving revision 1.1
diff -u -r1.1 DataSourceImport.java
--- DataSourceImport.java 8 Mar 2007 00:28:45 -0000 1.1
+++ DataSourceImport.java 20 Mar 2007 04:36:34 -0000
@@ -140,7 +140,7 @@
return ( validationTable == null ? "" : validationTable ) ; // NOI18N
}
public void setValidationTable(String table) {
- setValidationQuery( DesignTimeDataSource.composeValidationQuery(table) ) ;
+// setValidationQuery( DesignTimeDataSource.composeValidationQuery(table) ) ;
}

public void setAlias(String alias) {



Index: DesignTimeDataSourceHelper.java
===================================================================
RCS file: /cvs/visualweb/dataconnectivity/src/org/netbeans/modules/visualweb/dataconnectivity/sql/DesignTimeDataSourceHelper.java,v
retrieving revision 1.1
diff -u -r1.1 DesignTimeDataSourceHelper.java
--- DesignTimeDataSourceHelper.java 8 Mar 2007 00:28:45 -0000 1.1
+++ DesignTimeDataSourceHelper.java 20 Mar 2007 04:37:12 -0000
@@ -21,12 +21,14 @@
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
-import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
-import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.Locale;
+import java.util.Map;
import java.util.ResourceBundle;
+import java.util.Set;
import javax.naming.Binding;
import javax.naming.CompositeName;
import javax.naming.Context;
@@ -35,9 +37,12 @@
import javax.naming.NamingException;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NameNotFoundException;
-import javax.sql.DataSource;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.visualweb.api.j2ee.common.RequestedJdbcResource;
+import org.netbeans.modules.visualweb.dataconnectivity.model.ProjectDataSourceManager;
+import org.netbeans.modules.visualweb.dataconnectivity.project.datasource.ProjectDataSourceTracker;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
@@ -69,11 +74,13 @@
private Context ctx;
private DesignTimeDataSource[] dataSources;
private String[] dataSourceNames;
+ private boolean isDataSourceAdded;

public DesignTimeDataSourceHelper() throws NamingException {
dataSources = null;
dataSourceNames = null;
ctx = new InitialContext();
+ isDataSourceAdded = false;
}

public DataSourceExport[] getDataSourceExports() throws NamingException {
@@ -334,6 +341,7 @@
String url, String validationQuery, String username, String password)
throws NamingException {

+ isDataSourceAdded = true;
return addFullNameDataSource(DS_SUBCTX + "/" + name, driverClassName, url, validationQuery, // NOI18N
username, password);
}
@@ -350,7 +358,7 @@
public DesignTimeDataSource addFullNameDataSource(String name, DesignTimeDataSource ds )
throws NamingException {

- try {
+ try {
ctx.bind(name, ds);
} catch (NameAlreadyBoundException e) {
throw e;
@@ -452,5 +460,90 @@
public void refresh() {
dataSources = null;
dataSourceNames = null;
+ }
+
+
+ public Map updateDataSource(Project currentProj) {
+
+ // Get the data sources in the project then bind them to the project's context
+ String[] dynamicDataSources = ProjectDataSourceTracker.getDynamicDataSources(currentProj);
+ String[] hardCodedDataSources = ProjectDataSourceTracker.getHardcodedDataSources(currentProj);
+ ArrayList <RequestedJdbcResource> jdbcResources = new ArrayList();
+ RequestedJdbcResource jdbcResource = null;
+ ArrayList <DesignTimeDataSource> ds = null;
+ Map binding = new HashMap();
+
+ ProjectDataSourceManager projectDataSourceManager = new ProjectDataSourceManager(currentProj);
+
+ if (dynamicDataSources.length > 0 || hardCodedDataSources.length > 0) {
+ try {
+
+ DesignTimeDataSourceHelper dsHelper = new DesignTimeDataSourceHelper();
+ for (String name : dynamicDataSources) {
+ jdbcResource = (projectDataSourceManager.getDataSourceWithName(name.substring(name.lastIndexOf("/")+1)));
+
+ if (jdbcResource != null)
+ jdbcResources.add(jdbcResource);
+ }
+
+
+ for (String name : hardCodedDataSources) {
+ jdbcResource = (projectDataSourceManager.getDataSourceWithName(name.substring(name.lastIndexOf("/")+1)));
+
+ if (jdbcResource != null)
+ jdbcResources.add(jdbcResource);
+ }
+
+ } catch (NamingException ne) {
+ ne.printStackTrace();
+ }
+
+
+
+ // Check if datasource exists in the context. If it doesn't exist then bind the datasource .
+ Iterator it = jdbcResources.iterator();
+ boolean found = false;
+
+ while (it.hasNext()) {
+
+ jdbcResource = (RequestedJdbcResource) it.next();
+ String name = ((String)jdbcResource.getResourceName());
+ name = name.substring(name.indexOf("/")+1);
+ found = false;
+ if (!found)
+ binding.put(DS_SUBCTX + "/" + name, new DesignTimeDataSource(null, false, jdbcResource.getDriverClassName(),
+ jdbcResource.getUrl(), null, jdbcResource.getUsername(), jdbcResource.getPassword()));
+ }
+ }
+
+ return binding;
+ }
+
+ public boolean dataSourceAdded() {
+ return isDataSourceAdded;
+ }
+
+ // Update context with existing project's data sources, if any.
+ public void updateCtxBindings(Map bindings) {
+ Iterator it = bindings.keySet().iterator();
+
+ try {
+ while (it.hasNext()) {
+ String key = (String)it.next();
+ ctx.bind(key, bindings.get(key));
+ }
+ } catch (NamingException ne) {
+ ne.printStackTrace();
+ }
+ }
+
+ public boolean datasourcesInProject(Project currentProj) {
+ String[] dynamicDataSources = ProjectDataSourceTracker.getDynamicDataSources(currentProj);
+ String[] hardCodedDataSources = ProjectDataSourceTracker.getHardcodedDataSources(currentProj);
+
+ if (dynamicDataSources.length > 0 || hardCodedDataSources.length > 0)
+ return true;
+ else
+ return false;
}
}




Index: DesignTimeContext.java
===================================================================
RCS file: /cvs/visualweb/dataconnectivity/src/org/netbeans/modules/visualweb/dataconnectivity/naming/DesignTimeContext.java,v
retrieving revision 1.1
diff -u -r1.1 DesignTimeContext.java
--- DesignTimeContext.java 8 Mar 2007 00:28:42 -0000 1.1
+++ DesignTimeContext.java 20 Mar 2007 04:39:14 -0000
@@ -18,10 +18,9 @@
*/
package org.netbeans.modules.visualweb.dataconnectivity.naming;

+
import java.io.File;
-import java.io.FileInputStream;
import java.io.OutputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -30,9 +29,9 @@
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Locale;
+import java.util.Map;
import java.util.ResourceBundle;
import java.util.Stack;
-import java.util.Set;
import java.util.TreeMap;
import java.util.Vector;
import javax.naming.Binding;
@@ -51,6 +50,9 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.visualweb.dataconnectivity.sql.DesignTimeDataSourceHelper;
+import org.netbeans.modules.visualweb.insync.models.FacesModelSet;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
@@ -62,7 +64,9 @@
* @author John Kline
*/
class DesignTimeContext implements Context {
- static final String USER_CTX = "context.xml"; // NOI18N
+ static final String PRJ_CTX_FILE = "datasources.xml"; // NOI18N
+ static final String USER_CTX = "context.xml"; // NOI18N
+ private static Project currentProj;
public static final String ROOT_CTX_TAG = "rootContext"; // NOI18N
public static final String CTX_TAG = "context"; // NOI18N
public static final String OBJ_TAG = "object"; // NOI18N
@@ -72,12 +76,14 @@
public static final String VALUE_ATTR = "value"; // NOI18N
private static final int TAB_WIDTH = 4;
private DesignTimeContext parent;
+ private static DesignTimeContext thisInstance;
private String ctxName;
- private TreeMap map;
- private Hashtable env;
+ private File userCtxFile;
+ private TreeMap map;
+ private static Hashtable env;
private NameParser nameParser = DesignTimeNameParser.getInstance();
private String ctxPathName;
- private File userCtxFile;
+ private boolean update = false;
private boolean initMode; /* used only by initial context ctor, signals not to
* call saveContext during InitialContext construction
*/
@@ -88,7 +94,7 @@
private ObjectChangeListener objectChangeListener = new ObjectChangeListener() {
public void objectChanged(ObjectChangeEvent evt) throws NamingException {
Log.getLogger().entering(getClass().getName(), "objectChanged", evt); //NOI18N
- saveContext();
+// saveContext();
}
};

@@ -102,40 +108,52 @@
}
}

- // ctor for creating initial context
- public DesignTimeContext(Hashtable env) {
- Log.getLogger().entering(getClass().getName(), "DesignTimeContext", env); //NOI18N
- initMode = true;
- parent = null;
- ctxName = null;
- ctxPathName = System.getProperty("netbeans.user") + File.separator + File.separator + USER_CTX; // NOI18N
- userCtxFile = new File(ctxPathName);
- map = new TreeMap();
- this.env = new Hashtable(env);
- //EnvProcessor envProcessor = new EnvProcessor(this);
-
- /*
- * Look for context.xml in the user's directory. If doesn't exist, copy
- * the master file from netbeans.home/../ide4/startup/samples.
- */
- try {
- if (!userCtxFile.exists()) {
- writeNewUserContextFile();
- }
- try {
- parseContextFile();
- } catch (SAXException e) {
- rebuildContextFile(e);
- } catch (IOException e) {
- rebuildContext

Mon, 19 Mar 2007 23:54:31 +0000Should set the framework configuration panel before calling extend() to avoid NULL panel exception.
potingwu@netbeans.org [Mon, 19 Mar 2007 23:54:31 +0000] rev 348
Should set the framework configuration panel before calling extend() to avoid NULL panel exception.

Mon, 19 Mar 2007 23:01:11 +0000Fix Default Java Package GUI location.
potingwu@netbeans.org [Mon, 19 Mar 2007 23:01:11 +0000] rev 347
Fix Default Java Package GUI location.

Mon, 19 Mar 2007 22:24:22 +0000Preparing to move the Document, Range and Position classes.
pzavadsky@netbeans.org [Mon, 19 Mar 2007 22:24:22 +0000] rev 346
Preparing to move the Document, Range and Position classes.

Mon, 19 Mar 2007 22:23:33 +0000Fixed NPE due to not reseting member variable when the property set statement is removed
deva@netbeans.org [Mon, 19 Mar 2007 22:23:33 +0000] rev 345
Fixed NPE due to not reseting member variable when the property set statement is removed

Mon, 19 Mar 2007 21:50:17 +0000Update project logical view nodes when adding Visual Web framework or Page in addition to project creating.
potingwu@netbeans.org [Mon, 19 Mar 2007 21:50:17 +0000] rev 344
Update project logical view nodes when adding Visual Web framework or Page in addition to project creating.

Mon, 19 Mar 2007 19:34:42 +0000Fixed a typo in my previous commit
deva@netbeans.org [Mon, 19 Mar 2007 19:34:42 +0000] rev 343
Fixed a typo in my previous commit

Mon, 19 Mar 2007 19:08:08 +0000Use 'Visual Web' as the prefix.
potingwu@netbeans.org [Mon, 19 Mar 2007 19:08:08 +0000] rev 342
Use 'Visual Web' as the prefix.

Mon, 19 Mar 2007 19:08:00 +0000Get Default Package Name of pagebean from the new Page wizard.
potingwu@netbeans.org [Mon, 19 Mar 2007 19:08:00 +0000] rev 341
Get Default Package Name of pagebean from the new Page wizard.