1 22 package org.jboss.resource.deployment.ds; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.jboss.logging.Logger; 28 import org.jboss.resource.deployment.ds.metadata.AbstractConnectionFactoryMetaData; 29 import org.jboss.resource.deployment.ds.metadata.AvailabilitySupportMetaData; 30 import org.jboss.resource.deployment.ds.metadata.ConnectionFactoryMetaData; 31 import org.jboss.resource.deployment.ds.metadata.ConnectionFactoryMetaDataFactory; 32 import org.jboss.resource.deployment.ds.metadata.ConnectionPoolMetaData; 33 import org.jboss.resource.deployment.ds.metadata.DataSourceMetaData; 34 import org.jboss.resource.deployment.ds.metadata.DsDefinitionMetaData; 35 import org.jboss.resource.deployment.ds.metadata.DsMetaData; 36 import org.jboss.resource.deployment.ds.metadata.DsPropertyMetaData; 37 import org.jboss.resource.deployment.ds.metadata.PoolCriteriaMetaData; 38 import org.jboss.resource.deployment.ds.metadata.SqlSupportMetaData; 39 import org.jboss.resource.deployment.ds.metadata.TransactionSupportFactory; 40 import org.jboss.resource.deployment.ds.metadata.TransactionSupportMetaData; 41 import org.jboss.xb.binding.ObjectModelFactory; 42 import org.jboss.xb.binding.UnmarshallingContext; 43 import org.xml.sax.Attributes ; 44 45 51 public class DsObjectModelFactory implements ObjectModelFactory 52 { 53 54 private static final Logger log = Logger.getLogger(DsObjectModelFactory.class); 55 56 57 private static final List connectionPoolElementNames = new ArrayList (); 58 59 60 private static final List sqlSupportElementNames = new ArrayList (); 61 62 63 private static final List criteriaSupportElementNames = new ArrayList (); 64 65 66 private static final List txnSupportElementnames = new ArrayList (); 67 68 private static final List availablitySupportElementNames = new ArrayList (); 69 70 static 71 { 72 73 connectionPoolElementNames.add("min-pool-size"); 75 connectionPoolElementNames.add("max-pool-size"); 76 connectionPoolElementNames.add("blocking-timeout-millis"); 77 connectionPoolElementNames.add("idle-timeout-minutes"); 78 connectionPoolElementNames.add("prefill"); 79 connectionPoolElementNames.add("background-validation"); 80 connectionPoolElementNames.add("background-validtion-interval"); 81 connectionPoolElementNames.add("validate-on-match"); 82 connectionPoolElementNames.add("no-tx-separate-pools"); 83 84 sqlSupportElementNames.add("new-connection-sql"); 86 sqlSupportElementNames.add("check-valid-connection-sql"); 87 sqlSupportElementNames.add("valid-connection-checker-class-name"); 88 sqlSupportElementNames.add("exception-sorter-class-name"); 89 sqlSupportElementNames.add("prepared-statement-cache-size"); 90 sqlSupportElementNames.add("share-prepared-statements"); 91 sqlSupportElementNames.add("track-statements"); 92 sqlSupportElementNames.add("query-timeout"); 93 sqlSupportElementNames.add("set-tx-query-timeout"); 94 sqlSupportElementNames.add("transaction-isolation"); 95 96 criteriaSupportElementNames.add("application-managed-security"); 97 criteriaSupportElementNames.add("security-domain"); 98 criteriaSupportElementNames.add("security-domain-and-application"); 99 100 txnSupportElementnames.add("no-tx-datasource"); 101 txnSupportElementnames.add("local-tx-datasource"); 102 txnSupportElementnames.add("xa-datasource"); 103 txnSupportElementnames.add("no-tx-connection-factory"); 104 txnSupportElementnames.add("tx-connection-factory"); 105 txnSupportElementnames.add("ha-local-tx-datasource"); 106 txnSupportElementnames.add("ha-xa-datasource"); 107 108 availablitySupportElementNames.add("ha-local-tx-datasource"); 109 availablitySupportElementNames.add("ha-xa-datasource"); 110 111 } 112 113 114 private boolean trace = log.isTraceEnabled(); 115 116 public Object newRoot(Object root, UnmarshallingContext navigator, String namespaceURI, String localName, 117 Attributes attrs) 118 { 119 checkRoot(localName); 120 DsMetaData md = new DsMetaData(); 121 final DsDefinitionMetaData dsdmd = ConnectionFactoryMetaDataFactory.getDefinitionMetaData(localName); 122 md.setDsDefinitionMetaData(dsdmd); 123 return dsdmd; 124 } 125 126 public Object newChild(DsDefinitionMetaData md, UnmarshallingContext navigator, String namespaceURI, 127 String localName, Attributes attrs) 128 { 129 AbstractConnectionFactoryMetaData abmd = ConnectionFactoryMetaDataFactory.getFactoryMetaData(localName); 130 md.addDsDefinition(abmd); 131 return abmd; 132 133 } 134 135 public Object addChild(DsDefinitionMetaData md, ConnectionFactoryMetaData cfmd, UnmarshallingContext navigator, 136 String namespaceURI, String localName) 137 { 138 if (txnSupportElementnames.contains(localName)) 139 { 140 TransactionSupportMetaData txmd = handleTransactionSupportMetaData(cfmd, localName); 141 cfmd.setTxnSupport(txmd); 142 143 } 144 145 return cfmd; 146 147 } 148 149 public Object addChild(DsDefinitionMetaData md, DataSourceMetaData dsmd, UnmarshallingContext navigator, 150 String namespaceURI, String localName) 151 { 152 153 if (txnSupportElementnames.contains(localName)) 154 { 155 156 TransactionSupportMetaData txmd = handleTransactionSupportMetaData(dsmd, localName); 157 dsmd.setTxnSupport(txmd); 158 159 } 160 161 if (availablitySupportElementNames.contains(localName)) 162 { 163 AvailabilitySupportMetaData amd = handleAvailabilitySupportMetaData(dsmd, localName); 164 dsmd.setAvailabilitySupport(amd); 165 166 } 167 168 if (localName.equals("no-tx-datasource") || localName.equals("local-tx-datasource")) 169 { 170 dsmd.setRarName("jboss-local-jdbc.rar"); 171 dsmd.setConnectionDefintion("javax.sql.DataSource"); 172 173 } 174 else if (localName.equals("xa-tx-datasource")) 175 { 176 dsmd.setRarName("jboss-xa-jdbc.rar"); 177 dsmd.setConnectionDefintion("javax.sql.DataSource"); 178 179 } 180 else if (localName.equals("ha-local-tx-datasource")) 181 { 182 dsmd.setRarName("jboss-ha-local-jdbc.rar"); 183 dsmd.setConnectionDefintion("javax.sql.DataSource"); 184 185 } 186 else if (localName.equals("ha-xa-datasource")) 187 { 188 dsmd.setRarName("jboss-ha-xa-jdbc.rar"); 189 dsmd.setConnectionDefintion("javax.sql.DataSource"); 190 191 } 192 193 194 return dsmd; 195 196 } 197 198 public Object newChild(ConnectionFactoryMetaData cfmd, UnmarshallingContext navigator, String namespaceURI, 199 String localName, Attributes attrs) 200 { 201 202 if (localName.equals("config-property")) 203 { 204 DsPropertyMetaData pmd = handlePropertyMetaData(localName, attrs); 205 cfmd.addProperty(pmd); 206 return pmd; 207 } 208 else if (connectionPoolElementNames.contains(localName)) 209 { 210 return handlePoolMetaData(cfmd); 211 212 } 213 else if (criteriaSupportElementNames.contains(localName)) 214 { 215 return handlePoolCriteriaMetaData(cfmd, localName); 216 217 } 218 else if (localName.equals("local-transaction") || localName.equals("xa-transaction")) 219 { 220 cfmd.setTxnSupport(TransactionSupportFactory.getTransactionSupport(localName)); 223 224 } 225 226 return null; 227 } 228 229 public Object newChild(DataSourceMetaData dsmd, UnmarshallingContext navigator, String namespaceURI, 230 String localName, Attributes attrs) 231 { 232 233 if (localName.equals("connection-property") || localName.equals("xa-datasource-property")) 234 { 235 DsPropertyMetaData pmd = handlePropertyMetaData(localName, attrs); 236 dsmd.addProperty(pmd); 237 return pmd; 238 239 } 240 241 else if (sqlSupportElementNames.contains(localName)) 242 { 243 return handleSqlSupportMetaData(dsmd); 244 245 } 246 else if (connectionPoolElementNames.contains(localName)) 247 { 248 return handlePoolMetaData(dsmd); 249 250 } 251 else if (criteriaSupportElementNames.contains(localName)) 252 { 253 return handlePoolCriteriaMetaData(dsmd, localName); 254 255 } 256 257 return null; 258 259 } 260 261 public void setValue(final DsPropertyMetaData dsmd, UnmarshallingContext navigator, String namespaceURI, 262 String localName, String value) 263 { 264 dsmd.setValue(value); 265 266 } 267 268 public void setValue(final ConnectionFactoryMetaData cfmd, UnmarshallingContext navigator, String namespaceURI, 269 String localName, String value) 270 { 271 if (localName.equals("jndi-name")) 272 { 273 cfmd.setJndiName(value); 274 275 } 276 else if (localName.equals("use-java-context")) 277 { 278 cfmd.setUseJavaConext(Boolean.valueOf(localName).booleanValue()); 279 280 } 281 else if (localName.equals("connection-definition")) 282 { 283 cfmd.setConnectionDefintion(localName); 284 } 285 286 } 287 288 public void setValue(final DataSourceMetaData dsmd, UnmarshallingContext navigator, String namespaceURI, 289 String localName, String value) 290 { 291 292 if (localName.equals("jndi-name")) 293 { 294 dsmd.setJndiName(value); 295 296 } 297 else if (localName.equals("use-java-context")) 298 { 299 dsmd.setUseJavaConext(Boolean.valueOf(localName).booleanValue()); 300 301 } 302 else if (localName.equals("connection-definition")) 303 { 304 dsmd.setConnectionDefintion(localName); 305 } 306 else if (localName.equals("xa-datasource-class")) 307 { 308 dsmd.setDriverClass(value); 309 310 } 311 else if (localName.equals("isSameRM-override-value")) 312 { 313 dsmd.setSameRMOverride(Boolean.valueOf(value).booleanValue()); 314 315 } 316 else if (localName.equals("type-mapping")) 317 { 318 dsmd.setTypeMapping(value); 319 320 } 321 else if(localName.equals("username")) 322 { 323 dsmd.setUserName(value); 324 } 325 else if(localName.equals("password")) 326 { 327 dsmd.setPassWord(value); 328 329 } 330 else if(localName.equals("connection-url")) 331 { 332 dsmd.setConnectionUrl(value); 333 334 }else if(localName.equals("driver-class") || localName.equals("xa-datasource-class")) 335 { 336 dsmd.setDriverClass(value); 337 338 }else if(localName.equals("url-delimeter")) 339 { 340 341 dsmd.getAvailabilitySupport().setUrlDelimeter(value); 342 343 }else if(localName.equals("url-property")) 344 { 345 dsmd.getAvailabilitySupport().setUrlProperty(value); 346 347 } 348 349 else 350 { 351 } 353 354 } 355 356 public void setValue(final ConnectionPoolMetaData cpmd, UnmarshallingContext navigator, String namespaceURI, 357 String localName, String value) 358 { 359 360 if (localName.equals("min-pool-size")) 361 { 362 cpmd.setMinPoolSize(Integer.valueOf(value).intValue()); 363 } 364 else if (localName.equals("max-pool-size")) 365 { 366 cpmd.setMaxPoolSize(Integer.valueOf(value).intValue()); 367 } 368 else if (localName.equals("blocking-timeout-millis")) 369 { 370 cpmd.setBlockingTimeoutMilliseconds(Long.valueOf(value).longValue()); 371 } 372 else if (localName.equals("idle-timeout-minutes")) 373 { 374 cpmd.setIdleTimeoutMinutes(Integer.valueOf(value).intValue()); 375 376 } 377 else if (localName.equals("security-damain") || localName.equals("application-managed-security") 378 || localName.equals("security-domain-and-application")) 379 { 380 cpmd.setPoolCriteria(PoolCriteriaMetaData.fromDsElement(localName)); 381 382 } 383 else if (localName.equals("background-validation")) 384 { 385 cpmd.setBackgroundValidation(Boolean.valueOf(value).booleanValue()); 386 387 } 388 else if (localName.equals("background-validation-interval")) 389 { 390 cpmd.setBackgroundValidationInterval(Integer.valueOf(value).intValue()); 391 392 } 393 else if (localName.equals("no-tx-separate-pools")) 394 { 395 cpmd.setNoTxSeperatePool(Boolean.valueOf(value).booleanValue()); 396 397 } 398 else if (localName.equals("prefill")) 399 { 400 cpmd.setPrefill(Boolean.valueOf(value).booleanValue()); 401 402 } 403 404 else 405 { 406 407 throw new IllegalArgumentException ("Unknown connection pool setValue: nuri=" + namespaceURI + " localName=" 408 + localName + " value=" + value); 409 410 } 411 412 } 413 414 public void setValue(final SqlSupportMetaData sqlmd, UnmarshallingContext navigator, String namespaceURI, 415 String localName, String value) 416 { 417 418 if (localName.equals("prepared-statement-cache-size")) 419 { 420 sqlmd.setPreparedStatementCacheSize(new Integer (value).intValue()); 421 422 } 423 else if (localName.equals("share-prepared-statements")) 424 { 425 sqlmd.setShareStatements(Boolean.valueOf(value).booleanValue()); 426 } 427 else if (localName.equals("track-statements")) 428 { 429 sqlmd.setTrackStatements(Boolean.valueOf(value).booleanValue()); 430 431 } 432 else if (localName.equals("new-connection-sql")) 433 { 434 435 sqlmd.setNewConnectionSql(value); 436 437 } 438 else if (localName.equals("check-valid-connection-sql")) 439 { 440 441 sqlmd.setCheckValidConnectionSql(value); 442 443 } 444 else if (localName.equals("valid-connection-checker-class-name")) 445 { 446 447 sqlmd.setValidConnectionCheckerClassName(value); 448 449 } 450 else if (localName.equals("exception-sorter-class-name")) 451 { 452 453 sqlmd.setExceptionSorterClassName(value); 454 455 } 456 else if (localName.equals("query-timeout")) 457 { 458 sqlmd.setQueryTimeout(Integer.valueOf(value).intValue()); 459 460 } 461 else if (localName.equals("set-tx-query-timeout")) 462 { 463 sqlmd.setTxQueryTimeout(true); 464 465 }else if(localName.equals("track-statements")) 466 { 467 468 if(value.equals("nowarn")) 469 { 470 sqlmd.setTrackStatements(Boolean.TRUE.booleanValue()); 471 sqlmd.setTrackStatementsNoWarn(Boolean.TRUE.booleanValue()); 472 473 }else if(value.equals("true")) 474 { 475 sqlmd.setTrackStatements(Boolean.TRUE.booleanValue()); 476 477 } 478 479 480 } 481 } 482 483 public Object completeRoot(Object root, UnmarshallingContext ctx, String uri, String name) 484 { 485 return root; 486 } 487 488 private void checkRoot(String localName) 489 { 490 if (!localName.equals("datasources") && !localName.equals("connection-factories")) 491 { 492 493 throw new IllegalStateException ( 494 "Unexpected root element: was expecting 'datasources' or 'connection-factories' but got '" + localName 495 + "'"); 496 } 497 498 } 499 500 private DsPropertyMetaData handlePropertyMetaData(String localName, Attributes attrs) 501 { 502 DsPropertyMetaData pmd = new DsPropertyMetaData(); 503 504 if (attrs != null && attrs.getLength() > 0) 505 { 506 for (int i = 0; i < attrs.getLength(); i++) 507 { 508 if (attrs.getLocalName(i).equals("name")) 509 { 510 pmd.setName(attrs.getValue(i)); 511 512 } 513 if (attrs.getLocalName(i).equals("type")) 514 { 515 pmd.setType(attrs.getValue(i)); 516 517 } 518 } 519 } 520 return pmd; 521 } 522 523 private ConnectionPoolMetaData handlePoolCriteriaMetaData(ConnectionFactoryMetaData cfmd, String localName) 524 { 525 526 ConnectionPoolMetaData cpmd = cfmd.getPoolMetaData(); 527 528 if (cpmd == null) 529 { 530 cpmd = new ConnectionPoolMetaData(); 531 } 532 533 if (cpmd.getPoolCriteria().equals(PoolCriteriaMetaData.NOTHING)) 534 { 535 PoolCriteriaMetaData pcmd = PoolCriteriaMetaData.fromDsElement(localName); 536 cpmd.setPoolCriteria(pcmd); 537 538 } 539 540 return cpmd; 541 542 } 543 544 private ConnectionPoolMetaData handlePoolMetaData(ConnectionFactoryMetaData cfmd) 545 { 546 547 ConnectionPoolMetaData cpmd = cfmd.getPoolMetaData(); 548 549 if (cpmd == null) 550 { 551 552 cpmd = new ConnectionPoolMetaData(); 553 cfmd.setPoolMetaData(cpmd); 554 555 } 556 557 return cpmd; 558 559 } 560 561 private SqlSupportMetaData handleSqlSupportMetaData(DataSourceMetaData dsmd) 562 { 563 564 SqlSupportMetaData sqlmd = dsmd.getSqlSupport(); 565 566 if (sqlmd == null) 567 { 568 sqlmd = new SqlSupportMetaData(); 569 dsmd.setSqlSupportMetaData(sqlmd); 570 571 } 572 573 return sqlmd; 574 575 } 576 577 private TransactionSupportMetaData handleTransactionSupportMetaData(ConnectionFactoryMetaData cfmd, String localName) 578 { 579 TransactionSupportMetaData txmd = cfmd.getTxnSupport(); 580 581 if (txmd == null) 582 { 583 584 txmd = TransactionSupportMetaData.fromString(localName); 585 cfmd.setTxnSupport(txmd); 586 587 } 588 589 return txmd; 590 591 } 592 593 private AvailabilitySupportMetaData handleAvailabilitySupportMetaData(DataSourceMetaData dsmd, String localName) 594 { 595 AvailabilitySupportMetaData amd = dsmd.getAvailabilitySupport(); 596 597 if (amd == null || amd.equals(AvailabilitySupportMetaData.NONE)) 598 { 599 amd = AvailabilitySupportMetaData.fromString(localName); 600 601 } 602 603 return amd; 604 605 } 606 } 607 | Popular Tags |