001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.component.mina;
018
019 import java.nio.charset.Charset;
020 import java.util.List;
021
022 import org.apache.camel.LoggingLevel;
023 import org.apache.camel.RuntimeCamelException;
024 import org.apache.mina.common.IoFilter;
025 import org.apache.mina.filter.codec.ProtocolCodecFactory;
026
027 /**
028 * Mina configuration
029 */
030 public class MinaConfiguration implements Cloneable {
031 private String protocol;
032 private String host;
033 private int port;
034 private boolean sync = true;
035 private boolean textline;
036 private TextLineDelimiter textlineDelimiter;
037 private ProtocolCodecFactory codec;
038 private String encoding;
039 private long timeout = 30000;
040 private boolean lazySessionCreation = true;
041 private boolean transferExchange;
042 private boolean minaLogger;
043 private int encoderMaxLineLength = -1;
044 private int decoderMaxLineLength = -1;
045 private List<IoFilter> filters;
046 private boolean allowDefaultCodec = true;
047 private boolean disconnect;
048 private boolean disconnectOnNoReply = true;
049 private LoggingLevel noReplyLogLevel = LoggingLevel.WARN;
050
051 /**
052 * Returns a copy of this configuration
053 */
054 public MinaConfiguration copy() {
055 try {
056 return (MinaConfiguration) clone();
057 } catch (CloneNotSupportedException e) {
058 throw new RuntimeCamelException(e);
059 }
060 }
061
062 public String getCharsetName() {
063 if (encoding == null) {
064 return null;
065 }
066 if (!Charset.isSupported(encoding)) {
067 throw new IllegalArgumentException("The encoding: " + encoding + " is not supported");
068 }
069
070 return Charset.forName(encoding).name();
071 }
072
073 public String getProtocol() {
074 return protocol;
075 }
076
077 public void setProtocol(String protocol) {
078 this.protocol = protocol;
079 }
080
081 public String getHost() {
082 return host;
083 }
084
085 public void setHost(String host) {
086 this.host = host;
087 }
088
089 public int getPort() {
090 return port;
091 }
092
093 public void setPort(int port) {
094 this.port = port;
095 }
096
097 public boolean isSync() {
098 return sync;
099 }
100
101 public void setSync(boolean sync) {
102 this.sync = sync;
103 }
104
105 public boolean isTextline() {
106 return textline;
107 }
108
109 public void setTextline(boolean textline) {
110 this.textline = textline;
111 }
112
113 public TextLineDelimiter getTextlineDelimiter() {
114 return textlineDelimiter;
115 }
116
117 public void setTextlineDelimiter(TextLineDelimiter textlineDelimiter) {
118 this.textlineDelimiter = textlineDelimiter;
119 }
120
121 public ProtocolCodecFactory getCodec() {
122 return codec;
123 }
124
125 public void setCodec(ProtocolCodecFactory codec) {
126 this.codec = codec;
127 }
128
129 public String getEncoding() {
130 return encoding;
131 }
132
133 public void setEncoding(String encoding) {
134 this.encoding = encoding;
135 }
136
137 public long getTimeout() {
138 return timeout;
139 }
140
141 public void setTimeout(long timeout) {
142 this.timeout = timeout;
143 }
144
145 public boolean isLazySessionCreation() {
146 return lazySessionCreation;
147 }
148
149 public void setLazySessionCreation(boolean lazySessionCreation) {
150 this.lazySessionCreation = lazySessionCreation;
151 }
152
153 public boolean isTransferExchange() {
154 return transferExchange;
155 }
156
157 public void setTransferExchange(boolean transferExchange) {
158 this.transferExchange = transferExchange;
159 }
160
161 public void setEncoderMaxLineLength(int encoderMaxLineLength) {
162 this.encoderMaxLineLength = encoderMaxLineLength;
163 }
164
165 public int getEncoderMaxLineLength() {
166 return encoderMaxLineLength;
167 }
168
169 public void setDecoderMaxLineLength(int decoderMaxLineLength) {
170 this.decoderMaxLineLength = decoderMaxLineLength;
171 }
172
173 public int getDecoderMaxLineLength() {
174 return decoderMaxLineLength;
175 }
176
177 public boolean isMinaLogger() {
178 return minaLogger;
179 }
180
181 public void setMinaLogger(boolean minaLogger) {
182 this.minaLogger = minaLogger;
183 }
184
185 public List<IoFilter> getFilters() {
186 return filters;
187 }
188
189 public void setFilters(List<IoFilter> filters) {
190 this.filters = filters;
191 }
192
193 public boolean isDatagramProtocol() {
194 return protocol.equals("udp");
195 }
196
197 public void setAllowDefaultCodec(boolean allowDefaultCodec) {
198 this.allowDefaultCodec = allowDefaultCodec;
199 }
200
201 public boolean isAllowDefaultCodec() {
202 return allowDefaultCodec;
203 }
204
205 public boolean isDisconnect() {
206 return disconnect;
207 }
208
209 public void setDisconnect(boolean disconnect) {
210 this.disconnect = disconnect;
211 }
212
213 public boolean isDisconnectOnNoReply() {
214 return disconnectOnNoReply;
215 }
216
217 public void setDisconnectOnNoReply(boolean disconnectOnNoReply) {
218 this.disconnectOnNoReply = disconnectOnNoReply;
219 }
220
221 public LoggingLevel getNoReplyLogLevel() {
222 return noReplyLogLevel;
223 }
224
225 public void setNoReplyLogLevel(LoggingLevel noReplyLogLevel) {
226 this.noReplyLogLevel = noReplyLogLevel;
227 }
228 }