Slides - Gustavus Adolphus College
Download
Report
Transcript Slides - Gustavus Adolphus College
MCS 270 Spring 2014
Object-Oriented Software Development
MCS 270 Object-Oriented Software Development
Today’s schedule
Google Web Toolkit
Domain Analysis/Application Analysis
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Google Web Toolkit Features
Communication between client and server using Java objects.
GWT applications do not need to fetch new HTML pages as
they execute.
Uses Remote Procedure Call (RPC) for interaction with the
server across a network.
GWT compiles client-side Java code into JavaScript code that is
then inserted into the HTML page and used to run app
JavaScript client implementation -> runs on multiple browsers.
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Google Web Toolkit Client Side Programming
Client-side code includes:
Core (non-GUI) Java classes
GWT UI widgets – buttons, menus, panels, etc
RPC Servlet Interface Definitions (including Async)
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Google Web Toolkit Server Side Programming
Server-side code includes:
Core (non-GUI) Java classes
RPC Servlet Implementation Classes
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Google Web Toolkit Shared Programming
Shared code includes:
Core (non-GUI) Java classes that are used by
both server and client.
Note: These should not contain GUI components
or RPC components.
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Client <-> Server Communication
RPC - The mechanism for exchanging data with a server
across a network.
The server-side code that gets invoked from the client is
often referred to as a service
The act of making a remote procedure call is sometimes
referred to as invoking a service.
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
RPC architecture
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Example – Client Side Interface Definition
package com.example.foo.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath(”myservicetarget")
public interface MyService extends RemoteService {
public List getEmployeeList(String department);
public String getEmployeeTitle(int employeeID);
}
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Example – Client Side Interface Definition – Async
package com.example.foo.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
interface MyServiceAsync {
public void getEmployeeList (String department,
AsyncCallback<List> callback);
public void getEmployeeTitle(int employeeID,
AsyncCallback<String> callback);
}
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Example – Server Side Implementation
package com.example.foo.server;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.example.client.MyService;
public class MyServiceImpl extends RemoteServiceServlet implements
MyService {
public List getEmployeeList (String department) {
// construct List list from database
return list;
}
public String getEmployeeTitle(int employeeID){ return “title”; }
}
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Example – web.xml servlet – module definition
<servlet>
<servlet-name>myServiceImpl</servlet-name>
<servlet-class>com.example.foo.server.MyServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myServiceImpl</servlet-name>
<url-pattern>/foo/myservicetarget</url-pattern>
</servlet-mapping>
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Serialization
Data that is transferred from client to sevrer (or viceversa) needs to be serializable. (List in last example)
For an object to be serialized, every parameter and return
type must be serializable.
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Serialization
For a type to be serializable it must satisfy at least one of
the following requirements.
•
It is a primitive type (int, char, boolean, etc.)
•
It is an array of serializable types
•
It is a serializable class
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Serialization
A serializable class must satisfy all of following:
• It implements either Java Serializable or GWT’s
‘IsSerializable’ interface or derives from a superclass
that does.
• It’s non-final, non-transient instance fields are themselves
serializable.
• It has a default (zero argument) constructor with any
access modifier (e.g. private Foo(){} will work).
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Example
public class PostData implements IsSerializable {
private String title="no title”;
private String description="empty”;
private double price=0.0;
private Seller seller=null;
private Buyer buyer=null;
// GWT serializable Objects need a no=argument constructor
public PostData() {}
public PostData(String t, String d, double p, Seller s, Buyer b){
title = t; description = d; price = p; seller = s; buyer = b;
}
}
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Client-Side Service Callback
For each operation of the service interface we define a class to
specify how to handle the returned result of the operation.
Class must implement the AsyncCallback<T> interface, which
specifies two operations:
void onFailure(Throwable caught)
void onSuccess(T t).
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Client-Side Service Callback
onFailure(Throwable caught): called when the procedure fails or
an exception occurred; exception is passed to the procedure as a
parameter.
onSuccess(T t): called when the procedure successfully returns a
result of type T, and the result is passed to the operation as a
parameter.
T must be the same data type of the return of the service
operation.
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Client-Side Service Callback Example
private final PostDataServiceAsync postDataService =
GWT.create(PostDataService.class);
public void handlePostSubmit(PostData post) {
submitPostService.submitPostToServer(post,
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
return;
}
public void onSuccess(String result) {
System.out.println(result);
}
});
}
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Domain Model Exercise
Groups of 3-4: Create a Domain Model analysis of “GusList” – an on-line
classified ad service for the Gustavus community.
Task: Identify
Classes
Associations
Attributes
Assumptions: We will use the MVC architecture
Assignment: By next Thursday (March 6), prepare (group) a Domain Model
Class Diagram with all associations and attributes, plus a Data Dictionary.
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu
MCS 270 Object-Oriented Software Development
Assignments
Monday – Work on GWT Project:
Homework:
GusList Domain Class Model
Due: Thursday, March 6
GUSTAVUS ADOLPHUS COLLEGE
gustavus.edu