boot/src/main/java/org/apidesign/html/boot/impl/FnContext.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 10 Oct 2013 14:02:18 +0200
changeset 309 7025177bd67e
child 322 4a93f2679691
permissions -rw-r--r--
FnUtils are bloated and contain references to Asm classes. Separate the code needed by generated JsCallbacks into own class
     1 /**
     2  * HTML via Java(tm) Language Bindings
     3  * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, version 2 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details. apidesign.org
    13  * designates this particular file as subject to the
    14  * "Classpath" exception as provided by apidesign.org
    15  * in the License file that accompanied this code.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program. Look for COPYING file in the top folder.
    19  * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
    20  */
    21 package org.apidesign.html.boot.impl;
    22 
    23 import org.apidesign.html.boot.spi.Fn;
    24 
    25 /**
    26  *
    27  * @author Jaroslav Tulach <jtulach@netbeans.org>
    28  */
    29 public final class FnContext {
    30     private FnContext() {
    31     }
    32     
    33     private static final ThreadLocal<Fn.Presenter> CURRENT = new ThreadLocal<Fn.Presenter>();
    34 
    35     public static Fn.Presenter currentPresenter(Fn.Presenter p) {
    36         Fn.Presenter prev = CURRENT.get();
    37         CURRENT.set(p);
    38         return prev;
    39     }
    40 
    41     public static Fn.Presenter currentPresenter() {
    42         Fn.Presenter p = CURRENT.get();
    43         if (p == null) {
    44             throw new IllegalStateException("No current WebView context around!");
    45         }
    46         return p;
    47     }
    48     
    49 }