1.1 --- a/boot/src/main/java/org/apidesign/html/boot/impl/FnContext.java Thu Oct 10 14:02:18 2013 +0200
1.2 +++ b/boot/src/main/java/org/apidesign/html/boot/impl/FnContext.java Tue Nov 05 23:06:32 2013 +0100
1.3 @@ -20,15 +20,42 @@
1.4 */
1.5 package org.apidesign.html.boot.impl;
1.6
1.7 +import java.io.Closeable;
1.8 +import java.io.IOException;
1.9 +import java.util.logging.Logger;
1.10 import org.apidesign.html.boot.spi.Fn;
1.11
1.12 /**
1.13 *
1.14 * @author Jaroslav Tulach <jtulach@netbeans.org>
1.15 */
1.16 -public final class FnContext {
1.17 - private FnContext() {
1.18 +public final class FnContext implements Closeable {
1.19 + private static final Logger LOG = Logger.getLogger(FnContext.class.getName());
1.20 +
1.21 + private Fn.Presenter prev;
1.22 + private FnContext(Fn.Presenter p) {
1.23 + this.prev = p;
1.24 }
1.25 +
1.26 + @Override
1.27 + public void close() throws IOException {
1.28 + if (prev != null) {
1.29 + currentPresenter(prev);
1.30 + prev = null;
1.31 + }
1.32 + }
1.33 +/*
1.34 + @Override
1.35 + protected void finalize() throws Throwable {
1.36 + if (prev != null) {
1.37 + LOG.warning("Unclosed context!");
1.38 + }
1.39 + }
1.40 +*/
1.41 + public static Closeable activate(Fn.Presenter newP) {
1.42 + return new FnContext(currentPresenter(newP));
1.43 + }
1.44 +
1.45
1.46 private static final ThreadLocal<Fn.Presenter> CURRENT = new ThreadLocal<Fn.Presenter>();
1.47