KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > datastore > jdbc > JDBCDataStore


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.datastore.jdbc;
17
18 import java.sql.Connection JavaDoc;
19 import java.sql.SQLException JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.juddi.datastore.DataStore;
25 import org.apache.juddi.datatype.Address;
26 import org.apache.juddi.datatype.CategoryBag;
27 import org.apache.juddi.datatype.DiscoveryURLs;
28 import org.apache.juddi.datatype.IdentifierBag;
29 import org.apache.juddi.datatype.KeyedReference;
30 import org.apache.juddi.datatype.OverviewDoc;
31 import org.apache.juddi.datatype.SharedRelationships;
32 import org.apache.juddi.datatype.TModelBag;
33 import org.apache.juddi.datatype.assertion.PublisherAssertion;
34 import org.apache.juddi.datatype.binding.BindingTemplate;
35 import org.apache.juddi.datatype.binding.BindingTemplates;
36 import org.apache.juddi.datatype.binding.InstanceDetails;
37 import org.apache.juddi.datatype.binding.TModelInstanceDetails;
38 import org.apache.juddi.datatype.binding.TModelInstanceInfo;
39 import org.apache.juddi.datatype.business.BusinessEntity;
40 import org.apache.juddi.datatype.business.Contact;
41 import org.apache.juddi.datatype.business.Contacts;
42 import org.apache.juddi.datatype.publisher.Publisher;
43 import org.apache.juddi.datatype.request.FindQualifiers;
44 import org.apache.juddi.datatype.response.AssertionStatusItem;
45 import org.apache.juddi.datatype.response.BusinessInfo;
46 import org.apache.juddi.datatype.response.CompletionStatus;
47 import org.apache.juddi.datatype.response.PublisherInfo;
48 import org.apache.juddi.datatype.response.RelatedBusinessInfo;
49 import org.apache.juddi.datatype.response.ServiceInfo;
50 import org.apache.juddi.datatype.response.ServiceInfos;
51 import org.apache.juddi.datatype.response.TModelInfo;
52 import org.apache.juddi.datatype.service.BusinessService;
53 import org.apache.juddi.datatype.service.BusinessServices;
54 import org.apache.juddi.datatype.tmodel.TModel;
55 import org.apache.juddi.error.RegistryException;
56 import org.apache.juddi.error.UnknownUserException;
57 import org.apache.juddi.util.Config;
58 import org.apache.juddi.util.jdbc.ConnectionManager;
59 import org.apache.juddi.util.jdbc.Transaction;
60 import org.apache.juddi.uuidgen.UUIDGen;
61 import org.apache.juddi.uuidgen.UUIDGenFactory;
62
63 /**
64  * @author Steve Viens (sviens@apache.org)
65  * @author Anil Saldhana (anil@apache.org)
66  */

