KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > store > AbstractStore


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/store/AbstractStore.java,v 1.43.2.1 2004/10/18 09:13:10 luetzkendorf Exp $
3  * $Revision: 1.43.2.1 $
4  * $Date: 2004/10/18 09:13:10 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.store;
25
26 import java.util.Enumeration JavaDoc;
27 import java.util.Hashtable JavaDoc;
28
29 import javax.transaction.Transaction JavaDoc;
30 import javax.transaction.xa.XAException JavaDoc;
31 import javax.transaction.xa.Xid JavaDoc;
32
33 import org.apache.slide.authenticate.CredentialsToken;
34 import org.apache.slide.common.AbstractSimpleService;
35 import org.apache.slide.common.Namespace;
36 import org.apache.slide.common.NamespaceAccessToken;
37 import org.apache.slide.common.Scope;
38 import org.apache.slide.common.Service;
39 import org.apache.slide.common.ServiceAccessException;
40 import org.apache.slide.common.ServiceConnectionFailedException;
41 import org.apache.slide.common.ServiceDisconnectionFailedException;
42 import org.apache.slide.common.ServiceInitializationFailedException;
43 import org.apache.slide.common.ServiceParameterErrorException;
44 import org.apache.slide.common.ServiceParameterMissingException;
45 import org.apache.slide.common.ServiceResetFailedException;
46 import org.apache.slide.common.SlideToken;
47 import org.apache.slide.common.Uri;
48 import org.apache.slide.content.NodeRevisionContent;
49 import org.apache.slide.content.NodeRevisionDescriptor;
50 import org.apache.slide.content.NodeRevisionDescriptors;
51 import org.apache.slide.content.NodeRevisionNumber;
52 import org.apache.slide.content.RevisionAlreadyExistException;
53 import org.apache.slide.content.RevisionDescriptorNotFoundException;
54 import org.apache.slide.content.RevisionNotFoundException;
55 import org.apache.slide.lock.LockTokenNotFoundException;
56 import org.apache.slide.lock.NodeLock;
57 import org.apache.slide.security.NodePermission;
58 import org.apache.slide.structure.ObjectAlreadyExistsException;
59 import org.apache.slide.structure.ObjectNode;
60 import org.apache.slide.structure.ObjectNotFoundException;
61 import org.apache.slide.util.Messages;
62 import org.apache.slide.util.logger.Logger;
63
64 /**
65  * Abstract implementation of a store. Handles all caching operations.
66  *
67  * @version $Revision: 1.43.2.1 $
68  */

