HTML and CSS Reference
In-Depth Information
Step 1—Create the Component Model and Logic
When creating components it is tempting to mingle your component logic with the classes that must be implemented
to make it work on the framework. However, this makes the component difficult to test and you mix framework
specificities with logic that could be encapsulated and reused. It also makes it difficult to upgrade in case the
framework suddenly has new or different requirements on how to implement components.
The first step in component creation is to build the model and logic before getting into how the model and logic
will interface with the UIComponent and Renderer classes. The model for the RandomText component is rather simple.
It is a simple class called RandomTextAPI with a single method that invokes the RandomText REST service and returns
the output received from the service. Listing 6-1 show the source code of the simplified service.
Listing 6-1. Implementing a Simplified API for Obtaining Random Text from the Online REST Service
package com.apress.projsf2html5.chapter6.components;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
* Simple API for obtaining random text from an online REST service.
* @see <a href="">RandomText</a >
public class RandomTextAPI {
* Enumeration containing the type of text to return.
public enum TextType {
/** Return gibberish text. */
/** Return lorem ipsum text. */
* Enumeration containing the type of formatting to return.
Search WWH ::

Custom Search