Custom configuration

From Resin 3.0

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

Please visit for the most up-to-date documentation.



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 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"/>

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

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

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

  public void addMovie(Movie movie)
Personal tools