69 public abstract class AbstractStore extends AbstractSimpleService
70     implements Store {
71     
72     
73     // ----------------------------------------------------------- Constructors
74

75     
76     // ----------------------------------------------------- Instance Variables
77

78     
79     /**
80      * Node store.
81      */

82     protected NodeStore nodeStore;
83     
84     
85     /**
86      * Security store.
87      */

88     protected SecurityStore securityStore;
89     
90     
91     /**
92      * Lock store.
93      */

94     protected LockStore lockStore;
95     
96     
97     /**
98      * Revision descriptors store.
99      */

100     protected RevisionDescriptorsStore revisionDescriptorsStore;
101     
102     
103     /**
104      * Revision descriptor store.
105      */

106     protected RevisionDescriptorStore revisionDescriptorStore;
107     
108     
109     /**
110      * Content store.
111      */

112     protected ContentStore contentStore;
113     
114     /**
115      * DescriptorIndex store
116      */

117     protected IndexStore propertiesIndexer;
118     
119     /**
120      * ContentIndex store
121      */

122     protected IndexStore contentIndexer;
123     
124     /**
125      * Sequence store
126      */

127     protected SequenceStore sequenceStore = null;
128     
129     /**
130      * Active resource manager list.
131      */

132     protected Service resourceManagers[] = new Service[0];
133     
134     
135     
136     // the name of this store as specified in domain.xml
137
private String JavaDoc name;
138     
139     
140     /**
141      * Set the name of the store as specified in domain.xml.
142      */

143     public void setName(String JavaDoc name) {
144         this.name = name;
145     }
146     
147     
148     
149     /**
150      * Return the name of the store as specified in domain.xml.
151      */

152     public String JavaDoc getName() {
153         return this.name;
154     }
155     
156     
157     
158     /**
159      * Set the scope of the store as specified in domain.xml.
160      */

161     public void setScope(Scope scope) {
162         super.setScope(scope);
163         for (int i = 0; i < resourceManagers.length; i++) {
164             resourceManagers[i].setScope(scope);
165         }
166     }
167     
168     
169     
170     // ---------------------------------------------------- ServiceImpl Methods
171

172     
173     /**
174      * Namespace setter.
175      */

176     public void setNamespace(Namespace namespace) {
177         
178         super.setNamespace(namespace);
179         
180         for (int i = 0; i < resourceManagers.length; i++) {
181             resourceManagers[i].setNamespace(namespace);
182         }
183         
184     }
185     
186     
187     protected Hashtable JavaDoc parameters = null;
188     
189     /**
190      * Remeber the store parameters to initialise the default child stores on request
191      *
192      * @param parameters Hashtable containing the parameters' name
193      * and associated value
194      * @exception ServiceParameterErrorException Incorrect service parameter
195      * @exception ServiceParameterMissingException Service parameter missing
196      */

197     public void setParameters(Hashtable JavaDoc parameters)
198         throws ServiceParameterErrorException,
199         ServiceParameterMissingException {
200         this.parameters = parameters;
201     }
202     
203     public Object JavaDoc getParameter (Object JavaDoc key) {
204         return parameters.get (key);
205     }
206     
207     /**
208      * Connects to descriptors store.
209      *
210      * @exception DataException
211      */

212     public void connect(CredentialsToken crdtoken)
213         throws ServiceConnectionFailedException {
214         
215         for (int i = 0; i < resourceManagers.length; i++) {
216             resourceManagers[i].connect(crdtoken);
217         }
218         
219     }
220     
221     
222     
223     /**
224      * Connects to descriptors store.
225      *
226      * @exception DataException
227      */

228     public void connect()
229         throws ServiceConnectionFailedException {
230         
231         for (int i = 0; i < resourceManagers.length; i++) {
232             resourceManagers[i].connect();
233         }
234         
235     }
236     
237     
238     /**
239      * Disconnects from descriptors store.
240      *
241      * @exception ServiceDisconnectionFailedException
242      */

243     public void disconnect()
244         throws ServiceDisconnectionFailedException {
245         
246         for (int i = 0; i < resourceManagers.length; i++) {
247             resourceManagers[i].disconnect();
248         }
249         
250     }
251     
252     
253     /**
254      * Initializes descriptors store.
255      *
256      * @exception ServiceInitializationFailedException Throws an exception
257      * if the descriptors store has already been initialized before
258      */

259     public void initialize(NamespaceAccessToken token)
260         throws ServiceInitializationFailedException {
261         
262         super.initialize(token);
263         
264         for (int i = 0; i < resourceManagers.length; i++) {
265             resourceManagers[i].initialize(token);
266         }
267         
268     }
269     
270     
271     /**
272      * Deletes descriptors store. Should remove stored data if possible.
273      *
274      * @exception ServiceResetFailedException Reset failed
275      */

276     public void reset()
277         throws ServiceResetFailedException {
278         
279         for (int i = 0; i < resourceManagers.length; i++) {
280             resourceManagers[i].reset();
281         }
282         
283     }
284     
285     
286     /**
287      * This function tells whether or not the descriptors store is connected.
288      *
289      * @return boolean true if we are connected
290      * @exception ServiceAccessException Service access error
291      */

292     public boolean isConnected()
293         throws ServiceAccessException {
294         
295         for (int i = 0; i < resourceManagers.length; i++) {
296             if (!resourceManagers[i].isConnected())
297                 return false;
298         }
299         return true;
300         
301     }
302     
303     
304     // ----------------------------------------------------- XAResource Methods
305

306     
307     /**
308      * Commit the global transaction specified by xid.
309      *
310      * @param xid A global transaction identifier
311      * @param onePhase If true, the resource manager should use a one-phase
312      * commit protocol to commit the work done on behalf of xid.
313      * @exception XAException An error has occurred. Possible XAExceptions
314      * are XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR,
315      * XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO. If the resource
316      * manager did not commit the transaction and the paramether onePhase is
317      * set to true, the resource manager may throw one of the XA_RB*
318      * exceptions. Upon return, the resource manager has rolled back the
319      * branch's work and has released all held resources.
320      */

321     public void commit(Xid JavaDoc xid, boolean onePhase)
322         throws XAException JavaDoc {
323         super.commit(xid, onePhase);
324     }
325     
326     
327     /**
328      * Ends the work performed on behalf of a transaction branch.
329      *
330      * @param xid A global transaction identifier that is the same as what
331      * was used previously in the start method.
332      * @param flags One of TMSUCCESS, TMFAIL, or TMSUSPEND
333      * @exception XAException An error has occurred. Possible XAException
334      * values are XAER_RMERR, XAER_RMFAILED, XAER_NOTA, XAER_INVAL,
335      * XAER_PROTO, or XA_RB*.
336      */

337     public void end(Xid JavaDoc xid, int flags)
338         throws XAException JavaDoc {
339         super.end(xid, flags);
340     }
341     
342     
343     /**
344      * Tell the resource manager to forget about a heuristically completed
345      * transaction branch.
346      *
347      * @param xid A global transaction identifier
348      * @exception XAException An error has occurred. Possible exception values
349      * are XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
350      */

351     public void forget(Xid JavaDoc xid)
352         throws XAException JavaDoc {
353         super.forget(xid);
354     }
355     
356     
357     /**
358      * Ask the resource manager to prepare for a transaction commit of the
359      * transaction specified in xid.
360      *
361      * @param xid A global transaction identifier
362      * @return A value indicating the resource manager's vote on the outcome
363      * of the transaction. The possible values are: XA_RDONLY or XA_OK. If
364      * the resource manager wants to roll back the transaction, it should do
365      * so by raising an appropriate XAException in the prepare method.
366      * @exception XAException An error has occurred. Possible exception
367      * values are: XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL,
368      * or XAER_PROTO.
369      */

370     public int prepare(Xid JavaDoc xid)
371         throws XAException JavaDoc {
372         return super.prepare(xid);
373     }
374     
375     
376     /**
377      * Inform the resource manager to roll back work done on behalf of a
378      * transaction branch.
379      *
380      * @param xid A global transaction identifier
381      * @exception XAException An error has occurred
382      */

383     public void rollback(Xid JavaDoc xid)
384         throws XAException JavaDoc {
385         super.rollback(xid);
386     }
387     
388     
389     /**
390      * Start work on behalf of a transaction branch specified in xid.
391      *
392      * @param xid A global transaction identifier to be associated with the
393      * resource
394      * @param flags One of TMNOFLAGS, TMJOIN, or TMRESUME
395      * @exception XAException An error has occurred. Possible exceptions are
396      * XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_DUPID, XAER_OUTSIDE, XAER_NOTA,
397      * XAER_INVAL, or XAER_PROTO.
398      */

399     public void start(Xid JavaDoc xid, int flags)
400         throws XAException JavaDoc {
401         super.start(xid, flags);
402     }
403     
404     
405     // ---------------------------------------------------------- Store Methods
406

407     
408     /**
409      * Set the node store associated with this store.
410      */

411     public void setNodeStore(NodeStore nodeStore) {
412         if (nodeStore == null) {
413             throw new IllegalArgumentException JavaDoc("Nodestore must not be null");
414         }
415         this.nodeStore = nodeStore;
416         addResourceManager(this.nodeStore);
417     }
418     
419     
420     /**
421      * Set the security store associated with this store.
422      */

423     public void setSecurityStore(SecurityStore securityStore) {
424         if (securityStore == null) {
425             throw new IllegalArgumentException JavaDoc("Securitystore must not be null");
426         }
427         this.securityStore = securityStore;
428         addResourceManager(this.securityStore);
429     }
430     
431     
432     /**
433      * Set the lock store associated with this store.
434      */

435     public void setLockStore(LockStore lockStore) {
436         if (lockStore == null) {
437             throw new IllegalArgumentException JavaDoc("Lockstore must not be null");
438         }
439         this.lockStore = lockStore;
440         addResourceManager(this.lockStore);
441     }
442     
443     
444     /**
445      * Set the revision descriptors store associated with this store.
446      */

447     public void setRevisionDescriptorsStore
448         (RevisionDescriptorsStore revisionDescriptorsStore) {
449         if (revisionDescriptorsStore == null) {
450             throw new IllegalArgumentException JavaDoc("Revisiondescriptorsstore must not be null");
451         }
452         this.revisionDescriptorsStore = revisionDescriptorsStore;
453         addResourceManager(this.revisionDescriptorsStore);
454     }
455     
456     
457     /**
458      * Set the revision descriptor store associated with this store.
459      */

460     public void setRevisionDescriptorStore
461         (RevisionDescriptorStore revisionDescriptorStore) {
462         if (revisionDescriptorStore == null) {
463             throw new IllegalArgumentException JavaDoc("Revisiondescriptorstore must not be null");
464         }
465         this.revisionDescriptorStore = revisionDescriptorStore;
466         addResourceManager(this.revisionDescriptorStore);
467     }
468     
469     
470     /**
471      * Set the content store associated with this store.
472      */

473     public void setContentStore(ContentStore contentStore) {
474         if (contentStore == null) {
475             
476         }
477         this.contentStore = contentStore;
478         addResourceManager(this.contentStore);
479     }
480     
481     
482     /**
483      * Set the Indexer associated to the properties store
484      *
485      * @param propertiesIndexer an IndexStore
486      *
487      */

488     public void setPropertiesIndexer (IndexStore propertiesIndexer) {
489         if (propertiesIndexer == null) {
490             throw new IllegalArgumentException JavaDoc("PropertiesIndexer must not be null");
491         }
492         this.propertiesIndexer = propertiesIndexer;
493         addResourceManager(this.propertiesIndexer);
494         
495     }
496     
497     
498     /**
499      * Set the Indexer associated to the conten store
500      *
501      * @param contentIndexer an IndexStore
502      *
503      */

504     public void setContentIndexer (IndexStore contentIndexer) {
505         if (contentIndexer == null) {
506             throw new IllegalArgumentException JavaDoc("ContentIndexer must not be null");
507         }
508         this.contentIndexer = contentIndexer;
509         addResourceManager(this.contentIndexer);
510         
511     }
512     
513     /**
514      * Method getContentIndexer
515      *
516      * @return an IndexStore
517      *
518      */

519     public IndexStore getContentIndexer () {
520         return contentIndexer;
521     }
522     
523     /**
524      * Method getPropertiesIndexer
525      *
526      * @return an IndexStore
527      *
528      */

529     public IndexStore getPropertiesIndexer () {
530         return propertiesIndexer;
531     }
532     
533     /**
534      * Set the sequence store associated with this store.
535      */

536     public void setSequenceStore(SequenceStore store) {
537         sequenceStore = store;
538     }
539         
540     //
541
// sequence methods
542
//
543

544     /**
545      * @see org.apache.slide.store.SequenceStore#isSequenceSupported()
546      */

547     public boolean isSequenceSupported() {
548         return (sequenceStore != null && sequenceStore.isSequenceSupported());
549     }
550
551     /**
552      * @see org.apache.slide.store.SequenceStore#sequenceExists(java.lang.String)
553      */

554     public boolean sequenceExists(String JavaDoc sequenceName) throws ServiceAccessException {
555         if (!isSequenceSupported()) {
556             throw new ServiceAccessException(this, "Sequences not supported");
557         }
558         return sequenceStore.sequenceExists(sequenceName);
559     }
560
561     /**
562      * @see org.apache.slide.store.SequenceStore#createSequence(java.lang.String)
563      */

564     public boolean createSequence(String JavaDoc sequenceName) throws ServiceAccessException {
565         if (!isSequenceSupported()) {
566             throw new ServiceAccessException(this, "Sequences not supported");
567         }
568         return sequenceStore.createSequence(sequenceName);
569     }
570
571     /**
572      * @see org.apache.slide.store.SequenceStore#nextSequenceValue(java.lang.String)
573      */

574     public long nextSequenceValue(String JavaDoc sequenceName) throws ServiceAccessException {
575         if (!isSequenceSupported()) {
576             throw new ServiceAccessException(this, "Sequences not supported");
577         }
578         return sequenceStore.nextSequenceValue(sequenceName);
579     }
580
581     /**
582      * Retrive an object from the Descriptors Store.
583      *
584      * @param uri Uri of the object we want to retrieve
585      * @exception ServiceAccessException Error accessing the Descriptors Store
586      * @exception ObjectNotFoundException The object to retrieve was not found
587      */

588     public ObjectNode retrieveObject(Uri uri)
589         throws ServiceAccessException, ObjectNotFoundException {
590         ObjectNode objectNode = null;
591         if (isForceStoreEnlistment(uri)) {
592             enlist(nodeStore);
593             try {
594                 objectNode = nodeStore.retrieveObject(uri);
595             } catch (ServiceAccessException e) {
596                 delist(nodeStore, false);
597                 throw e;
598             } catch (ObjectNotFoundException e) {
599                 // Note : Failed reads aren't considered fatal (ie, the
600
// transaction won't be always rolledback when committed)
601
delist(nodeStore);
602                 throw e;
603             } catch (Throwable JavaDoc t) {
604                 delist(nodeStore, false);
605                 // Wrap everything else in a ServiceAccessException
606
throw new ServiceAccessException(nodeStore, t);
607             }
608             delist(nodeStore);
609         } else {
610             try {
611                 objectNode = nodeStore.retrieveObject(uri);
612             } catch (ServiceAccessException e) {
613                 throw e;
614             } catch (ObjectNotFoundException e) {
615                 throw e;
616             } catch (Throwable JavaDoc t) {
617                 // Wrap everything else in a ServiceAccessException
618
throw new ServiceAccessException(nodeStore, t);
619             }
620         }
621         objectNode.validate(uri.toString());
622         return objectNode;
623     }
624     
625     
626     /**
627      * Store an object in the Descriptors Store.
628      *
629      * @param object Object to update
630      * @exception ServiceAccessException Error accessing the Descriptors Store
631      * @exception ObjectNotFoundException The object to update was not found
632      */

633     public void storeObject(Uri uri, ObjectNode object)
634         throws ServiceAccessException, ObjectNotFoundException {
635         ObjectNode tempObject = object.cloneObject();
636         tempObject.validate(uri.toString());
637         enlist(nodeStore);
638         try {
639             nodeStore.storeObject(uri, tempObject);
640         } catch (ServiceAccessException e) {
641             delist(nodeStore, false);
642             throw e;
643         } catch (ObjectNotFoundException e) {
644             delist(nodeStore);
645             throw e;
646         } catch (Throwable JavaDoc t) {
647             delist(nodeStore, false);
648             // Wrap everything else in a ServiceAccessException
649
throw new ServiceAccessException(contentStore, t);
650         }
651         delist(nodeStore);
652     }
653     
654     
655     /**
656      * Create a new object in the Descriptors Store.
657      *
658      * @param object SlideObject
659      * @param uri Uri of the object we want to create
660      * @exception ServiceAccessException Error accessing the Descriptors Store
661      * @exception ObjectAlreadyExistsException An object already exists
662      * at this Uri
663      */

664     public void createObject(Uri uri, ObjectNode object)
665         throws ServiceAccessException, ObjectAlreadyExistsException {
666         ObjectNode tempObject = object.cloneObject();
667         tempObject.validate(uri.toString());
668         enlist(nodeStore);
669         try {
670             nodeStore.createObject(uri, tempObject);
671             if (useBinding()) {
672                 String JavaDoc uuri = tempObject.getUuri();
673                 if (uuri == null) {
674                     throw new IllegalStateException JavaDoc();
675                 }
676                 object.setUuri(uuri);
677             } else {
678                 object.setUuri(tempObject.getUri());
679             }
680         } catch (ServiceAccessException e) {
681             delist(nodeStore, false);
682             throw e;
683         } catch (ObjectAlreadyExistsException e) {
684             delist(nodeStore);
685             throw e;
686         } catch (Throwable JavaDoc t) {
687             delist(nodeStore, false);
688             // Wrap everything else in a ServiceAccessException
689
throw new ServiceAccessException(nodeStore, t);
690         }
691         delist(nodeStore);
692     }
693     
694     
695     /**
696      * Remove an object from the Descriptors Store.
697      *
698      * @param object Object to remove
699      * @exception ServiceAccessException Error accessing the Descriptors Store
700      * @exception ObjectNotFoundException The object to remove was not found
701      */

702     public void removeObject(Uri uri, ObjectNode object)
703         throws ServiceAccessException, ObjectNotFoundException {
704         object.validate(uri.toString());
705         enlist(nodeStore);
706         try {
707             nodeStore.removeObject(uri, object);
708         } catch (ServiceAccessException e) {
709             delist(nodeStore, false);
710             throw e;
711         } catch (ObjectNotFoundException e) {
712             delist(nodeStore);
713             throw e;
714         } catch (Throwable JavaDoc t) {
715             delist(nodeStore, false);
716             // Wrap everything else in a ServiceAccessException
717
throw new ServiceAccessException(nodeStore, t);
718         }
719         delist(nodeStore);
720     }
721     
722     
723     /**
724      * Store an object permissions in the Descriptors Store.
725      *
726      * @param permission Permission we want to create
727      * @exception ServiceAccessException Error accessing the Descriptors Store
728      */

729     public void grantPermission(Uri uri, NodePermission permission)
730         throws ServiceAccessException {
731         NodePermission tempPermission = permission.cloneObject();
732         tempPermission.validate(uri.toString());
733         enlist(securityStore);
734         try {
735             securityStore.grantPermission(uri, tempPermission);
736         } catch (ServiceAccessException e) {
737             delist(securityStore, false);
738             throw e;
739         } catch (Throwable JavaDoc t) {
740             delist(securityStore, false);
741             // Wrap everything else in a ServiceAccessException
742
throw new ServiceAccessException(securityStore, t);
743         }
744         delist(securityStore);
745     }
746     
747     
748     /**
749      * Store an object permissions in the Descriptors Store.
750      *
751      * @param permission Permission we want to create
752      * @exception ServiceAccessException Error accessing the Descriptors Store
753      */

754     public void revokePermission(Uri uri, NodePermission permission)
755         throws ServiceAccessException {
756         permission.validate(uri.toString());
757         enlist(securityStore);
758         try {
759             securityStore.revokePermission(uri, permission);
760         } catch (ServiceAccessException e) {
761             delist(securityStore, false);
762             throw e;
763         } catch (Throwable JavaDoc t) {
764             delist(securityStore, false);
765             // Wrap everything else in a ServiceAccessException
766
throw new ServiceAccessException(securityStore, t);
767         }
768         delist(securityStore);
769     }
770     
771     
772     /**
773      * Revoke all the permissions on the object.
774      *
775      * @param uri Uri of the object
776      * @exception ServiceAccessException Error accessing the Descriptors Store
777      */

778     public void revokePermissions(Uri uri)
779         throws ServiceAccessException {
780         enlist(securityStore);
781         try {
782             securityStore.revokePermissions(uri);
783         } catch (ServiceAccessException e) {
784             delist(securityStore, false);
785             throw e;
786         } catch (Throwable JavaDoc t) {
787             delist(securityStore, false);
788             // Wrap everything else in a ServiceAccessException
789
throw new ServiceAccessException(securityStore, t);
790         }
791         delist(securityStore);
792     }
793     
794     
795     /**
796      * Enumerate locks on an object.
797      *
798      * @param uri Uri of the subject
799      * @return Enumeration List of {@link org.apache.slide.lock.NodeLock locks}
800      * which have been put on the subject
801      * @exception ServiceAccessException Service access error
802      */

803     public Enumeration JavaDoc enumeratePermissions(Uri uri)
804         throws ServiceAccessException {
805         // TODO : The vectors elements MUST be cloned
806
if (isForceStoreEnlistment(uri)) {
807             enlist(securityStore);
808             Enumeration JavaDoc permissions = null;
809             try {
810                 permissions = securityStore.enumeratePermissions(uri);
811             } catch (ServiceAccessException e) {
812                 delist(securityStore, false);
813                 throw e;
814             } catch (Throwable JavaDoc t) {
815                 delist(securityStore, false);
816                 // Wrap everything else in a ServiceAccessException
817
throw new ServiceAccessException
818                     (securityStore, t);
819             }
820             delist(securityStore);
821             return permissions;
822         } else {
823             try {
824                 return securityStore.enumeratePermissions(uri);
825             } catch (ServiceAccessException e) {
826                 throw e;
827             } catch (Throwable JavaDoc t) {
828                 // Wrap everything else in a ServiceAccessException
829
throw new ServiceAccessException
830                     (securityStore, t);
831             }
832         }
833     }
834     
835     
836     /**
837      * Puts a lock on a subject.
838      *
839      * @param lock Lock token
840      * @exception ServiceAccessException Service access error
841      */

842     public void putLock(Uri uri, NodeLock lock)
843         throws ServiceAccessException {
844         lock.validate(uri.toString());
845         enlist(lockStore);
846         try {
847             lockStore.putLock(uri, lock);
848         } catch (ServiceAccessException e) {
849             delist(lockStore, false);
850             throw e;
851         } catch (Throwable JavaDoc t) {
852             delist(lockStore, false);
853             // Wrap everything else in a ServiceAccessException
854
throw new ServiceAccessException(lockStore, t);
855         }
856         delist(lockStore);
857     }
858     
859     
860     /**
861      * Renews a lock.
862      *
863      * @param lock Token to renew
864      * @exception ServiceAccessException Service access error
865      * @exception LockTokenNotFoundException Lock token was not found
866      */

867     public void renewLock(Uri uri, NodeLock lock)
868         throws ServiceAccessException, LockTokenNotFoundException {
869         lock.validate(uri.toString());
870         enlist(lockStore);
871         try {
872             lockStore.renewLock(uri, lock);
873         } catch (ServiceAccessException e) {
874             delist(lockStore, false);
875             throw e;
876         } catch (LockTokenNotFoundException e) {
877             delist(lockStore);
878             throw e;
879         } catch (Throwable JavaDoc t) {
880             delist(lockStore, false);
881             // Wrap everything else in a ServiceAccessException
882
throw new ServiceAccessException(lockStore, t);
883         }
884         delist(lockStore);
885     }
886     
887     
888     /**
889      * Removes (cancels) a lock.
890      *
891      * @param lock Token to remove
892      * @exception ServiceAccessException Service access error
893      * @exception LockTokenNotFoundException Lock token was not found
894      */

895     public void removeLock(Uri uri, NodeLock lock)
896         throws ServiceAccessException, LockTokenNotFoundException {
897         lock.validate(uri.toString());
898         enlist(lockStore);
899         try {
900             lockStore.removeLock(uri, lock);
901         } catch (ServiceAccessException e) {
902             delist(lockStore, false);
903             throw e;
904         } catch (LockTokenNotFoundException e) {
905             delist(lockStore);
906             throw e;
907         } catch (Throwable JavaDoc t) {
908             delist(lockStore, false);
909             // Wrap everything else in a ServiceAccessException
910
throw new ServiceAccessException(lockStore, t);
911         }
912         delist(lockStore);
913     }
914     
915     
916     /**
917      * Kills a lock.
918      *
919      * @param lock Token to remove
920      * @exception ServiceAccessException Service access error
921      * @exception LockTokenNotFoundException Lock token was not found
922      */

923     public void killLock(Uri uri, NodeLock lock)
924         throws ServiceAccessException, LockTokenNotFoundException {
925         lock.validate(uri.toString());
926         enlist(lockStore);
927         try {
928             lockStore.killLock(uri, lock);
929         } catch (ServiceAccessException e) {
930             delist(lockStore, false);
931             throw e;
932         } catch (LockTokenNotFoundException e) {
933             delist(lockStore);
934             throw e;
935         } catch (Throwable JavaDoc t) {
936             delist(lockStore, false);
937             // Wrap everything else in a ServiceAccessException
938
throw new ServiceAccessException(lockStore, t);
939         }
940         delist(lockStore);
941     }
942     
943     
944     /**
945      * Enumerate locks on an object.
946      *
947      * @param uri Uri of the subject
948      * @return Enumeration List of {@link org.apache.slide.lock.NodeLock locks}
949      * which have been put on the subject
950      * @exception ServiceAccessException Service access error
951      */

952     public Enumeration JavaDoc enumerateLocks(Uri uri)
953         throws ServiceAccessException {
954         if (isForceStoreEnlistment(uri)) {
955             enlist(lockStore);
956             Enumeration JavaDoc locks = null;
957             try {
958                 locks = lockStore.enumerateLocks(uri);
959             } catch (ServiceAccessException e) {
960                 delist(lockStore, false);
961                 throw e;
962             } catch (Throwable JavaDoc t) {
963                 delist(lockStore, false);
964                 // Wrap everything else in a ServiceAccessException
965
throw new ServiceAccessException(lockStore, t);
966             }
967             delist(lockStore);
968             return locks;
969         } else {
970             try {
971                 return lockStore.enumerateLocks(uri);
972             } catch (ServiceAccessException e) {
973                 throw e;
974             } catch (Throwable JavaDoc t) {
975                 // Wrap everything else in a ServiceAccessException
976
throw new ServiceAccessException(lockStore, t);
977             }
978         }
979     }
980     
981     
982     /**
983      * Retrieve a revision descriptors.
984      *
985      * @param uri Uri
986      * @exception ServiceAccessException Service access error
987      * @exception RevisionDescriptorNotFoundException Revision descriptor
988      * was not found
989      */

990     public NodeRevisionDescriptors retrieveRevisionDescriptors(Uri uri)
991         throws ServiceAccessException, RevisionDescriptorNotFoundException {
992         NodeRevisionDescriptors revisionDescriptors = null;
993         if (isForceStoreEnlistment(uri)) {
994             enlist(revisionDescriptorsStore);
995             try {
996                 revisionDescriptors =
997                     revisionDescriptorsStore.retrieveRevisionDescriptors(uri);
998             } catch (ServiceAccessException e) {
999                 delist(revisionDescriptorsStore, false);
1000                throw e;
1001            } catch (RevisionDescriptorNotFoundException e) {
1002                // Normal read failures aren't considered fatal
1003
delist(revisionDescriptorsStore);
1004                throw e;
1005            } catch (Throwable JavaDoc t) {
1006                delist(revisionDescriptorsStore, false);
1007                // Wrap everything else in a ServiceAccessException
1008
throw new ServiceAccessException
1009                    (revisionDescriptorsStore, t);
1010            }
1011            delist(revisionDescriptorsStore);
1012        } else {
1013            try {
1014                revisionDescriptors =
1015                    revisionDescriptorsStore.retrieveRevisionDescriptors(uri);
1016            } catch (ServiceAccessException e) {
1017                throw e;
1018            } catch (RevisionDescriptorNotFoundException e) {
1019                throw e;
1020            } catch (Throwable JavaDoc t) {
1021                // Wrap everything else in a ServiceAccessException
1022
throw new ServiceAccessException
1023                    (revisionDescriptorsStore, t);
1024            }
1025        }
1026        revisionDescriptors.validate(uri.toString());
1027        return revisionDescriptors;
1028    }
1029    
1030    
1031    /**
1032     * Create new revision descriptors.
1033     *
1034     * @param uri Uri
1035     * @param revisionDescriptors Node revision descriptors
1036     * @exception ServiceAccessException Service access error
1037     */

1038    public void createRevisionDescriptors
1039        (Uri uri, NodeRevisionDescriptors revisionDescriptors)
1040        throws ServiceAccessException {
1041        revisionDescriptors.validate(uri.toString());
1042        enlist(revisionDescriptorsStore);
1043        try {
1044            revisionDescriptorsStore.createRevisionDescriptors
1045                (uri, revisionDescriptors);
1046        } catch (ServiceAccessException e) {
1047            delist(revisionDescriptorsStore, false);
1048            throw e;
1049        } catch (Throwable JavaDoc t) {
1050            delist(revisionDescriptorsStore, false);
1051            // Wrap everything else in a ServiceAccessException
1052
throw new ServiceAccessException
1053                (revisionDescriptorsStore, t);
1054        }
1055        delist(revisionDescriptorsStore);
1056    }
1057    
1058    
1059    /**
1060     * Update revision descriptors.
1061     *
1062     * @param uri Uri
1063     * @param revisionDescriptors Node revision descriptors
1064     * @exception ServiceAccessException Service access error
1065     * @exception RevisionDescriptorNotFoundException Revision descriptor
1066     * was not found
1067     */

1068    public void storeRevisionDescriptors
1069        (Uri uri, NodeRevisionDescriptors revisionDescriptors)
1070        throws ServiceAccessException, RevisionDescriptorNotFoundException {
1071        revisionDescriptors.validate(uri.toString());
1072        enlist(revisionDescriptorsStore);
1073        try {
1074            revisionDescriptorsStore.storeRevisionDescriptors
1075                (uri, revisionDescriptors);
1076        } catch (ServiceAccessException e) {
1077            delist(revisionDescriptorsStore, false);
1078            throw e;
1079        } catch (RevisionDescriptorNotFoundException e) {
1080            delist(revisionDescriptorsStore);
1081            throw e;
1082        } catch (Throwable JavaDoc t) {
1083            delist(revisionDescriptorsStore, false);
1084            // Wrap everything else in a ServiceAccessException
1085
throw new ServiceAccessException
1086                (revisionDescriptorsStore, t);
1087        }
1088        delist(revisionDescriptorsStore);
1089    }
1090    
1091    
1092    /**
1093     * Remove revision descriptors.
1094     *
1095     * @param uri Uri
1096     * @exception ServiceAccessException Service access error
1097     */

1098    public void removeRevisionDescriptors(Uri uri)
1099        throws ServiceAccessException {
1100        enlist(revisionDescriptorsStore);
1101        try {
1102            revisionDescriptorsStore.removeRevisionDescriptors(uri);
1103        } catch (ServiceAccessException e) {
1104            delist(revisionDescriptorsStore, false);
1105            throw e;
1106        } catch (Throwable JavaDoc t) {
1107            delist(revisionDescriptorsStore, false);
1108            // Wrap everything else in a ServiceAccessException
1109
throw new ServiceAccessException
1110                (revisionDescriptorsStore, t);
1111        }
1112        delist(revisionDescriptorsStore);
1113    }
1114    
1115    
1116    /**
1117     * Retrieve revision descriptor.
1118     *
1119     * @param uri uri
1120     * @param revisionNumber Node revision number
1121     */

1122    public NodeRevisionDescriptor retrieveRevisionDescriptor
1123        (Uri uri, NodeRevisionNumber revisionNumber)
1124        throws ServiceAccessException, RevisionDescriptorNotFoundException {
1125        NodeRevisionDescriptor revisionDescriptor = null;
1126        if (isForceStoreEnlistment(uri)) {
1127            enlist(revisionDescriptorStore);
1128            try {
1129                revisionDescriptor =
1130                    revisionDescriptorStore.retrieveRevisionDescriptor
1131                    (uri, revisionNumber);
1132            } catch (ServiceAccessException e) {
1133                delist(revisionDescriptorStore, false);
1134                throw e;
1135            } catch (RevisionDescriptorNotFoundException e) {
1136                // Normal read failures aren't considered fatal
1137
delist(revisionDescriptorStore);
1138                throw e;
1139            } catch (Throwable JavaDoc t) {
1140                delist(revisionDescriptorStore, false);
1141                // Wrap everything else in a ServiceAccessException
1142
throw new ServiceAccessException
1143                    (revisionDescriptorStore, t);
1144            }
1145            delist(revisionDescriptorStore);
1146        } else {
1147            try {
1148                revisionDescriptor =
1149                    revisionDescriptorStore.retrieveRevisionDescriptor
1150                    (uri, revisionNumber);
1151            } catch (ServiceAccessException e) {
1152                throw e;
1153            } catch (RevisionDescriptorNotFoundException e) {
1154                throw e;
1155            } catch (Throwable JavaDoc t) {
1156                // Wrap everything else in a ServiceAccessException
1157
throw new ServiceAccessException
1158                    (revisionDescriptorStore, t);
1159            }
1160        }
1161        revisionDescriptor.validate();
1162        return revisionDescriptor;
1163    }
1164    
1165    
1166    /**
1167     * Create new revision descriptor.
1168     *
1169     * @param uri Uri
1170     * @param revisionDescriptor Node revision descriptor
1171     * @exception ServiceAccessException Service access error
1172     */

1173    public void createRevisionDescriptor
1174        (Uri uri, NodeRevisionDescriptor revisionDescriptor)
1175        throws ServiceAccessException {
1176        revisionDescriptor.validate();
1177        
1178        enlist(propertiesIndexer);
1179        enlist(revisionDescriptorStore);
1180        try {
1181            propertiesIndexer.createIndex (uri, revisionDescriptor, null);
1182            revisionDescriptorStore.createRevisionDescriptor
1183                (uri, revisionDescriptor);
1184            
1185        } catch (ServiceAccessException e) {
1186            delist (propertiesIndexer, false);
1187            delist(revisionDescriptorStore, false);
1188            throw e;
1189        } catch (Throwable JavaDoc t) {
1190            delist (propertiesIndexer, false);
1191            delist(revisionDescriptorStore, false);
1192            // Wrap everything else in a ServiceAccessException
1193
throw new ServiceAccessException
1194                (revisionDescriptorStore, t);
1195        }
1196        delist (propertiesIndexer);
1197        delist (revisionDescriptorStore);
1198    }
1199    
1200    
1201    /**
1202     * Update revision descriptor.
1203     *
1204     * @param uri Uri
1205     * @param revisionDescriptor Node revision descriptor
1206     * @exception ServiceAccessException Service access error
1207     * @exception RevisionDescriptorNotFoundException Revision descriptor
1208     * was not found
1209     */

1210    public void storeRevisionDescriptor
1211        (Uri uri, NodeRevisionDescriptor revisionDescriptor)
1212        throws ServiceAccessException, RevisionDescriptorNotFoundException {
1213        revisionDescriptor.validate();
1214        
1215        enlist (propertiesIndexer);
1216        enlist(revisionDescriptorStore);
1217        try {
1218            propertiesIndexer.updateIndex (uri, revisionDescriptor, null);
1219            revisionDescriptorStore.storeRevisionDescriptor
1220                (uri, revisionDescriptor);
1221            
1222        } catch (ServiceAccessException e) {
1223            delist (propertiesIndexer, false);
1224            delist(revisionDescriptorStore, false);
1225            throw e;
1226        } catch (RevisionDescriptorNotFoundException e) {
1227            delist (propertiesIndexer);
1228            delist(revisionDescriptorStore);
1229            throw e;
1230        } catch (Throwable JavaDoc t) {
1231            delist (propertiesIndexer, false);
1232            delist(revisionDescriptorStore, false);
1233            // Wrap everything else in a ServiceAccessException
1234
throw new ServiceAccessException
1235                (revisionDescriptorStore, t);
1236        }
1237        delist (propertiesIndexer);
1238        delist(revisionDescriptorStore);
1239    }
1240    
1241    
1242    /**
1243     * Remove revision descriptor.
1244     *
1245     * @param uri Uri
1246     * @param revisionNumber Revision number
1247     * @exception ServiceAccessException Service access error
1248     */

1249    public void removeRevisionDescriptor (Uri uri, NodeRevisionNumber number)
1250        throws ServiceAccessException
1251    {
1252        number.validate();
1253        
1254        enlist(propertiesIndexer);
1255        enlist(revisionDescriptorStore);
1256        
1257        try {
1258            propertiesIndexer.dropIndex (uri, number);
1259            revisionDescriptorStore.removeRevisionDescriptor(uri, number);
1260        } catch (ServiceAccessException e) {
1261            delist(propertiesIndexer, false);
1262            delist(revisionDescriptorStore, false);
1263            throw e;
1264        } catch (Throwable JavaDoc t) {
1265            delist(propertiesIndexer, false);
1266            delist(revisionDescriptorStore, false);
1267            
1268            // Wrap everything else in a ServiceAccessException
1269
throw new ServiceAccessException
1270                (revisionDescriptorStore, t);
1271        }
1272        delist(propertiesIndexer);
1273        delist(revisionDescriptorStore);
1274    }
1275    
1276    
1277    /**
1278     * Retrive revision content.
1279     *
1280     * @param uri Uri
1281     * @param revisionDescriptor Node revision descriptor
1282     */

1283    public NodeRevisionContent retrieveRevisionContent
1284        (Uri uri, NodeRevisionDescriptor revisionDescriptor)
1285        throws ServiceAccessException, RevisionNotFoundException {
1286        NodeRevisionContent revisionContent = null;
1287        if (isForceStoreEnlistment(uri)) {
1288            enlist(contentStore);
1289            try {
1290                revisionContent =
1291                    contentStore.retrieveRevisionContent
1292                    (uri, revisionDescriptor);
1293                
1294            } catch (ServiceAccessException e) {
1295                delist(contentStore, false);
1296                throw e;
1297            } catch (RevisionNotFoundException e) {
1298                // Normal read failures aren't considered fatal
1299
delist(contentStore);
1300                throw e;
1301            } catch (Throwable JavaDoc t) {
1302                delist(contentStore, false);
1303                // Wrap everything else in a ServiceAccessException
1304
throw new ServiceAccessException
1305                    (contentStore, t);
1306            }
1307            delist(contentStore);
1308        } else {
1309            try {
1310                revisionContent =
1311                    contentStore.retrieveRevisionContent
1312                    (uri, revisionDescriptor);
1313            } catch (ServiceAccessException e) {
1314                throw e;
1315            } catch (RevisionNotFoundException e) {
1316                throw e;
1317            } catch (Throwable JavaDoc t) {
1318                // Wrap everything else in a ServiceAccessException
1319
throw new ServiceAccessException
1320                    (contentStore, t);
1321            }
1322        }
1323        revisionContent.validate();
1324        return revisionContent;
1325    }
1326    
1327    
1328    /**
1329     * Create a new revision
1330     *
1331     * @param uri Uri
1332     * @param revisionDescriptor Node revision descriptor
1333     * @param revisionContent Node revision content
1334     */

1335    public void createRevisionContent
1336        (Uri uri, NodeRevisionDescriptor revisionDescriptor,
1337         NodeRevisionContent revisionContent)
1338        throws ServiceAccessException, RevisionAlreadyExistException
1339    {
1340        revisionDescriptor.validate();
1341        revisionContent.validate();
1342        
1343        enlist(contentIndexer);
1344        enlist(contentStore);
1345        try {
1346            contentIndexer.createIndex (uri, revisionDescriptor, revisionContent);
1347            contentStore.createRevisionContent(uri, revisionDescriptor,
1348                                               revisionContent);
1349            
1350        } catch (ServiceAccessException e) {
1351            delist(contentIndexer, false);
1352            delist(contentStore, false);
1353            throw e;
1354        } catch (RevisionAlreadyExistException e) {
1355            delist(contentIndexer);
1356            delist(contentStore);
1357            throw e;
1358        } catch (Throwable JavaDoc t) {
1359            delist(contentIndexer, false);
1360            delist(contentStore, false);
1361            // Wrap everything else in a ServiceAccessException
1362
throw new ServiceAccessException(contentStore, t);
1363        }
1364        delist(contentIndexer);
1365        delist(contentStore);
1366    }
1367    
1368    
1369    /**
1370     * Modify the latest revision of an object.
1371     *
1372     * @param uri Uri
1373     * @param revisionDescriptor Node revision descriptor
1374     * @param revisionContent Node revision content
1375     */

1376    public void storeRevisionContent
1377        (Uri uri, NodeRevisionDescriptor revisionDescriptor,
1378         NodeRevisionContent revisionContent)
1379        throws ServiceAccessException, RevisionNotFoundException {
1380        revisionDescriptor.validate();
1381        revisionContent.validate();
1382        
1383        enlist (contentIndexer);
1384        enlist(contentStore);
1385        try {
1386            contentIndexer.updateIndex (uri, revisionDescriptor, revisionContent);
1387            contentStore.storeRevisionContent(uri, revisionDescriptor,
1388                                              revisionContent);
1389        } catch (ServiceAccessException e) {
1390            delist (contentIndexer, false);
1391            delist (contentStore, false);
1392            throw e;
1393        } catch (RevisionNotFoundException e) {
1394            delist(contentIndexer);
1395            delist(contentStore);
1396            throw e;
1397        } catch (Throwable JavaDoc t) {
1398            delist(contentIndexer, false);
1399            delist(contentStore, false);
1400            
1401            // Wrap everything else in a ServiceAccessException
1402
throw new ServiceAccessException (contentStore, t);
1403        }
1404        
1405        delist(contentIndexer);
1406        delist(contentStore);
1407    }
1408    
1409    
1410    /**
1411     * Remove revision.
1412     *
1413     * @param uri Uri
1414     * @param revisionDescriptor Node revision descriptor
1415     */

1416    public void removeRevisionContent
1417        (Uri uri, NodeRevisionDescriptor revisionDescriptor)
1418        throws ServiceAccessException {
1419        revisionDescriptor.validate();
1420        
1421        enlist(contentIndexer);
1422        enlist(contentStore);
1423        
1424        try {
1425            contentIndexer.dropIndex (uri, revisionDescriptor.getRevisionNumber());
1426            contentStore.removeRevisionContent(uri, revisionDescriptor);
1427            
1428        } catch (ServiceAccessException e) {
1429            delist(contentIndexer, false);
1430            delist(contentStore, false);
1431            throw e;
1432        } catch (Throwable JavaDoc t) {
1433            delist(contentIndexer, false);
1434            delist(contentStore, false);
1435            
1436            // Wrap everything else in a ServiceAccessException
1437
throw new ServiceAccessException(contentStore, t);
1438        }
1439        
1440        delist(contentIndexer);
1441        delist(contentStore);
1442    }
1443    
1444    
1445    // ------------------------------------------------------ Protected Methods
1446

1447    
1448    /**
1449     * Return true if the store should also be enlisted for a read operation.
1450     */

1451    protected boolean isForceStoreEnlistment(Uri uri) {
1452        
1453        SlideToken token = uri.getToken();
1454        
1455        if (token == null)
1456            return false;
1457        
1458        return token.isForceStoreEnlistment();
1459        
1460    }
1461    
1462    
1463    /**
1464     * Add a new resource manager.
1465     *
1466     * @param service New resource manager
1467     */

1468    protected void addResourceManager(Service service) {
1469        if (service == null)
1470            return;
1471        // First check if the new store isn't already in the array
1472
for (int i = 0; i < resourceManagers.length; i++) {
1473            try {
1474                if (resourceManagers[i].isSameRM(service))
1475                    return;
1476            } catch (XAException JavaDoc e) {
1477            }
1478        }
1479        Service results[] = new Service[resourceManagers.length + 1];
1480        System.arraycopy(resourceManagers, 0, results, 0,
1481                         resourceManagers.length);
1482        results[resourceManagers.length] = service;
1483        resourceManagers = results;
1484    }
1485    
1486    
1487    /**
1488     * Enlist the resource manager in the current transaction.
1489     */

1490    protected void enlist()
1491        throws ServiceAccessException {
1492        enlist(this);
1493    }
1494    
1495    
1496    /**
1497     * Enlist the resource manager in the current transaction.
1498     */

1499    protected void enlist(Service service)
1500        throws ServiceAccessException {
1501        // Note: No exception is thrown
1502
boolean enlisted = false;
1503        // FIXME : Enhance retries.
1504
int nbTry = 0;
1505        while ((!enlisted) && (nbTry++ < 20)) {
1506            Transaction JavaDoc transaction = null;
1507            try {
1508                transaction =
1509                    namespace.getTransactionManager().getTransaction();
1510            } catch (Exception JavaDoc e) {
1511            }
1512            if (transaction == null) {
1513                getLogger().log("WARNING: No active transaction", Logger.WARNING);
1514                return;
1515            }
1516            try {
1517                enlisted = transaction.enlistResource(service);
1518            } catch (Exception JavaDoc e) {
1519                // Something went wrong.
1520
setRollbackOnly();
1521                throw new ServiceAccessException(this, e);
1522            }
1523            if (!enlisted) {
1524                try {
1525                    Thread.sleep(200);
1526                } catch (InterruptedException JavaDoc e) {
1527                    // Then go on.
1528
}
1529            }
1530        }
1531        if (!enlisted) {
1532            String JavaDoc exMessage = Messages.format
1533                (AbstractStore.class.getName() + ".enlistFail", service);
1534            setRollbackOnly();
1535            throw new ServiceAccessException(this, exMessage);
1536        }
1537        if (getLogger().isEnabled(LOG_CHANNEL, Logger.DEBUG)) {
1538            String JavaDoc logMessage = Messages.format
1539                (AbstractStore.class.getName() + ".enlist", service);
1540            getLogger().log(logMessage, LOG_CHANNEL, Logger.DEBUG);
1541        }
1542    }
1543    
1544    
1545    /**
1546     * Delist (suspend) the resource manager in the current transaction.
1547     */

1548    protected void delist(boolean success)
1549        throws ServiceAccessException {
1550        delist(this, success);
1551    }
1552    
1553    
1554    /**
1555     * Delist (suspend) the resource manager in the current transaction.
1556     */

1557    protected void delist(Service service)
1558        throws ServiceAccessException {
1559        delist(service, true);
1560    }
1561    
1562    
1563    /**
1564     * Delist (suspend) the resource manager in the current transaction.
1565     */

1566    protected void delist(Service service, boolean success)
1567        throws ServiceAccessException {
1568        try {
1569            Transaction JavaDoc transaction =
1570                namespace.getTransactionManager().getTransaction();
1571            if (transaction == null)
1572                return;
1573            if (success) {
1574                transaction.delistResource(service, TMSUSPEND);
1575                if (getLogger().isEnabled(LOG_CHANNEL, Logger.DEBUG)) {
1576                    String JavaDoc logMessage = Messages.format
1577                        (AbstractStore.class.getName() + ".delist", service);
1578                    getLogger().log(logMessage, LOG_CHANNEL, Logger.DEBUG);
1579                }
1580            } else {
1581                transaction.delistResource(service, TMFAIL);
1582                String JavaDoc logMessage = Messages.format
1583                    (AbstractStore.class.getName() + ".delistFail", service);
1584                getLogger().log(logMessage, LOG_CHANNEL, Logger.DEBUG);
1585            }
1586        } catch (Exception JavaDoc e) {
1587            // Something went wrong.
1588
throw new ServiceAccessException(this, e);
1589        }
1590    }
1591    
1592    
1593    /**
1594     * Mark transaction as rollback in case of enlistment failure.
1595     */

1596    protected void setRollbackOnly() {
1597        try {
1598            Transaction JavaDoc transaction =
1599                namespace.getTransactionManager().getTransaction();
1600            if (transaction == null)
1601                return;
1602            transaction.setRollbackOnly();
1603        } catch (Exception JavaDoc e) {
1604        }
1605    }
1606    
1607    /**
1608     * Always returns false. Default implementation for this method
1609     * Stores that support binding should override this method.
1610     */

1611    public boolean useBinding() {
1612        return false;
1613    }
1614    
1615    public void exclusiveTransientLock(String JavaDoc uri) throws ServiceAccessException {
1616    }
1617
1618}
1619
Popular Tags