KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > mail > Quota


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)Quota.java 1.6 05/08/29
24  *
25  * Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package javax.mail;
29
30 import java.util.Vector JavaDoc;
31
32 /**
33  * This class represents a set of quotas for a given quota root.
34  * Each quota root has a set of resources, represented by the
35  * <code>Quota.Resource</code> class. Each resource has a name
36  * (for example, "STORAGE"), a current usage, and a usage limit.
37  * See RFC 2087.
38  *
39  * @since JavaMail 1.4
40  * @version 1.6, 05/08/29
41  * @author Bill Shannon
42  */

43
44 public class Quota {
45
46     /**
47      * An individual resource in a quota root.
48      *
49      * @since JavaMail 1.4
50      */

51     public static class Resource {
52     /** The name of the resource. */
53     public String JavaDoc name;
54     /** The current usage of the resource. */
55     public long usage;
56     /** The usage limit for the resource. */
57     public long limit;
58
59     /**
60      * Construct a Resource object with the given name,
61      * usage, and limit.
62      *
63      * @param name the resource name
64      * @param usage the current usage of the resource
65      * @param limit the usage limit for the resource
66      */

67     public Resource(String JavaDoc name, long usage, long limit) {
68         this.name = name;
69         this.usage = usage;
70         this.limit = limit;
71     }
72     }
73
74     /**
75      * The name of the quota root.
76      */

77     public String JavaDoc quotaRoot;
78
79     /**
80      * The set of resources associated with this quota root.
81      */

82     public Quota.Resource JavaDoc[] resources;
83
84     /**
85      * Create a Quota object for the named quotaroot with no associated
86      * resources.
87      *
88      * @param quotaRoot the name of the quota root
89      */

90     public Quota(String JavaDoc quotaRoot) {
91     this.quotaRoot = quotaRoot;
92     }
93
94     /**
95      * Set a resource limit for this quota root.
96      *
97      * @param name the name of the resource
98      * @param limit the resource limit
99      */

100     public void setResourceLimit(String JavaDoc name, long limit) {
101     if (resources == null) {
102         resources = new Quota.Resource JavaDoc[1];
103         resources[0] = new Quota.Resource JavaDoc(name, 0, limit);
104         return;
105     }
106     for (int i = 0; i < resources.length; i++) {
107         if (resources[i].name.equalsIgnoreCase(name)) {
108         resources[i].limit = limit;
109         return;
110         }
111     }
112     Quota.Resource JavaDoc[] ra = new Quota.Resource JavaDoc[resources.length + 1];
113     System.arraycopy(resources, 0, ra, 0, resources.length);
114     ra[ra.length - 1] = new Quota.Resource JavaDoc(name, 0, limit);
115     resources = ra;
116     }
117 }
118
Popular Tags