KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > common > OperationProgress


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.common;
25
26 //JDK imports
27
import java.io.Serializable JavaDoc;
28
29 /**
30     A class that denotes the Progress of an operation carried out earlier.
31 */

32
33 public class OperationProgress implements Serializable JavaDoc
34 {
35     /* javac 1.3 generated serialVersionUID */
36     public static final long serialVersionUID = -5562129808433683519L;
37     
38     private boolean mIsFinished = false;
39     private String JavaDoc mMessage = null;
40     private int mPercentage = 0;
41     
42     public OperationProgress()
43     {
44         mIsFinished = false;
45         mPercentage = 0;
46         mMessage = "STARTED"; //i18n ?
47
}
48     /**
49         Creates new OperationProgress
50     */

51     public OperationProgress (int percentage, String JavaDoc message)
52     {
53         if (percentage < 0 || percentage > 100)
54         {
55             throw new IllegalArgumentException JavaDoc();
56         }
57         if (percentage == 100)
58         {
59             mIsFinished = true;
60         }
61         mPercentage = percentage;
62         mMessage = message;
63     }
64     
65     /**
66         Returns the percentage indicating amount of work done.
67      
68         @return int x such that 0 <= x <= 100.
69     */

70     
71     public int getPercentage()
72     {
73         return ( mPercentage );
74     }
75     
76     /**
77         Returns a boolean indicating whether the work is finished.
78     */

79     
80     public boolean isFinished()
81     {
82         return ( mIsFinished );
83     }
84     
85     /*
86         Returns a String representing the message associated with this
87         stage of the entire work.
88      
89         @return String indicating phase of work.
90     */

91     public String JavaDoc getMessage()
92     {
93         return ( mMessage );
94     }
95     
96     /**
97         Sets the percentage to given value. The value may not be greater than
98         100 or less than 0. If the value is 100, the internal state of this
99         Object will be set to finished.
100         
101         @param percentage integer representing the percentage of work done.
102     */

103     
104     public void setPercentage(int percentage)
105     {
106         if (percentage < 0 || percentage > 100)
107         {
108             throw new IllegalArgumentException JavaDoc();
109         }
110         mPercentage = percentage;
111         if (percentage == 100)
112         {
113             mIsFinished = true;
114         }
115     }
116     
117     /**
118         Sets the state to finished or unfinished. If the parameter is true,
119         the internal state of the Object will be modified to show the percentage
120         as 100.
121         @param boolean representing whether work is done.
122     */

123     public void setIsFinished(boolean finished)
124     {
125         mIsFinished = finished;
126         if (finished)
127         {
128             setPercentage(100);
129         }
130     }
131 }
Popular Tags