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