Archiving static compilation demo
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 24 Dec 2012 07:51:15 +0100
changeset 37352386a70f9d9
parent 340 785b53689e29
child 374 e5b4bd29f268
Archiving static compilation demo
javaquery/demo-static-calculator/nbactions.xml
javaquery/demo-static-calculator/pom.xml
javaquery/demo-static-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java
javaquery/demo-static-calculator/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml
javaquery/pom.xml
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/javaquery/demo-static-calculator/nbactions.xml	Mon Dec 24 07:51:15 2012 +0100
     1.3 @@ -0,0 +1,29 @@
     1.4 +<?xml version="1.0" encoding="UTF-8"?>
     1.5 +<!--
     1.6 +
     1.7 +    Back 2 Browser Bytecode Translator
     1.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.9 +
    1.10 +    This program is free software: you can redistribute it and/or modify
    1.11 +    it under the terms of the GNU General Public License as published by
    1.12 +    the Free Software Foundation, version 2 of the License.
    1.13 +
    1.14 +    This program is distributed in the hope that it will be useful,
    1.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.17 +    GNU General Public License for more details.
    1.18 +
    1.19 +    You should have received a copy of the GNU General Public License
    1.20 +    along with this program. Look for COPYING file in the top folder.
    1.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
    1.22 +
    1.23 +-->
    1.24 +<actions>
    1.25 +        <action>
    1.26 +            <actionName>run</actionName>
    1.27 +            <goals>
    1.28 +                <goal>process-classes</goal>
    1.29 +                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
    1.30 +            </goals>
    1.31 +        </action>
    1.32 +    </actions>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/javaquery/demo-static-calculator/pom.xml	Mon Dec 24 07:51:15 2012 +0100
     2.3 @@ -0,0 +1,73 @@
     2.4 +<?xml version="1.0"?>
     2.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     2.6 +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     2.7 +  <modelVersion>4.0.0</modelVersion>
     2.8 +
     2.9 +  <groupId>org.apidesign.bck2brwsr</groupId>
    2.10 +  <artifactId>demo.static.calculator</artifactId>
    2.11 +  <version>0.3-SNAPSHOT</version>
    2.12 +  <packaging>jar</packaging>
    2.13 +
    2.14 +  <name>JavaQuery Demo - Calculator - Static Compilation</name>
    2.15 +  <url>http://maven.apache.org</url>
    2.16 +
    2.17 +  <properties>
    2.18 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    2.19 +  </properties>
    2.20 +  <build>
    2.21 +      <plugins>
    2.22 +          <plugin>
    2.23 +              <groupId>org.apidesign.bck2brwsr</groupId>
    2.24 +              <artifactId>mojo</artifactId>
    2.25 +              <version>0.3-SNAPSHOT</version>
    2.26 +              <executions>
    2.27 +                  <execution>
    2.28 +                      <goals>
    2.29 +                          <goal>j2js</goal>
    2.30 +                      </goals>
    2.31 +                  </execution>
    2.32 +              </executions>
    2.33 +          </plugin>
    2.34 +            <plugin>
    2.35 +                <groupId>org.codehaus.mojo</groupId>
    2.36 +                <artifactId>exec-maven-plugin</artifactId>
    2.37 +                <version>1.2.1</version>
    2.38 +                <executions>
    2.39 +                    <execution>
    2.40 +                        <goals>
    2.41 +                            <goal>exec</goal>
    2.42 +                        </goals>
    2.43 +                    </execution>
    2.44 +                </executions>
    2.45 +                <configuration>
    2.46 +                    <executable>xdg-open</executable>
    2.47 +                    <arguments>
    2.48 +                        <argument>${project.build.directory}/classes/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml</argument>
    2.49 +                    </arguments>
    2.50 +                </configuration>
    2.51 +            </plugin>
    2.52 +         <plugin>
    2.53 +            <groupId>org.apache.maven.plugins</groupId>
    2.54 +            <artifactId>maven-compiler-plugin</artifactId>
    2.55 +            <version>2.3.2</version>
    2.56 +            <configuration>
    2.57 +               <source>1.7</source>
    2.58 +               <target>1.7</target>
    2.59 +            </configuration>
    2.60 +         </plugin>
    2.61 +      </plugins>
    2.62 +  </build>
    2.63 +
    2.64 +  <dependencies>
    2.65 +    <dependency>
    2.66 +      <groupId>org.apidesign.bck2brwsr</groupId>
    2.67 +      <artifactId>emul</artifactId>
    2.68 +      <version>0.3-SNAPSHOT</version>
    2.69 +    </dependency>
    2.70 +    <dependency>
    2.71 +      <groupId>org.apidesign.bck2brwsr</groupId>
    2.72 +      <artifactId>javaquery.api</artifactId>
    2.73 +      <version>0.3-SNAPSHOT</version>
    2.74 +    </dependency>
    2.75 +  </dependencies>
    2.76 +</project>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/javaquery/demo-static-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java	Mon Dec 24 07:51:15 2012 +0100
     3.3 @@ -0,0 +1,88 @@
     3.4 +/**
     3.5 + * Back 2 Browser Bytecode Translator
     3.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     3.7 + *
     3.8 + * This program is free software: you can redistribute it and/or modify
     3.9 + * it under the terms of the GNU General Public License as published by
    3.10 + * the Free Software Foundation, version 2 of the License.
    3.11 + *
    3.12 + * This program is distributed in the hope that it will be useful,
    3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.15 + * GNU General Public License for more details.
    3.16 + *
    3.17 + * You should have received a copy of the GNU General Public License
    3.18 + * along with this program. Look for COPYING file in the top folder.
    3.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    3.20 + */
    3.21 +package org.apidesign.bck2brwsr.mavenhtml;
    3.22 +
    3.23 +import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
    3.24 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
    3.25 +
    3.26 +/** HTML5 & Java demo showing the power of 
    3.27 + * <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
    3.28 + * as well as other goodies.
    3.29 + * 
    3.30 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    3.31 + */
    3.32 +@Page(xhtml="Calculator.xhtml")
    3.33 +public class App {
    3.34 +    private static double memory;
    3.35 +    private static String operation;
    3.36 +    
    3.37 +    @OnClick(id="clear")
    3.38 +    static void clear() {
    3.39 +        memory = 0;
    3.40 +        operation = null;
    3.41 +        Calculator.DISPLAY.setValue("0");
    3.42 +    }
    3.43 +    
    3.44 +    @OnClick(id= { "plus", "minus", "mul", "div" })
    3.45 +    static void applyOp(String op) {
    3.46 +        memory = getValue();
    3.47 +        operation = op;
    3.48 +        Calculator.DISPLAY.setValue("0");
    3.49 +    }
    3.50 +    
    3.51 +    @OnClick(id="result")
    3.52 +    static void computeTheValue() {
    3.53 +        switch (operation) {
    3.54 +            case "plus": setValue(memory + getValue()); break;
    3.55 +            case "minus": setValue(memory - getValue()); break;
    3.56 +            case "mul": setValue(memory * getValue()); break;
    3.57 +            case "div": setValue(memory / getValue()); break;
    3.58 +            default: throw new IllegalStateException(operation);
    3.59 +        }
    3.60 +    }
    3.61 +    
    3.62 +    @OnClick(id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) 
    3.63 +    static void addDigit(String digit) {
    3.64 +        digit = digit.substring(1);
    3.65 +        String v = Calculator.DISPLAY.getValue();
    3.66 +        if (getValue() == 0.0) {
    3.67 +            Calculator.DISPLAY.setValue(digit);
    3.68 +        } else {
    3.69 +            Calculator.DISPLAY.setValue(v + digit);
    3.70 +        }
    3.71 +    }
    3.72 +    
    3.73 +    private static void setValue(double v) {
    3.74 +        StringBuilder sb = new StringBuilder();
    3.75 +        sb.append(v);
    3.76 +        if (sb.toString().endsWith(".0")) {
    3.77 +            final int l = sb.length();
    3.78 +            sb.delete(l - 2, l);
    3.79 +        }
    3.80 +        Calculator.DISPLAY.setValue(sb.toString());
    3.81 +    }
    3.82 +
    3.83 +    private static double getValue() {
    3.84 +        try {
    3.85 +            return Double.parseDouble(Calculator.DISPLAY.getValue());
    3.86 +        } catch (NumberFormatException ex) {
    3.87 +            Calculator.DISPLAY.setValue("err");
    3.88 +            return 0.0;
    3.89 +        }
    3.90 +    }
    3.91 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/javaquery/demo-static-calculator/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml	Mon Dec 24 07:51:15 2012 +0100
     4.3 @@ -0,0 +1,154 @@
     4.4 +<?xml version="1.0" encoding="UTF-8"?>
     4.5 +<!--
     4.6 +
     4.7 +    Back 2 Browser Bytecode Translator
     4.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4.9 +
    4.10 +    This program is free software: you can redistribute it and/or modify
    4.11 +    it under the terms of the GNU General Public License as published by
    4.12 +    the Free Software Foundation, version 2 of the License.
    4.13 +
    4.14 +    This program is distributed in the hope that it will be useful,
    4.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.17 +    GNU General Public License for more details.
    4.18 +
    4.19 +    You should have received a copy of the GNU General Public License
    4.20 +    along with this program. Look for COPYING file in the top folder.
    4.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
    4.22 +
    4.23 +-->
    4.24 +<!DOCTYPE html>
    4.25 +<html xmlns="http://www.w3.org/1999/xhtml">
    4.26 +    <head>
    4.27 +        <title>Simple Calculator in HTML5 and Java</title>
    4.28 +
    4.29 +        <style type="text/css">
    4.30 +        body {color: #ffffff; background-color: #121e31; font-family: Monospaced}
    4.31 +        pre {color: #ffffff; background-color: #121e31; font-family: Monospaced}
    4.32 +        table {color: #ffffff; background-color: #121e31; font-family: Monospaced}
    4.33 +        .string {color: #e2ce00}
    4.34 +        a {color: #e2ce00}
    4.35 +        .ST1 {color: #0000cc; font-family: Monospaced; font-weight: bold}
    4.36 +        .ST0 {color: #0000ff}
    4.37 +        .comment {color: #428bdd}
    4.38 +        .keyword-directive {color: #f8bb00}
    4.39 +        .tag {color: #f8bb00}
    4.40 +        .ST0 {color: #628fb5; background-color: #1b3450}
    4.41 +        .sgml-comment {color: #808080}
    4.42 +        .value {color: #99006b}
    4.43 +        .argument {color: #007c00}
    4.44 +        .sgml-declaration {color: #bf9221}
    4.45 +        </style>    
    4.46 +        </head>
    4.47 +    <body>
    4.48 +        <h1>Java and HTML5 - Together at Last!</h1>
    4.49 +        <table border="0" cellspacing="2">
    4.50 +            <tbody>
    4.51 +                <tr>
    4.52 +                    <td colspan="4"><input id="display" value="0" 
    4.53 +                            style="text-align: right"/>
    4.54 +                </td>
    4.55 +                </tr>
    4.56 +                <tr>
    4.57 +                    <td><button id="n1">1</button></td>
    4.58 +                    <td><button id="n2">2</button></td>
    4.59 +                    <td><button id="n3">3</button></td>
    4.60 +                    <td><button id="plus">+</button></td>
    4.61 +                </tr>
    4.62 +                <tr>
    4.63 +                    <td><button id="n4">4</button></td>
    4.64 +                    <td><button id="n5">5</button></td>
    4.65 +                    <td><button id="n6">6</button></td>
    4.66 +                    <td><button id="minus">-</button></td>
    4.67 +                </tr>
    4.68 +                <tr>
    4.69 +                    <td><button id="n7">7</button></td>
    4.70 +                    <td><button id="n8">8</button></td>
    4.71 +                    <td><button id="n9">9</button></td>
    4.72 +                    <td><button id="mul">*</button></td>
    4.73 +                </tr>
    4.74 +                <tr>
    4.75 +                    <td><button id="clear">C</button></td>
    4.76 +                    <td><button id="n0">0</button></td>
    4.77 +                    <td><button id="result">=</button></td>
    4.78 +                    <td><button id="div">/</button></td>
    4.79 +                </tr>
    4.80 +            </tbody>
    4.81 +        </table>
    4.82 +
    4.83 +        <script src="bootjava.js"/>
    4.84 +        
    4.85 +        <hr/>
    4.86 +    <pre>
    4.87 +    <span class="keyword-directive">package</span> org.apidesign.bck2brwsr.mavenhtml;
    4.88 +
    4.89 +    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.OnClick;
    4.90 +    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.Page;
    4.91 +
    4.92 +    <span class="comment">/**</span> <span class="comment">HTML5</span><span class="comment"> &amp; </span><span class="comment">Java</span> <span class="comment">demo</span> <span class="comment">showing</span> <span class="comment">the</span> <span class="comment">power</span> <span class="comment">of</span> <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
    4.93 +    <span class="comment"> * </span><span class="comment">as</span> <span class="comment">well</span> <span class="comment">as</span> <span class="comment">other</span> <span class="comment">goodies</span><span class="comment">, including type-safe association between</span>
    4.94 +    <span class="comment"> * </span><span class="comment">an XHTML page and Java.</span>
    4.95 +    <span class="comment"> * </span>
    4.96 +    <span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">Jaroslav</span> <span class="comment">Tulach</span> <span class="ST0">&lt;jaroslav.tulach@apidesign.org&gt;</span>
    4.97 +     <span class="comment">*/</span>
    4.98 +    @Page(xhtml=<span class="string">&quot;</span><span class="string">Calculator.xhtml</span><span class="string">&quot;</span>)
    4.99 +    <span class="keyword-directive">public</span> <span class="keyword-directive">class</span> App {
   4.100 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> memory;
   4.101 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> String operation;
   4.102 +
   4.103 +        @OnClick(id=<span class="string">&quot;</span><span class="string">clear</span><span class="string">&quot;</span>)
   4.104 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> clear() {
   4.105 +            memory = <span class="number">0</span>;
   4.106 +            operation = <span class="keyword-directive">null</span>;
   4.107 +            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
   4.108 +        }
   4.109 +
   4.110 +        @OnClick(id= { <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span> })
   4.111 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> applyOp(String op) {
   4.112 +            memory = getValue();
   4.113 +            operation = op;
   4.114 +            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
   4.115 +        }
   4.116 +
   4.117 +        @OnClick(id=<span class="string">&quot;</span><span class="string">result</span><span class="string">&quot;</span>)
   4.118 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> computeTheValue() {
   4.119 +            <span class="keyword-directive">switch</span> (operation) {
   4.120 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>: setValue(memory + getValue()); <span class="keyword-directive">break</span>;
   4.121 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>: setValue(memory - getValue()); <span class="keyword-directive">break</span>;
   4.122 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>: setValue(memory * getValue()); <span class="keyword-directive">break</span>;
   4.123 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span>: setValue(memory / getValue()); <span class="keyword-directive">break</span>;
   4.124 +                <span class="keyword-directive">default</span>: <span class="keyword-directive">throw</span> <span class="keyword-directive">new</span> IllegalStateException(operation);
   4.125 +            }
   4.126 +        }
   4.127 +
   4.128 +        @OnClick(id={<span class="string">&quot;</span><span class="string">n0</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n1</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n2</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n3</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n4</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n5</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n6</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n7</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n8</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n9</span><span class="string">&quot;</span>}) 
   4.129 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> addDigit(String digit) {
   4.130 +            digit = digit.substring(<span class="number">1</span>);
   4.131 +            String v = Calculator.DISPLAY.getValue();
   4.132 +            <span class="keyword-directive">if</span> (getValue() == <span class="number">0.0</span>) {
   4.133 +                Calculator.DISPLAY.setValue(digit);
   4.134 +            } <span class="keyword-directive">else</span> {
   4.135 +                Calculator.DISPLAY.setValue(v + digit);
   4.136 +            }
   4.137 +        }
   4.138 +
   4.139 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> setValue(<span class="keyword-directive">double</span> v) {
   4.140 +            StringBuilder sb = <span class="keyword-directive">new</span> StringBuilder();
   4.141 +            sb.append(v);
   4.142 +            Calculator.DISPLAY.setValue(sb.toString());
   4.143 +        }
   4.144 +
   4.145 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> getValue() {
   4.146 +            <span class="keyword-directive">try</span> {
   4.147 +                <span class="keyword-directive">return</span> Double.parseDouble(Calculator.DISPLAY.getValue());
   4.148 +            } <span class="keyword-directive">catch</span> (NumberFormatException ex) {
   4.149 +                Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">err</span><span class="string">&quot;</span>);
   4.150 +                <span class="keyword-directive">return</span> <span class="number">0.0</span>;
   4.151 +            }
   4.152 +        }
   4.153 +    }
   4.154 +
   4.155 +    </pre>
   4.156 +    </body>
   4.157 +</html>
     5.1 --- a/javaquery/pom.xml	Mon Dec 17 10:05:55 2012 +0100
     5.2 +++ b/javaquery/pom.xml	Mon Dec 24 07:51:15 2012 +0100
     5.3 @@ -14,5 +14,6 @@
     5.4      <modules>
     5.5          <module>api</module>
     5.6          <module>demo-calculator</module>
     5.7 +        <module>demo-static-calculator</module>
     5.8      </modules>
     5.9  </project>