KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.quickserver.net.server.DataMode;
18 import org.quickserver.net.server.DataType;
19
20 /**
21  * This class encapsulate default DataMode for ClientHandler.
22  * The xml is &lt;default-data-mode&gt;...&lt;/default-data-mode&gt;
23  * @author Akshathkumar Shetty
24  * @since 1.4.6
25  */

26 public class DefaultDataMode implements java.io.Serializable JavaDoc {
27     private DataMode defaultDataModeIN;
28     private DataMode defaultDataModeOUT;
29
30     public DefaultDataMode() {
31         defaultDataModeIN = DataMode.STRING;
32         defaultDataModeOUT = DataMode.STRING;
33     }
34
35     /**
36      * Sets DataMode for DataType.IN
37      * Valid values are <code>STRING|BYTE|OBJECT|BINARY</code>
38      */

39     public void setDataModeIn(String JavaDoc dataMode) {
40         if(dataMode.toUpperCase().equals("STRING"))
41             defaultDataModeIN = DataMode.STRING;
42         else if(dataMode.toUpperCase().equals("BYTE"))
43             defaultDataModeIN = DataMode.BYTE;
44         else if(dataMode.toUpperCase().equals("OBJECT"))
45             defaultDataModeIN = DataMode.OBJECT;
46         else if(dataMode.toUpperCase().equals("BINARY"))
47             defaultDataModeIN = DataMode.BINARY;
48     }
49
50     public String JavaDoc getDataModeIn() {
51         return defaultDataModeIN.toString();
52     }
53
54     /**
55      * Sets DataMode for DataType.OUT
56      * Valid values are <code>STRING|BYTE|OBJECT|BINARY</code>
57      */

58     public void setDataModeOut(String JavaDoc dataMode) {
59         if(dataMode.toUpperCase().equals("STRING"))
60             defaultDataModeOUT = DataMode.STRING;
61         else if(dataMode.toUpperCase().equals("BYTE"))
62             defaultDataModeOUT = DataMode.BYTE;
63         else if(dataMode.toUpperCase().equals("OBJECT"))
64             defaultDataModeOUT = DataMode.OBJECT;
65         else if(dataMode.toUpperCase().equals("BINARY"))
66             defaultDataModeOUT = DataMode.BINARY;
67     }
68
69     public String JavaDoc getDataModeOut() {
70         return defaultDataModeOUT.toString();
71     }
72
73
74     /**
75      * Sets the default {@link DataMode} for the ClientHandler
76      */

77     public void setDataMode(DataMode dataMode, DataType dataType) {
78         if(dataType==DataType.IN)
79             this.defaultDataModeIN = dataMode;
80         if(dataType==DataType.OUT)
81             this.defaultDataModeOUT = dataMode;
82     }
83     /**
84      * Returns the default {@link DataMode} for the ClientHandler
85      */

86     public DataMode getDataMode(DataType dataType) {
87         if(dataType==DataType.IN)
88             return defaultDataModeIN;
89         if(dataType==DataType.OUT)
90             return defaultDataModeOUT;
91         else
92             throw new IllegalArgumentException JavaDoc("Unknown DataType: "+dataType);
93     }
94     
95     /**
96      * Returns XML config of this class.
97      */

98     public String JavaDoc toXML(String JavaDoc pad) {
99         if(pad==null) pad="";
100         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
101         sb.append(pad+"<default-data-mode>\n");
102         sb.append(pad+"\t<data-type-in>"+getDataModeIn()+"</data-type-in>\n");
103         sb.append(pad+"\t<data-type-out>"+getDataModeOut()+"</data-type-out>\n");
104         sb.append(pad+"</default-data-mode>\n");
105         return sb.toString();
106     }
107 }
Popular Tags