C:\uddi\inspireit\uddi\examples\SaveTModelExample.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   import inspireit.uddi.response.base.*; 
11    
12   /** 
13    * This example shows how to save a tModel. You will have to open an account at 
14    * one of the official UDDI registries if you don't have access to a local UDDI 
15    * registry. For example, you can use the beta registry of IBM located at 
16    * http://uddi.ibm.com/beta/registry.html.<p> 
17    * 
18    * The example first saves a business entity and a service via the 
19    * SaveServiceExample example. If the size of your account is limited, you will 
20    * have to make a clean-up first, for example via the Web interface of the 
21    * on-line registry. 
22    * 
23    * @author Bertrand Fontaine, <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a> 
24    */ 
25   public class SaveTModelExample { 
26    
27       protected BusinessKey businessKey = null; 
28       protected ServiceKey serviceKey = null; 
29       protected TModelKey tModelKey = null; 
30    
31       public SaveTModelExample(String queryURL, String publishURL, String securityURL, String username, String password) throws Exception { 
32           SaveServiceExample saveService = new SaveServiceExample(queryURL, publishURL, securityURL, username, password); 
33           businessKey = saveService.getBusinessKey(); 
34           serviceKey  = saveService.getServiceKey(); 
35    
36           System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol"); 
37           java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); 
38    
39           UDDIProfile profile = new UDDIProfile(); 
40           profile.setQueryURL(new URL(queryURL)); 
41           profile.setPublishURL(new URL(publishURL)); 
42    
43           if (securityURL != null) { 
44               profile.setSecurityURL(new URL(securityURL)); 
45           } 
46    
47           profile.setUsername(username); 
48           profile.setPassword(password); 
49    
50           // uncomment one of the following lines to use UDDI V2 or V3 messaging instead of the default V1 
51           // profile.setVersion(UDDIConstants.UDDI_V2); 
52           // profile.setVersion(UDDIConstants.UDDI_V3); 
53    
54           try { 
55               // get an appropriate publisher 
56               UDDIPublisher publisher = UDDIPublisher.getPublisher(profile); 
57    
58               // build up the TModel to save in the registry 
59               TModelKey tModelKey = null; 
60               Name name = new Name("INSPIRE IT UDDI - TModel Example"); 
61               TModel tModel = new TModel(tModelKey, name); 
62    
63               TModelDetail tModelDetail = publisher.saveTModel(tModel); 
64    
65               // get the saved TModel 
66               TModels tModels = tModelDetail.getTModels(); 
67               TModel savedTModel = (tModels.toArray())[0]; 
68    
69               this.tModelKey = savedTModel.getTModelKey(); 
70               System.out.println("TModel saved with tModel key : " + this.tModelKey); 
71           } catch(UDDIException e) { 
72               System.out.println("An error has occured. More information follows."); 
73    
74               DispositionReport dispositionReport = e.getDispositionReport(); 
75               Results results  = dispositionReport.getResults(); 
76               Result  result[] = results.toArray(); 
77    
78               for(int i=0; i< result.length; i++) { 
79                   System.out.println("Errno   : " + result[i].getErrNo() + 
80                                   "\n KeyType : " + result[i].getKeyType() + 
81                                   "\n ErrInfo : " + result[i].getErrInfo()); 
82               } 
83           } 
84       } 
85    
86       public BusinessKey getBusinessKey() { 
87           return businessKey; 
88       } 
89    
90       public ServiceKey getServiceKey() { 
91           return serviceKey; 
92       } 
93    
94       public TModelKey getTModelKey() { 
95           return tModelKey; 
96       } 
97    
98       public static void main(String args[]) throws Exception { 
99           if ((args.length != 4) && (args.length != 5)) { 
100              System.out.println("SaveTModelExample usage: java SaveTModelExample <queryURL> <publishURL> [<securityURL>] <username> <password>"); 
101              System.exit(0); 
102          } 
103   
104          String queryURL    = args[0]; 
105          String publishURL  = args[1]; 
106          String securityURL = null; 
107          String username    = null; 
108          String password    = null; 
109   
110          if (args.length == 4) { 
111              username = args[2]; 
112              password = args[3]; 
113          } else { // must be 5 ... 
114              securityURL = args[2]; 
115              username = args[3]; 
116              password = args[4]; 
117          } 
118   
119          new SaveTModelExample(queryURL, publishURL, securityURL, username, password); 
120          return; 
121      } 
122  }