Wednesday, June 17, 2015

A Summary of Section One of the Second Chapter on Oracle's Ozark MVC 1. 0 - Early Draft

The entire second chapter provides a concise summary and introduction for the three main components found in Oracle's Ozark product: the model, the view, and the controller. Oracle sets aside a section for each.

The components are addressed in order of importance and detail. The first and longest section is on controllers. The second on models, And, the last on views.

Section One of the Second Chapter : Controllers

A controller for an Oracle's MVC 1.0 architecture is a JAX-RS resources method annotated with "@Controller". One might make all of the resource methods in a JAX-RS service controllers by placing the "@Controller" annotation on the class representing all of the resources. Also, one can produce a hybrid JAX-RS webservice with a mixed of "@controller" annotated methods and regular resource methods.

The following is a definition of a simple "Hello World" controller:

//the "hello" controller method returns the path for a JSP resource.
@Path("hello")
public class HelloController {
    @GET
    @Controller
    public String hello() {
        return "hello.jsp";
    }
}

Controller methods and the regular JAX-RS resource methods interpret the String return type differently. Controller methods see a String return type as a path for viewable instead of text content. A controller might might have one of four different return types: void which requires that the method be annotated with @View, String ( a path for view content ), Viewable which bundles information about a view and how it should be processed, and JAX-RS response whose entity type is any one of the aforementioned types. It should be noted that the default content-type returned by a controller is text/html unless one specifies differently using the @Produces annotation. Also, the "@View" annotation is only applicable for controller methods with a void return type. Although only four possible return types from controller methods are allowed, the parameters of such methods do not have any limitations other than any of those imposed on regular JAX-RS service methods. Also, like regular JAX-RS services, the default resource class instance is per-request. Despite this similarity with regular JAX-RS services, controllers must be CDI-managed beans. This includes any hybrid classes.

//The controller methods in this class are all equivalent

@Controller
@Path("hello")
public class HelloController {

    @GET
    @View("hello.jsp")
    public void helloVoid() {
    }


    @GET
    public String helloString() {
        return("hello.jsp");
    }

    @GET
    public Viewable hellowViewable() {
        return new Viewable("hello.jsp");
    }

    @GET
    public Response helloResponse() {
        return Response.status(Response.Status.OK).entity("hello.jsp").build();       
    }

}


The summaries for the next couple of sections of this chapter will be coming later this week or next week. It seems that the 40+ hours of "fun" each week recently will continue for some time. This has limited the available effort on Saturdays. We will gradually adjust and hopefully resume our Monday,Wednesday, and Friday post.

Happy Coding. La-La.

The CABOOSE Team.

No comments:

Post a Comment