Custom configuration

From Resin 3.0

Jump to: navigation, search
40px-Edit-clear.png This article requires cleanup and may refer to a legacy version of Resin.

Please visit http://www.caucho.com/documentation/ for the most up-to-date documentation.

http://www.caucho.com/resin-3.0/config/init.xtp

Contents

Overview

Resin provides a configuration API to populate application beans from an XML file. Resin's configuration machinery supports Inversion of Control and allows the use of EL expressions.

Using Resin to parse XML

Resin's configuration API is the easiest method to parse XML.

  • Create Java classes mirroring the XML file.
  • Call Resin's configuration with an instance of the classes and the XML file.

Calling the Configuration

import com.caucho.config.*;

...

Config config = new Config();
MovieListing movies = new MovieList();

InputStream is = ...;

config.configure(bean, is);

Sample XML Parsing

Sample XML File

<movie-listing>
  <movie director="Jackson" title="LOTR: Fellowship of the Ring"/>
  <movie director="Jackson" title="LOTR: The Two Towers"/>
  <movie director="Jackson" title="LOTR: Return of the King"/>

  <movie director="Gilliam" title="Monty Python's Holy Grail"/>
  <movie director="Gilliam" title="Brazil"/>
</movie-listing>

To model the XML file, you'll use a Movie class and a MovieListener class:

Movie.java

public class Movie {
  private String _director;
  private String _title;

  public void setDirector(String director)
  {
    _director = director;
  }

  public void setTitle(String title)
  {
    _title = title;
  }
}

The movie listing encapsulates a list of movies

MovieListing.java

public class MovieListing {
  private ArrayList _movies = new ArrayList();

  public void addMovie(Movie movie)
  {
    _movies.add(movie);
  }
}
Personal tools