View Javadoc

1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2007 Beck et al. projects GmbH Munich, Germany (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21   */
22  
23  package de.bea.domingo.map;
24  
25  import de.bea.domingo.DDocument;
26  
27  /***
28   * Class defining and performing a mapping of an attribute that itself is a
29   * complex sub object of a business object.
30   *
31   * @author <a href="mailto:kriede@users.sourceforge.net">Kurt Riede</a>
32   */
33  public abstract class SubMapper implements Mapper {
34  
35      /*** Reference to the associated mapper. */
36      private final Mapper mapper;
37  
38      /***
39       * Constructor. Creates a direct mapper where the Notes item name is equal
40       * to the <tt>itemName</tt> attribute and the names of the get/set methods
41       * in the business class are equal to <tt>"get" + itemName</tt> and
42       * <tt>"set" + itemName</tt>.
43       *
44       * @param mapper the mapper for the sub-object
45       */
46      public SubMapper(final Mapper mapper) {
47          this.mapper = mapper;
48      }
49  
50      /***
51       * Implementing class must return the sub-object to map.
52       *
53       * @param object base object
54       * @return sub-object
55       */
56      protected abstract Object getObject(final Object object);
57  
58      /***
59       * Performs the mapping from a document to a business object.
60       *
61       * @param document the Notes document
62       * @param object the business object
63       * @throws MappingException if an error occurred during mapping
64       */
65      public final void map(final DDocument document, final Object object) throws MappingException {
66          mapper.map(document, getObject(object));
67      }
68  
69      /***
70       * Performs the mapping from a business object to a document.
71       *
72       * @param object the business object
73       * @param document the Notes document
74       * @throws MappingException if an error occurred during mapping
75       */
76      public final void map(final Object object, final DDocument document) throws MappingException {
77          mapper.map(getObject(object), document);
78      }
79  }