launcher/api/src/main/java/org/apidesign/bck2brwsr/launcher/InvocationContext.java
branchclassloader
changeset 1186 265edcee24ed
parent 1033 b8773b7b9ecd
child 1188 4d324bf6ede9
     1.1 --- a/launcher/api/src/main/java/org/apidesign/bck2brwsr/launcher/InvocationContext.java	Sun Apr 28 10:14:31 2013 +0200
     1.2 +++ b/launcher/api/src/main/java/org/apidesign/bck2brwsr/launcher/InvocationContext.java	Fri Jun 21 22:34:09 2013 +0200
     1.3 @@ -19,6 +19,7 @@
     1.4  
     1.5  import java.io.IOException;
     1.6  import java.io.InputStream;
     1.7 +import java.net.URI;
     1.8  import java.util.ArrayList;
     1.9  import java.util.List;
    1.10  import java.util.concurrent.CountDownLatch;
    1.11 @@ -95,6 +96,31 @@
    1.12          wait.countDown();
    1.13      }
    1.14  
    1.15 +    private static RegisterResource RR;
    1.16 +    static void register(RegisterResource rr) {
    1.17 +        RR = rr;
    1.18 +    }
    1.19 +    /** A running {@link InvocationContext test} can register additional 
    1.20 +     * resources to the associated browser (if any). 
    1.21 +     * 
    1.22 +     * @param content the stream to deliver content from
    1.23 +     * @param mimeType mime type for the HTTP reply
    1.24 +     * @param path suggested path in the server to use
    1.25 +     * @param parameters additional parameters
    1.26 +     * @return the URI the resource is made available at
    1.27 +     * @throws NullPointerException if there is no {@link InvocationContext test} 
    1.28 +     *    currently running
    1.29 +     * @since 0.8
    1.30 +     */
    1.31 +    public static URI register(
    1.32 +        InputStream content, String mimeType, String path, String[] parameters
    1.33 +    ) {
    1.34 +        final Resource r = new Resource(content, mimeType, path, parameters);
    1.35 +        return RR.registerResource(r);
    1.36 +    }
    1.37 +    static interface RegisterResource {
    1.38 +        public URI registerResource(Resource r);
    1.39 +    }
    1.40  
    1.41      static final class Resource {
    1.42          final InputStream httpContent;