KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > util > xmlreader > IpFilterConfig


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package org.quickserver.util.xmlreader;
16
17 import java.util.*;
18 /**
19  * This class encapsulate the IP based Filter config.
20  * The xml is &lt;ip-filter&gt;...&lt;/ip-filter&gt;<br>
21  * <b>Note:</b> Make sure that access from 127.0.0.1 is allowed at
22  * all times, else some of the QsAdmin command will fail.
23  * @author Akshathkumar Shetty
24  * @since 1.3.3
25  */

26 public class IpFilterConfig implements java.io.Serializable JavaDoc {
27     private ArrayList ipCollection=null;
28     private boolean enable = false;
29     private boolean allowAccess = false;
30
31     public IpFilterConfig() {
32         ipCollection = new ArrayList();
33     }
34
35     /**
36      * Adds a Client Ip Address to the list
37      */

38     public void addClientIpAddress(String JavaDoc clientIpAddress) {
39         if(clientIpAddress!=null) {
40             ipCollection.add(clientIpAddress);
41         }
42     }
43
44     /**
45      * Returns ClientIpAddress collection
46      */

47     public ArrayList getIpCollection() {
48         return ipCollection;
49     }
50
51     public Iterator iterator() {
52         return ipCollection.iterator();
53     }
54     
55     /**
56      * Sets the IP filter enable flag.
57      * XML Tag: &lt;ip-filter&gt;&lt;enable&gt;true&lt;/enable&gt;&lt;/ip-filter&gt;
58      * Allowed values = <code>true</code> | <code>false</code>
59      * @see #getEnable
60      */

61     public void setEnable(boolean enable) {
62         this.enable = enable;
63     }
64     /**
65      * Returns the IP filter enable flag.
66      * @see #setEnable
67      */

68     public boolean getEnable() {
69         return enable;
70     }
71
72     /**
73      * Sets the allow access flag.
74      * XML Tag: &lt;ip-filter&gt;&lt;allow-access&gt;true&lt;/allow-access&gt;&lt;/ip-filter&gt;
75      * Allowed values = <code>true</code> | <code>false</code>
76      * @see #getAllowAccess
77      */

78     public void setAllowAccess(boolean enable) {
79         this.allowAccess = enable;
80     }
81     /**
82      * Returns the allow access flag.
83      * @see #setAllowAccess
84      */

85     public boolean getAllowAccess() {
86         return allowAccess;
87     }
88
89     /**
90      * Returns XML config of this class.
91      * @since 1.3
92      */

93     public String JavaDoc toXML(String JavaDoc pad) {
94         if(pad==null) pad="";
95         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
96         sb.append(pad+"<ip-filter>\n");
97         sb.append(pad+"\t<enable>"+getEnable()+"</enable>\n");
98         sb.append(pad+"\t<allow-access>"+getAllowAccess()+"</allow-access>\n");
99         sb.append(pad+"\t<ip-collection>\n");
100         Iterator iterator = iterator();
101         while(iterator.hasNext()) {
102             String JavaDoc cip = (String JavaDoc)iterator.next();
103             sb.append(pad+"\t\t<client-ip-address>"+cip+"</client-ip-address>\n");
104         }
105         sb.append(pad+"\t</ip-collection>\n");
106         sb.append(pad+"</ip-filter>\n");
107         return sb.toString();
108     }
109 }
110
Popular Tags