Author: norman
Date: Fri Jan 29 09:13:33 2010
New Revision: 904428
URL: http://svn.apache.org/viewvc?rev=904428&view=rev
Log:
Share more code
Added:
james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/BaseRequest.java
Modified:
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Request.java
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/core/POP3CommandDispatcherLineHandler.java
james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerRequest.java
james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoteManagerCommandDispatcherLineHandler.java
james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/SMTPRequest.java
james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SMTPCommandDispatcherLineHandler.java
james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/AbstractCommandDispatcher.java
Modified:
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Request.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Request.java?rev=904428&r1=904427&r2=904428&view=diff
==============================================================================
---
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Request.java
(original)
+++
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Request.java
Fri Jan 29 09:13:33 2010
@@ -19,47 +19,17 @@
package org.apache.james.pop3server;
-import org.apache.james.api.protocol.Request;
+import org.apache.james.api.protocol.BaseRequest;
/**
* POP3Request object
*
*/
-public class POP3Request implements Request{
+public class POP3Request extends BaseRequest{
- private final String command;
-
- private final String argument;
-
-
- /**
- * Return the current POP3 argument. If there is no argument null is
returned
- *
- * @return argument
- */
- public String getArgument() {
- return argument;
- }
-
- /**
- * Return the current POP3 command
- *
- * @return command
- */
- public String getCommand() {
- return command;
- }
+
public POP3Request(final String command, final String argument) {
- this.command = command;
- this.argument = argument;
- }
-
- public String toString() {
- if (argument == null) {
- return command;
- } else {
- return command + " " + argument;
- }
+ super(command,argument);
}
}
Modified:
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/core/POP3CommandDispatcherLineHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/core/POP3CommandDispatcherLineHandler.java?rev=904428&r1=904427&r2=904428&view=diff
==============================================================================
---
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/core/POP3CommandDispatcherLineHandler.java
(original)
+++
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/core/POP3CommandDispatcherLineHandler.java
Fri Jan 29 09:13:33 2010
@@ -24,9 +24,6 @@
import org.apache.james.api.protocol.AbstractCommandDispatcher;
import org.apache.james.api.protocol.CommandHandler;
-import org.apache.james.api.protocol.Response;
-import org.apache.james.pop3server.POP3Request;
-import org.apache.james.pop3server.POP3Response;
import org.apache.james.pop3server.POP3Session;
/**
@@ -62,28 +59,4 @@
return UnknownCmdHandler.COMMAND_NAME;
}
- @Override
- protected void dispatchCommand(POP3Session session, String command, String
argument) {
- // fetch the command handlers registered to the command
- List<CommandHandler<POP3Session>> commandHandlers =
getCommandHandlers(command, session);
- if (commandHandlers == null) {
- // end the session
- POP3Response resp = new POP3Response(POP3Response.ERR_RESPONSE,
"Local configuration error: unable to find a command handler.");
- resp.setEndSession(true);
- session.writeResponse(resp);
- } else {
- int count = commandHandlers.size();
- for (int i = 0; i < count; i++) {
- Response response = commandHandlers.get(i).onCommand(session,
new POP3Request(command, argument));
- if (response != null) {
- session.writeResponse(response);
- break;
- }
- }
-
- }
-
- }
-
-
}
Modified:
james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerRequest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerRequest.java?rev=904428&r1=904427&r2=904428&view=diff
==============================================================================
---
james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerRequest.java
(original)
+++
james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerRequest.java
Fri Jan 29 09:13:33 2010
@@ -19,44 +19,11 @@
package org.apache.james.remotemanager;
-import org.apache.james.api.protocol.Request;
+import org.apache.james.api.protocol.BaseRequest;
-public class RemoteManagerRequest implements Request{
-
-
- private final String command;
-
- private final String argument;
-
-
- /**
- * Return the current RemoteManager argument. If there is no argument null
is returned
- *
- * @return argument
- */
- public String getArgument() {
- return argument;
- }
-
- /**
- * Return the current POP3 command
- *
- * @return command
- */
- public String getCommand() {
- return command;
- }
+public class RemoteManagerRequest extends BaseRequest{
public RemoteManagerRequest(final String command, final String argument) {
- this.command = command;
- this.argument = argument;
- }
-
- public String toString() {
- if (argument == null) {
- return command;
- } else {
- return command + " " + argument;
- }
+ super(command, argument);
}
}
Modified:
james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoteManagerCommandDispatcherLineHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoteManagerCommandDispatcherLineHandler.java?rev=904428&r1=904427&r2=904428&view=diff
==============================================================================
---
james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoteManagerCommandDispatcherLineHandler.java
(original)
+++
james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/RemoteManagerCommandDispatcherLineHandler.java
Fri Jan 29 09:13:33 2010
@@ -24,10 +24,7 @@
import java.util.List;
import org.apache.james.api.protocol.AbstractCommandDispatcher;
-import org.apache.james.api.protocol.Response;
import org.apache.james.remotemanager.CommandHandler;
-import org.apache.james.remotemanager.RemoteManagerRequest;
-import org.apache.james.remotemanager.RemoteManagerResponse;
import org.apache.james.remotemanager.RemoteManagerSession;
/**
@@ -64,28 +61,6 @@
}
@Override
- protected void dispatchCommand(RemoteManagerSession session, String
command, String argument) {
- // fetch the command handlers registered to the command
-
List<org.apache.james.api.protocol.CommandHandler<RemoteManagerSession>>
commandHandlers = getCommandHandlers(command, session);
- if (commandHandlers == null) {
- // end the session
- RemoteManagerResponse resp = new RemoteManagerResponse("Local
configuration error: unable to find a command handler.");
- resp.setEndSession(true);
- session.writeResponse(resp);
- } else {
- int count = commandHandlers.size();
- for (int i = 0; i < count; i++) {
- Response response = commandHandlers.get(i).onCommand(session,
new RemoteManagerRequest(command, argument));
- if (response != null) {
- session.writeResponse(response);
- break;
- }
- }
-
- }
- }
-
- @Override
protected Charset getLineDecodingCharset() {
return Charset.forName("ISO-8859-1");
}
Modified:
james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/SMTPRequest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/SMTPRequest.java?rev=904428&r1=904427&r2=904428&view=diff
==============================================================================
---
james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/SMTPRequest.java
(original)
+++
james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/SMTPRequest.java
Fri Jan 29 09:13:33 2010
@@ -19,43 +19,12 @@
package org.apache.james.smtpserver.protocol;
-import org.apache.james.api.protocol.Request;
+import org.apache.james.api.protocol.BaseRequest;
-public final class SMTPRequest implements Request{
- private final String command;
-
- private final String argument;
-
-
- /**
- * Return the current SMTP argument. If there is no argument null is
returned
- *
- * @return argument
- */
- public String getArgument() {
- return argument;
- }
-
- /**
- * Return the current SMTP command
- *
- * @return command
- */
- public String getCommand() {
- return command;
- }
+public final class SMTPRequest extends BaseRequest {
public SMTPRequest(final String command, final String argument) {
- this.command = command;
- this.argument = argument;
- }
-
- public String toString() {
- if (argument == null) {
- return command;
- } else {
- return command + " " + argument;
- }
+ super(command, argument);
}
}
Modified:
james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SMTPCommandDispatcherLineHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SMTPCommandDispatcherLineHandler.java?rev=904428&r1=904427&r2=904428&view=diff
==============================================================================
---
james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SMTPCommandDispatcherLineHandler.java
(original)
+++
james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SMTPCommandDispatcherLineHandler.java
Fri Jan 29 09:13:33 2010
@@ -24,10 +24,6 @@
import org.apache.james.api.protocol.AbstractCommandDispatcher;
import org.apache.james.api.protocol.CommandHandler;
-import org.apache.james.api.protocol.Response;
-import org.apache.james.smtpserver.protocol.SMTPRequest;
-import org.apache.james.smtpserver.protocol.SMTPResponse;
-import org.apache.james.smtpserver.protocol.SMTPRetCode;
import org.apache.james.smtpserver.protocol.SMTPSession;
@@ -44,42 +40,6 @@
private final static String[] mandatoryCommands = { "MAIL" , "RCPT",
"DATA"};
- /*
- * (non-Javadoc)
- * @see
org.apache.james.api.protocol.AbstractCommandDispatcher#dispatchCommand(org.apache.james.api.protocol.ProtocolSession,
java.lang.String, java.lang.String)
- */
- protected void dispatchCommand(SMTPSession session, String command, String
argument) {
-
- List<CommandHandler<SMTPSession>> commandHandlers =
getCommandHandlers(command, session);
- // fetch the command handlers registered to the command
- if (commandHandlers == null) {
- // end the session
- SMTPResponse resp = new SMTPResponse(SMTPRetCode.LOCAL_ERROR,
"Local configuration error: unable to find a command handler.");
- resp.setEndSession(true);
- session.writeResponse(resp);
- } else {
- int count = commandHandlers.size();
- for (int i = 0; i < count; i++) {
- Response response = commandHandlers.get(i).onCommand(session,
new SMTPRequest(command, argument));
-
- session.writeResponse(response);
-
- // if the response is received, stop processing of command
- // handlers
- if (response != null) {
- break;
- }
-
- // NOTE we should never hit this line, otherwise we ended the
- // CommandHandlers with
- // no responses.
- // (The note is valid for i == count-1)
- }
-
- }
-
- }
-
/**
* @see
org.apache.james.api.protocol.AbstractCommandDispatcher#getUnknownCommandHandlerIdentifier()
Modified:
james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/AbstractCommandDispatcher.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/AbstractCommandDispatcher.java?rev=904428&r1=904427&r2=904428&view=diff
==============================================================================
---
james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/AbstractCommandDispatcher.java
(original)
+++
james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/AbstractCommandDispatcher.java
Fri Jan 29 09:13:33 2010
@@ -29,6 +29,7 @@
import java.util.Locale;
+
/**
* Abstract base class which CommandDispatcher implementations should extend
*
@@ -131,22 +132,30 @@
}
curCommandName = curCommandName.toUpperCase(Locale.US);
- dispatchCommand(session, curCommandName, curCommandArgument);
+ List<CommandHandler<Session>> commandHandlers =
getCommandHandlers(curCommandName, session);
+ // fetch the command handlers registered to the command
+ int count = commandHandlers.size();
+ for (int i = 0; i < count; i++) {
+ Response response = commandHandlers.get(i).onCommand(session, new
BaseRequest(curCommandName, curCommandArgument));
+ session.writeResponse(response);
+
+ // if the response is received, stop processing of command
+ // handlers
+ if (response != null) {
+ break;
+ }
+
+ // NOTE we should never hit this line, otherwise we ended the
+ // CommandHandlers with
+ // no responses.
+ // (The note is valid for i == count-1)
+ }
+
}
protected Charset getLineDecodingCharset() {
return Charset.forName("US-ASCII");
}
-
- /**
- * Dispatch the given command and its parameters
- *
- * @param session
- * @param command
- * @param argument
- */
- protected abstract void dispatchCommand(Session session, String command,
String argument);
-
/**
* @see
org.apache.james.api.protocol.ExtensibleHandler#getMarkerInterfaces()
Added:
james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/BaseRequest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/BaseRequest.java?rev=904428&view=auto
==============================================================================
---
james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/BaseRequest.java
(added)
+++
james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/BaseRequest.java
Fri Jan 29 09:13:33 2010
@@ -0,0 +1,61 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.api.protocol;
+
+/**
+ * Basic Request which contains a command and argument
+ *
+ */
+public class BaseRequest implements Request{
+
+ private final String command;
+ private final String argument;
+
+ public BaseRequest(final String command, final String argument) {
+ this.command = command;
+ this.argument = argument;
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.api.protocol.Request#getArgument()
+ */
+ public String getArgument() {
+ return argument;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.api.protocol.Request#getCommand()
+ */
+ public String getCommand() {
+ return command;
+ }
+
+
+ public String toString() {
+ if (argument == null) {
+ return command;
+ } else {
+ return command + " " + argument;
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]