Usage Model for the MapViewer JavaBean-Based API

4 MapViewer JavaBean-Based API 4-1 4 MapViewer JavaBean-Based API This chapter describes the JavaBean-based MapViewer API. This API exposes all capabilities of MapViewer through a single JavaBean, oracle.lbs.mapclient.MapViewer. This bean is a lightweight client that handles all communications with the actual MapViewer service running on the middle tier on behalf of a user making map requests. All communications between the bean and the actual MapViewer service follow a requestresponse model. Requests are always sent as XML documents to the service. Depending on the type and nature of a request, the response received by the bean is either an XML document or some binary data. However, using the MapViewer bean is easier than manipulating XML documents for forming and sending MapViewer requests, as well as for extracting information from the responses. The bean delegates most of map data processing and rendering to the MapViewer service. All the bean does is formulate user requests into valid MapViewer XML requests and send them to a MapViewer service for processing. This chapter contains the following major sections: ■ Section 4.1, Usage Model for the MapViewer JavaBean-Based API ■ Section 4.2, Preparing to Use the MapViewer JavaBean-Based API ■ Section 4.3, Using the MapViewer Bean

4.1 Usage Model for the MapViewer JavaBean-Based API

The MapViewer bean can be created and used in either server-side objects such as JavaServer Pages JSP and servlets, or in client-side objects such as Java applets or standalone Java applications. The bean is a lightweight class that maintains an active HTTP connection to the MapViewer service and the current map request and map response objects. In most cases, you will create only one MapViewer bean and use it for all subsequent tasks; however, you can create more than one bean and use these beans simultaneously. For example, you may need to create a Web page where a small overview map displays the whole world and a large map image displays a more detailed map of the region that is selected on the overview map. In this case, it is probably easier to create two MapViewer beans, one dedicated to the smaller overview map, and the other to the larger detail map. Figure 4–1 shows some possible usage scenarios for the MapViewer bean. 4-2 Oracle Fusion Middleware Users Guide for Oracle MapViewer Figure 4–1 MapViewer Bean Usage Scenarios The MapViewer bean can communicate through the HTTP protocol with the MapViewer service in several usage scenarios, the following of which are shown in Figure 4–1 : ■ In a Java application ■ In a Java applet ■ In a servlet within a Java 2 Enterprise Edition J2EE container different from the J2EE container that contains the MapViewer service ■ In JavaServer Pages JSP code within the J2EE container that contains the MapViewer service In all usage models, the same JavaBean class is used, and most of its methods apply. However, some methods work or are useful only in a JSP HTML-based context, and other methods work or are useful only in an interactive standalone Java application or applet context thick clients. For example, consider the following methods of the bean: ■ java.awt.Image getGeneratedMapImage ■ String getGeneratedMapImageURL Both methods extract the generated map image information from a response received from a MapViewer service; however, the first method returns the actual binary image data that is a java.awt.BufferedImage class, and the second method returns an HTTP URL string to the generated map image that is stored in the host running the MapViewer service. Clearly, if your application is a JavaServer Page, you should use the second method, because otherwise the JSP page will not know how to handle the BufferedImage. However, if you are programming a standalone Java application where you have a Java panel or window for displaying the map, you can use the first method to get the actual image and render it inside your panel or window, plus any other features that you may have created locally and want to render on top of the map. The set of methods that are only applicable in the thick client context, which are designed to achieve optimal performance for such clients, are described in more detail in Section 4.3.10 . MapViewer Bean MapViewer Beans MapViewer Bean MapViewer Bean Java Applications Applets Servlet J2EE Container JSP MapViewer Service J2EE Container HTTP HTTP HTTP HTTP MapViewer JavaBean-Based API 4-3

4.2 Preparing to Use the MapViewer JavaBean-Based API