1 package com.sun.xml.registry.ebxml; 2 3 import java.net.*; 4 import java.util.*; 5 6 import javax.activation.*; 7 import javax.xml.registry.*; 8 import javax.xml.registry.infomodel.*; 9 10 /* 11 * 12 * $Header: /cvsroot/ebxmlrr/jaxr/test/com/sun/xml/registry/ebxml/EbxmlProviderTest.java,v 1.15 2002/11/09 01:44:09 jasilva Exp $ 13 * 14 */ 15 16 public class EbxmlProviderTest { 17 public static void out(String s) { 18 System.out.println(s); 19 } 20 21 public static void outp(String s) { 22 System.out.print(s); 23 } 24 25 static String toName(Object registryObject) throws JAXRException { 26 RegistryObject ro = (RegistryObject)registryObject; 27 return ro.getName().getValue(); 28 } 29 30 static String toStatusString(int status) throws JAXRException { 31 if (status == JAXRResponse.STATUS_FAILURE) { 32 return "STATUS_FAILURE"; 33 } else if (status == JAXRResponse.STATUS_SUCCESS) { 34 return "STATUS_SUCCESS"; 35 } else if (status == JAXRResponse.STATUS_UNAVAILABLE) { 36 return "STATUS_UNAVAILABLE"; 37 } else if (status == JAXRResponse.STATUS_WARNING) { 38 return "STATUS_WARNING"; 39 } else { 40 return "[unkown status]"; 41 } 42 } 43 44 static void outResponse(BulkResponse br) throws JAXRException { 45 out("BulkResponse: status=" + toStatusString(br.getStatus())); 46 outCollection(br.getCollection(), " .collection:"); 47 outCollection(br.getExceptions(), " .exceptions:"); 48 } 49 50 static void outCollection(Collection col, String prompt) 51 throws JAXRException 52 { 53 outp(prompt); 54 if (col == null || col.size() == 0) { 55 out(" [empty collection]"); 56 return; 57 } 58 out(""); 59 for (Iterator it = col.iterator(); it.hasNext(); ) { 60 Object obj = it.next(); 61 if (obj instanceof RegistryObject) { 62 RegistryObject ro = (RegistryObject)obj; 63 String objType = ro.getObjectType() != null ? 64 ro.getObjectType().getValue() : "null"; 65 out(" name=" + toName(obj) + ", type=" 66 + obj.getClass().getName() 67 + ", objType=" + objType); 68 } else { 69 out(" obj=" + obj); 70 } 71 } 72 } 73 74 private static void usage() { 75 System.err.println("Usage: xxxTest [-opts] <SQL query>"); 76 System.err.println(" -qm1"); 77 System.err.println(" -[no]proxy"); 78 System.err.println(" -usage or -help = this message"); 79 System.exit(1); 80 } 81 82 public static void main(String[] args) throws Exception 83 { 84 String qmUrl = "http://localhost:8081/ebxmlrr/registry"; 85 boolean useProxy = true; 86 String qs = null; 87 88 for (int i = 0; i < args.length; i++) { 89 if (args[i].equals("-qm0")) { 90 // use default 91 } else if (args[i].equals("-qm1")) { 92 qmUrl = "http://registry.csis.hku.hk:8201/ebxmlrr/registry"; 93 } else if (args[i].equals("-proxy")) { 94 useProxy = true; 95 } else if (args[i].equals("-noproxy")) { 96 useProxy = false; 97 } else if (args[i].equals("-usage")) { 98 usage(); 99 } else if (args[i].equals("-help")) { 100 usage(); 101 } else { 102 qs = args[i]; 103 104 // Must be last arg 105 if (i != args.length - 1) { 106 usage(); 107 } 108 } 109 } 110 111 if (useProxy) { 112 System.setProperty("http.proxyHost", "webcache"); 113 System.setProperty("http.proxyPort", "8080"); 114 System.setProperty("http.noProxyHosts", "localhost"); 115 } 116 117 System.setProperty("javax.xml.registry.ConnectionFactoryClass", 118 "com.sun.xml.registry.ebxml.ConnectionFactoryImpl"); 119 ConnectionFactory connFactory = ConnectionFactory.newInstance(); 120 121 Properties props = new Properties(); 122 props.put("javax.xml.registry.queryManagerURL", qmUrl); 123 connFactory.setProperties(props); 124 Connection connection = connFactory.createConnection(); 125 RegistryService service = connection.getRegistryService(); 126 127 BusinessQueryManager bqm = service.getBusinessQueryManager(); 128 BusinessLifeCycleManager lcm = service.getBusinessLifeCycleManager(); 129 DeclarativeQueryManager dqm = service.getDeclarativeQueryManager(); 130 131 if (qs != null) { 132 // String qs = "SELECT * FROM ClassificationScheme"; 133 // qs = "SELECT * FROM Organization o"; 134 // qs = "SELECT o.id FROM Organization o, Name n WHERE n.value LIKE 'S%'AND n.parent = o.id;"; 135 136 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, qs); 137 BulkResponse br = dqm.executeQuery(query); 138 outResponse(br); 139 // out("br.getCollection()=" + br.getCollection()); 140 } else if (false) { 141 ArrayList al = new ArrayList(); 142 al.add("ISO%"); 143 al.add("foo%"); 144 BulkResponse br = bqm.findClassificationSchemes( 145 null, al, null, null); 146 out("br.getCollection()=" + br.getCollection()); 147 Iterator i = br.getCollection().iterator(); 148 ClassificationScheme cs = (ClassificationScheme) i.next(); 149 out("cs=" + toName(cs)); 150 Collection children = cs.getChildrenConcepts(); 151 for (Iterator it = children.iterator(); it.hasNext(); ) { 152 Concept con = (Concept)it.next(); 153 out("child=" + toName(con)); 154 for (Iterator jIt = con.getChildrenConcepts().iterator(); 155 jIt.hasNext(); ) { 156 out(" child2=" + toName(jIt.next())); 157 } 158 } 159 } else if (true) { 160 ArrayList cNamePats = new ArrayList(); 161 cNamePats.add("Y%"); 162 BulkResponse c = bqm.findConcepts(null, cNamePats, null, null, null); 163 outResponse(c); 164 165 Collection classifications = new ArrayList(); 166 Classification cla = null; 167 168 for (Iterator ci = c.getCollection().iterator(); ci.hasNext(); ) { 169 cla = lcm.createClassification((Concept)ci.next()); 170 classifications.add(cla); 171 } 172 173 ArrayList namePats = new ArrayList(); 174 namePats.add("Su%"); 175 BulkResponse br = bqm.findOrganizations(null, namePats, classifications, null, null, null); 176 outResponse(br); 177 178 Iterator it = br.getCollection().iterator(); 179 180 if (it.hasNext()) { 181 Organization org = (Organization)it.next(); 182 it = org.getClassifications().iterator(); 183 Classification cl = (Classification)it.next(); 184 out("ClassificationScheme=" + cl.getClassificationScheme()); 185 } 186 } else if (false) { 187 ArrayList namePats = new ArrayList(); 188 namePats.add("Su%"); 189 namePats.add("foo%"); 190 BulkResponse br = bqm.findOrganizations( 191 null, namePats, null, null, null, null); 192 outResponse(br); 193 194 Iterator it = br.getCollection().iterator(); 195 Organization org = (Organization)it.next(); 196 outCollection(org.getClassifications(), "Classifications:"); 197 198 it = org.getClassifications().iterator(); 199 Classification cl = (Classification)it.next(); 200 201 out("Slots:"); 202 it = org.getSlots().iterator(); 203 while (it.hasNext()) { 204 Slot slot = (Slot)it.next(); 205 outp("name=" + slot.getName()); 206 outp(", type=" + slot.getSlotType()); 207 out(", values=" + slot.getValues()); 208 } 209 210 // br = bqm.findOrganizations( 211 // null, namePats, org.getClassifications(), null, null, null); 212 // outResponse(br); 213 } else if (false) { 214 ArrayList namePats = new ArrayList(); 215 namePats.add("foo%"); 216 BulkResponse br = bqm.findOrganizations( 217 null, namePats, null, null, null, null); 218 outResponse(br); 219 } else if (true) { 220 BulkResponse br = bqm.findClassificationSchemes( 221 null, null, null, null); 222 out("br.getCollection()=" + br.getCollection()); 223 } else { 224 BulkResponse br = bqm.findOrganizations( 225 null, null, null, null, null, null); 226 out("br.getCollection()=" + br.getCollection()); 227 } 228 } 229 }

This page was automatically generated by Maven