KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DeleteBusinessExample


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.response.AuthToken;
17 import org.uddi4j.response.BusinessInfo;
18 import org.uddi4j.response.BusinessList;
19 import org.uddi4j.response.DispositionReport;
20 import org.uddi4j.response.Result;
21 import org.uddi4j.util.FindQualifier;
22 import org.uddi4j.util.FindQualifiers;
23
24 /**
25  * Sample code that exercises the publish API. Attempts
26  * to delete a businessEntity.
27  * <ol>
28  * <li>Performs an inquiry to find this business
29  * <li>get_authToken to login to server
30  * <li>delete any businesses with key found in step 1.
31  * </ol>
32  *
33  * @author David Melgar (dmelgar@us.ibm.com)
34  * @author Rajesh Sumra (rajesh_sumra@hp.com)
35  */

36 public class DeleteBusinessExample
37 {
38
39     Properties JavaDoc config = null;
40
41     public static void main (String JavaDoc args[])
42     {
43         DeleteBusinessExample app = new DeleteBusinessExample();
44         System.out.println("\n*********** Running DeleteBusinessExample ***********");
45         app.run();
46         System.exit(0);
47     }
48
49     public void run()
50     {
51         // Load samples configuration
52
config = Configurator.load();
53
54         // Construct a UDDIProxy object
55
UDDIProxy proxy = new UDDIProxy();
56         try
57         {
58             // Select the desired UDDI server node
59
proxy.setInquiryURL(config.getProperty("inquiryURL"));
60             proxy.setPublishURL(config.getProperty("publishURL"));
61
62             // Get an authorization token
63
System.out.println("\nGet authtoken");
64
65             // Pass in userid and password registered at the UDDI site
66
AuthToken token = proxy.get_authToken(config.getProperty("userid"),
67                                                                                         config.getProperty("password"));
68
69             System.out.println("Returned authToken:" + token.getAuthInfoString());
70
71             System.out.println("Search for '" + config.getProperty("businessName") + "' to delete");
72
73             //creating vector of Name Object
74
Vector JavaDoc names = new Vector JavaDoc();
75             names.add(new Name(config.getProperty("businessName")));
76
77             // Setting FindQualifiers to 'caseSensitiveMatch'
78
FindQualifiers findQualifiers = new FindQualifiers();
79             Vector JavaDoc qualifier = new Vector JavaDoc();
80             qualifier.add(new FindQualifier("caseSensitiveMatch"));
81             findQualifiers.setFindQualifierVector(qualifier);
82
83             // Find businesses by Business name
84
// And setting the maximum rows to be returned as 5.
85
BusinessList businessList = proxy.find_business(names, null, null, null,null,findQualifiers,5);
86
87             Vector JavaDoc businessInfoVector = businessList.getBusinessInfos().getBusinessInfoVector();
88
89             // Try to delete any businesses with this name. Multiple businesses with the same
90
// name may have been created by different userids. Delete will fail for businesses
91
// not created by this id
92
for( int i = 0; i < businessInfoVector.size(); i++ )
93             {
94                 BusinessInfo bi = (BusinessInfo)businessInfoVector.elementAt(i);
95                 System.out.println("Found business key:" + bi.getBusinessKey());
96
97                 // Have found the matching business key, delete using the authToken
98
DispositionReport dr = proxy.delete_business(token.getAuthInfoString(),
99                                                                                                          bi.getBusinessKey());
100
101                 if( dr.success() )
102                 {
103                     System.out.println("Business successfully deleted");
104                 }
105                 else
106                 {
107                     System.out.println(" Error during deletion of Business\n"+
108                                                          "\n operator:" + dr.getOperator() +
109                                                          "\n generic:" + dr.getGeneric() );
110
111                     Vector JavaDoc results = dr.getResultVector();
112                     for( int j=0; j<results.size(); j++ )
113                     {
114                         Result r = (Result)results.elementAt(j);
115                         System.out.println("\n errno:" + r.getErrno() );
116                         if( r.getErrInfo()!=null )
117                         {
118                             System.out.println("\n errCode:" + r.getErrInfo().getErrCode() +
119                                                                  "\n errInfoText:" + r.getErrInfo().getText());
120                         }
121                     }
122                 }
123             }
124         }
125         // Handle possible errors
126
catch( UDDIException e )
127         {
128             DispositionReport dr = e.getDispositionReport();
129             if( dr!=null )
130             {
131                 System.out.println("UDDIException faultCode:" + e.getFaultCode() +
132                                                      "\n operator:" + dr.getOperator() +
133                                                      "\n generic:" + dr.getGeneric() );
134
135                 Vector JavaDoc results = dr.getResultVector();
136                 for( int i=0; i<results.size(); i++ )
137                 {
138                     Result r = (Result)results.elementAt(i);
139                     System.out.println("\n errno:" + r.getErrno() );
140                     if( r.getErrInfo()!=null )
141                     {
142                         System.out.println("\n errCode:" + r.getErrInfo().getErrCode() +
143                                                              "\n errInfoText:" + r.getErrInfo().getText());
144                     }
145                 }
146             }
147             e.printStackTrace();
148         }
149         // Catch any other exception that may occur
150
catch( Exception JavaDoc e )
151         {
152             e.printStackTrace();
153         }
154     }
155 }
156
157
Popular Tags