001// Licensed under the Apache License, Version 2.0 (the "License");
002// you may not use this file except in compliance with the License.
003// You may obtain a copy of the License at
004//
005// http://www.apache.org/licenses/LICENSE-2.0
006//
007// Unless required by applicable law or agreed to in writing, software
008// distributed under the License is distributed on an "AS IS" BASIS,
009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010// See the License for the specific language governing permissions and
011// limitations under the License.
012
013package org.apache.tapestry5.annotations;
014
015import org.apache.tapestry5.ioc.annotations.UseWith;
016import org.apache.tapestry5.services.javascript.JavaScriptStack;
017import org.apache.tapestry5.services.javascript.JavaScriptSupport;
018
019import java.lang.annotation.*;
020
021import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.*;
022
023/**
024 * Annotations to control the importing of JavaScript stacks and libraries as well as stylesheets. This annotation may
025 * be placed on a class, in which case importing will occur as part of the {@link SetupRender} render phase.
026 * Alternately, the annotation maybe placed on any method (though typically it will be placed on a render phase
027 * method) and the import operations will be associated of that method.
028 *
029 * Use of this annotation is translated into invocations against the {@link org.apache.tapestry5.services.javascript.JavaScriptSupport}
030 * environmental; all imports there will implicitly import the core stack.
031 *
032 * Assets are localized during the {@link org.apache.tapestry5.runtime.PageLifecycleAdapter#containingPageDidLoad()} lifecycle
033 * method.
034 *
035 * @since 5.2.0
036 */
037@Target(
038        {ElementType.TYPE, ElementType.METHOD})
039@Retention(RetentionPolicy.RUNTIME)
040@Documented
041@UseWith(
042        {COMPONENT, MIXIN, PAGE})
043public @interface Import
044{
045    /**
046     * JavaScript Stacks to import. Stacks are imported before individual libraries. Note that
047     * stacks themselves may have {@linkplain JavaScriptStack#getStacks() dependencies on other
048     * stacks}.
049     *
050     * @see JavaScriptStack
051     * @see JavaScriptSupport#importStack(String)
052     */
053    String[] stack() default {};
054
055    /**
056     * JavaScript libraries to import. Each value is an asset path; symbols in each path are expanded. The library may
057     * be localized.
058     *
059     * @see JavaScriptSupport#importJavaScriptLibrary(org.apache.tapestry5.Asset)
060     */
061    String[] library() default {};
062
063    /**
064     * Stylesheets to import. Each value is an asset path; symbols in each path are expanded. The stylesheet may be
065     * localized. The stylesheet is imported with no options.
066     *
067     * @see JavaScriptSupport#importStylesheet(org.apache.tapestry5.Asset)
068     */
069    String[] stylesheet() default {};
070
071    /**
072     * Names of modules to import. A module name consists of a path, with the terms seperated by a slash character. The first
073     * term is the library name (or "app" for the application), e.g. <code>flash/gordon</code> would map to the file
074     * <code>META-INF/modules/flash/gordon.js</code>.  Alternately a function name can be included, after a colon seperator.
075     * e.g., <code>flash/gordon:setup</code>.
076     *
077     * Module initializations specified this way may not have an parameters, so they are typically doing single-use
078     * setup.
079     *
080     * @see org.apache.tapestry5.services.javascript.ModuleManager
081     * @see JavaScriptSupport#require(String)
082     * @since 5.4
083     */
084    String[] module() default {};
085}