C:\uddi\inspireit\uddi\examples\FindTModelExample.java

1    package inspireit.uddi.examples; 
2     
3    import java.net.*; 
4     
5    import inspireit.uddi.*; 
6    import inspireit.uddi.base.*; 
7    import inspireit.uddi.collections.*; 
8    import inspireit.uddi.request.*; 
9    import inspireit.uddi.response.*; 
10    
11   /** 
12    * This example shows how to find a tModel. You will have to open an account at 
13    * one of the official UDDI registries if you don't have access to a local UDDI 
14    * registry. For example, you can use the beta registry of IBM located at 
15    * http://uddi.ibm.com/beta/registry.html.<p> 
16    * 
17    * The example first saves a business entity, a service, and a tModel via the 
18    * SaveBindingExample example. If the size of your account is limited, you will 
19    * have to make a clean-up first, for example via the Web interface of the 
20    * on-line registry. 
21    * 
22    * @author Bertrand Fontaine, <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a> 
23    */ 
24   public class FindTModelExample { 
25    
26       public FindTModelExample(String queryURL, String publishURL, String securityURL, String username, String password) throws Exception { 
27           // first ensure that we have a saved TModel 
28           SaveTModelExample saveTModel = new SaveTModelExample(queryURL, publishURL, securityURL, username, password); 
29           TModelKey tModelKey = saveTModel.getTModelKey(); 
30    
31           // define the appropriate UDDI profile 
32           UDDIProfile profile = new UDDIProfile(); 
33           profile.setQueryURL(new URL(queryURL)); 
34    
35           // uncomment one of the following lines to use UDDI V2 or V3 messaging instead of the default V1 
36           // profile.setVersion(UDDIConstants.UDDI_V2); 
37           // profile.setVersion(UDDIConstants.UDDI_V3); 
38    
39           UDDIQuerier querier = UDDIQuerier.getQuerier(profile); 
40    
41           try { 
42               TModelDetail tModelList = querier.getTModelDetail(tModelKey); 
43               TModels tModels = tModelList.getTModels(); 
44    
45               if ((tModels == null) || (tModels.size() == 0)) { 
46                   System.out.println("Ooops, no tModel found."); 
47               } else { 
48                   TModel tModel = (tModels.toArray())[0]; 
49                   System.out.println("Found tModel: " + tModel.getName()); 
50               } 
51           } catch(UDDIException e) { 
52               e.printStackTrace(); 
53           } 
54       } 
55    
56       public static void main(String args[]) throws Exception { 
57           if ((args.length != 4) && (args.length != 5)) { 
58               System.out.println("FindTModelExample usage: java FindTModelExample <queryURL> <publishURL> [<securityURL>] <username> <password>"); 
59               System.exit(0); 
60           } 
61    
62           String queryURL    = args[0]; 
63           String publishURL  = args[1]; 
64           String securityURL = null; 
65           String username    = null; 
66           String password    = null; 
67    
68           if (args.length == 4) { 
69               username = args[2]; 
70               password = args[3]; 
71           } else { // must be 5 ... 
72               securityURL = args[2]; 
73               username = args[3]; 
74               password = args[4]; 
75           } 
76    
77           new FindTModelExample(queryURL, publishURL, securityURL, username, password); 
78           return; 
79       } 
80   }