KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > security > license > ListLimitValue


1 /*
2  * Created on Sep 14, 2003
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package org.jahia.security.license;
8
9 import java.util.ArrayList JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import org.jahia.resourcebundle.ResourceMessage;
12
13 /**
14  * List of values limit
15  * @author loom
16  *
17  * To change the template for this generated type comment go to
18  * Window>Preferences>Java>Code Generation>Code and Comments
19  */

20 public class ListLimitValue extends LimitValue {
21
22     private static final String JavaDoc LIST_SEPERATOR = ";";
23
24     private ArrayList JavaDoc limitValues = new ArrayList JavaDoc();
25     private boolean lastCheckResult = false;
26
27     public ListLimitValue(String JavaDoc value) {
28         super(value);
29         int listSepPos = value.indexOf(LIST_SEPERATOR);
30         int curStrPos = 0;
31         while (listSepPos != -1) {
32             String JavaDoc curLimitStr = value.substring(curStrPos, listSepPos);
33             LimitValue subLimit = null;
34             if (RangeLimitValue.isRangeValue(curLimitStr)) {
35                 subLimit = new RangeLimitValue(curLimitStr);
36             } else {
37                 subLimit = new LimitValue(curLimitStr);
38             }
39             limitValues.add(subLimit);
40             curStrPos = listSepPos + LIST_SEPERATOR.length();
41             listSepPos = value.indexOf(LIST_SEPERATOR, curStrPos);
42         }
43         // we must still process the values until the end of the string.
44
String JavaDoc curLimitStr = value.substring(curStrPos);
45         LimitValue subLimit = null;
46         if (RangeLimitValue.isRangeValue(curLimitStr)) {
47             subLimit = new RangeLimitValue(curLimitStr);
48         } else {
49             subLimit = new LimitValue(curLimitStr);
50         }
51         limitValues.add(subLimit);
52     }
53
54     public static boolean isListValue(String JavaDoc value) {
55         return (value.indexOf(LIST_SEPERATOR) != -1);
56     }
57
58     /**
59      * @return
60      */

61     public ArrayList JavaDoc getLimitValues() {
62         return limitValues;
63     }
64
65     public boolean check(Validator validator) {
66         Iterator JavaDoc valueIter = limitValues.iterator();
67         while (valueIter.hasNext()) {
68             LimitValue curLimitValue = (LimitValue) valueIter.next();
69             if (curLimitValue.check(validator)) {
70                 lastCheckResult = true;
71                 return true;
72             }
73         }
74         lastCheckResult = false;
75         return false;
76     }
77
78     public ResourceMessage getErrorMessage(Validator validator) {
79         if (lastCheckResult == true) {
80             return null;
81         }
82         Iterator JavaDoc valueIter = limitValues.iterator();
83         while (valueIter.hasNext()) {
84             LimitValue curLimitValue = (LimitValue) valueIter.next();
85             ResourceMessage curResourceMessage = curLimitValue.getErrorMessage(validator);
86             if (curResourceMessage != null) {
87                 return curResourceMessage;
88             }
89         }
90         return null;
91     }
92
93 }
94
Popular Tags