View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 * 10 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/BusinessQueryPanel.java,v 1.3 2003/08/24 22:14:58 farrukh_najmi Exp $ 11 * 12 */ 13 package com.sun.xml.registry.client.browser; 14 15 import com.sun.xml.registry.ebxml.BusinessQueryManagerImpl; 16 import java.awt.GridBagConstraints; 17 import java.awt.Insets; 18 import java.awt.event.ActionEvent; 19 import java.awt.event.ActionListener; 20 import java.util.ArrayList; 21 import javax.swing.JLabel; 22 import javax.swing.JPanel; 23 import javax.swing.JScrollPane; 24 import javax.swing.SwingConstants; 25 import javax.xml.registry.JAXRException; 26 27 import com.sun.xml.registry.client.browser.conf.bindings.*; 28 29 /*** 30 * The panel that displays UI for specifying parameters to a BusinessQuery. 31 * 32 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 33 */ 34 public class BusinessQueryPanel extends QueryPanel implements java.beans.PropertyChangeListener { 35 36 private GridBagConstraints c = new GridBagConstraints(); 37 38 private com.sun.xml.registry.client.browser.TreeCombo objectTypeCombo = null; 39 private static ConceptsTreeModel objectTypesTreeModel = null; 40 private javax.swing.JTextField nameText = null; 41 private javax.swing.JTextField descText = null; 42 43 private javax.swing.JCheckBox caseSensitiveCheckBox = null; 44 45 private ClassificationsList classificationsList = null; 46 private ExternalIdentifiersList extIdsList = null; 47 private ExternalLinksList linksList = null; 48 49 50 private org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(this.getClass()); 51 com.sun.xml.registry.ebxml.util.QueryUtil qu = com.sun.xml.registry.ebxml.util.QueryUtil.getInstance(); 52 53 54 /*** 55 * Class Constructor. 56 */ 57 public BusinessQueryPanel(final FindParamsPanel findParamsPanel, Configuration cfg) throws javax.xml.registry.JAXRException { 58 super(findParamsPanel, cfg); 59 60 java.awt.GridBagLayout gbl = new java.awt.GridBagLayout(); 61 setLayout(gbl); 62 63 JLabel objectTypeLabel = new JLabel("Object Type:", SwingConstants.LEFT); 64 c.gridx = 0; 65 c.gridy = 0; 66 c.gridwidth = 1; 67 c.gridheight = 1; 68 c.weightx = 0.0; 69 c.weighty = 0.0; 70 c.fill = GridBagConstraints.NONE; 71 c.anchor = GridBagConstraints.WEST; 72 c.insets = new Insets(4, 4, 0, 4); 73 gbl.setConstraints(objectTypeLabel, c); 74 add(objectTypeLabel); 75 76 javax.xml.registry.infomodel.ClassificationScheme objectTypeScheme = null; 77 78 JAXRClient client = RegistryBrowser.getInstance().getClient(); 79 javax.xml.registry.BusinessQueryManager bqm = client.getBusinessQueryManager(); 80 objectTypeScheme = (javax.xml.registry.infomodel.ClassificationScheme)bqm.getRegistryObject("urn:uuid:3188a449-18ac-41fb-be9f-99a1adca02cb", javax.xml.registry.LifeCycleManager.CLASSIFICATION_SCHEME); 81 objectTypesTreeModel = new ConceptsTreeModel(true, objectTypeScheme); 82 objectTypeCombo = new com.sun.xml.registry.client.browser.TreeCombo(objectTypesTreeModel); 83 String selectedIndexStr = com.sun.xml.registry.ebxml.util.ProviderProperties.getInstance(). 84 getProperty("jaxr-ebxml.registryBrowser.objectTypeCombo.initialSelectionIndex", "1"); 85 int index = Integer.parseInt(selectedIndexStr); 86 objectTypeCombo.setSelectedIndex(index); 87 c.gridx = 0; 88 c.gridy = 1; 89 c.gridwidth = 2; 90 c.gridheight = 1; 91 c.weightx = 0.5; 92 c.weighty = 0.0; 93 c.fill = GridBagConstraints.HORIZONTAL; 94 c.anchor = GridBagConstraints.WEST; 95 c.insets = new Insets(4, 4, 4, 4); 96 gbl.setConstraints(objectTypeCombo, c); 97 add(objectTypeCombo); 98 objectTypeCombo.addItemListener(new java.awt.event.ItemListener() { 99 public void itemStateChanged(java.awt.event.ItemEvent ev) { 100 if (ev.getStateChange() == java.awt.event.ItemEvent.DESELECTED) { 101 return; 102 } 103 104 String objectType = getObjectType(); 105 } 106 }); 107 108 //The caseSensitive CheckBox 109 caseSensitiveCheckBox = new javax.swing.JCheckBox("Case Sensitive Search"); 110 caseSensitiveCheckBox.setSelected(false); 111 caseSensitiveCheckBox.setEnabled(true); 112 c.gridx = 0; 113 c.gridy = 2; 114 c.gridwidth = 1; 115 c.gridheight = 1; 116 c.weightx = 0.0; 117 c.weighty = 0.0; 118 c.fill = GridBagConstraints.NONE; 119 c.anchor = GridBagConstraints.WEST; 120 c.insets = new Insets(4, 4, 0, 4); 121 gbl.setConstraints(caseSensitiveCheckBox, c); 122 add(caseSensitiveCheckBox); 123 124 //The name Text 125 JLabel nameLabel = new JLabel("Name:", SwingConstants.LEFT); 126 c.gridx = 0; 127 c.gridy = 3; 128 c.gridwidth = 1; 129 c.gridheight = 1; 130 c.weightx = 0.5; 131 c.weighty = 0.0; 132 c.fill = GridBagConstraints.HORIZONTAL; 133 c.anchor = GridBagConstraints.WEST; 134 c.insets = new Insets(4, 4, 0, 4); 135 gbl.setConstraints(nameLabel, c); 136 add(nameLabel); 137 138 nameText = new javax.swing.JTextField(); 139 c.gridx = 0; 140 c.gridy = 4; 141 c.gridwidth = 2; 142 c.gridheight = 1; 143 c.weightx = 0.5; 144 c.weighty = 0.0; 145 c.fill = GridBagConstraints.HORIZONTAL; 146 c.anchor = GridBagConstraints.EAST; 147 c.insets = new Insets(4, 4, 4, 4); 148 gbl.setConstraints(nameText, c); 149 add(nameText); 150 151 nameText.addActionListener(new ActionListener() { 152 public void actionPerformed(ActionEvent e) { 153 findParamsPanel.find(); 154 } 155 }); 156 157 //The description text 158 JLabel descLabel = new JLabel("Description:", SwingConstants.LEFT); 159 c.gridx = 0; 160 c.gridy = 5; 161 c.gridwidth = 1; 162 c.gridheight = 1; 163 c.weightx = 0.0; 164 c.weighty = 0.0; 165 c.fill = GridBagConstraints.NONE; 166 c.anchor = GridBagConstraints.WEST; 167 c.insets = new Insets(4, 4, 0, 4); 168 gbl.setConstraints(descLabel, c); 169 add(descLabel); 170 171 descText = new javax.swing.JTextField(); 172 c.gridx = 0; 173 c.gridy = 6; 174 c.gridwidth = 2; 175 c.gridheight = 1; 176 c.weightx = 0.5; 177 c.weighty = 0.0; 178 c.fill = GridBagConstraints.HORIZONTAL; 179 c.anchor = GridBagConstraints.EAST; 180 c.insets = new Insets(4, 4, 4, 4); 181 gbl.setConstraints(descText, c); 182 add(descText); 183 184 descText.addActionListener(new ActionListener() { 185 public void actionPerformed(ActionEvent e) { 186 findParamsPanel.find(); 187 } 188 }); 189 190 //Classifications 191 JLabel classificationsLabel = new JLabel("Classifications:", SwingConstants.LEFT); 192 c.gridx = 0; 193 c.gridy = 7; 194 c.gridwidth = 1; 195 c.gridheight = 1; 196 c.weightx = 0.0; 197 c.weighty = 0.0; 198 c.fill = GridBagConstraints.NONE; 199 c.anchor = GridBagConstraints.WEST; 200 c.insets = new Insets(4, 4, 0, 4); 201 gbl.setConstraints(classificationsLabel, c); 202 add(classificationsLabel); 203 204 classificationsList = new ClassificationsList(); 205 classificationsList.setEditable(true); 206 classificationsList.setVisibleRowCount(3); 207 JScrollPane classificationsListScrollPane = new JScrollPane(classificationsList); 208 //Workaround for bug 740746 where very wide item resulted in too short a height 209 classificationsListScrollPane.setMinimumSize(new java.awt.Dimension(-1, 50)); 210 211 c.gridx = 0; 212 c.gridy = 8; 213 c.gridwidth = 2; 214 c.gridheight = 1; 215 c.weightx = 0.5; 216 c.weighty = 0.5; 217 c.fill = GridBagConstraints.HORIZONTAL; 218 c.anchor = GridBagConstraints.WEST; 219 c.insets = new Insets(4, 4, 4, 4); 220 gbl.setConstraints(classificationsListScrollPane, c); 221 add(classificationsListScrollPane); 222 223 //Identifiers 224 JLabel identifiersLabel = new JLabel("External Identifiers:", SwingConstants.LEFT); 225 c.gridx = 0; 226 c.gridy = 9; 227 c.gridwidth = 1; 228 c.gridheight = 1; 229 c.weightx = 0.0; 230 c.weighty = 0.0; 231 c.fill = GridBagConstraints.NONE; 232 c.anchor = GridBagConstraints.WEST; 233 c.insets = new Insets(4, 4, 0, 4); 234 gbl.setConstraints(identifiersLabel, c); 235 add(identifiersLabel); 236 237 extIdsList = new ExternalIdentifiersList(); 238 extIdsList.setEditable(true); 239 extIdsList.setVisibleRowCount(3); 240 JScrollPane extIdsListScrollPane = new JScrollPane(extIdsList); 241 //Workaround for bug 740746 where very wide item resulted in too short a height 242 extIdsListScrollPane.setMinimumSize(new java.awt.Dimension(-1, 50)); 243 244 c.gridx = 0; 245 c.gridy = 10; 246 c.gridwidth = 2; 247 c.gridheight = 1; 248 c.weightx = 0.5; 249 c.weighty = 0.5; 250 c.fill = GridBagConstraints.HORIZONTAL; 251 c.anchor = GridBagConstraints.WEST; 252 c.insets = new Insets(4, 4, 4, 4); 253 gbl.setConstraints(extIdsListScrollPane, c); 254 add(extIdsListScrollPane); 255 256 //External Links 257 JLabel linksLabel = new JLabel("External Links:", SwingConstants.LEFT); 258 c.gridx = 0; 259 c.gridy = 11; 260 c.gridwidth = 1; 261 c.gridheight = 1; 262 c.weightx = 0.0; 263 c.weighty = 0.0; 264 c.fill = GridBagConstraints.NONE; 265 c.anchor = GridBagConstraints.WEST; 266 c.insets = new Insets(4, 4, 0, 4); 267 gbl.setConstraints(linksLabel, c); 268 add(linksLabel); 269 270 linksList = new ExternalLinksList(); 271 linksList.setEditable(true); 272 linksList.setVisibleRowCount(3); 273 JScrollPane linksListScrollPane = new JScrollPane(linksList); 274 //Workaround for bug 740746 where very wide item resulted in too short a height 275 linksListScrollPane.setMinimumSize(new java.awt.Dimension(-1, 50)); 276 277 c.gridx = 0; 278 c.gridy = 12; 279 c.gridwidth = 2; 280 c.gridheight = 1; 281 c.weightx = 0.5; 282 c.weighty = 0.5; 283 c.fill = GridBagConstraints.HORIZONTAL; 284 c.anchor = GridBagConstraints.WEST; 285 c.insets = new Insets(4, 4, 4, 4); 286 gbl.setConstraints(linksListScrollPane, c); 287 add(linksListScrollPane); 288 289 } 290 291 protected void processConfiguration() { 292 } 293 294 //Allows sharing with JBGraph 295 public static ConceptsTreeModel getObjectTypesTreeModel() { 296 return objectTypesTreeModel; 297 } 298 299 private String getObjectType() { 300 String objectType = null; 301 Object selectedItem = objectTypeCombo.getSelectedItem(); 302 303 return selectedItem.toString(); 304 } 305 306 public static String[] getObjectTypes() { 307 String[] array = null; 308 ArrayList objectTypes = new ArrayList(); 309 310 try { 311 JAXRClient client = RegistryBrowser.getInstance().getClient(); 312 BusinessQueryManagerImpl bqm = (BusinessQueryManagerImpl)(client.getBusinessQueryManager()); 313 java.util.Collection concepts = bqm.findConceptsByPath("/urn:uuid:3188a449-18ac-41fb-be9f-99a1adca02cb/RegistryObject%"); 314 315 int size = concepts.size(); 316 317 java.util.Iterator iter = concepts.iterator(); 318 int i=0; 319 while (iter.hasNext()) { 320 javax.xml.registry.infomodel.Concept concept = (javax.xml.registry.infomodel.Concept)iter.next(); 321 String objectType = concept.getValue(); 322 if (objectType.equals( "ClassificationNode")) { 323 objectType = "Concept"; 324 } 325 objectTypes.add(objectType); 326 } 327 328 java.util.Collections.sort(objectTypes); 329 330 array = new String[size]; 331 } 332 catch (JAXRException e) { 333 RegistryBrowser.displayError(e); 334 } 335 336 return (String[])objectTypes.toArray(array); 337 } 338 339 /*** 340 * Execute the query using parameters defined by the fields in QueryPanel. 341 */ 342 javax.xml.registry.BulkResponse executeQuery() { 343 javax.xml.registry.BulkResponse resp = null; 344 345 try { 346 347 // create namePattern collection 348 String nameStr = nameText.getText(); 349 String descStr = descText.getText(); 350 351 ArrayList classifications = ((ClassificationsListModel)(classificationsList.getModel())).getModels(); 352 ArrayList extIds = ((ExternalIdentifiersListModel)(extIdsList.getModel())).getModels(); 353 ArrayList extLinks = ((ExternalLinksListModel)(linksList.getModel())).getModels(); 354 355 JAXRClient client = RegistryBrowser.getInstance().getClient(); 356 javax.xml.registry.Connection connection = RegistryBrowser.getInstance().client.getConnection(); 357 javax.xml.registry.RegistryService service = connection.getRegistryService(); 358 BusinessQueryManagerImpl bqm = (BusinessQueryManagerImpl)service.getBusinessQueryManager(); 359 com.sun.xml.registry.ebxml.DeclarativeQueryManagerImpl dqm = (com.sun.xml.registry.ebxml.DeclarativeQueryManagerImpl)service.getDeclarativeQueryManager(); 360 361 String objectType = getObjectType(); 362 363 if (qu.getUnsupportedObjectTypes().contains(objectType)) { 364 throw new JAXRException("Search not supported for: " + objectType); 365 } 366 367 boolean isIntrinsic = isIntrinsicObjectType(objectType); 368 boolean caseSensitive = caseSensitiveCheckBox.isSelected(); 369 370 // make declarative query 371 String queryStr = "SELECT * from "; 372 373 if (isIntrinsic) { 374 queryStr += objectType + " obj "; 375 } 376 else { 377 queryStr += "ExtrinsicObject obj, ClassificationNode typeNode "; 378 } 379 380 //Add name to tables in join 381 if ((nameStr != null) && (nameStr.length() != 0)) { 382 queryStr += ", Name name "; 383 } 384 385 //Add description to tables in join 386 if ((descStr != null) && (descStr.length() != 0)) { 387 queryStr += ", Description des "; 388 } 389 390 boolean addedPredicate = false; 391 392 //Add objectType predicate 393 if (!isIntrinsic) { 394 if (!addedPredicate) { 395 queryStr += "WHERE "; 396 addedPredicate = true; 397 } 398 else { 399 queryStr += "AND "; 400 } 401 402 queryStr += 403 "((obj.objectType = typeNode.id) AND (typeNode.path LIKE '%/" 404 + objectType + "%')) "; 405 } 406 407 //Add name predicate if needed 408 if ((nameStr != null) && (nameStr.length() > 0)) { 409 if (!addedPredicate) { 410 queryStr += "WHERE "; 411 addedPredicate = true; 412 } 413 else { 414 queryStr += "AND "; 415 } 416 417 queryStr += "((name.parent = obj.id) AND (" + 418 BusinessQueryManagerImpl.caseSensitise("name.value", caseSensitive) + 419 " LIKE " + 420 BusinessQueryManagerImpl.caseSensitise("'"+nameStr+"'", caseSensitive) + ")) "; 421 } 422 423 //Add description predicate if needed 424 if ((descStr != null) && (descStr.length() > 0)) { 425 if (!addedPredicate) { 426 queryStr += "WHERE "; 427 addedPredicate = true; 428 } 429 else { 430 queryStr += "AND "; 431 } 432 433 queryStr += "((des.parent = obj.id) AND (" + 434 BusinessQueryManagerImpl.caseSensitise("des.value", caseSensitive) + 435 " LIKE " + 436 BusinessQueryManagerImpl.caseSensitise("'"+descStr+"'", caseSensitive) + ")) "; 437 } 438 439 //Add nested query for Classifications if needed 440 if (classifications.size() > 0) { 441 if (!addedPredicate) { 442 queryStr += "WHERE "; 443 addedPredicate = true; 444 } 445 else { 446 queryStr += "AND "; 447 } 448 queryStr += qu.classificationsToPred(classifications, "obj.id"); 449 450 } 451 452 //Add predicate for ExternalIdentifiers if needed 453 if (extIds.size() > 0) { 454 if (!addedPredicate) { 455 queryStr += "WHERE "; 456 addedPredicate = true; 457 } 458 else { 459 queryStr += "AND "; 460 } 461 462 queryStr += qu.externalIdentifiersToPred(extIds, "obj.id"); 463 464 } 465 466 467 //Add nested query for ExternalLinks if needed 468 if (extLinks.size() > 0) { 469 if (!addedPredicate) { 470 queryStr += "WHERE "; 471 addedPredicate = true; 472 } 473 else { 474 queryStr += "AND "; 475 } 476 477 queryStr += qu.externalLinksToPred(extLinks, "obj.id"); 478 479 } 480 481 javax.xml.registry.Query query = dqm.createQuery( 482 javax.xml.registry.Query.QUERY_TYPE_SQL, queryStr); 483 484 // make JAXR request 485 resp = dqm.executeQuery(query); 486 487 client.checkBulkResponse(resp); 488 489 } 490 catch (JAXRException e) { 491 RegistryBrowser.displayError(e); 492 } 493 494 return resp; 495 } 496 497 public static boolean isIntrinsicObjectType(String objectType) throws JAXRException { 498 boolean isIntrinsic = true; 499 500 JAXRClient client = RegistryBrowser.getInstance().getClient(); 501 javax.xml.registry.Connection connection = RegistryBrowser.getInstance().client.getConnection(); 502 com.sun.xml.registry.ebxml.RegistryServiceImpl service = (com.sun.xml.registry.ebxml.RegistryServiceImpl)connection.getRegistryService(); 503 504 String className = "javax.xml.registry.infomodel." + service.mapEbXMLNameToJAXRName(objectType); 505 try { 506 Class.forName(className); 507 } 508 catch (ClassNotFoundException e) { 509 isIntrinsic = false; 510 } 511 512 return isIntrinsic; 513 } 514 515 public void propertyChange(java.beans.PropertyChangeEvent ev) { 516 //System.err.println(ev); 517 if (ev.getPropertyName().equals(ConceptsTreeDialog.PROPERTY_SELECTED_CONCEPTS)) { 518 519 try { 520 javax.xml.registry.Connection connection = RegistryBrowser.getInstance().client.getConnection(); 521 javax.xml.registry.RegistryService service = connection.getRegistryService(); 522 javax.xml.registry.LifeCycleManager lcm = service.getBusinessLifeCycleManager(); 523 524 ArrayList selectedConcepts = (ArrayList)ev.getNewValue(); 525 ArrayList classifications = new ArrayList(); 526 527 java.util.Iterator iter = selectedConcepts.iterator(); 528 while (iter.hasNext()) { 529 javax.xml.registry.infomodel.Concept concept = (javax.xml.registry.infomodel.Concept)iter.next(); 530 javax.xml.registry.infomodel.Classification classification = lcm.createClassification(concept); 531 classifications.add(classification); 532 } 533 ((ClassificationsListModel)(classificationsList.getModel())).setModels(classifications); 534 } 535 catch (JAXRException e) { 536 RegistryBrowser.displayError(e); 537 } 538 } 539 } 540 541 /*** 542 * Clears or resets the UI. 543 */ 544 public void clear() throws JAXRException { 545 nameText.setText(""); 546 descText.setText(""); 547 if (classificationsList != null) { 548 ((ClassificationsListModel)(classificationsList.getModel())).clear(); 549 } 550 551 if (extIdsList != null) { 552 ((ExternalIdentifiersListModel)(extIdsList.getModel())).clear(); 553 } 554 555 if (linksList != null) { 556 ((ExternalLinksListModel)(linksList.getModel())).clear(); 557 } 558 } 559 560 } 561 562 563 564

This page was automatically generated by Maven