launcher/src/main/java/org/apidesign/bck2brwsr/launcher/InvocationContext.java
branchcanvas
changeset 808 bd8b726902a3
parent 731 e8283f10a127
parent 807 e93506e603ad
child 809 5c61f5e4898e
     1.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/InvocationContext.java	Thu Feb 14 12:06:16 2013 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,101 +0,0 @@
     1.4 -/**
     1.5 - * Back 2 Browser Bytecode Translator
     1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 - *
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, version 2 of the License.
    1.11 - *
    1.12 - * This program is distributed in the hope that it will be useful,
    1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 - * GNU General Public License for more details.
    1.16 - *
    1.17 - * You should have received a copy of the GNU General Public License
    1.18 - * along with this program. Look for COPYING file in the top folder.
    1.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 - */
    1.21 -package org.apidesign.bck2brwsr.launcher;
    1.22 -
    1.23 -import java.io.IOException;
    1.24 -import java.io.InputStream;
    1.25 -import java.util.concurrent.CountDownLatch;
    1.26 -import java.util.concurrent.TimeUnit;
    1.27 -
    1.28 -/** Represents individual method invocation, its context and its result.
    1.29 - *
    1.30 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.31 - */
    1.32 -public final class InvocationContext {
    1.33 -    final CountDownLatch wait = new CountDownLatch(1);
    1.34 -    final Class<?> clazz;
    1.35 -    final String methodName;
    1.36 -    private final Launcher launcher;
    1.37 -    private String result;
    1.38 -    private Throwable exception;
    1.39 -    String html;
    1.40 -    InputStream httpContent;
    1.41 -    String httpType;
    1.42 -    String httpPath;
    1.43 -
    1.44 -    InvocationContext(Launcher launcher, Class<?> clazz, String methodName) {
    1.45 -        this.launcher = launcher;
    1.46 -        this.clazz = clazz;
    1.47 -        this.methodName = methodName;
    1.48 -    }
    1.49 -    
    1.50 -    /** An HTML fragment to be available for the execution. Useful primarily when
    1.51 -     * executing in a browser via {@link Launcher#createBrowser(java.lang.String)}.
    1.52 -     * @param html the html fragment
    1.53 -     */
    1.54 -    public void setHtmlFragment(String html) {
    1.55 -        this.html = html;
    1.56 -    }
    1.57 -    
    1.58 -    /** HTTP resource to be available during execution. An invocation may
    1.59 -     * perform an HTTP query and obtain a resource relative to the page.
    1.60 -     */
    1.61 -    public void setHttpResource(String relativePath, String mimeType, InputStream content) {
    1.62 -        if (relativePath == null || mimeType == null || content == null) {
    1.63 -            throw new NullPointerException();
    1.64 -        }
    1.65 -        this.httpPath = relativePath;
    1.66 -        this.httpType = mimeType;
    1.67 -        this.httpContent = content;
    1.68 -    }
    1.69 -    
    1.70 -    /** Invokes the associated method. 
    1.71 -     * @return the textual result of the invocation
    1.72 -     */
    1.73 -    public String invoke() throws IOException {
    1.74 -        launcher.runMethod(this);
    1.75 -        return toString();
    1.76 -    }
    1.77 -    
    1.78 -    /** Obtains textual result of the invocation.
    1.79 -     * @return text representing the exception or result value
    1.80 -     */
    1.81 -    @Override
    1.82 -    public String toString() {
    1.83 -        if (exception != null) {
    1.84 -            return exception.toString();
    1.85 -        }
    1.86 -        return result;
    1.87 -    }
    1.88 -    
    1.89 -    /**
    1.90 -     * @param timeOut
    1.91 -     * @throws InterruptedException 
    1.92 -     */
    1.93 -    void await(long timeOut) throws InterruptedException {
    1.94 -        wait.await(timeOut, TimeUnit.MILLISECONDS);
    1.95 -    }
    1.96 -    
    1.97 -    void result(String r, Throwable e) {
    1.98 -        this.result = r;
    1.99 -        this.exception = e;
   1.100 -        wait.countDown();
   1.101 -    }
   1.102 -
   1.103 -    
   1.104 -}