KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > BusinessEntityExample


1 /*
2  * The source code contained herein is licensed under the IBM Public License
3  * Version 1.0, which has been approved by the Open Source Initiative.
4  * Copyright (C) 2001, International Business Machines Corporation
5  * Copyright (C) 2001, Hewlett-Packard Company
6  * All Rights Reserved.
7  *
8  */

9
10 import java.util.Properties JavaDoc;
11 import java.util.Vector JavaDoc;
12
13 import org.uddi4j.UDDIException;
14 import org.uddi4j.client.UDDIProxy;
15 import org.uddi4j.datatype.Name;
16 import org.uddi4j.datatype.business.BusinessEntity;
17 import org.uddi4j.response.AuthToken;
18 import org.uddi4j.response.BusinessDetail;
19 import org.uddi4j.response.BusinessInfo;
20 import org.uddi4j.response.BusinessList;
21 import org.uddi4j.response.DispositionReport;
22 import org.uddi4j.response.Result;
23 import org.uddi4j.util.FindQualifier;
24 import org.uddi4j.util.FindQualifiers;
25
26 /**
27  * Sample code that exercises the publish API. Attempts
28  * to save a businessEntity , then finds the saved businessEntity and
29  * then deletes the saved businessEntity.
30  *
31  * <OL>
32  * <LI>Sets up an UDDIProxy object
33  * <LI>Requests an authorization token
34  * <LI>Saves a businessEntity
35  * <LI>Finds businessEntity saved in first step.
36  * <LI>Deletes the businessEntity saved in first step.
37  * </OL>
38  *
39  * @author David Melgar (dmelgar@us.ibm.com)
40  * @author Rajesh Sumra (rajesh_sumra@hp.com)
41  */

42 public class BusinessEntityExample
43 {
44
45     Properties JavaDoc config = null;
46
47     public static void main (String JavaDoc args[])
48     {
49         BusinessEntityExample app = new BusinessEntityExample();
50         System.out.println("\n*********** Running BusinessEntityExample ***********");
51         app.run();
52         System.exit(0);
53     }
54
55     public void run()
56     {
57         // Load samples configuration
58
config = Configurator.load();
59
60         // Construct a UDDIProxy object
61
UDDIProxy proxy = new UDDIProxy();
62
63         try
64         {
65             // Select the desired UDDI server node
66
proxy.setInquiryURL(config.getProperty("inquiryURL"));
67             proxy.setPublishURL(config.getProperty("publishURL"));
68
69             // Get an authorization token
70
System.out.println("\nGet authtoken");
71
72             // Pass in userid and password registered at the UDDI site
73
AuthToken token = proxy.get_authToken(config.getProperty("userid"),
74                                                                                         config.getProperty("password"));
75
76             System.out.println("Returned authToken:" + token.getAuthInfoString());
77
78             System.out.println("\nSave '" + config.getProperty("businessName") + "'");
79
80             // Create minimum required data objects
81
Vector JavaDoc entities = new Vector JavaDoc();
82
83             // Create a new business entity using required elements constructor
84
// Name is the business name. BusinessKey must be "" to save a new
85
// business
86
BusinessEntity be = new BusinessEntity("", config.getProperty("businessName"));
87             entities.addElement(be);
88
89             // **** First Save a business
90
BusinessDetail bd = proxy.save_business(token.getAuthInfoString(),entities);
91
92             // Process returned BusinessDetail object
93
Vector JavaDoc businessEntities = bd.getBusinessEntityVector();
94             BusinessEntity returnedBusinessEntity = (BusinessEntity)(businessEntities.elementAt(0));
95             System.out.println("Business Name : " + returnedBusinessEntity.getDefaultNameString());
96             System.out.println("Business Key : " + returnedBusinessEntity.getBusinessKey());
97
98             System.out.println("\nFinding business saved");
99
100             //creating vector of Name Object
101
Vector JavaDoc names = new Vector JavaDoc();
102             names.add(new Name(config.getProperty("businessName")));
103
104             // Setting FindQualifiers to 'exactNameMatch'
105
FindQualifiers findQualifiers = new FindQualifiers();
106             Vector JavaDoc qualifier = new Vector JavaDoc();
107             qualifier.add(new FindQualifier("exactNameMatch"));
108             findQualifiers.setFindQualifierVector(qualifier);
109
110             // **** Find business saved.
111
// And setting the maximum rows to be returned as 5.
112
BusinessList businessList = proxy.find_business(names, null, null, null,null,findQualifiers,5);
113             Vector JavaDoc businessInfoVector = businessList.getBusinessInfos().getBusinessInfoVector();
114             for( int i = 0; i < businessInfoVector.size(); i++ )
115             {
116                 BusinessInfo bi = (BusinessInfo)businessInfoVector.elementAt(i);
117                 System.out.println("Business Name : " + bi.getDefaultNameString());
118                 System.out.println("Business Key : " + bi.getBusinessKey());
119             }
120
121             System.out.println("\nDeleting the saved Business");
122             // Try to delete business saved in first step.
123
// Delete will fail for businesses not created by this id
124

125             // **** Having the business key, delete Business Entity using the authToken
126
DispositionReport dr = proxy.delete_business (
127                                                                                                      token.getAuthInfoString(),
128                                                                                                      returnedBusinessEntity.
129                                                                                                      getBusinessKey());
130
131             if( dr.success() )
132             {
133                 System.out.println("Business successfully deleted");
134             }
135             else
136             {
137                 System.out.println(" Error during deletion of Business\n"+
138                                                      "\n operator:" + dr.getOperator() +
139                                                      "\n generic:" + dr.getGeneric() );
140
141                 Vector JavaDoc results = dr.getResultVector();
142                 for( int i=0; i<results.size(); i++ )
143                 {
144                     Result r = (Result)results.elementAt(i);
145                     System.out.println("\n errno:" + r.getErrno() );
146                     if( r.getErrInfo()!=null )
147                     {
148                         System.out.println("\n errCode:" + r.getErrInfo().getErrCode() +
149                                                              "\n errInfoText:" + r.getErrInfo().getText());
150                     }
151                 }
152             }
153         }
154         // Handle possible errors
155
catch( UDDIException e )
156         {
157             DispositionReport dr = e.getDispositionReport();
158             if( dr!=null )
159             {
160                 System.out.println("UDDIException faultCode:" + e.getFaultCode() +
161                                                      "\n operator:" + dr.getOperator() +
162                                                      "\n generic:" + dr.getGeneric() );
163
164                 Vector JavaDoc results = dr.getResultVector();
165                 for( int i=0; i<results.size(); i++ )
166                 {
167                     Result r = (Result)results.elementAt(i);
168                     System.out.println("\n errno:" + r.getErrno() );
169                     if( r.getErrInfo()!=null )
170                     {
171                         System.out.println("\n errCode:" + r.getErrInfo().getErrCode() +
172                                                              "\n errInfoText:" + r.getErrInfo().getText());
173                     }
174                 }
175             }
176             e.printStackTrace();
177         }
178         // Catch any other exception that may occur
179
catch( Exception JavaDoc e )
180         {
181             e.printStackTrace();
182         }
183     }
184 }
185
Popular Tags