1 23 24 29 30 package com.sun.enterprise.tools.admingui.handlers; 31 32 import java.util.Iterator ; 33 import java.util.Map ; 34 import java.util.Enumeration ; 35 import java.util.ResourceBundle ; 36 37 import javax.servlet.http.HttpSession ; 38 import com.iplanet.jato.RequestContext; 39 import com.iplanet.jato.RequestManager; 40 import com.iplanet.jato.model.DefaultModel; 41 import com.iplanet.jato.model.Model; 42 import com.iplanet.jato.view.View; 43 import com.iplanet.jato.view.ViewBase; 44 import com.iplanet.jato.model.ModelControlException; 45 46 47 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 48 import com.sun.enterprise.tools.guiframework.model.ModelManager; 49 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 50 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 51 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 52 53 import com.sun.web.ui.model.CCActionTableModelInterface; 54 import com.sun.web.ui.view.html.CCCheckBox; 55 import com.sun.web.ui.view.html.CCTextField; 56 57 import com.sun.enterprise.connectors.util.ConnectionDefinitionUtils; 58 59 public class JdbcConnectionPoolHandlers { 60 61 public static final String PROPERTY_NAME = "propertyName"; 62 public static final String PROPERTY_VALUE = "propertyValue"; 63 64 65 66 public void getValuesFromStep1(RequestContext ctx, HandlerContext handlerCtx) throws ModelControlException { 67 View view = handlerCtx.getView(); 68 DescriptorContainerView descView = (DescriptorContainerView)(((ViewBase)view)); 69 ViewDescriptor vd = descView.getViewDescriptor(); 70 HttpSession session = RequestManager.getSession(); 71 DefaultModel step1Model = (DefaultModel)(session.getValue("connectionPoolStep1.model")); 72 DefaultModel step3Model = (DefaultModel)(session.getValue("connectionPoolStep3.model")); 73 String resourceType = (String )step1Model.getValue("ResourceType"); 74 String vendor = (String )step1Model.getValue("Vendor"); 75 boolean changed = true; 76 if (step3Model != null) { 77 if (resourceType != null && 78 resourceType.equals(step3Model.getValue("ResourceType")) && 79 vendor != null && 80 vendor.equals(step3Model.getValue("Vendor"))) { 81 changed = false; 82 } 83 } 84 if (changed) { 85 String datasourceClassName = getDatasourceClassName(vendor, resourceType); 86 if (datasourceClassName != null) { 87 descView.setDisplayFieldValue("DatasourceClassName", datasourceClassName.trim()); 88 } 89 CCActionTableModelInterface model = (CCActionTableModelInterface) handlerCtx.getInputValue("propertiesModel"); 90 populateProperties(datasourceClassName, model); 91 } 92 descView.setDisplayFieldValue("Name", step1Model.getValue("Name")); 93 descView.setDisplayFieldValue("ResourceType", resourceType); 94 descView.setDisplayFieldValue("Vendor", vendor); 95 } 96 97 public void setDatasourceClassName(RequestContext ctx, HandlerContext handlerCtx) { 98 DescriptorContainerView descView = (DescriptorContainerView)(handlerCtx.getView()); 99 ViewDescriptor vd = descView.getViewDescriptor(); 100 String vendor = (String )descView.getDisplayFieldValue("Vendor"); 101 String resourceType = (String )descView.getDisplayFieldValue("ResourceType"); 102 String datasourceClassName = getDatasourceClassName(vendor, resourceType); 103 if (datasourceClassName != null) { 104 descView.setDisplayFieldValue("DatasourceClassName", datasourceClassName.trim()); 105 } 106 } 107 108 public void enableGuaranteeIsolation(RequestContext ctx, HandlerContext handlerCtx) { 109 View view = handlerCtx.getView(); 110 CCCheckBox guaranteeIsolation = (CCCheckBox)view; 111 DescriptorContainerView descView = (DescriptorContainerView)view.getParent(); 112 String transIsolation = (String )descView.getDisplayFieldValue("TransactionIsolation"); 113 114 if (transIsolation != null && transIsolation.length() > 0) { 115 guaranteeIsolation.setDisabled(false); 116 } 117 else { 118 guaranteeIsolation.setValue("false"); 119 guaranteeIsolation.setDisabled(true); 120 } 121 } 122 123 public void enableTableName(RequestContext ctx, HandlerContext handlerCtx) { 124 View view = handlerCtx.getView(); 125 CCTextField tableName = (CCTextField)view; 126 DescriptorContainerView descView = (DescriptorContainerView)view.getParent(); 127 String validMethod = (String )descView.getDisplayFieldValue("ConnectionValidationMethod"); 128 129 if (validMethod != null && validMethod.equals("table")) { 130 tableName.setDisabled(false); 131 } 132 else { 133 tableName.setDisabled(true); 134 } 135 } 136 137 public static String getDatasourceClassName(String vendor, String resourceType) { 138 ResourceBundle bundle = 139 ResourceBundle.getBundle("com.sun.enterprise.tools.admingui.resources.JdbcVendors"); 140 if (vendor != null) { 141 try { 142 145 return bundle.getString(vendor.toLowerCase()+","+resourceType); 146 } catch (Exception ex) { 147 return null; } 149 } 150 return null; 151 } 152 153 public void populateProperties(String dataSource, 154 CCActionTableModelInterface model) throws ModelControlException{ 155 String [] defaultProperties = { 156 "databaseName", "serverName", "port", "networkProtocol", 157 "user", "password", "roleName", "datasourceName" }; 158 RequestContext ctx = RequestManager.getRequestContext(); 159 Map properties = null; 160 try { 161 properties = ConnectionDefinitionUtils.getConnectionDefinitionPropertiesAndDefaults(dataSource.trim()); 162 } catch (Exception ex) { 163 167 } 168 if (properties == null || properties.size() == 0) { 169 ((DefaultModel)model).clear(); 170 model.beforeFirst(); 171 for (int i = 0; i < defaultProperties.length; i++) { 172 model.appendRow(); 173 model.setValue(PROPERTY_NAME, defaultProperties[i]); 174 model.setValue(PROPERTY_VALUE, ""); 175 model.setRowSelected(false); 176 } 177 } 178 else { 179 Iterator keys = properties.keySet().iterator(); 180 ((DefaultModel)model).clear(); 181 model.beforeFirst(); 182 while (keys.hasNext()) { 183 model.appendRow(); 184 String name = (String )keys.next(); 185 model.setValue(PROPERTY_NAME, name); 186 model.setValue(PROPERTY_VALUE, properties.get(name)); 187 model.setRowSelected(false); 188 } 189 } 190 } 191 192 public static void main(String __args[]) { 193 System.out.println("DS = " + getDatasourceClassName("sybase" , "javax.sql.XADataSource")); 195 } 196 } 197 | Popular Tags |