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

1    package inspireit.uddi.examples; 
2     
3    import inspireit.uddi.*; 
4    import inspireit.uddi.base.*; 
5    import inspireit.uddi.util.validators.*; 
6     
7    /** 
8     * Validation example #2. 
9     * 
10    * @author Bertrand Fontaine, <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a> 
11    */ 
12   public class ValidationExample2 { 
13    
14       public static void main(String args[]) { 
15           ValidatorFactory factory = new ValidatorFactory(UDDIConstants.UDDI_V1); 
16           // uncomment the following line to use UDDI V2 validation instead of the default V1 
17           // factory = new ValidationFactory(UDDIConstants.UDDI_V2); 
18    
19           char toolong[] = new char[1024]; 
20    
21           // create a visibly too long name 
22           Name nameTooLong = new Name(new String(toolong)); 
23    
24           // create a visibly too long description 
25           Description descriptionTooLong = new Description(new String(toolong)); 
26    
27           // create a TModel from 'wrong' information 
28           TModel tModel = new TModel(null, nameTooLong); 
29           tModel.addDescription(descriptionTooLong); 
30    
31           // build up a TModel validator that will throw from the very first problem 
32           System.out.println("Throw 'ASAP' example:"); 
33           TModelValidator validator = factory.createTModelValidator(tModel, true); 
34    
35           try { 
36               validator.validate(); 
37           } catch(ValidationException ve) { 
38               //ve.printStackTrace(System.out); 
39               System.out.println(ve.getMessage()); 
40           } 
41    
42           System.out.println(); 
43    
44           // build up a TModel validator that will throw from the very first problem 
45           System.out.println("Throw 'after validation' example:"); 
46           validator = factory.createTModelValidator(tModel, false); 
47    
48           try { 
49               validator.validate(); 
50           } catch(ValidationException ve) { 
51               //ve.printStackTrace(System.out); 
52               System.out.println(ve.getMessage()); 
53    
54               System.out.println(); 
55               System.out.println("Listing of the successive exceptions detected:"); 
56               ValidationException exceptions[] = ve.getExceptions(); 
57    
58               for(int i=0; i< exceptions.length; i++) { 
59                   System.out.println(); 
60                   System.out.print("Exception #" + i + " detected on "); 
61    
62                   switch(exceptions[i].getType()) { 
63                       case TModelException.AUTHORIZEDNAME: 
64                           System.out.println("the AuthorizedName."); 
65                           break; 
66                       case TModelException.CATEGORYBAG: 
67                           System.out.println("the CategoryBag."); 
68                           break; 
69                       case TModelException.DESCRIPTION: 
70                           System.out.println("the Descriptions collection."); 
71                           System.out.println("The problematic description is the following:"); 
72                           System.out.println(exceptions[i].getFaulty()); 
73                           ValidationException vv[] = exceptions[i].getExceptions(); 
74                           for(int y=0; y< vv.length; y++) { 
75                               System.out.println(">>>" + vv[y].getClass()); 
76                           } 
77                           break; 
78                       case TModelException.IDENTIFIERBAG: 
79                           System.out.println("the IdentifierBag."); 
80                           break; 
81                       case TModelException.NAME: 
82                           System.out.println("the Name."); 
83                           break; 
84                       case TModelException.OPERATOR: 
85                           System.out.println("the Operator."); 
86                           break; 
87                       case TModelException.OVERVIEWDOC: 
88                           System.out.println("the OverviewDoc."); 
89                           break; 
90                       case TModelException.TMODELKEY: 
91                           System.out.println("the TModelKey"); 
92                           break; 
93                       default: 
94                           System.out.println("???"); 
95                   } 
96    
97                   System.out.println(exceptions[i].getMessage()); 
98               } 
99           } 
100   
101          return; 
102      } 
103  } 
104