Section 9.1. Getting Started

team bbl


9.1. Getting Started

In this section, you'll start creating a rich client RentABike with an emerging project built directly on the Spring Framework, the Spring Rich Client Project (Spring Rich). The first thing you'll do is get the necessary project files. You'll then see how to get a basic application shell with a splash screen up and running.

But first, a brief background on the aims of the project At its core, Spring Rich is a framework for constructing high-quality, professional Swing-powered desktop applications. It serves several important needs:


Simplification

Swing is the most complete Java widget toolkit today, but it's complex and cumbersome. Spring Rich provides a simpler programming model that's easy to leverage and extend.


Consistency

Low-level Swing provides no guidelines for constructing consistently well-layered enterprise applications. Through Spring, you get effective J2EE services integration and configuration with a consistent programming model.


Integration

Spring Rich integrates the best features of projects like JGoodies, JDNC, JDIC, Webstart, Glazed Lists, Spin, Foxtrot, JIDE, InfoNode, and FlexDock (to name a few), in order to provide a end-to-end platform for rich client development.

9.1.1. How do I do that?

You first want to get the Spring Rich project. Link to it from the Spring site at http://www.springframework.org and follow the directions that you see there. In a nutshell, you will:

  1. Access the Spring Rich sourceforge homepage at http://sourceforge.net/projects/spring-rich-c.

  2. Access the "Files" tab and select to download the latest "with-dependencies" release archive.


Note: Spring Rich ships two distributions for each release: a bare-bones distribution containing the minimal jars, and an all-in-one jar also containing all dependencies.

The "with dependencies" release has everything that you need, including Spring Rich and all of its dependencies.

The project is still rapidly evolving, so if you need to download and build the latest CVS snapshot to take advantage of the newest to-be released features, do the following:

  1. Connect to the spring-rich-c module repository using your favorite CVS plugin. Here are the parameters you'll need:

    Hostname: cvs.sourceforge.net
    Repository path: /cvsroot/spring-rich-c
    Username: anonymous
    Connection type: pserver

    Check out the spring-richclient module. If you're using eclipse, you can import this module directly as an eclipse project.

  2. Go to the spring-richclient root directory and run the build.xml file to build spring-richclient.jar. Use the alljars Ant target.

Now you've got the spring-richclient.jar, which you can plug right into your project. You're also going to need a set of image resources. Spring Rich ships a set of out-of-the-box images in spring-richclient-resources.jar you can use to jumpstart your UI development. You can also take the images that we packaged with the book's code examples and use them where an example calls for images.

Move the jars into your lib directory under your project, and you're off to the races. You'll next configure a splash screen and code a thin application bootstrapper to make sure that things are working.

A startup application context, which hosts services needed at initialization, defines your splash screen (Example 9-1).

Example 9-1. startup-context.xml
com.springbook.richclient.startup-context.xml <beans>     <bean             >        <property name="imageResourcePath">          <value>classpath:/images/splash-screen.jpg</value>        </property>     </bean> </beans>

Of course, you'll want to get a designer to build you an outrageously cool splash screen, but we all failed art, so you're on your own. In the mean time, you can use a simple JSP like the one in Example 9-2.

Example 9-2. splashScreen.jsp
<HTML>   <BODY>     Keith's Bikes   </BODY> </HTML>

You'll then want a simple main driver to kick of loading your application (Example 9-3).


Note: This is the main driver that starts the bikestore springbook application.
Example 9-3. RentABikeLauncher.xml
public class RentABikeLauncher {     public static void main(String[] args) {         try {             String packagePrefix = "com/springbook/richclient";             String startupContextPath =                 packagePrefix + "/startup-context.xml";             String[] rootContextPath =                 new String[] {                     packagePrefix + "/business-layer-definitions.xml",       packagePrefix + "/richclient-definitions.xml" };                          new ApplicationLauncher(startupContextPath,                  rootContextPath);         }         catch (Exception e) {             System.exit(1);         }     } }

This thin bootstrapper uses ApplicationLauncher to load your application from the configuration defined in two spring application contexts.

In a standalone rich client environment, you'll typically specify three context configuration files on the classpath. The first configuration file is startup-context.xml, which you just defined with your splash screen bean definition. The next two files are business-layer-definitions.xml and richclient-definitions.xml. These make up the central root application context, which you will define and configure in the next lab.

You're ready to let it fly.

9.1.2. What just happened?

Like most rich client apps, Spring Rich-powered apps can take a little bit of time to launch, so the framework lets you put up a splash screen when you launch your application while the user waits. As you've seen, Spring Rich lets you specify the splash-screen configuration in the context.

There's more to it than meets the eye. The framework forks off a thread for you, and loads your application while you look at the pretty splash screen. That way, the user gets the impression of immediate response. This boilerplate code exists in most rich client applications, but is completely managed by the framework.

    team bbl



    Spring. A developer's Notebook
    Spring: A Developers Notebook
    ISBN: 0596009100
    EAN: 2147483647
    Year: 2005
    Pages: 90

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net