KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > function > ValidateValuesFunction


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.function;
17
18 import java.util.Vector JavaDoc;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.juddi.datatype.CategoryBag;
23 import org.apache.juddi.datatype.IdentifierBag;
24 import org.apache.juddi.datatype.KeyedReference;
25 import org.apache.juddi.datatype.RegistryObject;
26 import org.apache.juddi.datatype.binding.BindingTemplate;
27 import org.apache.juddi.datatype.binding.BindingTemplates;
28 import org.apache.juddi.datatype.business.BusinessEntity;
29 import org.apache.juddi.datatype.request.ValidateValues;
30 import org.apache.juddi.datatype.response.DispositionReport;
31 import org.apache.juddi.datatype.response.Result;
32 import org.apache.juddi.datatype.service.BusinessService;
33 import org.apache.juddi.datatype.service.BusinessServices;
34 import org.apache.juddi.datatype.tmodel.TModel;
35 import org.apache.juddi.error.RegistryException;
36 import org.apache.juddi.registry.RegistryEngine;
37 import org.apache.juddi.util.Config;
38
39 /**
40  * @author Steve Viens (sviens@apache.org)
41  */

42 public class ValidateValuesFunction extends AbstractFunction
43 {
44   // private reference to jUDDI Logger
45
private static Log log = LogFactory.getLog(SetPublisherAssertionsFunction.class);
46
47   /**
48    *
49    */

50   public ValidateValuesFunction(RegistryEngine registry)
51   {
52     super(registry);
53   }
54
55   /**
56    *
57    * @param obj
58    * @return RegistryObject
59    * @throws RegistryException
60    */

61   public RegistryObject execute(RegistryObject obj)
62     throws RegistryException
63   {
64     ValidateValues request = (ValidateValues)obj;
65     String JavaDoc generic = request.getGeneric();
66
67     Vector JavaDoc businessVector = request.getBusinessEntityVector();
68     if ((businessVector != null) && (businessVector.size() > 0))
69       validateBusinessVector(businessVector);
70
71     Vector JavaDoc serviceVector = request.getBusinessServiceVector();
72     if ((serviceVector != null) && (serviceVector.size() > 0))
73       validateServiceVector(serviceVector);
74
75     Vector JavaDoc tModelVector = request.getTModelVector();
76     if ((tModelVector != null) && (tModelVector.size() > 0))
77       validateTModelVector(tModelVector);
78
79     // We don't currently support thh validate_values
80
// function so to keep things moving along let's
81
// just return a successful DispositionReport.
82

83     // We didn't encounter any problems so let's create an
84
// E_SUCCESS Result, embed it in a DispositionReport
85
// and return it.
86
Result result = new Result(Result.E_SUCCESS);
87     result.setErrCode(Result.lookupErrCode(Result.E_SUCCESS));
88     DispositionReport dispRpt = new DispositionReport();
89     dispRpt.setGeneric(generic);
90     dispRpt.setOperator(Config.getOperator());
91     dispRpt.addResult(result);
92     
93     return dispRpt;
94   }
95
96   /**
97    *
98    */

99   private RegistryObject validateBusinessVector(Vector JavaDoc businessVector)
100   {
101     if (businessVector == null)
102       return null;
103     
104     for (int i=0; i<businessVector.size(); i++)
105     {
106       BusinessEntity business = (BusinessEntity)businessVector.elementAt(i);
107       
108       CategoryBag catBag = business.getCategoryBag();
109       if (catBag != null)
110       {
111         Vector JavaDoc refs = catBag.getKeyedReferenceVector();
112         if ((refs != null) && (refs.size() > 0))
113           validate(refs);
114       }
115     
116       IdentifierBag idBag = business.getIdentifierBag();
117       if (idBag != null)
118       {
119         Vector JavaDoc refs = idBag.getKeyedReferenceVector();
120         if ((refs != null) && (refs.size() > 0))
121           validate(refs);
122       }
123       
124       BusinessServices services = business.getBusinessServices();
125       if (services != null)
126       {
127         Vector JavaDoc serviceVector = services.getBusinessServiceVector();
128         if (serviceVector != null)
129           validateServiceVector(serviceVector);
130       }
131     }
132     
133     return null;
134   }
135
136   /**
137    *
138    */

139   private RegistryObject validateServiceVector(Vector JavaDoc serviceVector)
140   {
141     if (serviceVector == null)
142       return null;
143     
144     for (int i=0; i<serviceVector.size(); i++)
145     {
146       BusinessService service = (BusinessService)serviceVector.elementAt(i);
147       
148       CategoryBag catBag = service.getCategoryBag();
149       if (catBag != null)
150       {
151         Vector JavaDoc refs = catBag.getKeyedReferenceVector();
152         if ((refs != null) && (refs.size() > 0))
153           validate(refs);
154       }
155       
156       BindingTemplates templates = service.getBindingTemplates();
157       if (templates != null)
158       {
159         Vector JavaDoc bindings = templates.getBindingTemplateVector();
160         if (bindings != null)
161           validateBindingVector(bindings);
162       }
163     }
164     
165     return null;
166   }
167
168   /**
169    *
170    */

171   private RegistryObject validateBindingVector(Vector JavaDoc bindingVector)
172   {
173     if (bindingVector == null)
174       return null;
175    
176     for (int i=0; i<bindingVector.size(); i++)
177     {
178       BindingTemplate binding = (BindingTemplate)bindingVector.elementAt(i);
179     
180       CategoryBag catBag = binding.getCategoryBag();
181       if (catBag != null)
182       {
183         Vector JavaDoc refs = catBag.getKeyedReferenceVector();
184         if ((refs != null) && (refs.size() > 0))
185           validate(refs);
186       }
187     }
188   
189     return null;
190   }
191  
192   /**
193    *
194    */

195   private RegistryObject validateTModelVector(Vector JavaDoc tModelVector)
196   {
197     if (tModelVector == null)
198       return null;
199     
200     for (int i=0; i<tModelVector.size(); i++)
201     {
202       TModel tModel = (TModel)tModelVector.elementAt(i);
203       
204       CategoryBag catBag = tModel.getCategoryBag();
205       if (catBag != null)
206       {
207         Vector JavaDoc refs = catBag.getKeyedReferenceVector();
208         if ((refs != null) && (refs.size() > 0))
209           validate(refs);
210       }
211       
212       IdentifierBag idBag = tModel.getIdentifierBag();
213       if (idBag != null)
214       {
215         Vector JavaDoc refs = idBag.getKeyedReferenceVector();
216         if ((refs != null) && (refs.size() > 0))
217           validate(refs);
218       }
219     }
220     
221     return null;
222   }
223   
224   /**
225    *
226    * @param args
227    */

228   private RegistryObject validate(Vector JavaDoc refs)
229   {
230     if (refs == null)
231       return null;
232     
233     for (int i=0; i<refs.size(); i++)
234     {
235       KeyedReference ref = (KeyedReference)refs.elementAt(i);
236      
237       // Perform the validation
238
}
239     
240     return null;
241   }
242
243   /***************************************************************************/
244   /***************************** TEST DRIVER *********************************/
245   /***************************************************************************/
246
247
248   public static void main(String JavaDoc[] args)
249   {
250     // initialize the registry
251
RegistryEngine reg = new RegistryEngine();
252     reg.init();
253
254     try
255     {
256     }
257     catch (Exception JavaDoc ex)
258     {
259       // write execption to the console
260
ex.printStackTrace();
261     }
262     finally
263     {
264       // destroy the registry
265
reg.dispose();
266     }
267   }
268 }
Popular Tags