001    /*
002     * ============================================================================
003     * GNU Lesser General Public License
004     * ============================================================================
005     *
006     * Beanlet - JSE Application Container.
007     * Copyright (C) 2006  Leon van Zantvoort
008     * 
009     * This library is free software; you can redistribute it and/or
010     * modify it under the terms of the GNU Lesser General Public
011     * License as published by the Free Software Foundation; either
012     * version 2.1 of the License, or (at your option) any later version.
013     * 
014     * This library is distributed in the hope that it will be useful,
015     * but WITHOUT ANY WARRANTY; without even the implied warranty of
016     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
017     * Lesser General Public License for more details.
018     * 
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this library; if not, write to the Free Software
021     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
022     * 
023     * Leon van Zantvoort
024     * 243 Acalanes Drive #11
025     * Sunnyvale, CA 94086
026     * USA
027     *
028     * zantvoort@users.sourceforge.net
029     * http://beanlet.org
030     */
031    package org.beanlet.springframework;
032    
033    import static java.lang.annotation.ElementType.*;
034    import java.lang.annotation.Retention;
035    import java.lang.annotation.RetentionPolicy;
036    import java.lang.annotation.Target;
037    
038    /**
039     * <p>Used to enabled Spring dependency injection.</p>
040     *
041     * <p>A member can be injected with a Spring bean if a {@code SpringContext} is 
042     * available for the specified member. Such a {@code SpringContext} can be
043     * defined at package-, class- or at member-level. There are two more requirements
044     * for members to support Spring beanlet injection:
045     * <ul>
046     * <li>Members must be marked with the {@code Inject} annotation.
047     * <li>Members, for which a {@code SpringContext} is made available at package- 
048     * or class-level, must enable wiring {@code BY_NAME} or wiring {@code BY_TYPE} 
049     * through the {@code Wiring} annotation. Members that are marked with the
050     * {@code SpringContext} support wiring {@code BY_NAME} and {@code BY_TYPE} by 
051     * default.
052     * </ul></p>
053     * 
054     * <p>Members marked with this annotation MUST also be annoted with 
055     * {@code Inject}, otherwise the beanlet definition fails.</p>
056     * 
057     * <p><h3>XML Representation</h3>The following xml-fragments show how to express 
058     * this annotation in xml. The 'spring-context' tags don't specify any element 
059     * attribute, which means that this tag is applied to the beanlet's class.<br><pre><tt>
060     * &lt;beanlets xmlns="http://beanlet.org/schema/beanlet"
061     *           xmlns:sf="http://beanlet.org/schema/springframework"
062     *           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
063     *           xsi:schemaLocation="http://beanlet.org/schema/beanlet http://beanlet.org/schema/beanlet/beanlet_1_0.xsd
064     *                            http://beanlet.org/schema/springframework http://beanlet.org/schema/springframework/beanlet_springframework_1_0.xsd"&gt;
065     *   &lt;beanlet name="foo" type="com.acme.Foo"&gt;
066     *     <b>&lt;sf:spring-contex path="spring.xml" type="CLASSPATH" format="XML" application-context="false"/&gt;</b>
067     *   &lt;/beanlet&gt;
068     * &lt;/beanlets&gt;</tt></pre></p>
069     * Or:
070     * <p><pre><tt>
071     * &lt;beanlets xmlns="http://beanlet.org/schema/beanlet"
072     *           xmlns:sf="http://beanlet.org/schema/springframework"
073     *           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
074     *           xsi:schemaLocation="http://beanlet.org/schema/beanlet http://beanlet.org/schema/beanlet/beanlet_1_0.xsd
075     *                            http://beanlet.org/schema/springframework http://beanlet.org/schema/springframework/beanlet_springframework_1_0.xsd"&gt;
076     *   &lt;beanlet name="foo" type="com.acme.Foo"&gt;
077     *     <b>&lt;sf:spring-contex application-context="false"&gt;
078     *       &lt;resource path="spring.xml" type="CLASSPATH" format="XML"/&gt;
079     *       &lt;resource path="http://demo.beanlet.org/spring.xml" type="URL" format="XML"/&gt;
080     *     &lt;/sf:spring-context&gt;</b>
081     *   &lt;/beanlet&gt;
082     * &lt;/beanlets&gt;</tt></pre></p>
083     * Or alternatively:
084     * <p><pre><tt>
085     * &lt;beanlets xmlns="http://beanlet.org/schema/beanlet"
086     *           xmlns:sf="http://beanlet.org/schema/springframework"
087     *           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
088     *           xsi:schemaLocation="http://beanlet.org/schema/beanlet http://beanlet.org/schema/beanlet/beanlet_1_0.xsd
089     *                            http://beanlet.org/schema/springframework http://beanlet.org/schema/springframework/beanlet_springframework_1_0.xsd"&gt;
090     *   &lt;beanlet name="foo" type="com.acme.Foo"&gt;
091     *     <b>&lt;sf:spring-contex type="CLASSPATH" format="XML" application-context="false"&gt;
092     *       &lt;resource path="spring.xml"/&gt;
093     *       &lt;resource path="http://demo.beanlet.org/spring.xml" type="URL"/&gt;
094     *     &lt;/sf:spring-context&gt;</b>
095     *   &lt;/beanlet&gt;
096     * &lt;/beanlets&gt;</tt></pre></p>
097     *
098     * @see org.beanlet.Inject
099     * @see org.beanlet.Wiring
100     * @author Leon van Zantvoort
101     */
102    @Retention(RetentionPolicy.RUNTIME)
103    @Target({PACKAGE, TYPE, CONSTRUCTOR, METHOD, FIELD, PARAMETER})
104    public @interface SpringContext {
105    
106        /**
107         * Spring configuration resources.
108         */
109        SpringResource[] value();
110    
111        /**
112         * Set to {@code true} for creating defining a Spring 
113         * {@code ApplicationContext}, set to {@code false} to define a 
114         * {@code BeanFactory}.
115         */
116        boolean applicationContext() default false;
117    }