Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is one of my BeanFactories, I hope it helps to explain the common pattern:</p> <pre><code>public class LineBeanFactory implements BeanFactory { @Override public Object createBean(final Object source, final Class&lt;?&gt; sourceClass, final String targetBeanId) { final LineDto dto = (LineDto) source; return new Line(dto.getCode(), dto.getElectrified(), dto.getName()); } } </code></pre> <p>And the corresponding XML mapping:</p> <pre><code>&lt;mapping&gt; &lt;class-a bean-factory="com.floyd.nav.web.ws.mapping.dozer.LineBeanFactory"&gt;com.floyd.nav.core.model.Line&lt;/class-a&gt; &lt;class-b&gt;com.floyd.nav.web.contract.dto.LineDto&lt;/class-b&gt; &lt;/mapping&gt; </code></pre> <p>This way I declare that when a <strong>new</strong> instance of Line is needed then it should create it with my BeanFactory. Here is a unit test, that can explain it:</p> <pre><code>@Test public void Line_is_created_with_three_arg_constructor_from_LineDto() { final LineDto dto = createTransientLineDto(); final Line line = (Line) this.lineBeanFactory.createBean(dto, LineDto.class, null); assertEquals(dto.getCode(), line.getCode()); assertEquals(dto.getElectrified(), line.isElectrified()); assertEquals(dto.getName(), line.getName()); } </code></pre> <p>So <em>Object source</em> is the source bean that is mapped, <em>Class sourceClass</em> is the class of the source bean (I'm ignoring it, 'cause it will always be a LineDto instance). <em>String targetBeanId</em> is the ID of the destination bean (too ignored).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload