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

1    package inspireit.uddi.examples; 
2     
3    import inspireit.uddi.base.*; 
4    import inspireit.uddi.util.*; 
5     
6    /** 
7     * This example shows how to use the various APIs for UDDI key manipulation. 
8     * 
9     * @author Bertrand Fontaine, INSPIRE IT 
10    */ 
11   public class UDDIKeyExample { 
12    
13       public UDDIKeyExample() { 
14           // The following creates a TModelKey with an automatically generated 
15           // UUID. UUID-based keys are recognized as UDDI V1 or V2 keys. 
16           // An UDDI V2 or V1 TModelKey always starts with "uuid:". In 
17           // V3, the key starts with "uddi:" 
18           System.out.println("Automatically generated TModelKey:"); 
19           TModelKey tModelKey = new TModelKey(); 
20           displayKeyCharacteristics(tModelKey); 
21    
22           // The following creates an UDDI V3 TModelKey by specifying an URI 
23           // as a string 
24           System.out.println("UDDI V3.0-compliant TModelKey:"); 
25           tModelKey = new TModelKey("uddi:tempuri.org:keyGenerator"); 
26           displayKeyCharacteristics(tModelKey); 
27    
28           // same exercise with a BusinessKey 
29           System.out.println("Automatically generated BusinessKey:"); 
30           BusinessKey businessKey = new BusinessKey(); 
31           displayKeyCharacteristics(businessKey); 
32    
33           System.out.println("UDDI V3.0-compliant BusinessKey:"); 
34           businessKey = new BusinessKey("uddi:tempuri.org"); 
35           displayKeyCharacteristics(businessKey); 
36    
37           // the following shows what happens when a non-UDDI BindingKey is 
38           // constructed. No UUID or URI can be computed. 
39           System.out.println("Wrong BindingKey:"); 
40           BindingKey bindingKey = new BindingKey("WRONG:uddi:tempuri.org"); 
41           displayKeyCharacteristics(bindingKey); 
42       } 
43    
44       protected void displayKeyCharacteristics(UDDIKey uddiKey) { 
45           // displays the string representation of the UDDI key 
46           System.out.println("uddiKey.toString() : " + uddiKey.toString()); 
47    
48           // displays the UUID portion of the UDDI key. If the key is actually 
49           // an UDDI V3 key, the UUID is automatically calculated using the 
50           // recommended algorithm described in the UDDI V3 spec 
51           System.out.println("uddiKey.getUUID()  : " + uddiKey.getUUID()); 
52    
53           // displays the URI corresponding to the UDDI key. If the key is 
54           // actually a UDDI V2 or V1 key, the URI is automatically 
55           // calculated using the recommended algorithm described in the 
56           // UDDI V3 spec 
57           System.out.println("uddiKey.getURI()   : " + uddiKey.getURI()); 
58    
59           // whether the key has a UDDI V1-compliant format 
60           System.out.println("uddiKey.isV1()     : " + KeysUtil.isV1(uddiKey)); 
61    
62           // whether the key has a UDDI V2-compliant format 
63           System.out.println("uddiKey.isV2()     : " + KeysUtil.isV2(uddiKey)); 
64    
65           // whether the key has a UDDI V3-compliant format 
66           System.out.println("uddiKey.isV3()     : " + KeysUtil.isV3(uddiKey)); 
67           System.out.println(""); 
68           return; 
69       } 
70    
71       /** Example entry point. */ 
72       public static void main(String args[]) { 
73           new UDDIKeyExample(); 
74           return; 
75       } 
76   } 
77