geo/src/main/java/net/java/html/geo/OnLocation.java
author Jaroslav Tulach <jaroslav.tulach@netbeans.org>
Fri, 07 Feb 2014 07:44:34 +0100
changeset 551 7ca2253fa86d
parent 365 5c93ad8c7a15
child 711 039d9a0dea07
permissions -rw-r--r--
Updating copyright headers to mention current year
jaroslav@172
     1
/**
jaroslav@358
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
jaroslav@172
     3
 *
jaroslav@551
     4
 * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
jaroslav@172
     5
 *
jaroslav@358
     6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
jaroslav@358
     7
 * Other names may be trademarks of their respective owners.
jaroslav@172
     8
 *
jaroslav@358
     9
 * The contents of this file are subject to the terms of either the GNU
jaroslav@358
    10
 * General Public License Version 2 only ("GPL") or the Common
jaroslav@358
    11
 * Development and Distribution License("CDDL") (collectively, the
jaroslav@358
    12
 * "License"). You may not use this file except in compliance with the
jaroslav@358
    13
 * License. You can obtain a copy of the License at
jaroslav@358
    14
 * http://www.netbeans.org/cddl-gplv2.html
jaroslav@358
    15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
jaroslav@358
    16
 * specific language governing permissions and limitations under the
jaroslav@358
    17
 * License.  When distributing the software, include this License Header
jaroslav@358
    18
 * Notice in each file and include the License file at
jaroslav@358
    19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
jaroslav@358
    20
 * particular file as subject to the "Classpath" exception as provided
jaroslav@358
    21
 * by Oracle in the GPL Version 2 section of the License file that
jaroslav@358
    22
 * accompanied this code. If applicable, add the following below the
jaroslav@358
    23
 * License Header, with the fields enclosed by brackets [] replaced by
jaroslav@358
    24
 * your own identifying information:
jaroslav@358
    25
 * "Portions Copyrighted [year] [name of copyright owner]"
jaroslav@358
    26
 *
jaroslav@358
    27
 * Contributor(s):
jaroslav@358
    28
 *
jaroslav@358
    29
 * The Original Software is NetBeans. The Initial Developer of the Original
jaroslav@551
    30
 * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
jaroslav@358
    31
 *
jaroslav@358
    32
 * If you wish your version of this file to be governed by only the CDDL
jaroslav@358
    33
 * or only the GPL Version 2, indicate your decision by adding
jaroslav@358
    34
 * "[Contributor] elects to include this software in this distribution
jaroslav@358
    35
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
jaroslav@358
    36
 * single choice of license, a recipient has the option to distribute
jaroslav@358
    37
 * your version of this file under either the CDDL, the GPL Version 2 or
jaroslav@358
    38
 * to extend the choice of license to its licensees as provided above.
jaroslav@358
    39
 * However, if you add GPL Version 2 code and therefore, elected the GPL
jaroslav@358
    40
 * Version 2 license, then the option applies only if the new code is
jaroslav@358
    41
 * made subject to such option by the copyright holder.
jaroslav@172
    42
 */
jaroslav@172
    43
package net.java.html.geo;
jaroslav@172
    44
jaroslav@172
    45
import java.lang.annotation.ElementType;
jaroslav@172
    46
import java.lang.annotation.Retention;
jaroslav@172
    47
import java.lang.annotation.RetentionPolicy;
jaroslav@172
    48
import java.lang.annotation.Target;
jaroslav@172
    49
jaroslav@179
    50
/** Generates a handle which can configure, {@link Position.Handle#start() start}
jaroslav@179
    51
 * and {@link Position.Handle#stop() stop} requests for obtaining current
jaroslav@179
    52
 * location of the application/device/user. Put the {@link OnLocation} annotation
jaroslav@179
    53
 * on top of a (non-private) method in your class which takes one argument
jaroslav@179
    54
 * {@link Position}. Based on name of your method (unless a class name is
jaroslav@179
    55
 * directly specified via {@link #className()} attribute) a handle class is
jaroslav@179
    56
 * generated. For example if your method name is <code>callMeWhenYouKnowWhereYouAre</code>
jaroslav@179
    57
 * a package private class <code>CallMeWhenYouKnowWhereYouAreHandle</code> will
jaroslav@179
    58
 * be generated in the same package. One can use its <code>createQuery</code>
jaroslav@179
    59
 * and <code>createWatch</code> static method to get one time/repeated time
jaroslav@179
    60
 * instance of a {@link Position.Handle handle}. After configuring the
jaroslav@179
    61
 * {@link Position.Handle handle} via its setter methods, one can 
jaroslav@179
    62
 * {@link Position.Handle#start() start} the location request.
jaroslav@179
    63
 * <p>
jaroslav@179
    64
 * In case something goes wrong a method in the same class named {@link #onError()}
jaroslav@179
    65
 * can be specified (should take one {@link Exception} parameter). 
jaroslav@179
    66
 * <p>
jaroslav@179
    67
 * The overall behavior of the system mimics <a href="http://www.w3.org/TR/2012/PR­geolocation­API­20120510/">
jaroslav@179
    68
 * W3C's Geolocation API</a>.
jaroslav@172
    69
 *
jaroslav@172
    70
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@172
    71
 */
jaroslav@172
    72
@Retention(RetentionPolicy.SOURCE)
jaroslav@172
    73
@Target(ElementType.METHOD)
jaroslav@172
    74
public @interface OnLocation {
jaroslav@179
    75
    /** Name of the {@link Position.Handle handle} class to generate. By
jaroslav@179
    76
     * default the name is derived from the name of annotated method by
jaroslav@179
    77
     * capitalizing the first character and appending <code>Handle</code>.
jaroslav@179
    78
     * <p>
jaroslav@179
    79
     * The generated class contains two static methods: <code>createQuery</code>
jaroslav@179
    80
     * and <code>createWatch</code> which take no parameters if this method 
jaroslav@179
    81
     * is static or one parameter (of this class) if this method is instance
jaroslav@179
    82
     * one. Both static methods return {@link Position.Handle}.
jaroslav@179
    83
     * 
jaroslav@179
    84
     * @return string suitable for a new class in the same package
jaroslav@179
    85
     */
jaroslav@172
    86
    public String className() default "";
jaroslav@172
    87
    
jaroslav@179
    88
    /** Name of a method in this class which should be called in case of 
jaroslav@179
    89
     * an error. The method has to be non-private and take {@link Exception} 
jaroslav@244
    90
     * parameter. If this method is not specified, the exception is just
jaroslav@244
    91
     * printed to console.
jaroslav@179
    92
     * 
jaroslav@179
    93
     * @return name of method in this class
jaroslav@179
    94
     */
jaroslav@172
    95
    public String onError() default "";
jaroslav@172
    96
}