001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: /**
042: *
043: * @author Winston Prakash
044: */package org.netbeans.modules.visualweb.dataconnectivity;
045:
046: import org.netbeans.modules.visualweb.dataconnectivity.project.datasource.ProjectDataSourceTracker;
047: import org.netbeans.modules.visualweb.dataconnectivity.naming.DesignTimeInitialContextFactory;
048: import java.beans.Introspector;
049: import java.io.File;
050: import java.util.ArrayList;
051: import java.util.Arrays;
052: import java.util.List;
053: import org.netbeans.api.db.explorer.ConnectionManager;
054: import org.netbeans.modules.derby.api.DerbyDatabases;
055: import org.netbeans.modules.visualweb.dataconnectivity.naming.DatabaseSettingsImporter;
056: import org.netbeans.modules.visualweb.dataconnectivity.naming.DerbyWaiter;
057: import org.netbeans.modules.visualweb.dataconnectivity.utils.SampleDatabaseCreator;
058: import org.openide.modules.ModuleInstall;
059: import org.openide.windows.WindowManager;
060:
061: /**
062: * Initialization code for dataconnectivity module.
063: * Copies various files from application bundle into userdir.
064: * Defines initial drivers.
065: */
066: public class DataconnectivityModuleInstaller extends ModuleInstall {
067:
068: private static String JSFCL_DATA_BEANINFO_PATH = "com.sun.jsfcl.data"; //NOI18N
069: private static String DATACONNECTIVITY_BEANINFO_PATH = "org.netbeans.modules.visualweb.dataconnectivity.designtime"; // NOI18N
070:
071: public void restored() {
072: // initialize settings for data source naming option
073: DataconnectivitySettings.getInstance();
074:
075: //!JK Temporary place to register the rowset customizer. This call may change.
076: //!JK See Carl for details.
077: //!JK Also, temporary place to add JSFCL_DATA_BEANINFO_PATH to the beanInfoSearchPath
078: org.netbeans.modules.visualweb.insync.live.LiveUnit
079: .registerCustomizer(
080: com.sun.sql.rowset.CachedRowSetXImpl.class
081: .getName(),
082: new org.netbeans.modules.visualweb.dataconnectivity.customizers.SqlCommandCustomizer(
083: com.sun.sql.rowset.CachedRowSetXImpl.class
084: .getName()));
085:
086: // data source tracking for NB4 JsfProjects - do prelim setup.
087: ProjectDataSourceTracker.getInstance();
088:
089: List bisp = Arrays.asList(Introspector.getBeanInfoSearchPath());
090: if (!bisp.contains(JSFCL_DATA_BEANINFO_PATH)) {
091: bisp = new ArrayList(bisp);
092: bisp.add(JSFCL_DATA_BEANINFO_PATH);
093: Introspector.setBeanInfoSearchPath((String[]) bisp
094: .toArray(new String[0]));
095: }
096:
097: // Register the designtime directory for dataconnectivity in the search path
098: if (!bisp.contains(DATACONNECTIVITY_BEANINFO_PATH)) {
099: bisp = new ArrayList(bisp);
100: bisp.add(this .DATACONNECTIVITY_BEANINFO_PATH);
101: Introspector.setBeanInfoSearchPath((String[]) bisp
102: .toArray(new String[0]));
103: }
104:
105: // database registration for sample databases and legacy projects
106: init();
107:
108: // Won't include other databases yet
109: // SampleDatabaseCreator.createAll("vir", "vir", "vir", "VIR", "modules/ext/vir.zip", true, "localhost", 1527);
110: }
111:
112: // Wait for IDE to start before taking care of database registration
113: public static void init() {
114: WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
115: public void run() {
116:
117: // Dataconnectivity implementation to support Project migration of previous releases projects
118: // For previous release userdir migration, if no context file then settings haven't been migrated
119: File contextFile = DatabaseSettingsImporter
120: .getInstance()
121: .retrieveMigratedSettingsAtStartup();
122: if (contextFile != null) {
123: new DerbyWaiter(contextFile.exists()); // waits for Derby drivers to be registered before migrating userdir settings
124: } else {
125: // Create sample database and connections if needed
126: new DerbyWaiter(false);
127: }
128: }
129: });
130: }
131: }
|