Adjust checkstyle rules. Make checkstyle fail the build when violations are found. Correct all current checkstyle violations.
This commit is contained in:
@ -2,32 +2,34 @@ package com.iluwatar.front.controller;
|
||||
|
||||
/**
|
||||
*
|
||||
* The Front Controller is a presentation tier pattern. Essentially it defines a
|
||||
* controller that handles all requests for a web site.
|
||||
* The Front Controller is a presentation tier pattern. Essentially it defines a controller that
|
||||
* handles all requests for a web site.
|
||||
* <p>
|
||||
* The Front Controller pattern consolidates request handling through a single handler
|
||||
* object ({@link FrontController}). This object can carry out the common the behavior such as
|
||||
* The Front Controller pattern consolidates request handling through a single handler object (
|
||||
* {@link FrontController}). This object can carry out the common the behavior such as
|
||||
* authorization, request logging and routing requests to corresponding views.
|
||||
* <p>
|
||||
* Typically the requests are mapped to command objects ({@link Command}) which then display
|
||||
* the correct view ({@link View}).
|
||||
* Typically the requests are mapped to command objects ({@link Command}) which then display the
|
||||
* correct view ({@link View}).
|
||||
* <p>
|
||||
* In this example we have implemented two views: {@link ArcherView} and {@link CatapultView}. These
|
||||
* are displayed by sending correct request to the {@link FrontController} object. For example,
|
||||
* the {@link ArcherView} gets displayed when {@link FrontController} receives request "Archer". When
|
||||
* are displayed by sending correct request to the {@link FrontController} object. For example, the
|
||||
* {@link ArcherView} gets displayed when {@link FrontController} receives request "Archer". When
|
||||
* the request is unknown, we display the error view ({@link ErrorView}).
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
FrontController controller = new FrontController();
|
||||
controller.handleRequest("Archer");
|
||||
controller.handleRequest("Catapult");
|
||||
controller.handleRequest("foobar");
|
||||
}
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
*
|
||||
* @param args
|
||||
* command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
FrontController controller = new FrontController();
|
||||
controller.handleRequest("Archer");
|
||||
controller.handleRequest("Catapult");
|
||||
controller.handleRequest("foobar");
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ package com.iluwatar.front.controller;
|
||||
*/
|
||||
public class ApplicationException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ApplicationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
public ApplicationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ package com.iluwatar.front.controller;
|
||||
*/
|
||||
public class ArcherCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
new ArcherView().display();
|
||||
}
|
||||
@Override
|
||||
public void process() {
|
||||
new ArcherView().display();
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ package com.iluwatar.front.controller;
|
||||
*/
|
||||
public class ArcherView implements View {
|
||||
|
||||
@Override
|
||||
public void display() {
|
||||
System.out.println("Displaying archers");
|
||||
}
|
||||
@Override
|
||||
public void display() {
|
||||
System.out.println("Displaying archers");
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ package com.iluwatar.front.controller;
|
||||
*/
|
||||
public class CatapultCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
new CatapultView().display();
|
||||
}
|
||||
@Override
|
||||
public void process() {
|
||||
new CatapultView().display();
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ package com.iluwatar.front.controller;
|
||||
*/
|
||||
public class CatapultView implements View {
|
||||
|
||||
@Override
|
||||
public void display() {
|
||||
System.out.println("Displaying catapults");
|
||||
}
|
||||
@Override
|
||||
public void display() {
|
||||
System.out.println("Displaying catapults");
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ package com.iluwatar.front.controller;
|
||||
*
|
||||
*/
|
||||
public interface Command {
|
||||
|
||||
void process();
|
||||
|
||||
void process();
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ package com.iluwatar.front.controller;
|
||||
*/
|
||||
public class ErrorView implements View {
|
||||
|
||||
@Override
|
||||
public void display() {
|
||||
System.out.println("Error 500");
|
||||
}
|
||||
@Override
|
||||
public void display() {
|
||||
System.out.println("Error 500");
|
||||
}
|
||||
}
|
||||
|
@ -2,33 +2,33 @@ package com.iluwatar.front.controller;
|
||||
|
||||
/**
|
||||
*
|
||||
* FrontController is the handler class that takes in all the requests and
|
||||
* renders the correct response.
|
||||
* FrontController is the handler class that takes in all the requests and renders the correct
|
||||
* response.
|
||||
*
|
||||
*/
|
||||
public class FrontController {
|
||||
|
||||
public void handleRequest(String request) {
|
||||
Command command = getCommand(request);
|
||||
command.process();
|
||||
}
|
||||
|
||||
private Command getCommand(String request) {
|
||||
Class commandClass = getCommandClass(request);
|
||||
try {
|
||||
return (Command) commandClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new ApplicationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Class getCommandClass(String request) {
|
||||
Class result;
|
||||
try {
|
||||
result = Class.forName("com.iluwatar.front.controller." + request + "Command");
|
||||
} catch (ClassNotFoundException e) {
|
||||
result = UnknownCommand.class;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void handleRequest(String request) {
|
||||
Command command = getCommand(request);
|
||||
command.process();
|
||||
}
|
||||
|
||||
private Command getCommand(String request) {
|
||||
Class commandClass = getCommandClass(request);
|
||||
try {
|
||||
return (Command) commandClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new ApplicationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Class getCommandClass(String request) {
|
||||
Class result;
|
||||
try {
|
||||
result = Class.forName("com.iluwatar.front.controller." + request + "Command");
|
||||
} catch (ClassNotFoundException e) {
|
||||
result = UnknownCommand.class;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ package com.iluwatar.front.controller;
|
||||
*/
|
||||
public class UnknownCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
new ErrorView().display();
|
||||
}
|
||||
@Override
|
||||
public void process() {
|
||||
new ErrorView().display();
|
||||
}
|
||||
}
|
||||
|
@ -7,5 +7,5 @@ package com.iluwatar.front.controller;
|
||||
*/
|
||||
public interface View {
|
||||
|
||||
void display();
|
||||
void display();
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ import com.iluwatar.front.controller.App;
|
||||
*
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.iluwatar.front.controller;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Date: 12/13/15 - 1:35 PM
|
||||
|
Reference in New Issue
Block a user