View Javadoc

1   package com.explosion.expfmodules.rdbmsconn.connectwizard.actions;
2   
3   /* =============================================================================
4    *       
5    *     Copyright 2004 Stephen Cowx
6    *
7    *     Licensed under the Apache License, Version 2.0 (the "License");
8    *     you may not use this file except in compliance with the License.
9    *     You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *     Unless required by applicable law or agreed to in writing, software
14   *     distributed under the License is distributed on an "AS IS" BASIS,
15   *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *     See the License for the specific language governing permissions and
17   *     limitations under the License.
18   * 
19   * =============================================================================
20   */
21  
22  /***
23   * @author Stephen Cowx
24   * Created on 21-Feb-2005
25   */
26  import java.util.Properties;
27  
28  import com.explosion.expf.Application;
29  import com.explosion.expfmodules.rdbmsconn.RdbmsConnModuleManager;
30  import com.explosion.expfmodules.rdbmsconn.connectwizard.ConnectNow;
31  import com.explosion.expfmodules.wizard.StepAction;
32  import com.explosion.expfmodules.wizard.Wizard;
33  import com.explosion.expfmodules.wizard.standard.PreferenceDataItem;
34  import com.explosion.utilities.exception.ExceptionManagerFactory;
35  import com.explosion.utilities.preferences.groups.PreferenceGroup;
36  
37  public class SaveConnectionAction implements StepAction {
38  
39  	/***
40  	 * Creates a MySQL database connection based on the information 
41  	 * collected in the wizard.
42  	 */
43  	public boolean execute(Wizard wizard) {
44  		
45  		try {
46  		    
47  		    /* Get the values for the connection from the wizard values */
48  		    String connectionName = (String) ((PreferenceDataItem) wizard.getWizardDataValues().get("connectionname")).getPreference().getValue();
49  		    boolean connectNow = ((Boolean) ((PreferenceDataItem) wizard.getWizardDataValues().get("connectnow")).getPreference().getValue()).booleanValue();
50  		    PreferenceGroup descriptor = (PreferenceGroup) wizard.getWizardDataValues().get("connection_descriptor");
51  		    
52  		    descriptor.setIdentifier(connectionName);
53  		    RdbmsConnModuleManager.instance().getConnectionDescriptorManager().addGroup(connectionName, descriptor);
54  		    descriptor.commit();
55  		    
56  		    if (connectNow)
57  		    {
58  		       Properties properties = Application.getInstance().getPropertiesForModule(RdbmsConnModuleManager.class.getName());
59  		       properties.list(System.out);
60  		       String className = properties.getProperty("connectionwizard.connectNowClassName");
61  		       if (className != null)
62  		       {
63  		       	 ConnectNow connectNowClass = (ConnectNow) Class.forName(className).newInstance();
64  		       	 connectNowClass.connect(descriptor);
65  		       }
66  		    }
67  		    
68  		    return true;
69  			
70  		} catch (Exception e) {
71  			ExceptionManagerFactory.getExceptionManager().manageException(e, "Error:");
72  		}
73  		
74  		return false;
75  		
76  	}
77  }