|

Example 2: Performing a query

This example shows how to perform queries programmatically. Ruddi allows you to find a business entity by name, classifications (such as NAICS), and WSDL classification. This example shows how to find business entities based on the NAICS classification scheme.

import java.net.*;

import inspireit.uddi.*;

import inspireit.uddi.request.*;

import inspireit.uddi.request.base.*;

import inspireit.uddi.request.inquiry.*;

import inspireit.uddi.response.*;

import inspireit.uddi.response.base.*;

import inspireit.uddi.collections.*;

import inspireit.uddi.base.*;

 

public class NaicsQuery {

 

public NaicsQuery(String queryURL) throws Exception {

// define the UDDI profile

UDDIProfile profile = new UDDIProfile();

profile.setProperty("inspireit.uddi.inquiry.url", queryURL);

profile.setProperty("inspireit.uddi.version", "2.0");

 

UDDIQuerier querier = UDDIQuerier.getQuerier(profile);

 

try {

KeyedReference softwarePublisher = new KeyedReference("5112");

softwarePublisher.setKeyName("NAICS: Software Publishers");

softwarePublisher.setTModelKey(TModel.NTIS_GOV_NAICS_1997.getTModelKey());

 

KeyedReferences keyedReferences = new KeyedReferences();

keyedReferences.add(softwarePublisher);

CategoryBag categoryBag = new CategoryBag(keyedReferences);

 

BusinessList businessList = querier.findBusiness(categoryBag);

BusinessInfos businessInfos = businessList.getBusinessInfos();

BusinessInfo businessInfo[] = businessInfos.toArray();

 

for(int i=0; i< businessInfo.length; i++) {

BusinessInfo bi = businessInfo[i];

Names names = bi.getNames();

Name _name[] = names.toArray();

System.out.println("BusinessInfo #" + i + ": " + _name[0]);

}

} catch(UDDIException e) {

e.printStackTrace();

}

}

 

public static void main(String args[]) throws Exception {

if (args.length != 1) {

System.out.println("NaicsQuery usage:

java FindBusinessExample <queryURL>");

System.exit(0);

}

 

new NaicsQuery(args[0]);

return;

}

}

 

This sample query searches for organizations classified under the "Software publishers" with the NAICS code number "5112". When run against the UDDI registry of Microsoft, we can read a list like the following:

BusinessInfo #0: 3G Scene Plc

BusinessInfo #1: B2eMarkets

BusinessInfo #2: Balisis Software

BusinessInfo #3: Broderbund LLC

BusinessInfo #4: Cape Clear Software

BusinessInfo #5: Cloanto Corporation

...

 

This example displays the name of the business entities. We can use the following snippet of code to display more information such as the binding key, descriptions and high-level informations on the published services:

BusinessInfo businessInfo = ...

BusinessKey businessKey = businessInfo.getBusinessKey();

System.out.println("Business key: " + businessKey);

 

Descriptions descriptions = businessInfo.getDescriptions();

Description description[] = descriptions.toArray();

for(int i=0;i< description.length; i++) {

System.out.println("Description #" + i + ": " + description[i]);

}

 

ServiceInfos serviceInfos = businessInfo.getServiceInfos();

ServiceInfo serviceInfo[] = serviceInfos.toArray();

for(int j=0; j< serviceInfo.length; j++) {

ServiceInfo info = serviceInfo[j];

ServiceKey serviceKey = info.getServiceKey();

System.out.println("Service key #" + j + ": " + serviceKey);

 

Names names = info.getNames();

Name name[] = names.toArray();

for(int k=0; k< name.length; k++) {

System.out.println("Name #" + k + ": " + name[k]);

}

}

For efficiency reasons, UDDI only returns high-level information on saved business entities. In order to get detailed information, we have to issue a get_businessDetail UDDI call.

For example:

BusinessInfo info = ...

BusinessKey businessKey = info.getBusinessKey();

BusinessDetail businessDetail = querier.getBusinessDetail(businessKey);

BusinessEntitys businessEntitys = businessDetail.getBusinessEntitys();

BusinessEntitybusinessEntity[] = businessEntitys.toArray();

...

|

(c) INSPIRE IT, 2003 | Send us your feedback: developers@ruddi.biz