Changeset 2944
- Timestamp:
- Nov 23, 2006, 11:09:29 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.1/src/plugins/core/net/sf/basedb/plugins/PluginConfigurationImporter.java
r2828 r2944 88 88 extends AbstractPlugin 89 89 implements InteractivePlugin, AutoDetectingImporter 90 { 91 90 { 92 91 private static final About about = new AboutImpl 93 92 ( … … 116 115 117 116 private RequestInformation configureJob; 118 119 // Counting variables for the job120 private int numImportedConfigurations;121 private int numNotImportedConfigurations;122 117 123 118 // Variables to store the job parameters in. … … 232 227 is.close(); 233 228 234 response.setDone( getSuccessMessage());229 response.setDone("The configurations were imported successfully!"); 235 230 236 231 } … … 300 295 throws BaseException 301 296 { 302 DbControl dc = null; 303 numNotImportedConfigurations = 0;297 DbControl dc = null; 298 304 299 try 305 300 { … … 319 314 String pluginClassName = configuration.getAttributeValue("pluginClassName"); 320 315 321 try 322 { 323 PluginDefinition pluginDefinition = PluginDefinition.getByClassName(dc, pluginClassName); 324 325 PluginConfiguration pluginConfig = PluginConfiguration.getNew(dc, pluginDefinition); 326 dc.saveItem(pluginConfig); 327 pluginConfig.setName(name); 328 pluginConfig.setDescription(description); 329 330 List parameters = configuration.getChildren("parameter"); 331 setPluginConf(parameters, pluginConfig); 332 numImportedConfigurations++; 333 } 334 catch(Throwable ex) 335 { 336 numNotImportedConfigurations++; 337 } 316 317 PluginDefinition pluginDefinition = PluginDefinition.getByClassName(dc, pluginClassName); 318 319 PluginConfiguration pluginConfig = PluginConfiguration.getNew(dc, pluginDefinition); 320 dc.saveItem(pluginConfig); 321 pluginConfig.setName(name); 322 pluginConfig.setDescription(description); 323 324 List parameters = configuration.getChildren("parameter"); 325 setPluginConf(parameters, pluginConfig); 338 326 } 339 327 dc.commit(); … … 355 343 ----------------------------------------------------- 356 344 */ 357 /**358 Gets the message of how many parameters that were handled/imported of the parameters in the xml-file359 */360 private String getSuccessMessage()361 {362 StringBuilder message = new StringBuilder();363 message.append(numImportedConfigurations + " configurations were imported.\n");364 if (numNotImportedConfigurations > 0)365 {366 message.append(numNotImportedConfigurations + " configurations were not imported.\n");367 }368 return message.toString();369 }370 345 371 346 private RequestInformation getConfiguredJobParameters() … … 413 388 Returns null if this importer doesn't support the class. 414 389 */ 415 private ParameterType getParameterType(Class parameterClass )390 private ParameterType getParameterType(Class parameterClass, List<?> values) 416 391 { 417 392 if (parameterClass.equals(Boolean.class)) return new BooleanParameterType(); … … 421 396 else if (parameterClass.equals(Integer.class)) return new IntegerParameterType(); 422 397 else if (parameterClass.equals(Long.class)) return new LongParameterType(); 423 else if (parameterClass.equals(String.class)) return new StringParameterType(); 398 else if (parameterClass.equals(String.class)) 399 { 400 StringParameterType stp = null; 401 if (values != null && !values.isEmpty()) 402 { 403 int maxLength = 0; 404 for (Object obj : values) 405 { 406 if (obj instanceof String) 407 { 408 String str = obj.toString(); 409 maxLength = maxLength < str.length() ? str.length() : maxLength; 410 } 411 } 412 stp = new StringParameterType(maxLength, null, false); 413 } 414 else 415 { 416 stp = new StringParameterType(); 417 } 418 return stp; 419 420 } 424 421 else return null; 425 422 } … … 448 445 clazz = Class.forName(cl); 449 446 values = getValueList(parameter, clazz); 450 plc.setParameterValues(name,label, "", getParameterType(clazz), values); 447 ParameterType pType = getParameterType(clazz, values); 448 plc.setParameterValues(name,label, "", pType, values); 451 449 } 452 450 }
Note: See TracChangeset
for help on using the changeset viewer.