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