Custom configuration

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
m (Custom Configuration moved to Custom configuration)
 
Line 1: Line 1:
[[Category:Configuration]] [[Category:Inversion of Control]]
+
{{Cleanup}} [[Category:Configuration]] [[Category:Inversion of Control]]
  
 
http://www.caucho.com/resin-3.0/config/init.xtp
 
http://www.caucho.com/resin-3.0/config/init.xtp

Latest revision as of 21:15, 1 December 2011

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