Documenting the bootstrap API classloader
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 26 Jun 2013 17:17:42 +0200
branchclassloader
changeset 166a3c7866bfb61
parent 165 823e9058cb4d
child 167 10005a498972
Documenting the bootstrap API
boot/pom.xml
boot/src/main/java/net/java/html/boot/BrowserBuilder.java
boot/src/main/java/net/java/html/boot/package.html
boot/src/main/java/net/java/html/js/package.html
     1.1 --- a/boot/pom.xml	Wed Jun 26 15:11:58 2013 +0200
     1.2 +++ b/boot/pom.xml	Wed Jun 26 17:17:42 2013 +0200
     1.3 @@ -15,6 +15,18 @@
     1.4    <properties>
     1.5      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     1.6    </properties>
     1.7 +  <build>
     1.8 +      <plugins>
     1.9 +          <plugin>
    1.10 +              <groupId>org.apache.maven.plugins</groupId>
    1.11 +              <artifactId>maven-javadoc-plugin</artifactId>
    1.12 +              <configuration>
    1.13 +                  <subpackages>net.java.html.js:net.java.html.boot</subpackages>
    1.14 +                  <skip>false</skip>
    1.15 +              </configuration>
    1.16 +          </plugin>
    1.17 +      </plugins>
    1.18 +  </build>
    1.19    <dependencies>
    1.20      <dependency>
    1.21        <groupId>org.ow2.asm</groupId>
     2.1 --- a/boot/src/main/java/net/java/html/boot/BrowserBuilder.java	Wed Jun 26 15:11:58 2013 +0200
     2.2 +++ b/boot/src/main/java/net/java/html/boot/BrowserBuilder.java	Wed Jun 26 17:17:42 2013 +0200
     2.3 @@ -30,11 +30,39 @@
     2.4  import java.util.ServiceLoader;
     2.5  import java.util.logging.Level;
     2.6  import java.util.logging.Logger;
     2.7 +import net.java.html.js.JavaScriptBody;
     2.8  import org.apidesign.html.boot.impl.FnUtils;
     2.9  import org.apidesign.html.boot.spi.Fn;
    2.10  import org.apidesign.html.boot.impl.FindResources;
    2.11  
    2.12 -/**
    2.13 +/** Use this builder to launch your Java/HTML based application. Typical
    2.14 + * usage in a main method of your application looks like this: 
    2.15 + * <pre>
    2.16 + * 
    2.17 + * <b>public static void</b> <em>main</em>(String... args) {
    2.18 + *     BrowserBuilder.{@link #newBrowser}.
    2.19 + *          {@link #loadClass(java.lang.Class) loadClass(YourMain.class)}.
    2.20 + *          {@link #loadPage(java.lang.String) loadPage("index.html")}.
    2.21 + *          {@link #invoke(java.lang.String, java.lang.String[]) invoke("initialized", args)}.
    2.22 + *          {@link #showAndWait()};
    2.23 + *     System.exit(0);
    2.24 + * }
    2.25 + * </pre>
    2.26 + * The above will load <code>YourMain</code> class via
    2.27 + * a special classloader, it will locate an <code>index.html</code> (relative
    2.28 + * to <code>YourMain</code> class) and show it in a browser window. When the
    2.29 + * initialization is over, a <b>public static</b> method <em>initialized</em>
    2.30 + * in <code>YourMain</code> will be called with provided string parameters.
    2.31 + * <p>
    2.32 + * This module provides only API for building browsers. To use it properly one
    2.33 + * also needs an implementation on the classpath of one's application. For example
    2.34 + * use: <pre>
    2.35 + * &lt;dependency&gt;
    2.36 + *   &lt;groupId&gt;org.apidesign.html&lt;/groupId&gt;
    2.37 + *   &lt;artifactId&gt;boot-fx&lt;/artifactId&gt;
    2.38 + *   &lt;scope&gt;runtime&lt;/scope&gt;
    2.39 + * &lt;/dependency&gt;
    2.40 + * </pre>
    2.41   *
    2.42   * @author Jaroslav Tulach <jtulach@netbeans.org>
    2.43   */
    2.44 @@ -50,31 +78,68 @@
    2.45      
    2.46      private BrowserBuilder() {
    2.47      }
    2.48 -    
    2.49 +
    2.50 +    /** Entry method to obtain a new browser builder. Follow by calling 
    2.51 +     * its instance methods like {@link #loadClass(java.lang.Class)} and
    2.52 +     * {@link #loadPage(java.lang.String)}.
    2.53 +     * 
    2.54 +     * @return new browser builder
    2.55 +     */
    2.56      public static BrowserBuilder newBrowser() {
    2.57          return new BrowserBuilder();
    2.58      }
    2.59      
    2.60 -    public BrowserBuilder loadPage(String resource) {
    2.61 -        this.resource = resource;
    2.62 -        return this;
    2.63 -    }
    2.64 -    
    2.65 +    /** The class to load when the browser is initialized. This class
    2.66 +     * is loaded by a special classloader (that supports {@link JavaScriptBody}
    2.67 +     * and co.). 
    2.68 +     * 
    2.69 +     * @param mainClass the class to load and resolve when the browser is ready
    2.70 +     * @return this builder
    2.71 +     */
    2.72      public BrowserBuilder loadClass(Class<?> mainClass) {
    2.73          this.clazz = mainClass;
    2.74          return this;
    2.75      }
    2.76  
    2.77 -    // invoked on browser thread
    2.78 +    /** Page to load into the browser. If the <code>page</code> represents
    2.79 +     * a {@link URL} known to the Java system, the URL is passed to the browser. 
    2.80 +     * Otherwise the system seeks for the resource via {@link Class#getResource(java.lang.String)}
    2.81 +     * method.
    2.82 +     * 
    2.83 +     * @param page the location (relative, absolute, or URL) of a page to load
    2.84 +     * @return this browser
    2.85 +     */
    2.86 +    public BrowserBuilder loadPage(String page) {
    2.87 +        this.resource = page;
    2.88 +        return this;
    2.89 +    }
    2.90 +    
    2.91 +    /** Specifies callback method to notify the application that the browser is ready.
    2.92 +     * There should be a <b>public static</b> method in the class specified
    2.93 +     * by {@link #loadClass(java.lang.Class)} which takes an array of {@link String}
    2.94 +     * argument. The method is called on the browser dispatch thread one
    2.95 +     * the browser finishes loading of the {@link #loadPage(java.lang.String) HTML page}.
    2.96 +     * 
    2.97 +     * @param methodName name of a method to seek for
    2.98 +     * @param args parameters to pass to the method
    2.99 +     * @return this builder
   2.100 +     */
   2.101      public BrowserBuilder invoke(String methodName, String... args) {
   2.102          this.methodName = methodName;
   2.103          this.methodArgs = args;
   2.104          return this;
   2.105      }
   2.106 -    
   2.107 +
   2.108 +    /** Shows the browser, loads specified page in and executes the 
   2.109 +     * {@link #invoke(java.lang.String, java.lang.String[]) initialization method}.
   2.110 +     * The method returns when the browser is closed.
   2.111 +     * 
   2.112 +     * @throws NullPointerException if some of essential parameters (like {@link #loadPage(java.lang.String) page} or
   2.113 +     *    {@link #loadClass(java.lang.Class) class} have not been specified
   2.114 +     */
   2.115      public void showAndWait() {
   2.116          if (resource == null) {
   2.117 -            throw new IllegalStateException("Need to specify resource via loadPage method");
   2.118 +            throw new NullPointerException("Need to specify resource via loadPage method");
   2.119          }
   2.120          
   2.121          FImpl impl = new FImpl(clazz.getClassLoader());
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/boot/src/main/java/net/java/html/boot/package.html	Wed Jun 26 17:17:42 2013 +0200
     3.3 @@ -0,0 +1,28 @@
     3.4 +<!--
     3.5 +
     3.6 +    HTML via Java(tm) Language Bindings
     3.7 +    Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     3.8 +
     3.9 +    This program is free software: you can redistribute it and/or modify
    3.10 +    it under the terms of the GNU General Public License as published by
    3.11 +    the Free Software Foundation, version 2 of the License.
    3.12 +
    3.13 +    This program is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.16 +    GNU General Public License for more details. apidesign.org
    3.17 +    designates this particular file as subject to the
    3.18 +    "Classpath" exception as provided by apidesign.org
    3.19 +    in the License file that accompanied this code.
    3.20 +
    3.21 +    You should have received a copy of the GNU General Public License
    3.22 +    along with this program. Look for COPYING file in the top folder.
    3.23 +    If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
    3.24 +
    3.25 +-->
    3.26 +<!DOCTYPE html>
    3.27 +<html>
    3.28 +    <body>
    3.29 +        <div>Builder class to bootstrap your Java/HTML based application</div>
    3.30 +    </body>
    3.31 +</html>
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/boot/src/main/java/net/java/html/js/package.html	Wed Jun 26 17:17:42 2013 +0200
     4.3 @@ -0,0 +1,28 @@
     4.4 +<!--
     4.5 +
     4.6 +    HTML via Java(tm) Language Bindings
     4.7 +    Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4.8 +
     4.9 +    This program is free software: you can redistribute it and/or modify
    4.10 +    it under the terms of the GNU General Public License as published by
    4.11 +    the Free Software Foundation, version 2 of the License.
    4.12 +
    4.13 +    This program is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.16 +    GNU General Public License for more details. apidesign.org
    4.17 +    designates this particular file as subject to the
    4.18 +    "Classpath" exception as provided by apidesign.org
    4.19 +    in the License file that accompanied this code.
    4.20 +
    4.21 +    You should have received a copy of the GNU General Public License
    4.22 +    along with this program. Look for COPYING file in the top folder.
    4.23 +    If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
    4.24 +
    4.25 +-->
    4.26 +<!DOCTYPE html>
    4.27 +<html>
    4.28 +    <body>
    4.29 +        <div>Essential support for those who write <em>native</em> methods communicating directly with JavaScript</div>
    4.30 +    </body>
    4.31 +</html>