1 package org.objectstyle.cayenne.modeler.action; 2 3 import org.objectstyle.cayenne.access.DataNode; 4 import org.objectstyle.cayenne.conf.DriverDataSourceFactory; 5 import org.objectstyle.cayenne.map.DataMap; 6 import org.objectstyle.cayenne.modeler.Application; 7 import org.objectstyle.cayenne.modeler.ProjectController; 8 import org.objectstyle.cayenne.modeler.pref.DBConnectionInfo; 9 import org.objectstyle.cayenne.modeler.pref.DataNodeDefaults; 10 import org.objectstyle.cayenne.modeler.util.CayenneAction; 11 import org.objectstyle.cayenne.project.ProjectDataSource; 12 13 16 public abstract class DBWizardAction extends CayenneAction { 17 18 public DBWizardAction(String name, Application application) { 19 super(name, application); 20 } 21 22 24 protected DataNode getPreferredNode() { 25 ProjectController projectController = getProjectController(); 26 DataNode node = projectController.getCurrentDataNode(); 27 28 if (node == null) { 30 DataMap map = projectController.getCurrentDataMap(); 31 if (map != null) { 32 node = projectController.getCurrentDataDomain().lookupDataNode(map); 33 } 34 } 35 36 return node; 37 } 38 39 protected String preferredDataSourceLabel(DBConnectionInfo nodeInfo) { 40 if (nodeInfo == null || nodeInfo.getDomainPreference() == null) { 41 42 DataNode node = getPreferredNode(); 44 return (node != null && DriverDataSourceFactory.class.getName().equals( 45 node.getDataSourceFactory())) ? "DataNode Connection Info" : null; 46 } 47 48 return nodeInfo.getKey(); 49 } 50 51 54 protected DBConnectionInfo preferredDataSource() { 55 DataNode node = getPreferredNode(); 56 57 if (node == null) { 59 return null; 60 } 61 62 DataNodeDefaults nodeDefaults = (DataNodeDefaults) getProjectController() 64 .getPreferenceDomainForDataDomain() 65 .getDetail(node.getName(), DataNodeDefaults.class, false); 66 67 String key = (nodeDefaults != null) ? nodeDefaults.getLocalDataSource() : null; 68 if (key != null) { 69 DBConnectionInfo info = (DBConnectionInfo) getApplication() 70 .getPreferenceDomain() 71 .getDetail(key, DBConnectionInfo.class, false); 72 if (info != null) { 73 return info; 74 } 75 } 76 77 if (!DriverDataSourceFactory.class.getName().equals(node.getDataSourceFactory())) { 79 return null; 80 } 81 82 DBConnectionInfo nodeInfo = new DBConnectionInfo(); 84 85 nodeInfo.copyFrom(((ProjectDataSource) node.getDataSource()).getDataSourceInfo()); 86 if (node.getAdapter() != null) { 87 nodeInfo.setDbAdapter(node.getAdapter().getClass().getName()); 88 } 89 90 return nodeInfo; 91 } 92 93 } | Popular Tags |