KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > backup > phase > PhasesBase


1 /*
2  * PhasesBase.java
3  *
4  * Created on December 24, 2003, 10:09 AM
5  */

6
7 package com.sun.enterprise.config.backup.phase;
8
9 import com.sun.enterprise.config.backup.status.Status;
10 import com.sun.enterprise.config.backup.status.StatusConstants;
11 import com.sun.enterprise.config.backup.utils.LocalStringsHelper;
12 import com.sun.enterprise.config.backup.StatusRegistry;
13 import com.sun.enterprise.config.backup.ActiveAssistanceManager;
14 import com.sun.enterprise.config.backup.utils.BackupHelper;
15 import com.sun.enterprise.config.backup.BackupAbortException;
16 import com.sun.enterprise.config.backup.utils.FactoryHelper;
17 /**
18  *
19  * @author sridatta
20  */

21 public class PhasesBase {
22     
23     /** Creates a new instance of PhasesBase */
24     public PhasesBase() {
25     }
26     
27     public void setStatusInRegistry(Status s) {
28         StatusRegistry.setStatus(s);
29     }
30     
31     protected Status getStatusFromRegistry() {
32         return StatusRegistry.getStatus();
33     }
34     
35     public void lock() {
36         FactoryHelper.getSynchronizer().lock();
37     }
38     
39     public void unlock() {
40         FactoryHelper.getSynchronizer().release();
41     }
42     
43     public void setSuccess() {
44         Status status = getStatusFromRegistry();
45         if(StatusConstants.STATUS_FAILURE.equals(status)) {
46             throw new BackupAbortException(
47                 "status_failure",
48                 LocalStringsHelper.getString("status_failure"));
49         }
50         
51         try {
52            status.setStatusCode(StatusConstants.STATUS_SUCCESS);
53         } catch(Exception JavaDoc e) {
54             //ignore.
55
}
56     }
57     
58     public void setFailure(Exception JavaDoc e) {
59         BackupHelper.setExceptionInStatus(getStatusFromRegistry(), e);
60     }
61     
62     public void addHistory() {
63         BackupHelper.addHistoryEntrySafe(getStatusFromRegistry());
64     }
65     
66     public void addAssistance() {
67         new ActiveAssistanceManager().assist(getStatusFromRegistry());
68     }
69     
70     public void assertStatusNotFailed() {
71         if(StatusConstants.STATUS_FAILURE.equals(getStatusFromRegistry().getStatusCode())) {
72             //already failed before. abort
73
throw new BackupAbortException(
74                 "error_status_failed",
75                 LocalStringsHelper.getString("error_status_failed"));
76         }
77     }
78
79 }
80
Popular Tags