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 11 package com.sun.xml.registry.client.browser; 12 13 import com.sun.xml.registry.ebxml.util.ProviderProperties; 14 15 import org.apache.commons.logging.Log; 16 17 import java.io.PrintWriter; 18 import java.io.StringWriter; 19 20 import java.util.ArrayList; 21 import java.util.Collection; 22 import java.util.Iterator; 23 24 import javax.xml.registry.BulkResponse; 25 import javax.xml.registry.BusinessLifeCycleManager; 26 import javax.xml.registry.BusinessQueryManager; 27 import javax.xml.registry.CapabilityProfile; 28 import javax.xml.registry.Connection; 29 import javax.xml.registry.ConnectionFactory; 30 import javax.xml.registry.JAXRException; 31 import javax.xml.registry.JAXRResponse; 32 import javax.xml.registry.RegistryService; 33 import javax.xml.registry.infomodel.RegistryObject; 34 35 36 /*** 37 * Contains the JAXR client code used by the browser 38 * 39 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 40 */ 41 public class JAXRClient { 42 43 /*** DOCUMENT ME! */ 44 com.sun.xml.registry.ebxml.ConnectionImpl connection; 45 46 /* 47 * This class handles all JAAS authentication tasks 48 */ 49 com.sun.xml.registry.ebxml.jaas.LoginModuleManager lmm; 50 51 /*** DOCUMENT ME! */ 52 BusinessQueryManager bqm; 53 54 /*** DOCUMENT ME! */ 55 BusinessLifeCycleManager lcm; 56 57 // Ought to be replaced by 58 // private final Log log = LogFactory.getLog(this) 59 60 /*** DOCUMENT ME! */ 61 Log log = null; 62 63 /*** 64 * Makes a connection to a JAXR Registry. 65 * 66 * @param url The URL of the registry. 67 */ 68 public void createConnection(String url) { 69 70 try { 71 Thread.currentThread().setContextClassLoader(RegistryBrowser 72 .getInstance().classLoader); 73 74 ProviderProperties.getInstance().put("javax.xml.registry.queryManagerURL", 75 url); 76 77 //Choose provider based on hack for now. 78 if (url.toLowerCase().indexOf("uddi") >= 0) { 79 System.setProperty("javax.xml.registry.ConnectionFactoryClass", 80 "com.sun.xml.registry.uddi.ConnectionFactoryImpl"); 81 } else { 82 System.setProperty("javax.xml.registry.ConnectionFactoryClass", 83 "com.sun.xml.registry.ebxml.ConnectionFactoryImpl"); 84 } 85 86 ConnectionFactory connFactory = 87 ConnectionFactory.newInstance(); 88 89 connection = 90 (com.sun.xml.registry.ebxml.ConnectionImpl)connFactory 91 .createConnection(); 92 93 RegistryService service = connection.getRegistryService(); 94 95 bqm = service.getBusinessQueryManager(); 96 lcm = service.getBusinessLifeCycleManager(); 97 98 log = ((com.sun.xml.registry.ebxml.RegistryServiceImpl)(lcm 99 .getRegistryService())).getConnection() 100 .getConnectionFactory().getLog(); 101 102 lmm = connection.getLoginModuleManager(); 103 lmm.setParentFrame(RegistryBrowser.getInstance()); 104 lmm.setParentLog(log); 105 106 } catch (JAXRException e) { 107 e.printStackTrace(); 108 System.err.println("Checking the cause"); 109 110 if (e.getCause() != null) { 111 System.err.println(getStackTraceFromThrowable(e 112 .getCause())); 113 } 114 115 RegistryBrowser.displayError("Error creating new Connection.", 116 e); 117 } 118 } 119 120 /*** 121 * DOCUMENT ME! 122 * 123 * @param t DOCUMENT ME! 124 * 125 * @return DOCUMENT ME! 126 */ 127 public String getStackTraceFromThrowable(Throwable t) { 128 129 String trace = null; 130 131 if (t != null) { 132 133 StringWriter sw = new StringWriter(); 134 PrintWriter pw = new PrintWriter(sw); 135 t.printStackTrace(pw); 136 trace = sw.toString(); 137 } 138 139 return trace; 140 } 141 142 /*** 143 * DOCUMENT ME! 144 * 145 * @return DOCUMENT ME! 146 * 147 * @throws JAXRException DOCUMENT ME! 148 */ 149 public Connection getConnection() throws JAXRException { 150 151 if (connection == null) { 152 throw new JAXRException("Connect to a registry by specifying Registry Location first."); 153 } 154 155 return connection; 156 } 157 158 /*** 159 * returns the business life cycle query manager. This should go 160 * away once the client code has all been moved here. 161 * 162 * @return DOCUMENT ME! 163 * 164 * @throws JAXRException DOCUMENT ME! 165 */ 166 public BusinessLifeCycleManager getBusinessLifeCycleManager() 167 throws JAXRException { 168 169 if (connection == null) { 170 throw new JAXRException("Connect to a registry by specifying Registry Location first."); 171 } 172 173 return lcm; 174 } 175 176 /*** 177 * returns the business life cycle query manager. This should go 178 * away once the client code has all been moved here. 179 * 180 * @return DOCUMENT ME! 181 * 182 * @throws JAXRException DOCUMENT ME! 183 */ 184 public BusinessQueryManager getBusinessQueryManager() 185 throws JAXRException { 186 187 if (connection == null) { 188 throw new JAXRException("Connect to a registry by specifying Registry Location first."); 189 } 190 191 return bqm; 192 } 193 194 /*** 195 * Find classification schemes 196 * 197 * @return DOCUMENT ME! 198 */ 199 Collection getClassificationSchemes() { 200 201 Collection schemes = null; 202 203 String errMsg = "Error getting ClassificationSchemes"; 204 205 try { 206 207 // Get all schemes 208 ArrayList findQualifiers = new ArrayList(); 209 ArrayList namePatterns = new ArrayList(); 210 211 namePatterns.add("%"); 212 213 BulkResponse response = 214 bqm.findClassificationSchemes(findQualifiers, 215 namePatterns, null, null); 216 217 checkBulkResponse(response); 218 schemes = response.getCollection(); 219 } catch (JAXRException e) { 220 RegistryBrowser.displayError(errMsg, e); 221 schemes = new ArrayList(); 222 } 223 224 return schemes; 225 } 226 227 /*** 228 * DOCUMENT ME! 229 * 230 * @return DOCUMENT ME! 231 */ 232 CapabilityProfile getCapabilityProfile() { 233 234 CapabilityProfile profile = null; 235 236 try { 237 profile = 238 connection.getRegistryService().getCapabilityProfile(); 239 } catch (JAXRException e) { 240 e.printStackTrace(); 241 RegistryBrowser.displayError(e); 242 } 243 244 return profile; 245 } 246 247 /*** 248 * DOCUMENT ME! 249 * 250 * @param objectsToSave DOCUMENT ME! 251 * 252 * @return DOCUMENT ME! 253 * 254 * @throws JAXRException DOCUMENT ME! 255 */ 256 public BulkResponse saveObjects(Collection objectsToSave) 257 throws JAXRException { 258 259 BulkResponse resp = null; 260 261 try { 262 resp = lcm.saveObjects(objectsToSave); 263 checkBulkResponse(resp); 264 } catch (JAXRException e) { 265 RegistryBrowser.displayError(e); 266 e.fillInStackTrace(); 267 throw e; 268 } 269 270 return resp; 271 } 272 273 /*** 274 * DOCUMENT ME! 275 * 276 * @param objectsToExport DOCUMENT ME! 277 */ 278 public void exportObjects(Collection objectsToExport) { 279 280 try { 281 282 Iterator iter = objectsToExport.iterator(); 283 284 while (iter.hasNext()) { 285 286 RegistryObject ro = (RegistryObject)iter.next(); 287 System.err.println(ro.toXML()); 288 } 289 } catch (JAXRException e) { 290 RegistryBrowser.displayError(e); 291 } 292 } 293 294 /*** 295 * DOCUMENT ME! 296 * 297 * @param resp DOCUMENT ME! 298 */ 299 public void checkBulkResponse(BulkResponse resp) { 300 301 try { 302 303 if ((resp != null) 304 && (!(resp.getStatus() == JAXRResponse.STATUS_SUCCESS))) { 305 306 Collection exceptions = resp.getExceptions(); 307 Iterator iter = exceptions.iterator(); 308 309 while (iter.hasNext()) { 310 311 Exception e = (Exception)iter.next(); 312 RegistryBrowser.displayError(e); 313 } 314 } 315 } catch (JAXRException e) { 316 RegistryBrowser.displayError(e); 317 } 318 } 319 }

This page was automatically generated by Maven