Custom configuration
From CauchoWiki
(Redirected from Custom Configuration)
http://www.caucho.com/resin-3.0/config/init.xtp
Contents |
[edit] 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.
[edit] 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.
[edit] Calling the Configuration
import com.caucho.config.*; ... Config config = new Config(); MovieListing movies = new MovieList(); InputStream is = ...; config.configure(bean, is);
[edit] Sample XML Parsing
[edit] 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:
[edit] 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
[edit] MovieListing.java
public class MovieListing {
private ArrayList _movies = new ArrayList();
public void addMovie(Movie movie)
{
_movies.add(movie);
}
}
