Личные заметки на Zaharov.info

 | Начало | Регистрация | Ответить | Поиск | Статистика | FAQ |
Естествознание Личные заметки на Zaharov.info / Естествознание /

Java Dozer sample usage tutorial

dimedrol
Администратор 

#1 | Дата: 23 Май 2008 17:50 
Dozer is a Java Bean to Java Bean mapper that recursively copies data from one object to another. Typically, these Java Beans will be of different complex types.

Dozer supports simple property mapping, complex type mapping, bi-directional mapping, implicit-explicit mapping, as well as recursive mapping. This includes mapping collection attributes that also need mapping at the element level.

Please read the about page for detailed information on Dozer - http://dozer.sourceforge.net/

The main thing we must remember working with Dozer is - valid mapping file and proper location for this.
In simplest sample (using Intellij IDEA 7) we've got the part of source file:
List myMappingFiles = new ArrayList();
myMappingFiles.add("beanmapping.xml");

in that case our "beanmapping.xml" must be located here:

"c:\Java\Projects\ DozerTest\out\production\DozerTest\beanmapping.xml"

Remember, it is - "out" directory. (path on local development machine!)

In that case we can simply run the project from IDEA IDE. Sample output goes like this:


C:\Java\jdk\bin\java -Didea.launcher.port=7553 -Didea.....

May 23, 2008 3:21:36 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Trying to find Dozer configuration file: dozer.properties
May 23, 2008 3:21:36 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Dozer configuration file not found: dozer.properties. Using defaults for all Dozer global properties.
May 23, 2008 3:21:36 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Initializing Dozer. Version: 4.2, Thread Name:main, Is this JDK 1.5.x?:true
May 23, 2008 3:21:36 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Dozer JMX MBean [net.sf.dozer.util.mapping.jmx:type=DozerStatisticsController] auto registered with the Platform MBean Server
May 23, 2008 3:21:36 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Dozer JMX MBean [net.sf.dozer.util.mapping.jmx:type=DozerAdminController] auto registered with the Platform MBean Server
May 23, 2008 3:21:36 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Initializing a new instance of the dozer bean mapper.
May 23, 2008 3:21:36 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Using the following xml files to load custom mappings for the bean mapper instance: [beanmapping.xml]
May 23, 2008 3:21:36 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Trying to find xml mapping file: beanmapping.xml
May 23, 2008 3:21:36 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Using URL [file:/C:/Java/Projects/DozerTest/out/production/DozerTest/beanmapping.xml] to load custom xml mappings
May 23, 2008 3:21:36 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Successfully loaded custom xml mappings from URL: [file:/C:/Java/Projects/DozerTest/out/production/DozerTest/beanmapping.xml]
Mapped name from latvian.........: Albert
Mapped surname from latvian .....: Ammons
Mapped age from latvian..........: 42
Not mapped latvian field (weight): 0

Process finished with exit code 0



Here we can see the output of logger.

So, to build JAR file with IntelliJ IDEA use the following settings:
(screenshot) http://i28.tinypic.com/2lazrc4.gif

Biuld JAR and now, you can run your JAR and see the output:

c:\Java\Projects\DozerTest>java -jar DozerTest.jar
May 23, 2008 3:50:29 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Trying to find Dozer configuration file: dozer.properties
May 23, 2008 3:50:29 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Dozer configuration file not found: dozer.properties. Using defaults for all Dozer global properties.
May 23, 2008 3:50:29 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Initializing Dozer. Version: 4.2, Thread Name:main, Is this JDK 1.5.x?:true
May 23, 2008 3:50:29 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Dozer JMX MBean [net.sf.dozer.util.mapping.jmx:type=DozerStatisticsController] auto registered with the Platform MBean Server
May 23, 2008 3:50:29 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Dozer JMX MBean [net.sf.dozer.util.mapping.jmx:type=DozerAdminController] auto registered with the Platform MBean Server
May 23, 2008 3:50:30 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Initializing a new instance of the dozer bean mapper.
May 23, 2008 3:50:30 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Using the following xml files to load custom mappings for the bean mapper instance: [beanmapping.xml]
May 23, 2008 3:50:30 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Trying to find xml mapping file: beanmapping.xml
May 23, 2008 3:50:30 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Using URL [jar:file:/C:/Java/Projects/DozerTest/DozerTest.jar!/beanmapping.xml] to load custom xml mappings
May 23, 2008 3:50:30 PM net.sf.dozer.util.mapping.util.InitLogger log
INFO: Successfully loaded custom xml mappings from URL: [jar:file:/C:/Java/Projects/DozerTest/DozerTest.jar!/beanmapping.xml]
Mapped name from latvian.........: Albert
Mapped surname from latvian .....: Ammons
Mapped age from latvian..........: 42
Not mapped latvian field (weight): 0

c:\Java\Projects\DozerTest>

ZIP-ed sample project: http://www.laterra.lv/downloads/DozerTest_IntelliJ_IDEA7_project.zip (~24kb)
Естествознание Личные заметки на Zaharov.info / Естествознание / Java Dozer sample usage tutorial Наверх
Ваш ответ Нажмите эту иконку для возврата на цитируемое сообщение
 
» Оставьте это поле пустым

» АНТИСПАМ! Сколько будет ТРИ плюс ТРИ? (ответ цифрой) 
 ?
Анонимные пользователи могут отправлять сообщения без предварительной регистрации. Для этого введите просто логин без пароля или оставьте оба поля пустыми. Зарегистрированные пользователи могут ввести свои логин и пароль при отправке сообщения.
 
  Личные заметки на Zaharov.info Поддержка: Online Community Script miniBB ®