cmQuerySample.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2008
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. /**
  9. * cmQuerySample.java
  10. *
  11. * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  12. * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. *
  14. * Description: Simple Content Manager query sample
  15. */
  16. import java.rmi.RemoteException;
  17. import org.apache.axis.AxisFault;
  18. import org.apache.axis.client.Stub;
  19. import org.apache.axis.message.SOAPHeaderElement;
  20. import com.cognos.developer.schemas.bibus._3.BaseClass;
  21. import com.cognos.developer.schemas.bibus._3.BiBusHeader;
  22. import com.cognos.developer.schemas.bibus._3.OrderEnum;
  23. import com.cognos.developer.schemas.bibus._3.PropEnum;
  24. import com.cognos.developer.schemas.bibus._3.QueryOptions;
  25. import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
  26. import com.cognos.developer.schemas.bibus._3.Sort;
  27. import com.cognos.developer.schemas.bibus._3.StringProp;
  28. import com.cognos.developer.schemas.bibus._3.TokenProp;
  29. public class cmQuerySample
  30. {
  31. public String prepareQuery(CRNConnect connection, String searchPath)
  32. {
  33. String output = "";
  34. try
  35. {
  36. if ((searchPath == null) || (searchPath.length() == 0) || (searchPath.compareTo("") == 0) )
  37. {
  38. return "Invalid searchPath" + System.getProperty("line.separator");
  39. }
  40. // Search properties: we need the defaultName and the searchPath.
  41. PropEnum[] properties =
  42. { PropEnum.defaultName, PropEnum.searchPath };
  43. // Sort options: ascending sort on the defaultName property.
  44. //
  45. // The cmQuery.pl sample doesn't do this, it returns the default unsorted response.
  46. Sort[] sortBy = { new Sort()};
  47. sortBy[0].setOrder(OrderEnum.ascending);
  48. sortBy[0].setPropName(PropEnum.defaultName);
  49. // Query options; use the defaults.
  50. QueryOptions options = new QueryOptions();
  51. try
  52. {
  53. // sn_dg_sdk_method_contentManagerService_query_start_1
  54. BaseClass[] results =
  55. connection.getCMService().query(
  56. new SearchPathMultipleObject(searchPath),
  57. properties,
  58. sortBy,
  59. options);
  60. // sn_dg_sdk_method_contentManagerService_query_end_1
  61. // Display the results.
  62. System.out.println("Results:");
  63. output = output + "Results:\n";
  64. for (int i = 0; i < results.length; i++)
  65. {
  66. TokenProp theDefaultName = results[i].getDefaultName();
  67. StringProp theSearchPath = results[i].getSearchPath();
  68. //Results are directed to both the console and the return string
  69. //as this module may be run in a console or a GUI
  70. System.out.print("\t");
  71. output = output + "\t";
  72. System.out.print(theDefaultName.getValue());
  73. output = output + theDefaultName.getValue();
  74. System.out.print("\t");
  75. output = output + "\t";
  76. System.out.print(theSearchPath.getValue() + "\n");
  77. output = output + theSearchPath.getValue() + "\n";
  78. }
  79. }
  80. catch (AxisFault ex)
  81. {
  82. // Fault details can be found via ex.getFaultDetails(),
  83. // which returns an Element array.
  84. System.out.println("SOAP Fault:");
  85. System.out.println(ex.toString());
  86. }
  87. catch (RemoteException remoteEx)
  88. {
  89. SOAPHeaderElement theException =
  90. ((Stub)connection.getCMService()).getHeader(
  91. "",
  92. "biBusHeader");
  93. // You can now use theException to find out more information
  94. // about the problem.
  95. System.out.println("The request threw an RMI exception:");
  96. System.out.println(remoteEx.getMessage());
  97. System.out.println("Stack trace:");
  98. remoteEx.printStackTrace();
  99. return theException.toString();
  100. }
  101. }
  102. catch (Exception ex)
  103. {}
  104. return output;
  105. }
  106. }