67 public class JDBCDataStore implements DataStore
68 {
69   // private reference to the jUDDI logger
70
private static Log log = LogFactory.getLog(JDBCDataStore.class);
71
72   // private db connection associated with this datastore
73
private Connection JavaDoc connection = null;
74
75   // private XA transaxtion object
76
private Transaction transaction = null;
77
78   /**
79    * Create a new JDBCDataStore and aquire a JDBC
80    * connection from the connection pool.
81    */

82   public JDBCDataStore()
83   {
84     try {
85       this.connection = ConnectionManager.aquireConnection();
86     }
87     catch(SQLException JavaDoc sqlex) {
88       log.error("Exception occured while attempting to " +
89         "aquire a JDBC connection: "+sqlex.getMessage());
90     }
91   }
92
93   /**
94    * Release all JDBC connections used by this
95    * JDBCDataStore back into the connection pool.
96    */

97   public void release()
98   {
99     try {
100       if (connection != null)
101       {
102         this.connection.close();
103         this.connection = null;
104       }
105     }
106     catch(SQLException JavaDoc sqlex) {
107       log.error("Exception occured while attempting to " +
108         "close a JDBC connection: "+sqlex.getMessage());
109     }
110   }
111
112   /**
113    *
114    */

115   public Connection JavaDoc getConnection()
116   {
117     return this.connection;
118   }
119
120  /**
121   * begin a new transaction
122   */

123   public void beginTrans()
124     throws org.apache.juddi.error.RegistryException
125   {
126     try {
127       this.transaction = new Transaction();
128       this.transaction.begin(connection);
129     }
130     catch(SQLException JavaDoc sqlex) {
131       throw new RegistryException(sqlex);
132     }
133   }
134
135  /**
136   * commit on all connections.
137   */

138   public void commit()
139     throws org.apache.juddi.error.RegistryException
140   {
141     try {
142       this.transaction.commit();
143     }
144     catch(SQLException JavaDoc sqlex) {
145       throw new RegistryException(sqlex);
146     }
147   }
148
149  /**
150   * rollback on all connections.
151   */

152   public void rollback()
153     throws org.apache.juddi.error.RegistryException
154   {
155     try {
156       this.transaction.rollback();
157     }
158     catch(SQLException JavaDoc sqlex) {
159       throw new RegistryException(sqlex);
160     }
161   }
162
163   /**
164    * verify that the individual or system identified by
165    * the 'publisherID' is a valid jUDDI user (aka publisher).
166    *
167    * @param publisherID
168    * @return publisher
169    * @throws RegistryException
170    */

171   public Publisher getPublisher(String JavaDoc publisherID)
172     throws RegistryException
173   {
174     // a publisherID must be specified.
175
if (publisherID == null)
176       return null;
177
178     Publisher publisher = null;
179
180     try {
181       publisher = PublisherTable.select(publisherID,connection);
182     }
183     catch(java.sql.SQLException JavaDoc sqlex) {
184       throw new RegistryException(sqlex);
185     }
186
187     return publisher;
188   }
189
190   /**
191    * Will return true if the publisherID parameter specified has been tagged
192    * with registry administrator priviledges otherwise returns false. An
193    * Unknown user exception is thrown if the publisherID specified is null,
194    * blank or does not exist (can't be found in the PUBLISHER table).
195    *
196    * @param publisherID
197    * @return Returns true if publisherID parameter specified has jUDDI
198    * administrator priv's otherwise returns false.
199    * @throws RegistryException
200    */

201   public boolean isAdministrator(String JavaDoc publisherID)
202     throws org.apache.juddi.error.RegistryException
203   {
204     if ((publisherID == null) || (publisherID.length() == 0))
205       throw new UnknownUserException("publisherID = "+publisherID);
206
207     try
208     {
209       Publisher publisher = PublisherTable.select(publisherID,connection);
210       if (publisher == null)
211         throw new UnknownUserException("publisherID = "+publisherID);
212       else
213         return publisher.isAdmin();
214     }
215     catch(java.sql.SQLException JavaDoc sqlex)
216     {
217       log.error(sqlex.getMessage());
218       throw new RegistryException(sqlex);
219     }
220   }
221
222   /**
223    * Will return true if the publisherID parameter specified is
224    * currently enabled otherwise returns false. An UnknownUserException
225    * is thrown if the publisherID specified is null, blank or does not
226    * exist (can't be found in the PUBLISHER table).
227    *
228    * @param publisherID
229    * @return Returns true if publisherID parameter specified has jUDDI
230    * administrator priv's otherwise returns false.
231    * @throws RegistryException
232    */

233   public boolean isEnabled(String JavaDoc publisherID)
234     throws org.apache.juddi.error.RegistryException
235   {
236     if ((publisherID == null) || (publisherID.length() == 0))
237       throw new UnknownUserException("publisherID = "+publisherID);
238
239     try
240     {
241       Publisher publisher = PublisherTable.select(publisherID,connection);
242       if (publisher == null)
243         throw new UnknownUserException("publisherID = "+publisherID);
244       else
245         return publisher.isEnabled();
246     }
247     catch(java.sql.SQLException JavaDoc sqlex)
248     {
249       log.error(sqlex.getMessage());
250       throw new RegistryException(sqlex);
251     }
252   }
253
254   /**
255    *
256    * @param publisher
257    * @return String
258    * @throws RegistryException
259    */

260   public String JavaDoc generateToken(Publisher publisher)
261     throws RegistryException
262   {
263     UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
264
265     String JavaDoc token = "authToken:"+uuidgen.uuidgen();
266
267     log.info("Generated token '"+token+"' for user: '" +
268       publisher.getPublisherID()+"/"+publisher.getName()+"'");
269
270     return token;
271   }
272
273   /**
274    *
275    */

276   public void storeAuthToken(String JavaDoc token,Publisher publisher)
277     throws org.apache.juddi.error.RegistryException
278   {
279     if ((token != null) && (publisher != null))
280     {
281       try {
282         AuthTokenTable.insert(token,publisher,connection);
283       }
284       catch(java.sql.SQLException JavaDoc sqlex) {
285         throw new RegistryException(sqlex);
286       }
287     }
288   }
289
290   /**
291    *
292    */

293   public void retireAuthToken(String JavaDoc token)
294     throws org.apache.juddi.error.RegistryException
295   {
296     if (token != null)
297     {
298       try {
299         AuthTokenTable.invalidate(token,connection);
300         AuthTokenTable.touch(token,connection);
301       }
302       catch(java.sql.SQLException JavaDoc sqlex) {
303         throw new RegistryException(sqlex);
304       }
305     }
306   }
307
308   /**
309    *
310    */

311   public Publisher getAuthTokenPublisher(String JavaDoc token)
312     throws org.apache.juddi.error.RegistryException
313   {
314     Publisher publisher = null;
315
316     if (token != null)
317     {
318       try {
319         publisher = AuthTokenTable.selectPublisher(token,connection);
320       }
321       catch(java.sql.SQLException JavaDoc sqlex) {
322         throw new RegistryException(sqlex);
323       }
324     }
325
326     return publisher;
327   }
328
329   /**
330    *
331    */

332   public boolean isAuthTokenExpired(String JavaDoc token)
333     throws org.apache.juddi.error.RegistryException
334   {
335     boolean expired = false;
336
337     if (token != null)
338     {
339       try
340       {
341         long tokenState = AuthTokenTable.selectTokenState(token, connection);
342         if (tokenState <= 0) {
343           return expired = true;
344         }
345
346         long lastUsed = AuthTokenTable.selectLastUsed(token,connection);
347         if (lastUsed > 0) // -1 is returned when token isn't found
348
{
349           long timeOut = Config.getLongProperty("juddi.authTokenTimeout",3600) * 1000L; // convert from seconds to milliseconds
350
long currTime = System.currentTimeMillis();
351           if ((currTime-lastUsed) >= timeOut)
352             expired = true;
353         }
354       }
355       catch(java.sql.SQLException JavaDoc sqlex) {
356         throw new RegistryException(sqlex);
357       }
358     }
359
360     return expired;
361   }
362
363   /**
364    *
365    */

366   public void touchAuthToken(String JavaDoc token)
367     throws org.apache.juddi.error.RegistryException
368   {
369     if (token != null)
370     {
371       try {
372         AuthTokenTable.touch(token,connection);
373       }
374       catch(java.sql.SQLException JavaDoc sqlex) {
375         throw new RegistryException(sqlex);
376       }
377     }
378   }
379
380   /**
381    *
382    */

383   public void saveBusiness(BusinessEntity business,String JavaDoc publisherID)
384     throws org.apache.juddi.error.RegistryException
385   {
386     try
387     {
388       if ((business != null) && (connection != null))
389       {
390         String JavaDoc businessKey = business.getBusinessKey();
391
392         // insert the BusinessEntity object
393
BusinessEntityTable.insert(business,publisherID,connection);
394
395         // insert all of the BusinessEntity Name objects
396
if (business.getNameVector() != null)
397           BusinessNameTable.insert(businessKey,business.getNameVector(),connection);
398
399         // insert all of the BusinessEntity Description objects
400
if (business.getDescriptionVector() != null)
401           BusinessDescTable.insert(businessKey,business.getDescriptionVector(),connection);
402
403         // insert the BusinessEntity's IdentiferBag KeyedReferences
404
IdentifierBag idBag = business.getIdentifierBag();
405         if ((idBag != null) && (idBag.getKeyedReferenceVector() != null))
406           BusinessIdentifierTable.insert(businessKey,idBag.getKeyedReferenceVector(),connection);
407
408         // insert the BusinessEntity's CategoryBag KeyedReferences
409
CategoryBag catBag = business.getCategoryBag();
410         if ((catBag != null) && (catBag.getKeyedReferenceVector() != null))
411           BusinessCategoryTable.insert(businessKey,catBag.getKeyedReferenceVector(),connection);
412
413         // insert the BusinessEntity's DiscoveryURLs
414
DiscoveryURLs discURLs = business.getDiscoveryURLs();
415         if ((discURLs != null) && (discURLs.getDiscoveryURLVector() != null))
416           DiscoveryURLTable.insert(businessKey,discURLs.getDiscoveryURLVector(),connection);
417
418         // insert the BusinessEntity's Contact objects & information
419
Contacts contacts = business.getContacts();
420         if (contacts != null)
421         {
422           Vector JavaDoc contactVector = contacts.getContactVector();
423           if ((contactVector != null) && (contactVector.size() > 0))
424           {
425             // insert the BusinessEntity's Contact objects
426
ContactTable.insert(businessKey,contacts.getContactVector(),connection);
427
428             // insert the BusinessEntity's Contact Phone, Address and Email Info
429
int listSize = contactVector.size();
430             for (int contactID=0; contactID<listSize; contactID++)
431             {
432               Contact contact = (Contact)contactVector.elementAt(contactID);
433               ContactDescTable.insert(businessKey,contactID,contact.getDescriptionVector(),connection);
434               EmailTable.insert(businessKey,contactID,contact.getEmailVector(),connection);
435               PhoneTable.insert(businessKey,contactID,contact.getPhoneVector(),connection);
436
437               // insert the Contact's AddressLine objects
438
Vector JavaDoc addrList = contact.getAddressVector();
439               if ((addrList != null) && (addrList.size() > 0))
440               {
441                 AddressTable.insert(businessKey,contactID,addrList,connection);
442                 for (int addrID=0; addrID<addrList.size(); addrID++)
443                 {
444                   Address address = (Address)addrList.elementAt(addrID);
445                   AddressLineTable.insert(businessKey,contactID,addrID,address.getAddressLineVector(),connection);
446                 }
447               }
448             }
449           }
450         }
451
452         // 'save' the BusinessEntity's BusinessService objects
453
BusinessServices services = business.getBusinessServices();
454         if ((services != null) && (services.getBusinessServiceVector() != null))
455         {
456           UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
457           Vector JavaDoc serviceVector = services.getBusinessServiceVector();
458           int serviceListSize = serviceVector.size();
459           for (int j=0; j<serviceListSize; j++)
460           {
461             BusinessService service = (BusinessService)serviceVector.elementAt(j);
462             service.setBusinessKey(businessKey);
463
464             // create a new key if serviceKey isn't specified
465
String JavaDoc serviceKey = service.getServiceKey();
466             if ((serviceKey == null) || (serviceKey.length() == 0)) {
467               service.setServiceKey(uuidgen.uuidgen());
468             }
469             
470             saveService(service);
471           }
472         }
473       }
474     }
475     catch(java.sql.SQLException JavaDoc sqlex)
476     {
477       throw new RegistryException(sqlex);
478     }
479   }
480
481   /**
482    *
483    */

484   public BusinessEntity fetchBusiness(String JavaDoc businessKey)
485     throws org.apache.juddi.error.RegistryException
486   {
487     BusinessEntity business = null;
488
489     try
490     {
491       if ((businessKey != null) && (connection != null))
492       {
493         business = BusinessEntityTable.select(businessKey,connection);
494         business.setNameVector(BusinessNameTable.select(businessKey,connection));
495         business.setDescriptionVector(BusinessDescTable.select(businessKey,connection));
496
497         Vector JavaDoc idVector = BusinessIdentifierTable.select(businessKey,connection);
498         if (idVector.size() > 0)
499         {
500           IdentifierBag identifierBag = new IdentifierBag();
501           identifierBag.setKeyedReferenceVector(idVector);
502           business.setIdentifierBag(identifierBag);
503         }
504
505         Vector JavaDoc catVector = BusinessCategoryTable.select(businessKey,connection);
506         if (catVector.size() > 0)
507         {
508           CategoryBag categoryBag = new CategoryBag();
509           categoryBag.setKeyedReferenceVector(catVector);
510           business.setCategoryBag(categoryBag);
511         }
512
513         DiscoveryURLs discoveryURLs = new DiscoveryURLs();
514         discoveryURLs.setDiscoveryURLVector(DiscoveryURLTable.select(businessKey,connection));
515         business.setDiscoveryURLs(discoveryURLs);
516
517         // 'select' the BusinessEntity's Contact objects
518
Vector JavaDoc contactList = ContactTable.select(businessKey,connection);
519         for (int contactID=0; contactID<contactList.size(); contactID++)
520         {
521           Contact contact = (Contact)contactList.elementAt(contactID);
522           contact.setPhoneVector(PhoneTable.select(businessKey,contactID,connection));
523           contact.setEmailVector(EmailTable.select(businessKey,contactID,connection));
524
525           Vector JavaDoc addressList = AddressTable.select(businessKey,contactID,connection);
526           for (int addressID=0; addressID<addressList.size(); addressID++)
527           {
528             Address address = (Address)addressList.elementAt(addressID);
529             address.setAddressLineVector(AddressLineTable.select(businessKey,contactID,addressID,connection));
530           }
531           contact.setAddressVector(addressList);
532         }
533
534         Contacts contacts = new Contacts();
535         contacts.setContactVector(contactList);
536         business.setContacts(contacts);
537
538         // 'fetch' the BusinessEntity's BusinessService objects
539
Vector JavaDoc serviceVector = fetchServiceByBusinessKey(businessKey);
540         BusinessServices services = new BusinessServices();
541         services.setBusinessServiceVector(serviceVector);
542         business.setBusinessServices(services);
543       }
544     }
545     catch(java.sql.SQLException JavaDoc sqlex)
546     {
547       throw new RegistryException(sqlex);
548     }
549
550     return business;
551   }
552
553   /**
554    *
555    */

556   public void deleteBusiness(String JavaDoc businessKey)
557     throws org.apache.juddi.error.RegistryException
558   {
559     try
560     {
561       if ((businessKey != null) && (connection != null))
562       {
563         // delete the BusinessEntity's Services (and dependents)
564
deleteServiceByBusinessKey(businessKey);
565
566         // delete the dependents of BusinessEntity
567
AddressLineTable.delete(businessKey,connection);
568         AddressTable.delete(businessKey,connection);
569         EmailTable.delete(businessKey,connection);
570         PhoneTable.delete(businessKey,connection);
571         ContactDescTable.delete(businessKey,connection);
572         ContactTable.delete(businessKey,connection);
573         DiscoveryURLTable.delete(businessKey,connection);
574         BusinessIdentifierTable.delete(businessKey,connection);
575         BusinessCategoryTable.delete(businessKey,connection);
576         BusinessDescTable.delete(businessKey,connection);
577         BusinessNameTable.delete(businessKey,connection);
578
579         // finally, delete the BusinessEntity itself.
580
BusinessEntityTable.delete(businessKey,connection);
581       }
582     }
583     catch(java.sql.SQLException JavaDoc sqlex)
584     {
585       log.error(sqlex.getMessage(),sqlex);
586       throw new RegistryException(sqlex);
587     }
588   }
589
590   /**
591    *
592    */

593   public boolean isBusinessPublisher(String JavaDoc businessKey,String JavaDoc publisherID)
594     throws org.apache.juddi.error.RegistryException
595   {
596     try
597     {
598       if ((publisherID != null) && (businessKey != null) && (connection != null))
599         return BusinessEntityTable.verifyOwnership(businessKey,publisherID,connection);
600     }
601     catch(java.sql.SQLException JavaDoc sqlex)
602     {
603       throw new RegistryException(sqlex);
604     }
605
606     // default to false
607
return false;
608   }
609
610   /**
611    *
612    */

613   public boolean isValidBusinessKey(String JavaDoc businessKey)
614     throws org.apache.juddi.error.RegistryException
615   {
616     try
617     {
618       if ((businessKey != null) && (connection != null) &&
619           (BusinessEntityTable.select(businessKey,connection) != null))
620         return true;
621     }
622     catch(java.sql.SQLException JavaDoc sqlex)
623     {
624       throw new RegistryException(sqlex);
625     }
626
627     // default to false
628
return false;
629   }
630
631   /**
632    *
633    */

634   public void saveService(BusinessService service)
635     throws org.apache.juddi.error.RegistryException
636   {
637     try
638     {
639       if ((service != null) && (connection != null))
640       {
641         String JavaDoc serviceKey = service.getServiceKey();
642
643         // insert the BusinessService object
644
BusinessServiceTable.insert(service,connection);
645
646         // insert all of the BusinessService's Name objects
647
if (service.getNameVector() != null)
648           ServiceNameTable.insert(serviceKey,service.getNameVector(),connection);
649
650         // insert all of the BusinessService's Description objects
651
if (service.getDescriptionVector() != null)
652           ServiceDescTable.insert(serviceKey,service.getDescriptionVector(),connection);
653
654         // insert the BusinessService's CategoryBag KeyedReferences
655
CategoryBag catBag = service.getCategoryBag();
656         if ((catBag != null) && (catBag.getKeyedReferenceVector() != null))
657           ServiceCategoryTable.insert(serviceKey,catBag.getKeyedReferenceVector(),connection);
658
659         // extract the binding template objects
660
BindingTemplates bindings = service.getBindingTemplates();
661         if (bindings == null)
662           return; // no binding templates were present
663

664         // convert the binding templates to a vector of templates
665
Vector JavaDoc bindingList = bindings.getBindingTemplateVector();
666         if (bindingList == null)
667           return; // a binding template vector wasn't found
668

669         // aquire a reference to the shared UUIDGen instance
670
UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
671
672         // save all of the binding templates that were found
673
int listSize = bindingList.size();
674         for (int i=0; i<listSize; i++)
675         {
676           BindingTemplate binding = (BindingTemplate)bindingList.elementAt(i);
677           binding.setServiceKey(serviceKey);
678           
679           // create a new key if bindingKey isn't specified
680
String JavaDoc bindingKey = binding.getBindingKey();
681           if ((bindingKey == null) || (bindingKey.length() == 0)) {
682              binding.setBindingKey(uuidgen.uuidgen());
683           }
684
685           saveBinding(binding);
686         }
687       }
688     }
689     catch(java.sql.SQLException JavaDoc sqlex)
690     {
691       throw new RegistryException(sqlex);
692     }
693   }
694
695   /**
696    *
697    */

698   public BusinessService fetchService(String JavaDoc serviceKey)
699     throws org.apache.juddi.error.RegistryException
700   {
701     BusinessService service = null;
702
703     try
704     {
705       if ((serviceKey != null) && (connection != null))
706       {
707         service = BusinessServiceTable.select(serviceKey,connection);
708         service.setNameVector(ServiceNameTable.select(serviceKey,connection));
709         service.setDescriptionVector(ServiceDescTable.select(serviceKey,connection));
710
711         Vector JavaDoc catVector = ServiceCategoryTable.select(serviceKey,connection);
712         if (catVector.size() > 0)
713         {
714           CategoryBag bag = new CategoryBag();
715           bag.setKeyedReferenceVector(catVector);
716           service.setCategoryBag(bag);
717         }
718
719         // 'fetch' the BusinessService's BindingTemplate objects
720
Vector JavaDoc bindingVector = fetchBindingByServiceKey(serviceKey);
721         BindingTemplates bindings = new BindingTemplates();
722         bindings.setBindingTemplateVector(bindingVector);
723         service.setBindingTemplates(bindings);
724       }
725     }
726     catch(java.sql.SQLException JavaDoc sqlex)
727     {
728       throw new RegistryException(sqlex);
729     }
730
731     return service;
732   }
733
734   /**
735    *
736    */

737   public void deleteService(String JavaDoc serviceKey)
738     throws org.apache.juddi.error.RegistryException
739   {
740     try
741     {
742       if ((serviceKey != null) && (connection != null))
743       {
744         // delete the BusinessService's BindingTemplates (and dependents)
745
deleteBindingByServiceKey(serviceKey);
746
747         // delete the immediate dependents of BusinessService
748
ServiceNameTable.delete(serviceKey,connection);
749         ServiceDescTable.delete(serviceKey,connection);
750         ServiceCategoryTable.delete(serviceKey,connection);
751
752         // finally, delete the BusinessService itself.
753
BusinessServiceTable.delete(serviceKey,connection);
754       }
755     }
756     catch(java.sql.SQLException JavaDoc sqlex)
757     {
758       throw new RegistryException(sqlex);
759     }
760   }
761
762   /**
763    *
764    */

765   private Vector JavaDoc fetchServiceByBusinessKey(String JavaDoc businessKey)
766     throws org.apache.juddi.error.RegistryException
767   {
768     Vector JavaDoc serviceList = new Vector JavaDoc();
769
770     try
771     {
772       if ((businessKey != null) && (connection != null))
773       {
774         Vector JavaDoc tempList = BusinessServiceTable.selectByBusinessKey(businessKey,connection);
775         for (int i=0; i<tempList.size(); i++)
776         {
777           BusinessService service = (BusinessService)tempList.elementAt(i);
778           serviceList.add(fetchService(service.getServiceKey()));
779         }
780       }
781     }
782     catch(java.sql.SQLException JavaDoc sqlex)
783     {
784       throw new RegistryException(sqlex);
785     }
786
787     return serviceList;
788   }
789
790   /**
791    *
792    */

793   private void deleteServiceByBusinessKey(String JavaDoc businessKey)
794     throws org.apache.juddi.error.RegistryException
795   {
796     try
797     {
798       if ((businessKey != null) && (connection != null))
799       {
800         // obtain a vector of BusinessServices associated with the BusinessKey
801
Vector JavaDoc services = BusinessServiceTable.selectByBusinessKey(businessKey,connection);
802
803         // loop through the vector deleting each server in turn
804
int listSize = services.size();
805         for (int i=0; i<listSize; i++)
806         {
807           BusinessService service = (BusinessService)services.elementAt(i);
808           deleteService(service.getServiceKey());
809         }
810       }
811     }
812     catch(java.sql.SQLException JavaDoc sqlex)
813     {
814       throw new RegistryException(sqlex);
815     }
816
817   }
818
819   /**
820    *
821    */

822   public boolean isValidServiceKey(String JavaDoc serviceKey)
823     throws org.apache.juddi.error.RegistryException
824   {
825     try
826     {
827       if ((serviceKey != null) && (connection != null) &&
828           (BusinessServiceTable.select(serviceKey,connection) != null))
829         return true;
830     }
831     catch(java.sql.SQLException JavaDoc sqlex)
832     {
833       throw new RegistryException(sqlex);
834     }
835
836     // default to false
837
return false;
838   }
839
840   /**
841    *
842    */

843   public boolean isServicePublisher(String JavaDoc serviceKey,String JavaDoc publisherID)
844     throws org.apache.juddi.error.RegistryException
845   {
846     try
847     {
848       if ((publisherID != null) && (serviceKey != null) && (connection != null))
849         return BusinessServiceTable.verifyOwnership(serviceKey,publisherID,connection);
850     }
851     catch(java.sql.SQLException JavaDoc sqlex)
852     {
853       throw new RegistryException(sqlex);
854     }
855
856     // default to false
857
return false;
858   }
859
860   /**
861    *
862    */

863   public void saveBinding(BindingTemplate binding)
864     throws org.apache.juddi.error.RegistryException
865   {
866     try
867     {
868       if ((binding != null) && (connection != null))
869       {
870         String JavaDoc bindingKey = binding.getBindingKey();
871
872         // insert the BindingTemplate object
873
BindingTemplateTable.insert(binding,connection);
874
875         // insert the BindingTemplate's CategoryBag KeyedReferences (UDDI v3.0)
876
CategoryBag catBag = binding.getCategoryBag();
877         if ((catBag != null) && (catBag.getKeyedReferenceVector() != null))
878           BindingCategoryTable.insert(bindingKey,catBag.getKeyedReferenceVector(),connection);
879
880         // insert all of the BindingTemplate's Description objects
881
if (binding.getDescriptionVector() != null)
882           BindingDescTable.insert(bindingKey,binding.getDescriptionVector(),connection);
883
884         TModelInstanceDetails details = binding.getTModelInstanceDetails();
885         if (details == null)
886           return;
887
888         Vector JavaDoc detailsVector = details.getTModelInstanceInfoVector();
889         if (detailsVector == null)
890           return;
891
892         TModelInstanceInfoTable.insert(bindingKey,detailsVector,connection);
893
894         // save all of the BindingTemplate objects
895
Vector JavaDoc infoList = detail