View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2006 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.services.persistence.generic.dao;
18  
19  import java.lang.annotation.Documented;
20  import java.lang.annotation.ElementType;
21  import java.lang.annotation.Retention;
22  import java.lang.annotation.RetentionPolicy;
23  import java.lang.annotation.Target;
24  
25  import org.springframework.stereotype.Component;
26  
27  import ch.elca.el4j.services.persistence.generic.dao.impl.DefaultDaoRegistry;
28  
29  /**
30   * Indicates that a GenericDao implementation should be added as singleton bean to spring
31   *  (and in a second step (by the @link {@link DefaultDaoRegistry}) to the DAO Registry). <a>
32   *
33   *  You can indicate as parameter the desired <code>id</code> for the spring bean. <a>
34   *
35   *  Requires config that looks something like the following (see sample for more details): <a>
36   *
37   *  <pre>
38   *  1) collect GenericDao implementations with this annotation <br>
39   *     &lt;!--  This section scans for DAOs annotated with @AutocollectedGenericDao that should be
40   *     added to the spring application context (as beans). Later, the DAO Registry
41   *     automatically collects these DAOs. --&gt;
42   *     &lt;!-- 	The attribute base-packages indicates the packages where we look for DAOs  --&gt;
43   *     &lt;context:component-scan use-default-filters="false"
44   *     annotation-config="false"
45   *     base-package="ch.elca.el4j.apps.keyword.dao, ch.elca.el4j.apps.refdb.dao"&gt;
46   *     &lt;context:include-filter type="annotation"
47   *     expression="ch.elca.el4j.services.persistence.generic.dao.AutocollectedGenericDao" /&gt;
48   *     &lt;/context:component-scan&gt;
49   *
50   *  2) set up dao registry <br>
51   *     &lt;!-- Allows to register DAOs. Automatically collects all GenericDaos from the application context --&gt;
52   *     &lt;bean id="daoRegistry"
53   *     class="ch.elca.el4j.services.persistence.generic.dao.impl.DefaultDaoRegistry"/&gt;
54   *
55   *
56   *  3) init the session factory on the DAOs <br>
57   *     &lt;!-- Inits the session factory in all the GenericDaos registered in the spring application context--&gt;
58   *     &lt;bean id="injectionPostProcessor"
59   *     class="ch.elca.el4j.services.persistence.hibernate.dao.HibernateSessionFactoryInjectorBeanPostProcessor" /&gt;
60   * </pre>
61   *
62   * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/main/java/ch/elca/el4j/services/persistence/generic/dao/AutocollectedGenericDao.java $
63   *
64   * @author Philipp Oser (POS)
65   */
66  @Target({ElementType.TYPE})
67  @Retention(RetentionPolicy.RUNTIME)
68  @Documented
69  @Component
70  public @interface AutocollectedGenericDao {
71  
72  	/**
73  	 * The value may indicate a suggestion for a logical component name,
74  	 * to be turned into a Spring bean in case of an autodetected component.
75  	 * @return the suggested component name, if any
76  	 */
77  	String value() default "";
78  	
79  }