1 19 20 23 24 package org.netbeans.modules.j2ee.sun.ws7.nodes; 25 26 import javax.enterprise.deploy.spi.DeploymentManager ; 27 import javax.enterprise.deploy.spi.TargetModuleID ; 28 import org.netbeans.modules.j2ee.sun.ws7.Constants; 29 import org.openide.util.Lookup; 30 import org.openide.nodes.AbstractNode; 31 import org.openide.nodes.Node; 32 import org.openide.nodes.Children; 33 import org.openide.util.NbBundle; 34 import java.util.HashMap ; 35 import java.util.Map ; 36 import java.util.Set ; 37 import java.util.HashSet ; 38 import java.util.Arrays ; 39 import java.util.ArrayList ; 40 import java.util.Iterator ; 41 import org.openide.nodes.Sheet; 42 import org.openide.nodes.PropertySupport; 43 import java.beans.PropertyEditor ; 44 45 import org.netbeans.modules.j2ee.sun.ws7.ide.editors.TaggedValue; 46 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePairsPropertyEditor; 47 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair; 48 import org.netbeans.modules.j2ee.sun.ws7.dm.WS70SunDeploymentManager; 49 import org.netbeans.modules.j2ee.sun.ws7.j2ee.ResourceType; 50 import org.netbeans.modules.j2ee.sun.ws7.ui.Util; 51 52 53 57 public class WS70Resource extends WS70ManagedObjectBase { 58 private String jndiName; 59 private ResourceType resType; 60 private String configName; 61 private HashMap attributes; 62 private WS70SunDeploymentManager manager; 63 private Map properties; 64 65 68 public WS70Resource(DeploymentManager manager, String config, 69 HashMap attributes, ResourceType type) { 70 Object name = attributes.get("jndi-name"); 71 if(name==null){ 72 this.jndiName = "jndiname"; 73 }else{ 74 this.jndiName = (String )name; 75 } 76 77 this.attributes = this.constructAttributes(attributes); 78 this.manager = (WS70SunDeploymentManager)manager; 79 configName = config; 80 resType = type; 81 } 82 83 public String getJndiName(){ 84 return jndiName; 85 } 86 public String getDisplayName(){ 87 return getJndiName(); 88 } 89 public void setProperties(String propType, Map props){ 90 if(properties==null){ 91 properties = new HashMap (); 92 } 93 properties.put(propType, props); 94 } 95 public void deleteResource()throws Exception { 96 try{ 97 manager.deleteResource(resType, configName, jndiName); 98 }catch(Exception ex){ 99 throw ex; 100 } 101 } 102 public Attribute setAttribute(String attribute, Object value) throws Exception { 103 try{ 104 HashMap map = new HashMap (); 105 map.put(attribute, value.toString()); 106 manager.setResource(resType, configName, getJndiName(), map, true); 107 if(attributes.containsKey(attribute)){ 108 attributes.put(attribute, value); 109 } 110 }catch(Exception ex){ 111 throw ex; 112 } 113 return new Attribute(attribute, value); 114 } 115 private void setResourceProperty(String type, HashMap props, ArrayList list) throws Exception { 116 try{ 117 manager.setUserResourceProp(configName, resType.toString(), 118 getJndiName(), type, list, true); 119 120 }catch(Exception ex){ 121 throw ex; 122 } 123 properties.put(type, props); 124 } 125 126 127 public Sheet updateSheet(Sheet sheet) { 128 Sheet.Set ps = sheet.get(Sheet.PROPERTIES); 129 try { 130 Set readOnlyResource = new HashSet (Arrays.asList(READ_ONLY_PROPS_RESOURCES)); 131 for(Iterator itr = attributes.keySet().iterator(); itr.hasNext(); ) { 132 Attribute a = (Attribute) itr.next(); 133 AttributeInfo attr = (AttributeInfo)attributes.get(a); 134 String shortDescription = getShortDescription(attr); 135 136 if (attr == null || ! attr.isReadable()) { 137 continue; 138 } 139 140 Class type = getSupportedType(attr.getType()); 141 if (readOnlyResource.contains(attr.getName())) { 144 ps.put(createReadOnlyProperty(a, attr, shortDescription)); 145 } else { 146 if (attr.isWritable()) { 147 if (a.getValue() instanceof String []) { 148 String [] props = (String [])a.getValue(); 149 if (props != null) { 150 ps.put(getStringArrayEditor(a, attr, 151 shortDescription, 152 props.getClass(), 153 true)); 154 } else { 155 ps.put(createReadOnlyProperty(a, attr, 156 shortDescription)); 157 } 158 } else if (type != null) { 159 if (a.getValue() instanceof TaggedValue) { 160 ps.put(createTaggedProperty(a, attr, shortDescription, type)); 161 }else { 162 ps.put(createWritableProperty(a, attr, shortDescription, type)); 163 } 165 } else { 166 ps.put(createReadOnlyProperty(a, attr, shortDescription)); 167 } 168 }else { 169 if (a.getValue() instanceof String []) { 170 String [] props = (String [])a.getValue(); 171 172 if (props != null) { 173 ps.put(getStringArrayEditor(a, attr, shortDescription, 174 props.getClass(), false)); 175 } else { 176 ps.put(createReadOnlyProperty(a, attr, 177 shortDescription)); 178 } 179 } else { 180 ps.put(createReadOnlyProperty(a, attr, 181 shortDescription)); 182 } 183 } } } 187 if(properties!=null){ 189 HashMap props = (HashMap )properties.get(Constants.RES_PROPERTY); 190 if(props!=null){ 191 ps.put(this.createExtraProperties(Constants.RES_PROPERTY, props)); 192 } 193 props = (HashMap )properties.get(Constants.JDBC_RES_CONN_LEASE_PROPERTY); 194 if(props!=null){ 195 ps.put(this.createExtraProperties(Constants.JDBC_RES_CONN_LEASE_PROPERTY, props)); 196 } 197 props = (HashMap )properties.get(Constants.JDBC_RES_CONN_CREATION_PROPERTY); 198 if(props!=null){ 199 ps.put(this.createExtraProperties(Constants.JDBC_RES_CONN_CREATION_PROPERTY, props)); 200 } 201 } 202 203 } catch (Exception t) { 204 t.printStackTrace(); 205 } 206 207 return sheet; 208 } 209 PropertySupport createExtraProperties(final String name, final Map props) { 210 return new PropertySupport.ReadWrite( 211 name, 212 NameValuePairsPropertyEditor.class, name, 213 NbBundle.getMessage(WS70Resource.class, "DSC_ExtParams")){ Map values = props; 215 String type = name; 216 public Object getValue() { 217 return values; 218 } 219 220 public void setValue(Object obj) { 221 if(obj instanceof Object []){ 222 Object [] currentVal = (Object [])obj; 224 225 HashMap propertyList = new HashMap (); 226 ArrayList list = new ArrayList (); 227 for(int i=0; i<currentVal.length; i++){ 228 NameValuePair pair = (NameValuePair)currentVal[i]; 229 propertyList.put(pair.getParamName(), pair.getParamValue()); 230 list.add(pair.getParamName()+"="+pair.getParamValue()); 231 } 232 try{ 233 setResourceProperty(name, propertyList, list); 234 values = propertyList; 235 }catch(Exception ex){ 236 Util.showError(ex.getLocalizedMessage()); 237 } 238 } 239 } 240 public PropertyEditor getPropertyEditor(){ 241 return new NameValuePairsPropertyEditor(values); 242 } 243 }; 244 } private HashMap constructAttributes(HashMap attrMap){ 246 HashMap attributes = new HashMap (); 247 for(Iterator itr = attrMap.keySet().iterator(); itr.hasNext(); ) { 248 String attrName = (String ) itr.next(); 249 Object attrValue = attrMap.get(attrName); 250 Attribute attr = null; 251 AttributeInfo attrInfo = null; 252 Set booleans = new HashSet (Arrays.asList(RESOURCE_BOOLEAN_VALS)); 253 if(attrName.equals("jndi-name")){ 254 attr = new Attribute(attrName, attrValue); 255 attrInfo = new AttributeInfo(attrName, "java.lang.String", null, 256 true, false, false); 257 }else if(attrName.equals("isolation-level")){ 258 Object obj = TransactionIsolation.getValue((String )attrValue); 259 attr = new Attribute(attrName, obj); 260 attrInfo = new AttributeInfo(attrName, obj.getClass().getName(), 261 null, true, true, false); 262 263 } 266 else if(booleans.contains(attrName)){ 267 268 Object obj = Boolean.getValue((java.lang.Boolean )attrValue); 269 attr = new Attribute(attrName, obj); 270 attrInfo = new AttributeInfo(attrName, obj.getClass().getName(), 271 null, true, true, true); 272 273 }else if(attrName.equals("connection-validation")){ 274 Object obj = ValidationMethod.getValue((String )attrValue); 275 attr = new Attribute(attrName, obj); 276 attrInfo = new AttributeInfo(attrName, obj.getClass().getName(), 277 null, true, true, false); 278 279 }else{ 280 attr = new Attribute(attrName, attrValue); 281 attrInfo = new AttributeInfo(attrName, "java.lang.String", 282 null, true, true, false); 283 284 } 285 attributes.put(attr, attrInfo); 286 } 287 return attributes; 288 } 289 private NameValuePair[] getNameValuePairs(Object attrVal){ 290 java.util.Map attributeMap = (java.util.Map )attrVal; 291 Set attributeKeys = attributeMap.keySet(); 292 java.util.Iterator it = attributeKeys.iterator(); 293 NameValuePair[] pairs = new NameValuePair[attributeKeys.size()]; 294 int i=0; 295 while(it.hasNext()){ 296 NameValuePair pair = new NameValuePair(); 297 Object key = it.next(); 298 pair.setParamName(key.toString()); 299 pair.setParamValue(attributeMap.get(key).toString()); 300 pairs[i] = pair; 301 i++; 302 } 303 return pairs; 304 } 305 306 public static class ValidationMethod extends TaggedValue { 307 private String id; 308 309 private ValidationMethod(String id) { 310 this.id = id; 311 } 312 private static final ValidationMethod FALSE = 313 new ValidationMethod("false"); private static final ValidationMethod AUTO_COMMIT = 315 new ValidationMethod("auto-commit"); private static final ValidationMethod META_DATA = 317 new ValidationMethod("meta-data"); private static final ValidationMethod TABLE = 319 new ValidationMethod("table"); 321 private static final ValidationMethod[] values = 322 new ValidationMethod[]{ FALSE, AUTO_COMMIT, META_DATA, TABLE }; 323 324 public static TaggedValue getValue(String s) { 325 for (int i = 0; i < values.length; i++) { 326 if (values[i].getId().equalsIgnoreCase(s)) { 327 return values[i]; 328 } } 331 return null; 332 } 333 334 public static TaggedValue[] getChoices() { 335 return values; 336 } 337 338 public String getId() { 339 return id; 340 } 341 342 public String toString() { 343 return id; 344 } 345 } 346 347 public static class TransactionIsolation extends TaggedValue { 348 private String id; 349 350 private TransactionIsolation(String id) { 351 this.id = id; 352 } 353 private static final TransactionIsolation DAFAULT = 354 new TransactionIsolation("default"); private static final TransactionIsolation READ_UNCOMMITTED = 356 new TransactionIsolation("read-uncommitted"); private static final TransactionIsolation READ_COMMITTED = 358 new TransactionIsolation("read-committed"); private static final TransactionIsolation REPEATABLE_READ = 360 new TransactionIsolation("repeatable-read"); private static final TransactionIsolation SERIALIZABLE = 362 new TransactionIsolation("serializable"); 364 private static final TransactionIsolation[] values = 365 new TransactionIsolation[]{ DAFAULT, READ_UNCOMMITTED, 366 READ_COMMITTED, 367 REPEATABLE_READ, 368 SERIALIZABLE }; 369 370 public static TaggedValue getValue(String s) { 371 for (int i = 0; i < values.length; i++) { 372 if (values[i].getId().equalsIgnoreCase(s)) { 373 return values[i]; 374 } } 377 return null; 378 } 379 380 public static TaggedValue[] getChoices() { 381 return values; 382 } 383 384 public String getId() { 385 return id; 386 } 387 388 public String toString() { 389 return id; 390 } 391 } 392 } 393 | Popular Tags |