KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > backup > status > Status


1 /*
2  * Status.java
3  *
4  * Created on December 13, 2000, 6:21 AM
5  */

6
7 package com.sun.enterprise.config.backup.status;
8
9 import java.io.Serializable JavaDoc;
10 import java.util.Date JavaDoc;
11 import com.sun.enterprise.config.backup.BackupException;
12 import com.sun.enterprise.config.backup.utils.FactoryHelper;
13
14 /**
15  * This class is the parent class for BackupStatus
16  * and Restore Status. It is used to store
17  * detailed information about the status of
18  * an operation.
19  *
20  * Implements StatusConstants and Serializable
21  *
22  * @author sridatta
23  */

24 public abstract class Status implements StatusConstants, Serializable JavaDoc {
25     
26     private StatusCode _statusCode = new StatusCode();
27     private Exception JavaDoc _exception;
28     private ExecutionType _executionType = new ExecutionType();
29     private long _creationTimeStamp = System.currentTimeMillis();
30     /** can be a directory or zip */
31     private String JavaDoc _backupStorageType;
32
33     private String JavaDoc _extraInfo;
34     
35     /** Creates a new instance of Status */
36     public Status() {
37     }
38     
39     public Status(boolean initialize) throws BackupException {
40         if(initialize) {
41             init();
42         }
43     }
44     
45             /**
46      * Determine the next number to be created
47      * Managed the max numbers.
48      * Delete the oldest one if required
49      * get the prefix
50      * add timestamp
51      * create fileName = dir/prefix + timestamp+ number
52      *
53      * Update BackupNumber, TargetFile in BackupStatus
54      * update source files, etc
55      */

56     private void init() throws BackupException {
57         setExecutionType(FactoryHelper.getEnv().getExecutionType());
58         setBackupStorageType(FactoryHelper.getEnv().getBackupStorageType());
59     }
60     
61     public long getCreationTimeStamp() {
62         return _creationTimeStamp;
63     }
64     
65     
66     public String JavaDoc getBackupStorageType() {
67         return _backupStorageType;
68     }
69     
70     public void setBackupStorageType(String JavaDoc type) {
71         _backupStorageType = type;
72     }
73     public String JavaDoc getStatusCode() {
74         return _statusCode.getStatusCode();
75     }
76     
77     public Exception JavaDoc getException() {
78         return _exception;
79     }
80     
81     public String JavaDoc getExecutionType() {
82         return _executionType.getExecutionType();
83     }
84     
85    public void setStatusCode(String JavaDoc status) throws BackupException {
86         _statusCode.setStatus(status);
87    }
88    
89    public void setExecutionType(String JavaDoc executionType) throws BackupException {
90        _executionType.setExecutionType(executionType);
91    }
92    
93    public void setException(Exception JavaDoc e) throws BackupException {
94        _exception = e;
95        _statusCode.setStatus(STATUS_FAILURE);
96    }
97  
98    private String JavaDoc baseToString() {
99        
100        String JavaDoc exceptionMessages = (_exception == null)?"":
101            ", ExceptionType= " + _exception.getClass().getName() +
102            ", ExceptionMessage= " + _exception.getMessage();
103            
104        String JavaDoc creationTime = ", Created Time= " + getCreationDate();
105        String JavaDoc result =
106             getOperation() + ":Status= " + _statusCode +
107             ", ExecutionType= " + _executionType +
108             ", Backup File Type " + _backupStorageType +
109
110             exceptionMessages + creationTime;
111
112        return result;
113    }
114    
115    public String JavaDoc toString() {
116       String JavaDoc result = " {" +
117         baseToString() + ", " +
118         thisToString() +
119         "}";
120       return result;
121     }
122    
123    private String JavaDoc getCreationDate() {
124       return new Date JavaDoc(_creationTimeStamp).toString();
125    }
126    
127    public boolean isSuccess() {
128        return STATUS_SUCCESS.equals(_statusCode.getStatusCode());
129    }
130    
131    public String JavaDoc getExtraInfo() {
132        return _extraInfo;
133    }
134    
135    public void setExtraInfo(String JavaDoc s) {
136        _extraInfo = s;
137    }
138    
139    public abstract String JavaDoc getOperation();
140    protected abstract String JavaDoc thisToString();
141 }
142
Popular Tags