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

1    package inspireit.uddi.examples; 
2     
3    import inspireit.uddi.base.*; 
4    import inspireit.uddi.collections.*; 
5    import inspireit.uddi.collections.iterators.*; 
6     
7    /** 
8     * This example shows a sample usage of the collections API of 
9     * <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a> UDDI. 
10    * 
11    * @author Bertrand Fontaine, <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a> 
12    */ 
13   public class CollectionExample { 
14    
15       public static void main(String args[]) { 
16           // define two address lines 
17           AddressLine addressLine1  = new AddressLine("Address line #1"); 
18           AddressLine addressLine2  = new AddressLine("Address line #2"); 
19    
20           // add the address lines in an AddressLine collection 
21           AddressLines addressLines = new AddressLines(); 
22           addressLines.add(addressLine1); 
23           addressLines.add(addressLine2); 
24    
25           // turn the collection to an array 
26           AddressLine addressLineArray[] = addressLines.toArray(); 
27           System.out.println("Listing of the elements of the collection via an array:"); 
28    
29           // list the elements of the array 
30           for(int i=0; i< addressLineArray.length; i++) { 
31               System.out.println(addressLineArray[i]); 
32           } 
33    
34           System.out.println(); 
35    
36           // instantiate an iterator 
37           AddressLineIterator iterator = addressLines.iterator(); 
38    
39           // list the elements of the collection 
40           System.out.println("Listing of the elements of the collection via an iterator:"); 
41    
42           while(iterator.hasNext()) { 
43               AddressLine addressLine = iterator.next(); 
44               System.out.println(addressLine); 
45           } 
46    
47           System.out.println(); 
48    
49           // try to read one AddressLine more than what is available 
50           System.out.println("Attempt to read one AddressLine more than what is available:"); 
51    
52           try { 
53               AddressLine addressLine = iterator.next(); 
54               System.out.println(addressLine); 
55           } catch(NoSuchElementException e) { 
56               System.out.println("Sorry, no more element in this collection!"); 
57           } 
58    
59           System.out.println(); 
60    
61           // deletion of the last AddressLine read from the collection 
62           System.out.println("Deletion of the last AddressLine read from the collection:"); 
63           iterator.remove(); 
64    
65           System.out.println("Deletion completed"); 
66           System.out.println(); 
67    
68           // verification of the content of the AddressLines collection 
69           System.out.println("Verification of the content of the AddressLines collection:"); 
70           iterator = addressLines.iterator(); 
71    
72           while(iterator.hasNext()) { 
73               AddressLine addressLine = iterator.next(); 
74               System.out.println(addressLine); 
75           } 
76    
77           return; 
78       } 
79   } 
80