<document>
  <header>
    <product>resin</product>
    <title>JAXB Bean configuration</title>
    <type>tutorial</type>
    <description>
      <p>
Resin's configuration integrates JAXB-style bean configuration.
      </p>
    </description>
    <tutorial-startpage>test</tutorial-startpage>
  </header>

  <body>
    <localtoc/>

<s1>
<p>With Resin, applications can use JAXB to configure its resources
directly from the resin.conf or resin-web.xml.  A "JAXB Bean"
is just a Java class that follows a simple set of rules.  Each configuration
parameter <var>foo</var> has a corresponding setter method
<code>setFoo</code> with a single argument for the value.  Resin can
look at the class using Java's reflection and find the <code>setFoo</code>
method.  Because Resin can find the bean-style setters from looking at the
class, it can configure those setters in a configuration file
like the resin-web.xml.</p>
</s1>

<s1 title="Files in this tutorial">
<deftable>
<tr><td><viewfile-link file="WEB-INF/resin-web.xml"/></td>
    <td>Configures the bean with JAXB init</td></tr>
<tr><td><viewfile-link file="WEB-INF/classes/example/Theater.java"/></td>
   <td>Theater model</td></tr>
<tr><td><viewfile-link file="WEB-INF/classes/example/Movie.java"/></td>
   <td>Movie model</td></tr>
<tr><td><viewfile-link file="WEB-INF/classes/example/TestServlet.java"/></td>
    <td>The servlet implementation.</td></tr>
</deftable>
</s1>

<s1 title="Configuration">

<p>The <a href="doc|env-tags.xtp#%3Cbean%3E">&lt;bean&gt;</a> tag creates
a singleton component for the Theater, which can be used by any servlet,
JSP, JSF, EJB or WebBeans component by using the WebBeans injection
annotations..</p>

<example title="WEB-INF/resin-web.xml">
&lt;web-app xmlns="http://caucho.com/ns/resin">

  &lt;bean name="beans/theater"
        class="example.Theater">
    &lt;init>
      &lt;name>Balboa Theater&lt;/name>
      
      &lt;movie>
        &lt;title>Plan 9 from Outer Space&lt;/title>
      &lt;/movie>
      
      &lt;movie>
        &lt;title>Snakes on a Plane&lt;/title>
	&lt;star>Samuel L Jackson&lt;/star>
      &lt;/movie>
      
      &lt;movie>
        &lt;title>The Maltese Falcon&lt;/title>
	&lt;star>Humphrey Bogart&lt;/star>
	&lt;star>Mary Astor&lt;/star>
	&lt;star>Peter Lorre&lt;/star>
	&lt;star>Sydney Greenstreet&lt;/star>
      &lt;/movie>
    &lt;/init>
  &lt;/bean>
      
  &lt;servlet-mapping url-pattern="/test"
                   servlet-class="example.TestServlet"/>
&lt;/web-app>
</example>

</s1>

<s1 title="Theater">

<example title="WEB-INF/classes/example/Theater.java">
package example;

import java.util.*;

import javax.xml.bind.annotation.*;

@XmlRootElement
public class Theater
{
  @XmlElement(name="name")
  private String _name;

  @XmlElement(name="movie")
  private ArrayList&lt;Movie> _movieList = new ArrayList&lt;Movie>();
}
</example>

</s1>

<s1 title="Movie">

<example title="WEB-INF/classes/example/Movie.java">
package example;

import java.util.*;

import javax.xml.bind.annotation.*;

@XmlRootElement
public class Movie
{
  @XmlElement(name="title")
  private String _title;
    
  @XmlElement(name="star")
  private ArrayList&lt;String> _starList = new ArrayList&lt;String>();
}
</example>

</s1>

<s1 title="TestServlet">

<example title="WEB-INF/classes/example/TestServlet.java">
package example;

import javax.servlet.*;
import javax.webbeans.In;

public class TestServlet extends GenericServlet {
  @In
  private Theater _theater;

  ...
}
</example>
</s1>

  </body>
</document>
