summaryrefslogtreecommitdiffstats
path: root/docs/devGuideDB
ModeNameSize
-rw-r--r--aj.xml1933logstatsplain
-rw-r--r--ajbrowser-building.gif26404logstatsplain
-rw-r--r--ajbrowser-options.gif9437logstatsplain
-rw-r--r--ajbrowser.xml16714logstatsplain
-rw-r--r--ajc.xml31357logstatsplain
-rw-r--r--ajdb.xml10319logstatsplain
-rw-r--r--ajdee.gif21193logstatsplain
-rw-r--r--ajdee.xml15737logstatsplain
-rw-r--r--ajdeforte.xml7823logstatsplain
-rw-r--r--ajdejbuilder.xml10914logstatsplain
-rw-r--r--ajdoc.xml5826logstatsplain
-rw-r--r--antsupport.xml51981logstatsplain
-rw-r--r--aspectj-docs.css1205logstatsplain
-rw-r--r--aspectj-mode.gif11988logstatsplain
-rw-r--r--aspectj-mode.xml12375logstatsplain
-rw-r--r--aspectj-mode2.gif20913logstatsplain
-rw-r--r--compatibility.xml7399logstatsplain
-rw-r--r--dd_arrow.gif851logstatsplain
-rw-r--r--devguide.xml2708logstatsplain
-rw-r--r--jbuilder-buildOptions.gif10064logstatsplain
-rw-r--r--jbuilder-building.gif27587logstatsplain
-rw-r--r--jbuilder-configs.gif24200logstatsplain
-rw-r--r--jbuilder-structureNavigation.gif30813logstatsplain
-rw-r--r--ltw.xml34848logstatsplain
-rw-r--r--netbeans-buildOptions.gif10273logstatsplain
-rw-r--r--netbeans-building.gif33075logstatsplain
-rw-r--r--tools-intro.xml8902logstatsplain
ng.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * Copyright 2000-2016 Vaadin Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.vaadin.ui;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;

import com.vaadin.annotations.HtmlImport;
import com.vaadin.annotations.JavaScript;
import com.vaadin.annotations.StyleSheet;
import com.vaadin.server.ClientConnector;
import com.vaadin.server.LegacyCommunicationManager;

/**
 * Represents a stylesheet or JavaScript to include on the page.
 *
 * @author Vaadin Ltd
 */
public class Dependency implements Serializable {
    /**
     * The type of dependency.
     */
    public enum Type {
        STYLESHEET(StyleSheet.class), //
        JAVASCRIPT(JavaScript.class), //
        HTMLIMPORT(HtmlImport.class);

        private Class<? extends Annotation> annotationType;

        private Type(Class<? extends Annotation> annotationType) {
            this.annotationType = annotationType;
        }
    }

    private final Type type;
    private final String url;

    /**
     * Creates a new dependency of the given type, to be loaded from the given
     * URL.
     * <p>
     * The URL is passed through the translation mechanism before loading, so
     * custom protocols such as "vaadin://" can be used.
     *
     * @param type
     *            the type of dependency, not <code>null</code>
     * @param url
     *            the URL to load the dependency from, not <code>null</code>
     */
    public Dependency(Type type, String url) {
        if (url == null) {
            throw new IllegalArgumentException("url cannot be null");
        }
        assert type != null;
        this.type = type;
        this.url = url;
    }

    /**
     * Gets the untranslated URL for the dependency.
     *
     * @return the URL for the dependency
     */
    public String getUrl() {
        return url;
    }

    /**
     * Gets the type of the dependency.
     *
     * @return the type of the dependency
     */
    public Type getType() {
        return type;
    }

    /**
     * Finds all the URLs defined for the given class using annotations for the
     * given type, registers the URLs to the communication manager and adds the
     * registered dependencies to the given list.
     *
     * @param type
     *            the type of dependencies to look for
     * @param cls
     *            the class to scan
     * @param manager
     *            a reference to the communication manager which tracks
     *            dependencies
     * @param dependencies
     *            the list to add registered dependencies to
     *
     * @return a stream of resource URLs in the order defined by the annotations
     */
    @SuppressWarnings("deprecation")
    private static void findAndRegisterResources(Type type,
            Class<? extends ClientConnector> cls,
            LegacyCommunicationManager manager, List<Dependency> dependencies) {
        Annotation[] annotations = cls
                .getAnnotationsByType(type.annotationType);
        if (annotations != null) {
            for (Annotation annotation : annotations) {
                String[] resources;
                if (annotation instanceof StyleSheet) {
                    resources = ((StyleSheet) annotation).value();
                } else if (annotation instanceof JavaScript) {
                    resources = ((JavaScript) annotation).value();
                } else if (annotation instanceof HtmlImport) {
                    resources = ((HtmlImport) annotation).value();
                } else {
                    throw new IllegalArgumentException(
                            "Unknown annotation type: "
                                    + annotation.annotationType().getName());
                }

                for (String resource : resources) {
                    String url = manager.registerDependency(resource, cls);
                    dependencies.add(new Dependency(type, url));
                }
            }
        }
    }

    /**
     * Finds all the URLs defined for the given classes, registers the URLs to
     * the communication manager and returns the registered dependencies.
     * <p>
     * The returned collection contains all types of dependencies for each class
     * in the given list in the order the classes are in the list, i.e. all
     * dependencies for the first class before all dependencies for the next
     * class.
     * <p>
     * JavaScript dependencies are returned before HTML imports.
     *
     * @param connectorTypes
     *            the collection of connector classes to scan
     * @param manager
     *            a reference to the communication manager which tracks
     *            dependencies
     * @return
     */
    @SuppressWarnings("deprecation")
    public static List<Dependency> findDependencies(
            List<Class<? extends ClientConnector>> connectorTypes,
            LegacyCommunicationManager manager) {
        List<Dependency> dependencies = new ArrayList<>();

        for (Class<? extends ClientConnector> connectorType : connectorTypes) {
            findAndRegisterResources(Type.JAVASCRIPT, connectorType, manager,
                    dependencies);
            findAndRegisterResources(Type.HTMLIMPORT, connectorType, manager,
                    dependencies);
            findAndRegisterResources(Type.STYLESHEET, connectorType, manager,
                    dependencies);
        }

        return dependencies;
    }

}