View Javadoc

1   /***
2    * 
3    */
4   package net.sourceforge.jdbdump.gui;
5   
6   import java.io.IOException;
7   import java.util.ArrayList;
8   import java.util.Collection;
9   
10  import javax.faces.model.SelectItem;
11  
12  import net.sourceforge.jdbdump.connect.Configuration;
13  import net.sourceforge.jdbdump.connect.DatabaseConnectionData;
14  import net.sourceforge.jdbdump.connect.DatabaseConnectorFactory;
15  
16  /***
17   * @author grabka
18   *
19   */
20  public class DbAddBean {
21  	private String dbTitle;
22  	private String dbServerName;
23  	private String port;
24  	private String engine;
25  	private String dbName;
26  	private String login;
27  	private String password;
28  	private String passwordAgain;
29  	private String url;
30  	private ArrayList<SelectItem> engines;
31  	
32  	public DbAddBean() {
33  		engines = new ArrayList<SelectItem>();
34  		String[] enginesStrings = DatabaseConnectorFactory.getInstance().listPlugins();
35  		
36  		for (int i=0; i<enginesStrings.length; i++) {
37  			String engineShortName = enginesStrings[i].substring(enginesStrings[i].lastIndexOf(".")+1);
38  			engines.add(new SelectItem(engineShortName));			
39  		}
40  	}
41  
42  	public String getDbName() {
43  		return dbName;
44  	}
45  
46  	public void setDbName(String dbName) {
47  		this.dbName = dbName;
48  	}
49  
50  	public String getDbServerName() {
51  		return dbServerName;
52  	}
53  
54  	public void setDbServerName(String dbServerName) {
55  		this.dbServerName = dbServerName;
56  	}
57  
58  	public String getDbTitle() {
59  		return dbTitle;
60  	}
61  
62  	public void setDbTitle(String dbTitle) {
63  		this.dbTitle = dbTitle;
64  	}
65  
66  	public String getEngine() {
67  		return engine;
68  	}
69  
70  	public void setEngine(String engine) {
71  		this.engine = engine;
72  	}
73  
74  	public String getLogin() {
75  		return login;
76  	}
77  
78  	public void setLogin(String login) {
79  		this.login = login;
80  	}
81  
82  	public String getPassword() {
83  		return password;
84  	}
85  
86  	public void setPassword(String password) {
87  		this.password = password;
88  	}
89  
90  	public String getPasswordAgain() {
91  		return passwordAgain;
92  	}
93  
94  	public void setPasswordAgain(String passwordAgain) {
95  		this.passwordAgain = passwordAgain;
96  	}
97  
98  	public String getPort() {
99  		return port;
100 	}
101 
102 	public void setPort(String port) {
103 		this.port = port;
104 	}
105 	
106 	public Collection<SelectItem> getEngines(){
107 		  return engines;
108 	}
109 	
110 	public void setEngines(Collection<SelectItem> engines){
111 		  this.engines = new ArrayList<SelectItem>(engines);
112 	} 	
113 	
114 	public String addDatabase() {		
115 		DatabaseConnectionData data = new DatabaseConnectionData(dbServerName, port, engine, login, password, dbName, dbTitle, url);  
116 		try {
117 			Configuration.getInstance().addDatabase(data);
118 		} catch (InstantiationException e) { 
119 			e.printStackTrace();
120 		} catch (IllegalAccessException e) { 
121 			e.printStackTrace();
122 		} catch (ClassNotFoundException e) { 
123 			e.printStackTrace();
124 		} catch (IOException e) {
125 			e.printStackTrace();
126 		}
127 		return "dbList";
128 	}
129 
130 	public String getUrl() {
131 		return url;
132 	}
133 
134 	public void setUrl(String url) {
135 		this.url = url;
136 	}
137 }