001: /*
002: * This file is part of the QuickServer library
003: * Copyright (C) 2003-2005 QuickServer.org
004: *
005: * Use, modification, copying and distribution of this software is subject to
006: * the terms and conditions of the GNU Lesser General Public License.
007: * You should have received a copy of the GNU LGP License along with this
008: * library; if not, you can download a copy from <http://www.quickserver.org/>.
009: *
010: * For questions, suggestions, bug-reports, enhancement-requests etc.
011: * visit http://www.quickserver.org
012: *
013: */
014:
015: package org.quickserver.util.xmlreader;
016:
017: import org.quickserver.net.server.DataMode;
018: import org.quickserver.net.server.DataType;
019:
020: /**
021: * This class encapsulate default DataMode for ClientHandler.
022: * The xml is <default-data-mode>...</default-data-mode>
023: * @author Akshathkumar Shetty
024: * @since 1.4.6
025: */
026: public class DefaultDataMode implements java.io.Serializable {
027: private DataMode defaultDataModeIN;
028: private DataMode defaultDataModeOUT;
029:
030: public DefaultDataMode() {
031: defaultDataModeIN = DataMode.STRING;
032: defaultDataModeOUT = DataMode.STRING;
033: }
034:
035: /**
036: * Sets DataMode for DataType.IN
037: * Valid values are <code>STRING|BYTE|OBJECT|BINARY</code>
038: */
039: public void setDataModeIn(String dataMode) {
040: if (dataMode.toUpperCase().equals("STRING"))
041: defaultDataModeIN = DataMode.STRING;
042: else if (dataMode.toUpperCase().equals("BYTE"))
043: defaultDataModeIN = DataMode.BYTE;
044: else if (dataMode.toUpperCase().equals("OBJECT"))
045: defaultDataModeIN = DataMode.OBJECT;
046: else if (dataMode.toUpperCase().equals("BINARY"))
047: defaultDataModeIN = DataMode.BINARY;
048: }
049:
050: public String getDataModeIn() {
051: return defaultDataModeIN.toString();
052: }
053:
054: /**
055: * Sets DataMode for DataType.OUT
056: * Valid values are <code>STRING|BYTE|OBJECT|BINARY</code>
057: */
058: public void setDataModeOut(String dataMode) {
059: if (dataMode.toUpperCase().equals("STRING"))
060: defaultDataModeOUT = DataMode.STRING;
061: else if (dataMode.toUpperCase().equals("BYTE"))
062: defaultDataModeOUT = DataMode.BYTE;
063: else if (dataMode.toUpperCase().equals("OBJECT"))
064: defaultDataModeOUT = DataMode.OBJECT;
065: else if (dataMode.toUpperCase().equals("BINARY"))
066: defaultDataModeOUT = DataMode.BINARY;
067: }
068:
069: public String getDataModeOut() {
070: return defaultDataModeOUT.toString();
071: }
072:
073: /**
074: * Sets the default {@link DataMode} for the ClientHandler
075: */
076: public void setDataMode(DataMode dataMode, DataType dataType) {
077: if (dataType == DataType.IN)
078: this .defaultDataModeIN = dataMode;
079: if (dataType == DataType.OUT)
080: this .defaultDataModeOUT = dataMode;
081: }
082:
083: /**
084: * Returns the default {@link DataMode} for the ClientHandler
085: */
086: public DataMode getDataMode(DataType dataType) {
087: if (dataType == DataType.IN)
088: return defaultDataModeIN;
089: if (dataType == DataType.OUT)
090: return defaultDataModeOUT;
091: else
092: throw new IllegalArgumentException("Unknown DataType: "
093: + dataType);
094: }
095:
096: /**
097: * Returns XML config of this class.
098: */
099: public String toXML(String pad) {
100: if (pad == null)
101: pad = "";
102: StringBuffer sb = new StringBuffer();
103: sb.append(pad + "<default-data-mode>\n");
104: sb.append(pad + "\t<data-type-in>" + getDataModeIn()
105: + "</data-type-in>\n");
106: sb.append(pad + "\t<data-type-out>" + getDataModeOut()
107: + "</data-type-out>\n");
108: sb.append(pad + "</default-data-mode>\n");
109: return sb.toString();
110: }
111: }
|