During the API review process (bug 246133) the reviewers decided that in order to include html4j to NetBeans Platform, we need to stop using org.apidesign namespace and switch to NetBeans one. Repackaging all SPI packages into org.netbeans.html.smthng.spi.
1.1 --- a/boot-fx/src/main/java/org/netbeans/html/boot/fx/AbstractFXPresenter.java Tue Aug 26 17:43:37 2014 +0200
1.2 +++ b/boot-fx/src/main/java/org/netbeans/html/boot/fx/AbstractFXPresenter.java Tue Aug 26 18:13:30 2014 +0200
1.3 @@ -61,7 +61,7 @@
1.4 import javafx.scene.web.WebEngine;
1.5 import javafx.scene.web.WebView;
1.6 import netscape.javascript.JSObject;
1.7 -import org.apidesign.html.boot.spi.Fn;
1.8 +import org.netbeans.html.boot.spi.Fn;
1.9
1.10 /**
1.11 *
2.1 --- a/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXPresenter.java Tue Aug 26 17:43:37 2014 +0200
2.2 +++ b/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXPresenter.java Tue Aug 26 18:13:30 2014 +0200
2.3 @@ -48,7 +48,7 @@
2.4 import java.net.URLClassLoader;
2.5 import javafx.scene.web.WebView;
2.6 import net.java.html.boot.BrowserBuilder;
2.7 -import org.apidesign.html.boot.spi.Fn;
2.8 +import org.netbeans.html.boot.spi.Fn;
2.9 import org.openide.util.lookup.ServiceProvider;
2.10
2.11 /** This is an implementation class, use {@link BrowserBuilder} API. Just
3.1 --- a/boot-fx/src/test/java/org/netbeans/html/boot/fx/BootstrapTest.java Tue Aug 26 17:43:37 2014 +0200
3.2 +++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/BootstrapTest.java Tue Aug 26 18:13:30 2014 +0200
3.3 @@ -49,9 +49,9 @@
3.4 import java.util.concurrent.Executors;
3.5 import net.java.html.BrwsrCtx;
3.6 import net.java.html.boot.BrowserBuilder;
3.7 -import org.apidesign.html.boot.spi.Fn;
3.8 -import org.apidesign.html.context.spi.Contexts;
3.9 -import org.apidesign.html.json.tck.KOTest;
3.10 +import org.netbeans.html.boot.spi.Fn;
3.11 +import org.netbeans.html.context.spi.Contexts;
3.12 +import org.netbeans.html.json.tck.KOTest;
3.13 import org.openide.util.lookup.ServiceProvider;
3.14 import org.testng.Assert;
3.15 import static org.testng.Assert.assertNotSame;
4.1 --- a/boot-fx/src/test/java/org/netbeans/html/boot/fx/FXJavaScriptTest.java Tue Aug 26 17:43:37 2014 +0200
4.2 +++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/FXJavaScriptTest.java Tue Aug 26 18:13:30 2014 +0200
4.3 @@ -48,8 +48,8 @@
4.4 import java.util.List;
4.5 import java.util.concurrent.Executors;
4.6 import net.java.html.boot.BrowserBuilder;
4.7 -import org.apidesign.html.boot.spi.Fn;
4.8 -import org.apidesign.html.json.tck.KOTest;
4.9 +import org.netbeans.html.boot.spi.Fn;
4.10 +import org.netbeans.html.json.tck.KOTest;
4.11 import org.testng.Assert;
4.12 import org.testng.annotations.Factory;
4.13
5.1 --- a/boot-fx/src/test/java/org/netbeans/html/boot/fx/FxJavaScriptTst.java Tue Aug 26 17:43:37 2014 +0200
5.2 +++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/FxJavaScriptTst.java Tue Aug 26 18:13:30 2014 +0200
5.3 @@ -42,7 +42,7 @@
5.4 */
5.5 package org.netbeans.html.boot.fx;
5.6
5.7 -import org.apidesign.html.json.tck.JavaScriptTCK;
5.8 +import org.netbeans.html.json.tck.JavaScriptTCK;
5.9
5.10 /**
5.11 *
6.1 --- a/boot-fx/src/test/java/org/netbeans/html/boot/fx/KOFx.java Tue Aug 26 17:43:37 2014 +0200
6.2 +++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/KOFx.java Tue Aug 26 18:13:30 2014 +0200
6.3 @@ -46,7 +46,7 @@
6.4 import java.lang.reflect.Method;
6.5 import javafx.application.Platform;
6.6 import org.netbeans.html.boot.impl.FnContext;
6.7 -import org.apidesign.html.boot.spi.Fn;
6.8 +import org.netbeans.html.boot.spi.Fn;
6.9 import org.testng.IHookCallBack;
6.10 import org.testng.IHookable;
6.11 import org.testng.ITest;
7.1 --- a/boot-fx/src/test/java/org/netbeans/html/boot/fx/ReloadTest.java Tue Aug 26 17:43:37 2014 +0200
7.2 +++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/ReloadTest.java Tue Aug 26 18:13:30 2014 +0200
7.3 @@ -48,7 +48,7 @@
7.4 import net.java.html.BrwsrCtx;
7.5 import net.java.html.boot.BrowserBuilder;
7.6 import net.java.html.js.JavaScriptBody;
7.7 -import org.apidesign.html.boot.spi.Fn;
7.8 +import org.netbeans.html.boot.spi.Fn;
7.9 import static org.testng.Assert.*;
7.10 import org.testng.annotations.Test;
7.11
8.1 --- a/boot-fx/src/test/java/org/netbeans/html/boot/fx/TestingProvider.java Tue Aug 26 17:43:37 2014 +0200
8.2 +++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/TestingProvider.java Tue Aug 26 18:13:30 2014 +0200
8.3 @@ -42,7 +42,7 @@
8.4 */
8.5 package org.netbeans.html.boot.fx;
8.6
8.7 -import org.apidesign.html.context.spi.Contexts;
8.8 +import org.netbeans.html.context.spi.Contexts;
8.9 import org.openide.util.lookup.ServiceProvider;
8.10 import static org.testng.Assert.assertTrue;
8.11
9.1 --- a/boot-script/src/main/java/net/java/html/boot/script/ScriptPresenter.java Tue Aug 26 17:43:37 2014 +0200
9.2 +++ b/boot-script/src/main/java/net/java/html/boot/script/ScriptPresenter.java Tue Aug 26 18:13:30 2014 +0200
9.3 @@ -55,8 +55,8 @@
9.4 import javax.script.ScriptEngine;
9.5 import javax.script.ScriptEngineManager;
9.6 import javax.script.ScriptException;
9.7 -import org.apidesign.html.boot.spi.Fn;
9.8 -import org.apidesign.html.boot.spi.Fn.Presenter;
9.9 +import org.netbeans.html.boot.spi.Fn;
9.10 +import org.netbeans.html.boot.spi.Fn.Presenter;
9.11
9.12 /** Implementation of {@link Presenter} that delegates
9.13 * to Java {@link ScriptEngine scripting} API. The presenter runs headless
10.1 --- a/boot-script/src/main/java/net/java/html/boot/script/Scripts.java Tue Aug 26 17:43:37 2014 +0200
10.2 +++ b/boot-script/src/main/java/net/java/html/boot/script/Scripts.java Tue Aug 26 18:13:30 2014 +0200
10.3 @@ -47,8 +47,8 @@
10.4 import javax.script.ScriptEngine;
10.5 import net.java.html.boot.BrowserBuilder;
10.6 import net.java.html.js.JavaScriptBody;
10.7 -import org.apidesign.html.boot.spi.Fn;
10.8 -import org.apidesign.html.boot.spi.Fn.Presenter;
10.9 +import org.netbeans.html.boot.spi.Fn;
10.10 +import org.netbeans.html.boot.spi.Fn.Presenter;
10.11
10.12 /** Implementations of {@link Presenter}s that delegate
10.13 * to Java {@link ScriptEngine scripting} API. Initialize your presenter
10.14 @@ -71,7 +71,7 @@
10.15 * <pre>
10.16 * {@code @Test} public void runInASimulatedBrowser() throws Exception {
10.17 * {@link Presenter Fn.Presenter} <b>p</b> = Scripts.{@link Scripts#createPresenter()};
10.18 - * try ({@link Closeable} c = {@link Fn#activate(org.apidesign.html.boot.spi.Fn.Presenter) Fn.activate}(<b>p</b>)) {
10.19 + * try ({@link Closeable} c = {@link Fn#activate(org.netbeans.html.boot.spi.Fn.Presenter) Fn.activate}(<b>p</b>)) {
10.20 * // your code operating in context of <b>p</b>
10.21 * }
10.22 * }
11.1 --- a/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java Tue Aug 26 17:43:37 2014 +0200
11.2 +++ b/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java Tue Aug 26 18:13:30 2014 +0200
11.3 @@ -48,8 +48,8 @@
11.4 import java.util.List;
11.5 import java.util.concurrent.Executors;
11.6 import net.java.html.boot.BrowserBuilder;
11.7 -import org.apidesign.html.boot.spi.Fn;
11.8 -import org.apidesign.html.json.tck.KOTest;
11.9 +import org.netbeans.html.boot.spi.Fn;
11.10 +import org.netbeans.html.json.tck.KOTest;
11.11 import org.testng.Assert;
11.12 import org.testng.annotations.Factory;
11.13
12.1 --- a/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTst.java Tue Aug 26 17:43:37 2014 +0200
12.2 +++ b/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTst.java Tue Aug 26 18:13:30 2014 +0200
12.3 @@ -42,7 +42,7 @@
12.4 */
12.5 package net.java.html.boot.script;
12.6
12.7 -import org.apidesign.html.json.tck.JavaScriptTCK;
12.8 +import org.netbeans.html.json.tck.JavaScriptTCK;
12.9
12.10 /**
12.11 *
13.1 --- a/boot-script/src/test/java/net/java/html/boot/script/SingleCase.java Tue Aug 26 17:43:37 2014 +0200
13.2 +++ b/boot-script/src/test/java/net/java/html/boot/script/SingleCase.java Tue Aug 26 18:13:30 2014 +0200
13.3 @@ -46,7 +46,7 @@
13.4 import java.lang.reflect.Method;
13.5 import java.util.concurrent.Executor;
13.6 import java.util.concurrent.Executors;
13.7 -import org.apidesign.html.boot.spi.Fn;
13.8 +import org.netbeans.html.boot.spi.Fn;
13.9 import org.netbeans.html.boot.impl.FnContext;
13.10 import org.testng.IHookCallBack;
13.11 import org.testng.IHookable;
14.1 --- a/boot-script/src/test/java/net/java/html/boot/script/ko4j/KOCase.java Tue Aug 26 17:43:37 2014 +0200
14.2 +++ b/boot-script/src/test/java/net/java/html/boot/script/ko4j/KOCase.java Tue Aug 26 18:13:30 2014 +0200
14.3 @@ -50,7 +50,7 @@
14.4 import java.util.concurrent.Executors;
14.5 import java.util.logging.Level;
14.6 import java.util.logging.Logger;
14.7 -import org.apidesign.html.boot.spi.Fn;
14.8 +import org.netbeans.html.boot.spi.Fn;
14.9 import org.testng.ITest;
14.10 import org.testng.SkipException;
14.11 import org.testng.annotations.Test;
15.1 --- a/boot-script/src/test/java/net/java/html/boot/script/ko4j/KnockoutEnvJSTest.java Tue Aug 26 17:43:37 2014 +0200
15.2 +++ b/boot-script/src/test/java/net/java/html/boot/script/ko4j/KnockoutEnvJSTest.java Tue Aug 26 18:13:30 2014 +0200
15.3 @@ -61,12 +61,12 @@
15.4 import net.java.html.boot.BrowserBuilder;
15.5 import net.java.html.boot.script.Scripts;
15.6 import net.java.html.js.JavaScriptBody;
15.7 -import org.apidesign.html.boot.spi.Fn;
15.8 -import org.apidesign.html.context.spi.Contexts;
15.9 -import org.apidesign.html.json.spi.Technology;
15.10 -import org.apidesign.html.json.spi.Transfer;
15.11 -import org.apidesign.html.json.tck.KOTest;
15.12 -import org.apidesign.html.json.tck.KnockoutTCK;
15.13 +import org.netbeans.html.boot.spi.Fn;
15.14 +import org.netbeans.html.context.spi.Contexts;
15.15 +import org.netbeans.html.json.spi.Technology;
15.16 +import org.netbeans.html.json.spi.Transfer;
15.17 +import org.netbeans.html.json.tck.KOTest;
15.18 +import org.netbeans.html.json.tck.KnockoutTCK;
15.19 import org.netbeans.html.ko4j.KO4J;
15.20 import org.netbeans.html.wstyrus.TyrusContext;
15.21 import org.openide.util.lookup.ServiceProvider;
16.1 --- a/boot/pom.xml Tue Aug 26 17:43:37 2014 +0200
16.2 +++ b/boot/pom.xml Tue Aug 26 18:13:30 2014 +0200
16.3 @@ -14,7 +14,7 @@
16.4 <url>http://maven.apache.org</url>
16.5 <properties>
16.6 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16.7 - <publicPackages>net.java.html.js,net.java.html.boot,org.apidesign.html.boot.spi</publicPackages>
16.8 + <publicPackages>net.java.html.js,net.java.html.boot,org.netbeans.html.boot.spi</publicPackages>
16.9 </properties>
16.10 <build>
16.11 <plugins>
17.1 --- a/boot/src/main/java/net/java/html/boot/BrowserBuilder.java Tue Aug 26 17:43:37 2014 +0200
17.2 +++ b/boot/src/main/java/net/java/html/boot/BrowserBuilder.java Tue Aug 26 18:13:30 2014 +0200
17.3 @@ -62,8 +62,8 @@
17.4 import java.util.logging.Logger;
17.5 import net.java.html.BrwsrCtx;
17.6 import net.java.html.js.JavaScriptBody;
17.7 -import org.apidesign.html.boot.spi.Fn;
17.8 -import org.apidesign.html.context.spi.Contexts;
17.9 +import org.netbeans.html.boot.spi.Fn;
17.10 +import org.netbeans.html.context.spi.Contexts;
17.11 import org.netbeans.html.boot.impl.FindResources;
17.12 import org.netbeans.html.boot.impl.FnContext;
17.13 import org.netbeans.html.boot.impl.FnUtils;
17.14 @@ -211,7 +211,7 @@
17.15
17.16 /** Loader to use when searching for classes to initialize.
17.17 * If specified, this loader is going to be used to load {@link Fn.Presenter}
17.18 - * and {@link Contexts#fillInByProviders(java.lang.Class, org.apidesign.html.context.spi.Contexts.Builder) fill} {@link BrwsrCtx} in.
17.19 + * and {@link Contexts#fillInByProviders(java.lang.Class, org.netbeans.html.context.spi.Contexts.Builder) fill} {@link BrwsrCtx} in.
17.20 * Specifying special classloader may be useful in modular systems,
17.21 * like OSGi, where one needs to load classes from many otherwise independent
17.22 * modules.
18.1 --- a/boot/src/main/java/net/java/html/js/package.html Tue Aug 26 17:43:37 2014 +0200
18.2 +++ b/boot/src/main/java/net/java/html/js/package.html Tue Aug 26 18:13:30 2014 +0200
18.3 @@ -202,7 +202,7 @@
18.4 Classes with {@link net.java.html.js.JavaScriptBody} annotated methods need to
18.5 be post processed before they can be used - e.g. their <code>native</code>
18.6 body needs to be generated to call into JavaScript (btw. the code is performed
18.7 - via {@link org.apidesign.html.boot.spi.Fn}). There are three ways
18.8 + via {@link org.netbeans.html.boot.spi.Fn}). There are three ways
18.9 such post processing can happen.
18.10 <p></p>
18.11 <b>Compile time</b> processing - this is the preferred method that
19.1 --- a/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java Tue Aug 26 17:43:37 2014 +0200
19.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
19.3 @@ -1,332 +0,0 @@
19.4 -/**
19.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
19.6 - *
19.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
19.8 - *
19.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
19.10 - * Other names may be trademarks of their respective owners.
19.11 - *
19.12 - * The contents of this file are subject to the terms of either the GNU
19.13 - * General Public License Version 2 only ("GPL") or the Common
19.14 - * Development and Distribution License("CDDL") (collectively, the
19.15 - * "License"). You may not use this file except in compliance with the
19.16 - * License. You can obtain a copy of the License at
19.17 - * http://www.netbeans.org/cddl-gplv2.html
19.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
19.19 - * specific language governing permissions and limitations under the
19.20 - * License. When distributing the software, include this License Header
19.21 - * Notice in each file and include the License file at
19.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
19.23 - * particular file as subject to the "Classpath" exception as provided
19.24 - * by Oracle in the GPL Version 2 section of the License file that
19.25 - * accompanied this code. If applicable, add the following below the
19.26 - * License Header, with the fields enclosed by brackets [] replaced by
19.27 - * your own identifying information:
19.28 - * "Portions Copyrighted [year] [name of copyright owner]"
19.29 - *
19.30 - * Contributor(s):
19.31 - *
19.32 - * The Original Software is NetBeans. The Initial Developer of the Original
19.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
19.34 - *
19.35 - * If you wish your version of this file to be governed by only the CDDL
19.36 - * or only the GPL Version 2, indicate your decision by adding
19.37 - * "[Contributor] elects to include this software in this distribution
19.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
19.39 - * single choice of license, a recipient has the option to distribute
19.40 - * your version of this file under either the CDDL, the GPL Version 2 or
19.41 - * to extend the choice of license to its licensees as provided above.
19.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
19.43 - * Version 2 license, then the option applies only if the new code is
19.44 - * made subject to such option by the copyright holder.
19.45 - */
19.46 -package org.apidesign.html.boot.spi;
19.47 -
19.48 -import java.io.Closeable;
19.49 -import java.io.IOException;
19.50 -import java.io.InputStream;
19.51 -import java.io.InputStreamReader;
19.52 -import java.io.Reader;
19.53 -import java.net.URL;
19.54 -import java.util.HashMap;
19.55 -import java.util.HashSet;
19.56 -import java.util.Map;
19.57 -import java.util.Set;
19.58 -import java.util.concurrent.Executor;
19.59 -import net.java.html.js.JavaScriptBody;
19.60 -import org.netbeans.html.boot.impl.FnContext;
19.61 -
19.62 -/** Represents single JavaScript function that can be invoked.
19.63 - * Created via {@link Presenter#defineFn(java.lang.String, java.lang.String...)}.
19.64 - *
19.65 - * @author Jaroslav Tulach
19.66 - */
19.67 -public abstract class Fn {
19.68 - private final Presenter presenter;
19.69 -
19.70 - /**
19.71 - * @deprecated Ineffective as of 0.6.
19.72 - * Provide a presenter via {@link #Fn(org.apidesign.html.boot.spi.Fn.Presenter)}
19.73 - * constructor
19.74 - */
19.75 - @Deprecated
19.76 - protected Fn() {
19.77 - this(null);
19.78 - }
19.79 -
19.80 - /** Creates new function object and associates it with given presenter.
19.81 - *
19.82 - * @param presenter the browser presenter associated with this function
19.83 - * @since 0.6
19.84 - */
19.85 - protected Fn(Presenter presenter) {
19.86 - this.presenter = presenter;
19.87 - }
19.88 -
19.89 - /** True, if currently active presenter is the same as presenter this
19.90 - * function has been created for via {@link #Fn(org.apidesign.html.boot.spi.Fn.Presenter)}.
19.91 - *
19.92 - * @return true, if proper presenter is used
19.93 - */
19.94 - public final boolean isValid() {
19.95 - return presenter != null && FnContext.currentPresenter(false) == presenter;
19.96 - }
19.97 -
19.98 - /** Helper method to check if the provided instance is valid function.
19.99 - * Checks if the parameter is non-null and if so, does {@link #isValid()}
19.100 - * check.
19.101 - *
19.102 - * @param fnOrNull function or <code>null</code>
19.103 - * @return true if the parameter is non-null and valid
19.104 - * @since 0.7
19.105 - */
19.106 - public static boolean isValid(Fn fnOrNull) {
19.107 - return fnOrNull != null && fnOrNull.isValid();
19.108 - }
19.109 -
19.110 - /** Helper method to find current presenter and ask it to define new
19.111 - * function by calling {@link Presenter#defineFn(java.lang.String, java.lang.String...)}.
19.112 - *
19.113 - * @param caller the class who wishes to define the function
19.114 - * @param code the body of the function (can reference <code>this</code> and <code>names</code> variables)
19.115 - * @param names names of individual parameters
19.116 - * @return the function object that can be {@link Fn#invoke(java.lang.Object, java.lang.Object...) invoked}
19.117 - * - can return <code>null</code> if there is {@link #activePresenter() no presenter}
19.118 - * @since 0.7
19.119 - */
19.120 - public static Fn define(Class<?> caller, String code, String... names) {
19.121 - final Presenter p = FnContext.currentPresenter(false);
19.122 - return p == null ? null : p.defineFn(code, names);
19.123 - }
19.124 -
19.125 - private static final Map<String,Set<Presenter>> LOADED = new HashMap<String, Set<Presenter>>();
19.126 -
19.127 - /** Wraps function to ensure that the script represented by <code>resource</code>
19.128 - * gets loaded into the browser environment before the function <code>fn</code>
19.129 - * is executed.
19.130 - *
19.131 - * @param fn original function to call (if <code>null</code> returns <code>null</code>)
19.132 - * @param caller the class who wishes to define/call the function
19.133 - * @param resource resources (accessible via {@link ClassLoader#getResource(java.lang.String)})
19.134 - * with a <em>JavaScript</em> that is supposed to loaded into the browser
19.135 - * environment
19.136 - * @return function that ensures the script is loaded and then delegates
19.137 - * to <code>fn</code>. Returns <code>null</code> if the input <code>fn</code> is null
19.138 - * @since 0.7
19.139 - */
19.140 - public static Fn preload(final Fn fn, final Class<?> caller, final String resource) {
19.141 - if (fn == null) {
19.142 - return null;
19.143 - }
19.144 - return new Fn(fn.presenter()) {
19.145 - @Override
19.146 - public Object invoke(Object thiz, Object... args) throws Exception {
19.147 - loadResource();
19.148 - return fn.invoke(thiz, args);
19.149 - }
19.150 -
19.151 - @Override
19.152 - public void invokeLater(Object thiz, Object... args) throws Exception {
19.153 - loadResource();
19.154 - fn.invokeLater(thiz, args);
19.155 - }
19.156 -
19.157 - private void loadResource() throws Exception {
19.158 - Presenter p = presenter();
19.159 - if (p == null) {
19.160 - p = FnContext.currentPresenter(false);
19.161 - }
19.162 - if (p != null) {
19.163 - Set<Presenter> there = LOADED.get(resource);
19.164 - if (there == null) {
19.165 - there = new HashSet<Presenter>();
19.166 - LOADED.put(resource, there);
19.167 - }
19.168 - if (there.add(p)) {
19.169 - final ClassLoader l = caller.getClassLoader();
19.170 - InputStream is = l.getResourceAsStream(resource);
19.171 - if (is == null && resource.startsWith("/")) {
19.172 - is = l.getResourceAsStream(resource.substring(1));
19.173 - }
19.174 - if (is == null) {
19.175 - throw new IOException("Cannot find " + resource + " in " + l);
19.176 - }
19.177 - try {
19.178 - InputStreamReader r = new InputStreamReader(is, "UTF-8");
19.179 - p.loadScript(r);
19.180 - } finally {
19.181 - is.close();
19.182 - }
19.183 - }
19.184 - }
19.185 - }
19.186 - };
19.187 - }
19.188 -
19.189 -
19.190 - /** The currently active presenter.
19.191 - *
19.192 - * @return the currently active presenter or <code>null</code>
19.193 - * @since 0.7
19.194 - */
19.195 - public static Presenter activePresenter() {
19.196 - return FnContext.currentPresenter(false);
19.197 - }
19.198 -
19.199 - /** Activates given presenter. Used to associate the native
19.200 - * JavaScript code specified by
19.201 - * {@link JavaScriptBody} annotation with certain presenter:
19.202 - * <pre>
19.203 - * try ({@link Closeable} c = Fn.activate(presenter)) {
19.204 - * doCallsInPresenterContext();
19.205 - * }
19.206 - * </pre>
19.207 - *
19.208 - * @param p the presenter that should be active until closable is closed
19.209 - * @return the closable to close
19.210 - * @since 0.7
19.211 - */
19.212 - public static Closeable activate(Presenter p) {
19.213 - return FnContext.activate(p);
19.214 - }
19.215 -
19.216 - /** Invokes the defined function with specified <code>this</code> and
19.217 - * appropriate arguments.
19.218 - *
19.219 - * @param thiz the meaning of <code>this</code> inside of the JavaScript
19.220 - * function - can be <code>null</code>
19.221 - * @param args arguments for the function
19.222 - * @return return value from the function
19.223 - * @throws Exception if something goes wrong, as exception may be thrown
19.224 - */
19.225 - public abstract Object invoke(Object thiz, Object... args) throws Exception;
19.226 -
19.227 - /** Invokes the defined function with specified <code>this</code> and
19.228 - * appropriate arguments asynchronously. The invocation may be
19.229 - * happen <em>"later"</em>.
19.230 - *
19.231 - * @param thiz the meaning of <code>this</code> inside of the JavaScript
19.232 - * function - can be <code>null</code>
19.233 - * @param args arguments for the function
19.234 - * @throws Exception if something goes wrong, as exception may be thrown
19.235 - * @since 0.7.6
19.236 - */
19.237 - public void invokeLater(Object thiz, Object... args) throws Exception {
19.238 - invoke(this, args);
19.239 - }
19.240 -
19.241 - /** Provides the function implementation access to the presenter provided
19.242 - * in {@link #Fn(org.apidesign.html.boot.spi.Fn.Presenter) the constructor}.
19.243 - *
19.244 - * @return presenter passed in the constructor (may be, but should not be <code>null</code>)
19.245 - * @since 0.7
19.246 - */
19.247 - protected final Presenter presenter() {
19.248 - return presenter;
19.249 - }
19.250 -
19.251 - /** The representation of a <em>presenter</em> - usually a browser window.
19.252 - * Should be provided by a library included in the application and registered
19.253 - * in <code>META-INF/services</code>, for example with
19.254 - * <code>@ServiceProvider(service = Fn.Presenter.class)</code> annotation.
19.255 - * <p>
19.256 - * Since 0.7 a presenter may implement {@link Executor} interface, in case
19.257 - * it supports single threaded execution environment. The executor's
19.258 - * {@link Executor#execute(java.lang.Runnable)} method is then supposed
19.259 - * to invoke the runnable immediately (in case we are on the right thread
19.260 - * already) or return and asynchronously invoke the runnable later on the
19.261 - * right thread (if we are on wrong thread).
19.262 - */
19.263 - public interface Presenter {
19.264 - /** Creates new function with given parameter names and provided body.
19.265 - *
19.266 - * @param code the body of the function. Can refer to variables named
19.267 - * as <code>names</code>
19.268 - * @param names names of parameters of the function - these will be
19.269 - * available when the <code>code</code> body executes
19.270 - *
19.271 - * @return function that can be later invoked
19.272 - */
19.273 - public Fn defineFn(String code, String... names);
19.274 -
19.275 - /** Opens the browser, loads provided page and when the
19.276 - * page is ready, it calls back to the provider runnable.
19.277 - *
19.278 - * @param page the URL for the page to display
19.279 - * @param onPageLoad callback when the page is ready
19.280 - */
19.281 - public void displayPage(URL page, Runnable onPageLoad);
19.282 -
19.283 - /** Loads a script into the browser JavaScript interpreter and
19.284 - * executes it.
19.285 - * @param code the script to execute
19.286 - * @throws Exception if something goes wrong, throw an exception
19.287 - */
19.288 - public void loadScript(Reader code) throws Exception;
19.289 - }
19.290 -
19.291 - /** Additional interface to be implemented by {@link Presenter}s that
19.292 - * wish to control what objects are passed into the JavaScript virtual
19.293 - * machine.
19.294 - * <p>
19.295 - * If a JavaScript engine makes callback to Java method that returns
19.296 - * a value, the {@link #toJavaScript(java.lang.Object)} method is
19.297 - * consulted to convert the Java value to something reasonable inside
19.298 - * JavaScript VM.
19.299 - * <p>
19.300 - * <em>Note:</em> The implementation based on <em>JavaFX</em> <code>WebView</code>
19.301 - * uses this interface to convert Java arrays to JavaScript ones.
19.302 - *
19.303 - * @see Presenter
19.304 - * @since 0.7
19.305 - */
19.306 - public interface ToJavaScript {
19.307 - /** Convert a Java return value into some object suitable for
19.308 - * JavaScript virtual machine.
19.309 - *
19.310 - * @param toReturn the Java object to be returned
19.311 - * @return the replacement value to return instead
19.312 - */
19.313 - public Object toJavaScript(Object toReturn);
19.314 - }
19.315 -
19.316 - /** Additional interface to be implemented by {@link Presenter}s that
19.317 - * need to convert JavaScript object (usually array) to Java object
19.318 - * when calling back from JavaScript to Java.
19.319 - * <p>
19.320 - * <em>Note:</em> The implementation based on <em>JavaFX</em>
19.321 - * <code>WebView</code> uses this interface to convert JavaScript arrays to
19.322 - * Java ones.
19.323 - *
19.324 - * @since 0.7
19.325 - */
19.326 - public interface FromJavaScript {
19.327 - /** Convert a JavaScript object into suitable Java representation
19.328 - * before a Java method is called with this object as an argument.
19.329 - *
19.330 - * @param js the JavaScript object
19.331 - * @return replacement object for
19.332 - */
19.333 - public Object toJava(Object js);
19.334 - }
19.335 -}
20.1 --- a/boot/src/main/java/org/apidesign/html/boot/spi/package.html Tue Aug 26 17:43:37 2014 +0200
20.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
20.3 @@ -1,54 +0,0 @@
20.4 -<!--
20.5 -
20.6 - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
20.7 -
20.8 - Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
20.9 -
20.10 - Oracle and Java are registered trademarks of Oracle and/or its affiliates.
20.11 - Other names may be trademarks of their respective owners.
20.12 -
20.13 - The contents of this file are subject to the terms of either the GNU
20.14 - General Public License Version 2 only ("GPL") or the Common
20.15 - Development and Distribution License("CDDL") (collectively, the
20.16 - "License"). You may not use this file except in compliance with the
20.17 - License. You can obtain a copy of the License at
20.18 - http://www.netbeans.org/cddl-gplv2.html
20.19 - or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
20.20 - specific language governing permissions and limitations under the
20.21 - License. When distributing the software, include this License Header
20.22 - Notice in each file and include the License file at
20.23 - nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20.24 - particular file as subject to the "Classpath" exception as provided
20.25 - by Oracle in the GPL Version 2 section of the License file that
20.26 - accompanied this code. If applicable, add the following below the
20.27 - License Header, with the fields enclosed by brackets [] replaced by
20.28 - your own identifying information:
20.29 - "Portions Copyrighted [year] [name of copyright owner]"
20.30 -
20.31 - Contributor(s):
20.32 -
20.33 - The Original Software is NetBeans. The Initial Developer of the Original
20.34 - Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
20.35 -
20.36 - If you wish your version of this file to be governed by only the CDDL
20.37 - or only the GPL Version 2, indicate your decision by adding
20.38 - "[Contributor] elects to include this software in this distribution
20.39 - under the [CDDL or GPL Version 2] license." If you do not indicate a
20.40 - single choice of license, a recipient has the option to distribute
20.41 - your version of this file under either the CDDL, the GPL Version 2 or
20.42 - to extend the choice of license to its licensees as provided above.
20.43 - However, if you add GPL Version 2 code and therefore, elected the GPL
20.44 - Version 2 license, then the option applies only if the new code is
20.45 - made subject to such option by the copyright holder.
20.46 -
20.47 --->
20.48 -<!DOCTYPE html>
20.49 -<html>
20.50 - <body>
20.51 - <div>Interfaces for integrators of various execution environments.</div>
20.52 - Not really interesting for clients. The clients should rather use
20.53 - {@link net.java.html.boot.BrowserBuilder} to launch their applications,
20.54 - or (if they need to do some JavaScript calls themselves) look at
20.55 - {@link net.java.html.js.JavaScriptBody} annotation and its usage.
20.56 - </body>
20.57 -</html>
21.1 --- a/boot/src/main/java/org/netbeans/html/boot/impl/FnContext.java Tue Aug 26 17:43:37 2014 +0200
21.2 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/FnContext.java Tue Aug 26 18:13:30 2014 +0200
21.3 @@ -46,7 +46,7 @@
21.4 import java.io.Flushable;
21.5 import java.io.IOException;
21.6 import java.util.logging.Logger;
21.7 -import org.apidesign.html.boot.spi.Fn;
21.8 +import org.netbeans.html.boot.spi.Fn;
21.9
21.10 /**
21.11 *
22.1 --- a/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java Tue Aug 26 17:43:37 2014 +0200
22.2 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java Tue Aug 26 18:13:30 2014 +0200
22.3 @@ -52,7 +52,7 @@
22.4 import java.util.List;
22.5 import net.java.html.js.JavaScriptBody;
22.6 import net.java.html.js.JavaScriptResource;
22.7 -import org.apidesign.html.boot.spi.Fn;
22.8 +import org.netbeans.html.boot.spi.Fn;
22.9 import org.objectweb.asm.AnnotationVisitor;
22.10 import org.objectweb.asm.ClassReader;
22.11 import org.objectweb.asm.ClassVisitor;
22.12 @@ -292,13 +292,13 @@
22.13 super.visitFieldInsn(
22.14 Opcodes.GETSTATIC, FindInClass.this.name,
22.15 "$$fn$$" + name + "_" + found,
22.16 - "Lorg/apidesign/html/boot/spi/Fn;"
22.17 + "Lorg/netbeans/html/boot/spi/Fn;"
22.18 );
22.19 super.visitInsn(Opcodes.DUP);
22.20 super.visitMethodInsn(
22.21 Opcodes.INVOKESTATIC,
22.22 - "org/apidesign/html/boot/spi/Fn", "isValid",
22.23 - "(Lorg/apidesign/html/boot/spi/Fn;)Z"
22.24 + "org/netbeans/html/boot/spi/Fn", "isValid",
22.25 + "(Lorg/netbeans/html/boot/spi/Fn;)Z"
22.26 );
22.27 Label ifNotNull = new Label();
22.28 super.visitJumpInsn(Opcodes.IFNE, ifNotNull);
22.29 @@ -320,8 +320,8 @@
22.30 super.visitInsn(Opcodes.AASTORE);
22.31 }
22.32 super.visitMethodInsn(Opcodes.INVOKESTATIC,
22.33 - "org/apidesign/html/boot/spi/Fn", "define",
22.34 - "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Lorg/apidesign/html/boot/spi/Fn;"
22.35 + "org/netbeans/html/boot/spi/Fn", "define",
22.36 + "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Lorg/netbeans/html/boot/spi/Fn;"
22.37 );
22.38 Label noPresenter = new Label();
22.39 if (hasCode) {
22.40 @@ -332,15 +332,15 @@
22.41 super.visitLdcInsn(Type.getObjectType(FindInClass.this.name));
22.42 super.visitLdcInsn(resource);
22.43 super.visitMethodInsn(Opcodes.INVOKESTATIC,
22.44 - "org/apidesign/html/boot/spi/Fn", "preload",
22.45 - "(Lorg/apidesign/html/boot/spi/Fn;Ljava/lang/Class;Ljava/lang/String;)Lorg/apidesign/html/boot/spi/Fn;"
22.46 + "org/netbeans/html/boot/spi/Fn", "preload",
22.47 + "(Lorg/netbeans/html/boot/spi/Fn;Ljava/lang/Class;Ljava/lang/String;)Lorg/netbeans/html/boot/spi/Fn;"
22.48 );
22.49 }
22.50 super.visitInsn(Opcodes.DUP);
22.51 super.visitFieldInsn(
22.52 Opcodes.PUTSTATIC, FindInClass.this.name,
22.53 "$$fn$$" + name + "_" + found,
22.54 - "Lorg/apidesign/html/boot/spi/Fn;"
22.55 + "Lorg/netbeans/html/boot/spi/Fn;"
22.56 );
22.57 // end of Fn init
22.58
22.59 @@ -469,7 +469,7 @@
22.60
22.61 if (fia.wait4js) {
22.62 super.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
22.63 - "org/apidesign/html/boot/spi/Fn", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"
22.64 + "org/netbeans/html/boot/spi/Fn", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"
22.65 );
22.66 switch (sv.returnType.getSort()) {
22.67 case Type.VOID:
22.68 @@ -496,7 +496,7 @@
22.69 }
22.70 } else {
22.71 super.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
22.72 - "org/apidesign/html/boot/spi/Fn", "invokeLater", "(Ljava/lang/Object;[Ljava/lang/Object;)V"
22.73 + "org/netbeans/html/boot/spi/Fn", "invokeLater", "(Ljava/lang/Object;[Ljava/lang/Object;)V"
22.74 );
22.75 super.visitInsn(Opcodes.RETURN);
22.76 }
22.77 @@ -518,7 +518,7 @@
22.78 FindInClass.this.visitField(
22.79 Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC,
22.80 "$$fn$$" + name + "_" + found,
22.81 - "Lorg/apidesign/html/boot/spi/Fn;",
22.82 + "Lorg/netbeans/html/boot/spi/Fn;",
22.83 null, null
22.84 );
22.85 }
23.1 --- a/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java Tue Aug 26 17:43:37 2014 +0200
23.2 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java Tue Aug 26 18:13:30 2014 +0200
23.3 @@ -353,13 +353,13 @@
23.4 source.append("package ").append(pkgName).append(";\n");
23.5 source.append("public final class $JsCallbacks$ {\n");
23.6 source.append(" static final $JsCallbacks$ VM = new $JsCallbacks$(null);\n");
23.7 - source.append(" private final org.apidesign.html.boot.spi.Fn.Presenter p;\n");
23.8 + source.append(" private final org.netbeans.html.boot.spi.Fn.Presenter p;\n");
23.9 source.append(" private $JsCallbacks$ last;\n");
23.10 - source.append(" private $JsCallbacks$(org.apidesign.html.boot.spi.Fn.Presenter p) {\n");
23.11 + source.append(" private $JsCallbacks$(org.netbeans.html.boot.spi.Fn.Presenter p) {\n");
23.12 source.append(" this.p = p;\n");
23.13 source.append(" }\n");
23.14 source.append(" final $JsCallbacks$ current() {\n");
23.15 - source.append(" org.apidesign.html.boot.spi.Fn.Presenter now = org.apidesign.html.boot.spi.Fn.activePresenter();\n");
23.16 + source.append(" org.netbeans.html.boot.spi.Fn.Presenter now = org.netbeans.html.boot.spi.Fn.activePresenter();\n");
23.17 source.append(" if (now == p) return this;\n");
23.18 source.append(" if (last != null && now == last.p) return last;\n");
23.19 source.append(" return last = new $JsCallbacks$(now);\n");
23.20 @@ -388,9 +388,9 @@
23.21 final TypeMirror t = ve.asType();
23.22 if (!t.getKind().isPrimitive()) {
23.23 source.append("Object");
23.24 - convert.append(" if (p instanceof org.apidesign.html.boot.spi.Fn.FromJavaScript) {\n");
23.25 + convert.append(" if (p instanceof org.netbeans.html.boot.spi.Fn.FromJavaScript) {\n");
23.26 convert.append(" arg").append(cnt).
23.27 - append(" = ((org.apidesign.html.boot.spi.Fn.FromJavaScript)p).toJava(arg").append(cnt).
23.28 + append(" = ((org.netbeans.html.boot.spi.Fn.FromJavaScript)p).toJava(arg").append(cnt).
23.29 append(");\n");
23.30 convert.append(" }\n");
23.31 } else {
23.32 @@ -402,9 +402,9 @@
23.33 source.append(") throws Throwable {\n");
23.34 source.append(convert);
23.35 if (useTryResources()) {
23.36 - source.append(" try (java.io.Closeable a = org.apidesign.html.boot.spi.Fn.activate(p)) { \n");
23.37 + source.append(" try (java.io.Closeable a = org.netbeans.html.boot.spi.Fn.activate(p)) { \n");
23.38 } else {
23.39 - source.append(" java.io.Closeable a = org.apidesign.html.boot.spi.Fn.activate(p); try {\n");
23.40 + source.append(" java.io.Closeable a = org.netbeans.html.boot.spi.Fn.activate(p); try {\n");
23.41 }
23.42 source.append(" ");
23.43 if (m.getReturnType().getKind() != TypeKind.VOID) {
23.44 @@ -430,8 +430,8 @@
23.45 if (m.getReturnType().getKind() == TypeKind.VOID) {
23.46 source.append(" return null;\n");
23.47 } else {
23.48 - source.append(" if (p instanceof org.apidesign.html.boot.spi.Fn.ToJavaScript) {\n");
23.49 - source.append(" $ret = ((org.apidesign.html.boot.spi.Fn.ToJavaScript)p).toJavaScript($ret);\n");
23.50 + source.append(" if (p instanceof org.netbeans.html.boot.spi.Fn.ToJavaScript) {\n");
23.51 + source.append(" $ret = ((org.netbeans.html.boot.spi.Fn.ToJavaScript)p).toJavaScript($ret);\n");
23.52 source.append(" }\n");
23.53 source.append(" return $ret;\n");
23.54 }
24.1 --- a/boot/src/main/java/org/netbeans/html/boot/impl/JsClassLoader.java Tue Aug 26 17:43:37 2014 +0200
24.2 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/JsClassLoader.java Tue Aug 26 18:13:30 2014 +0200
24.3 @@ -42,7 +42,7 @@
24.4 */
24.5 package org.netbeans.html.boot.impl;
24.6
24.7 -import org.apidesign.html.boot.spi.Fn;
24.8 +import org.netbeans.html.boot.spi.Fn;
24.9 import java.io.IOException;
24.10 import java.io.InputStream;
24.11 import java.io.Reader;
24.12 @@ -76,7 +76,7 @@
24.13 if (name.startsWith("com.sun")) {
24.14 return Class.forName(name);
24.15 }
24.16 - if (name.startsWith("org.apidesign.html.context.spi")) {
24.17 + if (name.startsWith("org.netbeans.html.context.spi")) {
24.18 return Class.forName(name);
24.19 }
24.20 if (name.startsWith("net.java.html.BrwsrCtx")) {
24.21 @@ -101,7 +101,7 @@
24.22 return FnUtils.class;
24.23 }
24.24 if (
24.25 - name.equals("org.apidesign.html.boot.spi.Fn") ||
24.26 + name.equals("org.netbeans.html.boot.spi.Fn") ||
24.27 name.equals("org.netbeans.html.boot.impl.FnUtils") ||
24.28 name.equals("org.netbeans.html.boot.impl.FnContext")
24.29 ) {
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
25.2 +++ b/boot/src/main/java/org/netbeans/html/boot/spi/Fn.java Tue Aug 26 18:13:30 2014 +0200
25.3 @@ -0,0 +1,332 @@
25.4 +/**
25.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
25.6 + *
25.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
25.8 + *
25.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
25.10 + * Other names may be trademarks of their respective owners.
25.11 + *
25.12 + * The contents of this file are subject to the terms of either the GNU
25.13 + * General Public License Version 2 only ("GPL") or the Common
25.14 + * Development and Distribution License("CDDL") (collectively, the
25.15 + * "License"). You may not use this file except in compliance with the
25.16 + * License. You can obtain a copy of the License at
25.17 + * http://www.netbeans.org/cddl-gplv2.html
25.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
25.19 + * specific language governing permissions and limitations under the
25.20 + * License. When distributing the software, include this License Header
25.21 + * Notice in each file and include the License file at
25.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
25.23 + * particular file as subject to the "Classpath" exception as provided
25.24 + * by Oracle in the GPL Version 2 section of the License file that
25.25 + * accompanied this code. If applicable, add the following below the
25.26 + * License Header, with the fields enclosed by brackets [] replaced by
25.27 + * your own identifying information:
25.28 + * "Portions Copyrighted [year] [name of copyright owner]"
25.29 + *
25.30 + * Contributor(s):
25.31 + *
25.32 + * The Original Software is NetBeans. The Initial Developer of the Original
25.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
25.34 + *
25.35 + * If you wish your version of this file to be governed by only the CDDL
25.36 + * or only the GPL Version 2, indicate your decision by adding
25.37 + * "[Contributor] elects to include this software in this distribution
25.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
25.39 + * single choice of license, a recipient has the option to distribute
25.40 + * your version of this file under either the CDDL, the GPL Version 2 or
25.41 + * to extend the choice of license to its licensees as provided above.
25.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
25.43 + * Version 2 license, then the option applies only if the new code is
25.44 + * made subject to such option by the copyright holder.
25.45 + */
25.46 +package org.netbeans.html.boot.spi;
25.47 +
25.48 +import java.io.Closeable;
25.49 +import java.io.IOException;
25.50 +import java.io.InputStream;
25.51 +import java.io.InputStreamReader;
25.52 +import java.io.Reader;
25.53 +import java.net.URL;
25.54 +import java.util.HashMap;
25.55 +import java.util.HashSet;
25.56 +import java.util.Map;
25.57 +import java.util.Set;
25.58 +import java.util.concurrent.Executor;
25.59 +import net.java.html.js.JavaScriptBody;
25.60 +import org.netbeans.html.boot.impl.FnContext;
25.61 +
25.62 +/** Represents single JavaScript function that can be invoked.
25.63 + * Created via {@link Presenter#defineFn(java.lang.String, java.lang.String...)}.
25.64 + *
25.65 + * @author Jaroslav Tulach
25.66 + */
25.67 +public abstract class Fn {
25.68 + private final Presenter presenter;
25.69 +
25.70 + /**
25.71 + * @deprecated Ineffective as of 0.6.
25.72 + * Provide a presenter via {@link #Fn(org.netbeans.html.boot.spi.Fn.Presenter)}
25.73 + * constructor
25.74 + */
25.75 + @Deprecated
25.76 + protected Fn() {
25.77 + this(null);
25.78 + }
25.79 +
25.80 + /** Creates new function object and associates it with given presenter.
25.81 + *
25.82 + * @param presenter the browser presenter associated with this function
25.83 + * @since 0.6
25.84 + */
25.85 + protected Fn(Presenter presenter) {
25.86 + this.presenter = presenter;
25.87 + }
25.88 +
25.89 + /** True, if currently active presenter is the same as presenter this
25.90 + * function has been created for via {@link #Fn(org.netbeans.html.boot.spi.Fn.Presenter)}.
25.91 + *
25.92 + * @return true, if proper presenter is used
25.93 + */
25.94 + public final boolean isValid() {
25.95 + return presenter != null && FnContext.currentPresenter(false) == presenter;
25.96 + }
25.97 +
25.98 + /** Helper method to check if the provided instance is valid function.
25.99 + * Checks if the parameter is non-null and if so, does {@link #isValid()}
25.100 + * check.
25.101 + *
25.102 + * @param fnOrNull function or <code>null</code>
25.103 + * @return true if the parameter is non-null and valid
25.104 + * @since 0.7
25.105 + */
25.106 + public static boolean isValid(Fn fnOrNull) {
25.107 + return fnOrNull != null && fnOrNull.isValid();
25.108 + }
25.109 +
25.110 + /** Helper method to find current presenter and ask it to define new
25.111 + * function by calling {@link Presenter#defineFn(java.lang.String, java.lang.String...)}.
25.112 + *
25.113 + * @param caller the class who wishes to define the function
25.114 + * @param code the body of the function (can reference <code>this</code> and <code>names</code> variables)
25.115 + * @param names names of individual parameters
25.116 + * @return the function object that can be {@link Fn#invoke(java.lang.Object, java.lang.Object...) invoked}
25.117 + * - can return <code>null</code> if there is {@link #activePresenter() no presenter}
25.118 + * @since 0.7
25.119 + */
25.120 + public static Fn define(Class<?> caller, String code, String... names) {
25.121 + final Presenter p = FnContext.currentPresenter(false);
25.122 + return p == null ? null : p.defineFn(code, names);
25.123 + }
25.124 +
25.125 + private static final Map<String,Set<Presenter>> LOADED = new HashMap<String, Set<Presenter>>();
25.126 +
25.127 + /** Wraps function to ensure that the script represented by <code>resource</code>
25.128 + * gets loaded into the browser environment before the function <code>fn</code>
25.129 + * is executed.
25.130 + *
25.131 + * @param fn original function to call (if <code>null</code> returns <code>null</code>)
25.132 + * @param caller the class who wishes to define/call the function
25.133 + * @param resource resources (accessible via {@link ClassLoader#getResource(java.lang.String)})
25.134 + * with a <em>JavaScript</em> that is supposed to loaded into the browser
25.135 + * environment
25.136 + * @return function that ensures the script is loaded and then delegates
25.137 + * to <code>fn</code>. Returns <code>null</code> if the input <code>fn</code> is null
25.138 + * @since 0.7
25.139 + */
25.140 + public static Fn preload(final Fn fn, final Class<?> caller, final String resource) {
25.141 + if (fn == null) {
25.142 + return null;
25.143 + }
25.144 + return new Fn(fn.presenter()) {
25.145 + @Override
25.146 + public Object invoke(Object thiz, Object... args) throws Exception {
25.147 + loadResource();
25.148 + return fn.invoke(thiz, args);
25.149 + }
25.150 +
25.151 + @Override
25.152 + public void invokeLater(Object thiz, Object... args) throws Exception {
25.153 + loadResource();
25.154 + fn.invokeLater(thiz, args);
25.155 + }
25.156 +
25.157 + private void loadResource() throws Exception {
25.158 + Presenter p = presenter();
25.159 + if (p == null) {
25.160 + p = FnContext.currentPresenter(false);
25.161 + }
25.162 + if (p != null) {
25.163 + Set<Presenter> there = LOADED.get(resource);
25.164 + if (there == null) {
25.165 + there = new HashSet<Presenter>();
25.166 + LOADED.put(resource, there);
25.167 + }
25.168 + if (there.add(p)) {
25.169 + final ClassLoader l = caller.getClassLoader();
25.170 + InputStream is = l.getResourceAsStream(resource);
25.171 + if (is == null && resource.startsWith("/")) {
25.172 + is = l.getResourceAsStream(resource.substring(1));
25.173 + }
25.174 + if (is == null) {
25.175 + throw new IOException("Cannot find " + resource + " in " + l);
25.176 + }
25.177 + try {
25.178 + InputStreamReader r = new InputStreamReader(is, "UTF-8");
25.179 + p.loadScript(r);
25.180 + } finally {
25.181 + is.close();
25.182 + }
25.183 + }
25.184 + }
25.185 + }
25.186 + };
25.187 + }
25.188 +
25.189 +
25.190 + /** The currently active presenter.
25.191 + *
25.192 + * @return the currently active presenter or <code>null</code>
25.193 + * @since 0.7
25.194 + */
25.195 + public static Presenter activePresenter() {
25.196 + return FnContext.currentPresenter(false);
25.197 + }
25.198 +
25.199 + /** Activates given presenter. Used to associate the native
25.200 + * JavaScript code specified by
25.201 + * {@link JavaScriptBody} annotation with certain presenter:
25.202 + * <pre>
25.203 + * try ({@link Closeable} c = Fn.activate(presenter)) {
25.204 + * doCallsInPresenterContext();
25.205 + * }
25.206 + * </pre>
25.207 + *
25.208 + * @param p the presenter that should be active until closable is closed
25.209 + * @return the closable to close
25.210 + * @since 0.7
25.211 + */
25.212 + public static Closeable activate(Presenter p) {
25.213 + return FnContext.activate(p);
25.214 + }
25.215 +
25.216 + /** Invokes the defined function with specified <code>this</code> and
25.217 + * appropriate arguments.
25.218 + *
25.219 + * @param thiz the meaning of <code>this</code> inside of the JavaScript
25.220 + * function - can be <code>null</code>
25.221 + * @param args arguments for the function
25.222 + * @return return value from the function
25.223 + * @throws Exception if something goes wrong, as exception may be thrown
25.224 + */
25.225 + public abstract Object invoke(Object thiz, Object... args) throws Exception;
25.226 +
25.227 + /** Invokes the defined function with specified <code>this</code> and
25.228 + * appropriate arguments asynchronously. The invocation may be
25.229 + * happen <em>"later"</em>.
25.230 + *
25.231 + * @param thiz the meaning of <code>this</code> inside of the JavaScript
25.232 + * function - can be <code>null</code>
25.233 + * @param args arguments for the function
25.234 + * @throws Exception if something goes wrong, as exception may be thrown
25.235 + * @since 0.7.6
25.236 + */
25.237 + public void invokeLater(Object thiz, Object... args) throws Exception {
25.238 + invoke(this, args);
25.239 + }
25.240 +
25.241 + /** Provides the function implementation access to the presenter provided
25.242 + * in {@link #Fn(org.netbeans.html.boot.spi.Fn.Presenter) the constructor}.
25.243 + *
25.244 + * @return presenter passed in the constructor (may be, but should not be <code>null</code>)
25.245 + * @since 0.7
25.246 + */
25.247 + protected final Presenter presenter() {
25.248 + return presenter;
25.249 + }
25.250 +
25.251 + /** The representation of a <em>presenter</em> - usually a browser window.
25.252 + * Should be provided by a library included in the application and registered
25.253 + * in <code>META-INF/services</code>, for example with
25.254 + * <code>@ServiceProvider(service = Fn.Presenter.class)</code> annotation.
25.255 + * <p>
25.256 + * Since 0.7 a presenter may implement {@link Executor} interface, in case
25.257 + * it supports single threaded execution environment. The executor's
25.258 + * {@link Executor#execute(java.lang.Runnable)} method is then supposed
25.259 + * to invoke the runnable immediately (in case we are on the right thread
25.260 + * already) or return and asynchronously invoke the runnable later on the
25.261 + * right thread (if we are on wrong thread).
25.262 + */
25.263 + public interface Presenter {
25.264 + /** Creates new function with given parameter names and provided body.
25.265 + *
25.266 + * @param code the body of the function. Can refer to variables named
25.267 + * as <code>names</code>
25.268 + * @param names names of parameters of the function - these will be
25.269 + * available when the <code>code</code> body executes
25.270 + *
25.271 + * @return function that can be later invoked
25.272 + */
25.273 + public Fn defineFn(String code, String... names);
25.274 +
25.275 + /** Opens the browser, loads provided page and when the
25.276 + * page is ready, it calls back to the provider runnable.
25.277 + *
25.278 + * @param page the URL for the page to display
25.279 + * @param onPageLoad callback when the page is ready
25.280 + */
25.281 + public void displayPage(URL page, Runnable onPageLoad);
25.282 +
25.283 + /** Loads a script into the browser JavaScript interpreter and
25.284 + * executes it.
25.285 + * @param code the script to execute
25.286 + * @throws Exception if something goes wrong, throw an exception
25.287 + */
25.288 + public void loadScript(Reader code) throws Exception;
25.289 + }
25.290 +
25.291 + /** Additional interface to be implemented by {@link Presenter}s that
25.292 + * wish to control what objects are passed into the JavaScript virtual
25.293 + * machine.
25.294 + * <p>
25.295 + * If a JavaScript engine makes callback to Java method that returns
25.296 + * a value, the {@link #toJavaScript(java.lang.Object)} method is
25.297 + * consulted to convert the Java value to something reasonable inside
25.298 + * JavaScript VM.
25.299 + * <p>
25.300 + * <em>Note:</em> The implementation based on <em>JavaFX</em> <code>WebView</code>
25.301 + * uses this interface to convert Java arrays to JavaScript ones.
25.302 + *
25.303 + * @see Presenter
25.304 + * @since 0.7
25.305 + */
25.306 + public interface ToJavaScript {
25.307 + /** Convert a Java return value into some object suitable for
25.308 + * JavaScript virtual machine.
25.309 + *
25.310 + * @param toReturn the Java object to be returned
25.311 + * @return the replacement value to return instead
25.312 + */
25.313 + public Object toJavaScript(Object toReturn);
25.314 + }
25.315 +
25.316 + /** Additional interface to be implemented by {@link Presenter}s that
25.317 + * need to convert JavaScript object (usually array) to Java object
25.318 + * when calling back from JavaScript to Java.
25.319 + * <p>
25.320 + * <em>Note:</em> The implementation based on <em>JavaFX</em>
25.321 + * <code>WebView</code> uses this interface to convert JavaScript arrays to
25.322 + * Java ones.
25.323 + *
25.324 + * @since 0.7
25.325 + */
25.326 + public interface FromJavaScript {
25.327 + /** Convert a JavaScript object into suitable Java representation
25.328 + * before a Java method is called with this object as an argument.
25.329 + *
25.330 + * @param js the JavaScript object
25.331 + * @return replacement object for
25.332 + */
25.333 + public Object toJava(Object js);
25.334 + }
25.335 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
26.2 +++ b/boot/src/main/java/org/netbeans/html/boot/spi/package.html Tue Aug 26 18:13:30 2014 +0200
26.3 @@ -0,0 +1,54 @@
26.4 +<!--
26.5 +
26.6 + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
26.7 +
26.8 + Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
26.9 +
26.10 + Oracle and Java are registered trademarks of Oracle and/or its affiliates.
26.11 + Other names may be trademarks of their respective owners.
26.12 +
26.13 + The contents of this file are subject to the terms of either the GNU
26.14 + General Public License Version 2 only ("GPL") or the Common
26.15 + Development and Distribution License("CDDL") (collectively, the
26.16 + "License"). You may not use this file except in compliance with the
26.17 + License. You can obtain a copy of the License at
26.18 + http://www.netbeans.org/cddl-gplv2.html
26.19 + or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
26.20 + specific language governing permissions and limitations under the
26.21 + License. When distributing the software, include this License Header
26.22 + Notice in each file and include the License file at
26.23 + nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
26.24 + particular file as subject to the "Classpath" exception as provided
26.25 + by Oracle in the GPL Version 2 section of the License file that
26.26 + accompanied this code. If applicable, add the following below the
26.27 + License Header, with the fields enclosed by brackets [] replaced by
26.28 + your own identifying information:
26.29 + "Portions Copyrighted [year] [name of copyright owner]"
26.30 +
26.31 + Contributor(s):
26.32 +
26.33 + The Original Software is NetBeans. The Initial Developer of the Original
26.34 + Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
26.35 +
26.36 + If you wish your version of this file to be governed by only the CDDL
26.37 + or only the GPL Version 2, indicate your decision by adding
26.38 + "[Contributor] elects to include this software in this distribution
26.39 + under the [CDDL or GPL Version 2] license." If you do not indicate a
26.40 + single choice of license, a recipient has the option to distribute
26.41 + your version of this file under either the CDDL, the GPL Version 2 or
26.42 + to extend the choice of license to its licensees as provided above.
26.43 + However, if you add GPL Version 2 code and therefore, elected the GPL
26.44 + Version 2 license, then the option applies only if the new code is
26.45 + made subject to such option by the copyright holder.
26.46 +
26.47 +-->
26.48 +<!DOCTYPE html>
26.49 +<html>
26.50 + <body>
26.51 + <div>Interfaces for integrators of various execution environments.</div>
26.52 + Not really interesting for clients. The clients should rather use
26.53 + {@link net.java.html.boot.BrowserBuilder} to launch their applications,
26.54 + or (if they need to do some JavaScript calls themselves) look at
26.55 + {@link net.java.html.js.JavaScriptBody} annotation and its usage.
26.56 + </body>
26.57 +</html>
27.1 --- a/boot/src/test/java/org/netbeans/html/boot/impl/CountFnCreationTest.java Tue Aug 26 17:43:37 2014 +0200
27.2 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/CountFnCreationTest.java Tue Aug 26 18:13:30 2014 +0200
27.3 @@ -53,7 +53,7 @@
27.4 import java.util.logging.Logger;
27.5 import net.java.html.js.JavaScriptBody;
27.6 import net.java.html.js.JavaScriptResource;
27.7 -import org.apidesign.html.boot.spi.Fn;
27.8 +import org.netbeans.html.boot.spi.Fn;
27.9 import static org.testng.Assert.assertEquals;
27.10 import org.testng.annotations.Test;
27.11
28.1 --- a/boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java Tue Aug 26 17:43:37 2014 +0200
28.2 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java Tue Aug 26 18:13:30 2014 +0200
28.3 @@ -56,7 +56,7 @@
28.4 import javax.script.ScriptEngine;
28.5 import javax.script.ScriptEngineManager;
28.6 import javax.script.ScriptException;
28.7 -import org.apidesign.html.boot.spi.Fn;
28.8 +import org.netbeans.html.boot.spi.Fn;
28.9 import static org.testng.Assert.assertEquals;
28.10 import org.testng.annotations.BeforeClass;
28.11 import org.testng.annotations.BeforeMethod;
29.1 --- a/boot/src/test/java/org/netbeans/html/boot/impl/JsCallbackTest.java Tue Aug 26 17:43:37 2014 +0200
29.2 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsCallbackTest.java Tue Aug 26 18:13:30 2014 +0200
29.3 @@ -55,7 +55,7 @@
29.4 }
29.5 @Test public void missingTypeSpecification() {
29.6 String body = "console[attr] = function(msg) {\n"
29.7 - + " @org.apidesign.html.charts.Main::log(msg);\n"
29.8 + + " @org.netbeans.html.charts.Main::log(msg);\n"
29.9 + "};\n";
29.10 JsCallback instance = new JsCallbackImpl();
29.11 try {
30.1 --- a/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java Tue Aug 26 17:43:37 2014 +0200
30.2 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java Tue Aug 26 18:13:30 2014 +0200
30.3 @@ -46,7 +46,7 @@
30.4 import java.lang.reflect.InvocationTargetException;
30.5 import java.lang.reflect.Method;
30.6 import java.lang.reflect.Modifier;
30.7 -import org.apidesign.html.boot.spi.Fn;
30.8 +import org.netbeans.html.boot.spi.Fn;
30.9 import static org.testng.Assert.*;
30.10 import org.testng.annotations.BeforeMethod;
30.11 import org.testng.annotations.Test;
31.1 --- a/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderTest.java Tue Aug 26 17:43:37 2014 +0200
31.2 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderTest.java Tue Aug 26 18:13:30 2014 +0200
31.3 @@ -44,7 +44,7 @@
31.4
31.5 import java.io.Closeable;
31.6 import java.io.Reader;
31.7 -import org.apidesign.html.boot.spi.Fn;
31.8 +import org.netbeans.html.boot.spi.Fn;
31.9 import java.net.URL;
31.10 import java.net.URLClassLoader;
31.11 import java.util.ArrayList;
32.1 --- a/context/pom.xml Tue Aug 26 17:43:37 2014 +0200
32.2 +++ b/context/pom.xml Tue Aug 26 18:13:30 2014 +0200
32.3 @@ -14,7 +14,7 @@
32.4 <url>http://maven.apache.org</url>
32.5 <properties>
32.6 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32.7 - <publicPackages>net.java.html,org.apidesign.html.context.spi</publicPackages>
32.8 + <publicPackages>net.java.html,org.netbeans.html.context.spi</publicPackages>
32.9 </properties>
32.10 <build>
32.11 <plugins>
33.1 --- a/context/src/main/java/net/java/html/BrwsrCtx.java Tue Aug 26 17:43:37 2014 +0200
33.2 +++ b/context/src/main/java/net/java/html/BrwsrCtx.java Tue Aug 26 18:13:30 2014 +0200
33.3 @@ -46,7 +46,7 @@
33.4 import java.util.logging.Logger;
33.5 import org.netbeans.html.context.impl.CtxAccssr;
33.6 import org.netbeans.html.context.impl.CtxImpl;
33.7 -import org.apidesign.html.context.spi.Contexts;
33.8 +import org.netbeans.html.context.spi.Contexts;
33.9
33.10 /** Represents context where the <code>net.java.html.json.Model</code>
33.11 * and other objects
33.12 @@ -100,7 +100,7 @@
33.13 return brwsr;
33.14 }
33.15
33.16 - org.apidesign.html.context.spi.Contexts.Builder cb = Contexts.newBuilder();
33.17 + org.netbeans.html.context.spi.Contexts.Builder cb = Contexts.newBuilder();
33.18 boolean found = Contexts.fillInByProviders(requestor, cb);
33.19 if (!found) {
33.20 LOG.warning("No browser context found. Returning empty technology!");
34.1 --- a/context/src/main/java/org/apidesign/html/context/spi/Contexts.java Tue Aug 26 17:43:37 2014 +0200
34.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
34.3 @@ -1,192 +0,0 @@
34.4 -/**
34.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
34.6 - *
34.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
34.8 - *
34.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
34.10 - * Other names may be trademarks of their respective owners.
34.11 - *
34.12 - * The contents of this file are subject to the terms of either the GNU
34.13 - * General Public License Version 2 only ("GPL") or the Common
34.14 - * Development and Distribution License("CDDL") (collectively, the
34.15 - * "License"). You may not use this file except in compliance with the
34.16 - * License. You can obtain a copy of the License at
34.17 - * http://www.netbeans.org/cddl-gplv2.html
34.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
34.19 - * specific language governing permissions and limitations under the
34.20 - * License. When distributing the software, include this License Header
34.21 - * Notice in each file and include the License file at
34.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
34.23 - * particular file as subject to the "Classpath" exception as provided
34.24 - * by Oracle in the GPL Version 2 section of the License file that
34.25 - * accompanied this code. If applicable, add the following below the
34.26 - * License Header, with the fields enclosed by brackets [] replaced by
34.27 - * your own identifying information:
34.28 - * "Portions Copyrighted [year] [name of copyright owner]"
34.29 - *
34.30 - * Contributor(s):
34.31 - *
34.32 - * The Original Software is NetBeans. The Initial Developer of the Original
34.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
34.34 - *
34.35 - * If you wish your version of this file to be governed by only the CDDL
34.36 - * or only the GPL Version 2, indicate your decision by adding
34.37 - * "[Contributor] elects to include this software in this distribution
34.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
34.39 - * single choice of license, a recipient has the option to distribute
34.40 - * your version of this file under either the CDDL, the GPL Version 2 or
34.41 - * to extend the choice of license to its licensees as provided above.
34.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
34.43 - * Version 2 license, then the option applies only if the new code is
34.44 - * made subject to such option by the copyright holder.
34.45 - */
34.46 -package org.apidesign.html.context.spi;
34.47 -
34.48 -import java.util.ServiceLoader;
34.49 -import net.java.html.BrwsrCtx;
34.50 -import org.netbeans.html.context.impl.CtxImpl;
34.51 -
34.52 -/** Factory class to assign various technologies
34.53 - * to a {@link BrwsrCtx browser context}. Start with {@link #newBuilder()}
34.54 - * and then assign technologies with {@link Builder#register(java.lang.Class, java.lang.Object, int)}
34.55 - * method.
34.56 - *
34.57 - * @author Jaroslav Tulach
34.58 - */
34.59 -public final class Contexts {
34.60 - private Contexts() {
34.61 - }
34.62 -
34.63 - /** Creates new, empty builder for creation of {@link BrwsrCtx}. At the
34.64 - * end call the {@link Builder#build()} method to generate the context.
34.65 - *
34.66 - * @return new instance of the builder
34.67 - */
34.68 - public static Builder newBuilder() {
34.69 - return new Builder();
34.70 - }
34.71 -
34.72 - /** Seeks for the specified technology in the provided context.
34.73 - *
34.74 - * @param <Tech> type of the technology
34.75 - * @param context the context to seek in
34.76 - * (previously filled with ({@link Builder#register(java.lang.Class, java.lang.Object, int)})
34.77 - * @param technology class that identifies the technology
34.78 - * @return the technology in the context or <code>null</code>
34.79 - */
34.80 - public static <Tech> Tech find(BrwsrCtx context, Class<Tech> technology) {
34.81 - return CtxImpl.find(context, technology);
34.82 - }
34.83 -
34.84 - /** Seeks {@link ServiceLoader} for all registered instances of
34.85 - * {@link Provider} and asks them to {@link Provider#fillContext(org.apidesign.html.context.spi.Contexts.Builder, java.lang.Class) fill
34.86 - * the builder}.
34.87 - *
34.88 - * @param requestor the application class for which to find the context
34.89 - * @param cb the context builder to register technologies into
34.90 - * @return <code>true</code>, if some instances of the provider were
34.91 - * found, <code>false</code> otherwise
34.92 - * @since 0.7.6
34.93 - */
34.94 - public static boolean fillInByProviders(Class<?> requestor, Contexts.Builder cb) {
34.95 - boolean found = false;
34.96 - ClassLoader l;
34.97 - try {
34.98 - l = requestor.getClassLoader();
34.99 - } catch (SecurityException ex) {
34.100 - l = null;
34.101 - }
34.102 - for (Provider cp : ServiceLoader.load(Provider.class, l)) {
34.103 - cp.fillContext(cb, requestor);
34.104 - found = true;
34.105 - }
34.106 - try {
34.107 - for (Provider cp : ServiceLoader.load(Provider.class, Provider.class.getClassLoader())) {
34.108 - cp.fillContext(cb, requestor);
34.109 - found = true;
34.110 - }
34.111 - } catch (SecurityException ex) {
34.112 - if (!found) {
34.113 - throw ex;
34.114 - }
34.115 - }
34.116 - if (!found) {
34.117 - for (Provider cp : ServiceLoader.load(Provider.class)) {
34.118 - cp.fillContext(cb, requestor);
34.119 - found = true;
34.120 - }
34.121 - }
34.122 - return found;
34.123 - }
34.124 -
34.125 - /** Implementors of various HTML technologies should
34.126 - * register their implementation via <code>org.openide.util.lookup.ServiceProvider</code>, so
34.127 - * {@link ServiceLoader} can find them, when their JARs are included
34.128 - * on the classpath of the running application.
34.129 - *
34.130 - * @author Jaroslav Tulach
34.131 - */
34.132 - public static interface Provider {
34.133 -
34.134 - /** Register into the context if suitable technology is
34.135 - * available for the requesting class.
34.136 - * The provider should check if its own technology is available in current
34.137 - * scope (e.g. proper JDK, proper browser, etc.). The provider
34.138 - * can also find the right context depending on requestor's classloader, etc.
34.139 - * <p>
34.140 - * Providers should use {@link Builder} to enrich appropriately
34.141 - * the context.
34.142 - *
34.143 - * @param context the context builder to fill with technologies
34.144 - * @param requestor the application class requesting access the the HTML page
34.145 - * @see BrwsrCtx#findDefault(java.lang.Class)
34.146 - */
34.147 - void fillContext(Builder context, Class<?> requestor);
34.148 - }
34.149 -
34.150 - /** Support for providers of new {@link BrwsrCtx}. Providers of different
34.151 - * technologies should be of particular interest in this class. End users
34.152 - * designing their application with existing technologies should rather
34.153 - * point their attention to {@link BrwsrCtx} and co.
34.154 - *
34.155 - * @author Jaroslav Tulach
34.156 - */
34.157 - public static final class Builder {
34.158 - private final CtxImpl impl = new CtxImpl();
34.159 -
34.160 - Builder() {
34.161 - }
34.162 -
34.163 - /** Registers new technology into the context. Each technology is
34.164 - * exactly identified by its implementation class and can be associated
34.165 - * with (positive) priority. In case of presence of multiple technologies
34.166 - * with the same class, the one with higher lower priority takes precedence.
34.167 - * @param <Tech> type of technology to register
34.168 - * @param type the real class of the technology type
34.169 - * @param impl an instance of the technology class
34.170 - * @param position the lower position, the more important implementation
34.171 - * which will be consulted sooner when seeking for a {@link Contexts#find(net.java.html.BrwsrCtx, java.lang.Class)}
34.172 - * an implementation
34.173 - * @return this builder
34.174 - */
34.175 - public <Tech> Builder register(Class<Tech> type, Tech impl, int position) {
34.176 - if (impl == null) {
34.177 - return this;
34.178 - }
34.179 - if (position <= 0) {
34.180 - throw new IllegalStateException();
34.181 - }
34.182 - this.impl.register(type, impl, position);
34.183 - return this;
34.184 - }
34.185 -
34.186 - /** Generates context based on values previously inserted into
34.187 - * this builder.
34.188 - *
34.189 - * @return new, immutable instance of {@link BrwsrCtx}
34.190 - */
34.191 - public BrwsrCtx build() {
34.192 - return impl.build();
34.193 - }
34.194 - }
34.195 -}
35.1 --- a/context/src/main/java/org/apidesign/html/context/spi/package.html Tue Aug 26 17:43:37 2014 +0200
35.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
35.3 @@ -1,50 +0,0 @@
35.4 -<!--
35.5 -
35.6 - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
35.7 -
35.8 - Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
35.9 -
35.10 - Oracle and Java are registered trademarks of Oracle and/or its affiliates.
35.11 - Other names may be trademarks of their respective owners.
35.12 -
35.13 - The contents of this file are subject to the terms of either the GNU
35.14 - General Public License Version 2 only ("GPL") or the Common
35.15 - Development and Distribution License("CDDL") (collectively, the
35.16 - "License"). You may not use this file except in compliance with the
35.17 - License. You can obtain a copy of the License at
35.18 - http://www.netbeans.org/cddl-gplv2.html
35.19 - or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
35.20 - specific language governing permissions and limitations under the
35.21 - License. When distributing the software, include this License Header
35.22 - Notice in each file and include the License file at
35.23 - nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
35.24 - particular file as subject to the "Classpath" exception as provided
35.25 - by Oracle in the GPL Version 2 section of the License file that
35.26 - accompanied this code. If applicable, add the following below the
35.27 - License Header, with the fields enclosed by brackets [] replaced by
35.28 - your own identifying information:
35.29 - "Portions Copyrighted [year] [name of copyright owner]"
35.30 -
35.31 - Contributor(s):
35.32 -
35.33 - The Original Software is NetBeans. The Initial Developer of the Original
35.34 - Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
35.35 -
35.36 - If you wish your version of this file to be governed by only the CDDL
35.37 - or only the GPL Version 2, indicate your decision by adding
35.38 - "[Contributor] elects to include this software in this distribution
35.39 - under the [CDDL or GPL Version 2] license." If you do not indicate a
35.40 - single choice of license, a recipient has the option to distribute
35.41 - your version of this file under either the CDDL, the GPL Version 2 or
35.42 - to extend the choice of license to its licensees as provided above.
35.43 - However, if you add GPL Version 2 code and therefore, elected the GPL
35.44 - Version 2 license, then the option applies only if the new code is
35.45 - made subject to such option by the copyright holder.
35.46 -
35.47 --->
35.48 -<body>
35.49 - <p>
35.50 - Service provider classes to build {@link net.java.html.BrwsrCtx}
35.51 - instances.
35.52 - </p>
35.53 -</body>
36.1 --- a/context/src/main/java/org/netbeans/html/context/impl/CtxAccssr.java Tue Aug 26 17:43:37 2014 +0200
36.2 +++ b/context/src/main/java/org/netbeans/html/context/impl/CtxAccssr.java Tue Aug 26 18:13:30 2014 +0200
36.3 @@ -43,7 +43,7 @@
36.4 package org.netbeans.html.context.impl;
36.5
36.6 import net.java.html.BrwsrCtx;
36.7 -import org.apidesign.html.context.spi.Contexts.Builder;
36.8 +import org.netbeans.html.context.spi.Contexts.Builder;
36.9
36.10 /** Internal communication between API (e.g. {@link BrwsrCtx}), SPI
36.11 * (e.g. {@link Builder}) and the implementation package.
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
37.2 +++ b/context/src/main/java/org/netbeans/html/context/spi/Contexts.java Tue Aug 26 18:13:30 2014 +0200
37.3 @@ -0,0 +1,192 @@
37.4 +/**
37.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
37.6 + *
37.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
37.8 + *
37.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
37.10 + * Other names may be trademarks of their respective owners.
37.11 + *
37.12 + * The contents of this file are subject to the terms of either the GNU
37.13 + * General Public License Version 2 only ("GPL") or the Common
37.14 + * Development and Distribution License("CDDL") (collectively, the
37.15 + * "License"). You may not use this file except in compliance with the
37.16 + * License. You can obtain a copy of the License at
37.17 + * http://www.netbeans.org/cddl-gplv2.html
37.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
37.19 + * specific language governing permissions and limitations under the
37.20 + * License. When distributing the software, include this License Header
37.21 + * Notice in each file and include the License file at
37.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
37.23 + * particular file as subject to the "Classpath" exception as provided
37.24 + * by Oracle in the GPL Version 2 section of the License file that
37.25 + * accompanied this code. If applicable, add the following below the
37.26 + * License Header, with the fields enclosed by brackets [] replaced by
37.27 + * your own identifying information:
37.28 + * "Portions Copyrighted [year] [name of copyright owner]"
37.29 + *
37.30 + * Contributor(s):
37.31 + *
37.32 + * The Original Software is NetBeans. The Initial Developer of the Original
37.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
37.34 + *
37.35 + * If you wish your version of this file to be governed by only the CDDL
37.36 + * or only the GPL Version 2, indicate your decision by adding
37.37 + * "[Contributor] elects to include this software in this distribution
37.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
37.39 + * single choice of license, a recipient has the option to distribute
37.40 + * your version of this file under either the CDDL, the GPL Version 2 or
37.41 + * to extend the choice of license to its licensees as provided above.
37.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
37.43 + * Version 2 license, then the option applies only if the new code is
37.44 + * made subject to such option by the copyright holder.
37.45 + */
37.46 +package org.netbeans.html.context.spi;
37.47 +
37.48 +import java.util.ServiceLoader;
37.49 +import net.java.html.BrwsrCtx;
37.50 +import org.netbeans.html.context.impl.CtxImpl;
37.51 +
37.52 +/** Factory class to assign various technologies
37.53 + * to a {@link BrwsrCtx browser context}. Start with {@link #newBuilder()}
37.54 + * and then assign technologies with {@link Builder#register(java.lang.Class, java.lang.Object, int)}
37.55 + * method.
37.56 + *
37.57 + * @author Jaroslav Tulach
37.58 + */
37.59 +public final class Contexts {
37.60 + private Contexts() {
37.61 + }
37.62 +
37.63 + /** Creates new, empty builder for creation of {@link BrwsrCtx}. At the
37.64 + * end call the {@link Builder#build()} method to generate the context.
37.65 + *
37.66 + * @return new instance of the builder
37.67 + */
37.68 + public static Builder newBuilder() {
37.69 + return new Builder();
37.70 + }
37.71 +
37.72 + /** Seeks for the specified technology in the provided context.
37.73 + *
37.74 + * @param <Tech> type of the technology
37.75 + * @param context the context to seek in
37.76 + * (previously filled with ({@link Builder#register(java.lang.Class, java.lang.Object, int)})
37.77 + * @param technology class that identifies the technology
37.78 + * @return the technology in the context or <code>null</code>
37.79 + */
37.80 + public static <Tech> Tech find(BrwsrCtx context, Class<Tech> technology) {
37.81 + return CtxImpl.find(context, technology);
37.82 + }
37.83 +
37.84 + /** Seeks {@link ServiceLoader} for all registered instances of
37.85 + * {@link Provider} and asks them to {@link Provider#fillContext(org.netbeans.html.context.spi.Contexts.Builder, java.lang.Class) fill
37.86 + * the builder}.
37.87 + *
37.88 + * @param requestor the application class for which to find the context
37.89 + * @param cb the context builder to register technologies into
37.90 + * @return <code>true</code>, if some instances of the provider were
37.91 + * found, <code>false</code> otherwise
37.92 + * @since 0.7.6
37.93 + */
37.94 + public static boolean fillInByProviders(Class<?> requestor, Contexts.Builder cb) {
37.95 + boolean found = false;
37.96 + ClassLoader l;
37.97 + try {
37.98 + l = requestor.getClassLoader();
37.99 + } catch (SecurityException ex) {
37.100 + l = null;
37.101 + }
37.102 + for (Provider cp : ServiceLoader.load(Provider.class, l)) {
37.103 + cp.fillContext(cb, requestor);
37.104 + found = true;
37.105 + }
37.106 + try {
37.107 + for (Provider cp : ServiceLoader.load(Provider.class, Provider.class.getClassLoader())) {
37.108 + cp.fillContext(cb, requestor);
37.109 + found = true;
37.110 + }
37.111 + } catch (SecurityException ex) {
37.112 + if (!found) {
37.113 + throw ex;
37.114 + }
37.115 + }
37.116 + if (!found) {
37.117 + for (Provider cp : ServiceLoader.load(Provider.class)) {
37.118 + cp.fillContext(cb, requestor);
37.119 + found = true;
37.120 + }
37.121 + }
37.122 + return found;
37.123 + }
37.124 +
37.125 + /** Implementors of various HTML technologies should
37.126 + * register their implementation via <code>org.openide.util.lookup.ServiceProvider</code>, so
37.127 + * {@link ServiceLoader} can find them, when their JARs are included
37.128 + * on the classpath of the running application.
37.129 + *
37.130 + * @author Jaroslav Tulach
37.131 + */
37.132 + public static interface Provider {
37.133 +
37.134 + /** Register into the context if suitable technology is
37.135 + * available for the requesting class.
37.136 + * The provider should check if its own technology is available in current
37.137 + * scope (e.g. proper JDK, proper browser, etc.). The provider
37.138 + * can also find the right context depending on requestor's classloader, etc.
37.139 + * <p>
37.140 + * Providers should use {@link Builder} to enrich appropriately
37.141 + * the context.
37.142 + *
37.143 + * @param context the context builder to fill with technologies
37.144 + * @param requestor the application class requesting access the the HTML page
37.145 + * @see BrwsrCtx#findDefault(java.lang.Class)
37.146 + */
37.147 + void fillContext(Builder context, Class<?> requestor);
37.148 + }
37.149 +
37.150 + /** Support for providers of new {@link BrwsrCtx}. Providers of different
37.151 + * technologies should be of particular interest in this class. End users
37.152 + * designing their application with existing technologies should rather
37.153 + * point their attention to {@link BrwsrCtx} and co.
37.154 + *
37.155 + * @author Jaroslav Tulach
37.156 + */
37.157 + public static final class Builder {
37.158 + private final CtxImpl impl = new CtxImpl();
37.159 +
37.160 + Builder() {
37.161 + }
37.162 +
37.163 + /** Registers new technology into the context. Each technology is
37.164 + * exactly identified by its implementation class and can be associated
37.165 + * with (positive) priority. In case of presence of multiple technologies
37.166 + * with the same class, the one with higher lower priority takes precedence.
37.167 + * @param <Tech> type of technology to register
37.168 + * @param type the real class of the technology type
37.169 + * @param impl an instance of the technology class
37.170 + * @param position the lower position, the more important implementation
37.171 + * which will be consulted sooner when seeking for a {@link Contexts#find(net.java.html.BrwsrCtx, java.lang.Class)}
37.172 + * an implementation
37.173 + * @return this builder
37.174 + */
37.175 + public <Tech> Builder register(Class<Tech> type, Tech impl, int position) {
37.176 + if (impl == null) {
37.177 + return this;
37.178 + }
37.179 + if (position <= 0) {
37.180 + throw new IllegalStateException();
37.181 + }
37.182 + this.impl.register(type, impl, position);
37.183 + return this;
37.184 + }
37.185 +
37.186 + /** Generates context based on values previously inserted into
37.187 + * this builder.
37.188 + *
37.189 + * @return new, immutable instance of {@link BrwsrCtx}
37.190 + */
37.191 + public BrwsrCtx build() {
37.192 + return impl.build();
37.193 + }
37.194 + }
37.195 +}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
38.2 +++ b/context/src/main/java/org/netbeans/html/context/spi/package.html Tue Aug 26 18:13:30 2014 +0200
38.3 @@ -0,0 +1,50 @@
38.4 +<!--
38.5 +
38.6 + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
38.7 +
38.8 + Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
38.9 +
38.10 + Oracle and Java are registered trademarks of Oracle and/or its affiliates.
38.11 + Other names may be trademarks of their respective owners.
38.12 +
38.13 + The contents of this file are subject to the terms of either the GNU
38.14 + General Public License Version 2 only ("GPL") or the Common
38.15 + Development and Distribution License("CDDL") (collectively, the
38.16 + "License"). You may not use this file except in compliance with the
38.17 + License. You can obtain a copy of the License at
38.18 + http://www.netbeans.org/cddl-gplv2.html
38.19 + or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
38.20 + specific language governing permissions and limitations under the
38.21 + License. When distributing the software, include this License Header
38.22 + Notice in each file and include the License file at
38.23 + nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
38.24 + particular file as subject to the "Classpath" exception as provided
38.25 + by Oracle in the GPL Version 2 section of the License file that
38.26 + accompanied this code. If applicable, add the following below the
38.27 + License Header, with the fields enclosed by brackets [] replaced by
38.28 + your own identifying information:
38.29 + "Portions Copyrighted [year] [name of copyright owner]"
38.30 +
38.31 + Contributor(s):
38.32 +
38.33 + The Original Software is NetBeans. The Initial Developer of the Original
38.34 + Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
38.35 +
38.36 + If you wish your version of this file to be governed by only the CDDL
38.37 + or only the GPL Version 2, indicate your decision by adding
38.38 + "[Contributor] elects to include this software in this distribution
38.39 + under the [CDDL or GPL Version 2] license." If you do not indicate a
38.40 + single choice of license, a recipient has the option to distribute
38.41 + your version of this file under either the CDDL, the GPL Version 2 or
38.42 + to extend the choice of license to its licensees as provided above.
38.43 + However, if you add GPL Version 2 code and therefore, elected the GPL
38.44 + Version 2 license, then the option applies only if the new code is
38.45 + made subject to such option by the copyright holder.
38.46 +
38.47 +-->
38.48 +<body>
38.49 + <p>
38.50 + Service provider classes to build {@link net.java.html.BrwsrCtx}
38.51 + instances.
38.52 + </p>
38.53 +</body>
39.1 --- a/context/src/test/java/net/java/html/BrwsrCtxTest.java Tue Aug 26 17:43:37 2014 +0200
39.2 +++ b/context/src/test/java/net/java/html/BrwsrCtxTest.java Tue Aug 26 18:13:30 2014 +0200
39.3 @@ -42,7 +42,7 @@
39.4 */
39.5 package net.java.html;
39.6
39.7 -import org.apidesign.html.context.spi.Contexts;
39.8 +import org.netbeans.html.context.spi.Contexts;
39.9 import static org.testng.Assert.*;
39.10
39.11 /**
40.1 --- a/json-tck/pom.xml Tue Aug 26 17:43:37 2014 +0200
40.2 +++ b/json-tck/pom.xml Tue Aug 26 18:13:30 2014 +0200
40.3 @@ -14,7 +14,7 @@
40.4 <url>http://maven.apache.org</url>
40.5 <properties>
40.6 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
40.7 - <publicPackages>org.apidesign.html.json.tck</publicPackages>
40.8 + <publicPackages>org.netbeans.html.json.tck</publicPackages>
40.9 </properties>
40.10 <build>
40.11 <plugins>
40.12 @@ -30,7 +30,7 @@
40.13 <groupId>org.apache.maven.plugins</groupId>
40.14 <artifactId>maven-javadoc-plugin</artifactId>
40.15 <configuration>
40.16 - <subpackages>org.apidesign.html.json.tck,org.apidesign.html.json.spi</subpackages>
40.17 + <subpackages>org.netbeans.html.json.tck,org.netbeans.html.json.spi</subpackages>
40.18 <skip>false</skip>
40.19 <includeDependencySources>true</includeDependencySources>
40.20 </configuration>
41.1 --- a/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java Tue Aug 26 17:43:37 2014 +0200
41.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java Tue Aug 26 18:13:30 2014 +0200
41.3 @@ -45,8 +45,8 @@
41.4 import java.io.StringReader;
41.5 import java.util.Arrays;
41.6 import java.util.concurrent.Callable;
41.7 -import org.apidesign.html.boot.spi.Fn;
41.8 -import org.apidesign.html.json.tck.KOTest;
41.9 +import org.netbeans.html.boot.spi.Fn;
41.10 +import org.netbeans.html.json.tck.KOTest;
41.11
41.12 /**
41.13 *
42.1 --- a/json-tck/src/main/java/net/java/html/json/tests/ConvertTypesTest.java Tue Aug 26 17:43:37 2014 +0200
42.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/ConvertTypesTest.java Tue Aug 26 18:13:30 2014 +0200
42.3 @@ -52,7 +52,7 @@
42.4 import java.util.Map;
42.5 import net.java.html.BrwsrCtx;
42.6 import net.java.html.json.Models;
42.7 -import org.apidesign.html.json.tck.KOTest;
42.8 +import org.netbeans.html.json.tck.KOTest;
42.9
42.10 /**
42.11 *
43.1 --- a/json-tck/src/main/java/net/java/html/json/tests/JSONTest.java Tue Aug 26 17:43:37 2014 +0200
43.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/JSONTest.java Tue Aug 26 18:13:30 2014 +0200
43.3 @@ -51,7 +51,7 @@
43.4 import net.java.html.json.Models;
43.5 import net.java.html.json.OnReceive;
43.6 import net.java.html.json.Property;
43.7 -import org.apidesign.html.json.tck.KOTest;
43.8 +import org.netbeans.html.json.tck.KOTest;
43.9
43.10 /** Need to verify that models produce reasonable JSON objects.
43.11 *
44.1 --- a/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java Tue Aug 26 17:43:37 2014 +0200
44.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java Tue Aug 26 18:13:30 2014 +0200
44.3 @@ -52,7 +52,7 @@
44.4 import net.java.html.json.Model;
44.5 import net.java.html.json.Models;
44.6 import net.java.html.json.Property;
44.7 -import org.apidesign.html.json.tck.KOTest;
44.8 +import org.netbeans.html.json.tck.KOTest;
44.9
44.10 /**
44.11 *
45.1 --- a/json-tck/src/main/java/net/java/html/json/tests/MinesTest.java Tue Aug 26 17:43:37 2014 +0200
45.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/MinesTest.java Tue Aug 26 18:13:30 2014 +0200
45.3 @@ -53,7 +53,7 @@
45.4 import net.java.html.json.ModelOperation;
45.5 import net.java.html.json.Models;
45.6 import net.java.html.json.Property;
45.7 -import org.apidesign.html.json.tck.KOTest;
45.8 +import org.netbeans.html.json.tck.KOTest;
45.9
45.10 /** Tests model of a mine field and its behavior in the browser.
45.11 */
46.1 --- a/json-tck/src/main/java/net/java/html/json/tests/OperationsTest.java Tue Aug 26 17:43:37 2014 +0200
46.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/OperationsTest.java Tue Aug 26 18:13:30 2014 +0200
46.3 @@ -43,7 +43,7 @@
46.4 package net.java.html.json.tests;
46.5
46.6 import net.java.html.json.Models;
46.7 -import org.apidesign.html.json.tck.KOTest;
46.8 +import org.netbeans.html.json.tck.KOTest;
46.9
46.10 /**
46.11 *
47.1 --- a/json-tck/src/main/java/net/java/html/json/tests/Utils.java Tue Aug 26 17:43:37 2014 +0200
47.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/Utils.java Tue Aug 26 18:13:30 2014 +0200
47.3 @@ -47,7 +47,7 @@
47.4 import java.util.Map;
47.5 import java.util.ServiceLoader;
47.6 import net.java.html.BrwsrCtx;
47.7 -import org.apidesign.html.json.tck.KnockoutTCK;
47.8 +import org.netbeans.html.json.tck.KnockoutTCK;
47.9
47.10 /**
47.11 *
48.1 --- a/json-tck/src/main/java/net/java/html/json/tests/WebSocketTest.java Tue Aug 26 17:43:37 2014 +0200
48.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/WebSocketTest.java Tue Aug 26 18:13:30 2014 +0200
48.3 @@ -47,7 +47,7 @@
48.4 import net.java.html.json.Models;
48.5 import net.java.html.json.OnReceive;
48.6 import net.java.html.json.Property;
48.7 -import org.apidesign.html.json.tck.KOTest;
48.8 +import org.netbeans.html.json.tck.KOTest;
48.9
48.10 /** Testing support of WebSocket communication.
48.11 *
49.1 --- a/json-tck/src/main/java/org/apidesign/html/json/tck/JavaScriptTCK.java Tue Aug 26 17:43:37 2014 +0200
49.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
49.3 @@ -1,72 +0,0 @@
49.4 -/**
49.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
49.6 - *
49.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
49.8 - *
49.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
49.10 - * Other names may be trademarks of their respective owners.
49.11 - *
49.12 - * The contents of this file are subject to the terms of either the GNU
49.13 - * General Public License Version 2 only ("GPL") or the Common
49.14 - * Development and Distribution License("CDDL") (collectively, the
49.15 - * "License"). You may not use this file except in compliance with the
49.16 - * License. You can obtain a copy of the License at
49.17 - * http://www.netbeans.org/cddl-gplv2.html
49.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
49.19 - * specific language governing permissions and limitations under the
49.20 - * License. When distributing the software, include this License Header
49.21 - * Notice in each file and include the License file at
49.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
49.23 - * particular file as subject to the "Classpath" exception as provided
49.24 - * by Oracle in the GPL Version 2 section of the License file that
49.25 - * accompanied this code. If applicable, add the following below the
49.26 - * License Header, with the fields enclosed by brackets [] replaced by
49.27 - * your own identifying information:
49.28 - * "Portions Copyrighted [year] [name of copyright owner]"
49.29 - *
49.30 - * Contributor(s):
49.31 - *
49.32 - * The Original Software is NetBeans. The Initial Developer of the Original
49.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
49.34 - *
49.35 - * If you wish your version of this file to be governed by only the CDDL
49.36 - * or only the GPL Version 2, indicate your decision by adding
49.37 - * "[Contributor] elects to include this software in this distribution
49.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
49.39 - * single choice of license, a recipient has the option to distribute
49.40 - * your version of this file under either the CDDL, the GPL Version 2 or
49.41 - * to extend the choice of license to its licensees as provided above.
49.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
49.43 - * Version 2 license, then the option applies only if the new code is
49.44 - * made subject to such option by the copyright holder.
49.45 - */
49.46 -package org.apidesign.html.json.tck;
49.47 -
49.48 -import net.java.html.js.tests.JavaScriptBodyTest;
49.49 -import org.apidesign.html.boot.spi.Fn;
49.50 -import org.apidesign.html.boot.spi.Fn.Presenter;
49.51 -
49.52 -/** Entry point for those who want to verify that their implementation of
49.53 - * {@link Presenter} is good enough to support existing Java/JavaScript
49.54 - * communication use-cases. Subclass this class, get list of {@link #testClasses() classes}
49.55 - * find methods annotated by {@link KOTest} annotation and execute them.
49.56 - * <p>
49.57 - *
49.58 - * @author Jaroslav Tulach
49.59 - * @since 0.7
49.60 - */
49.61 -public abstract class JavaScriptTCK {
49.62 - /** Gives you list of classes included in the TCK. Their test methods
49.63 - * are annotated by {@link KOTest} annotation. The methods are public
49.64 - * instance methods that take no arguments. The method should be
49.65 - * invoke in a presenter context {@link Fn#activate(org.apidesign.html.boot.spi.Fn.Presenter)}.
49.66 - *
49.67 - * @return classes with methods annotated by {@link KOTest} annotation
49.68 - */
49.69 - protected static Class<?>[] testClasses() {
49.70 - return new Class[] {
49.71 - JavaScriptBodyTest.class
49.72 - };
49.73 - }
49.74 -
49.75 -}
50.1 --- a/json-tck/src/main/java/org/apidesign/html/json/tck/KOTest.java Tue Aug 26 17:43:37 2014 +0200
50.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
50.3 @@ -1,60 +0,0 @@
50.4 -/**
50.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
50.6 - *
50.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
50.8 - *
50.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
50.10 - * Other names may be trademarks of their respective owners.
50.11 - *
50.12 - * The contents of this file are subject to the terms of either the GNU
50.13 - * General Public License Version 2 only ("GPL") or the Common
50.14 - * Development and Distribution License("CDDL") (collectively, the
50.15 - * "License"). You may not use this file except in compliance with the
50.16 - * License. You can obtain a copy of the License at
50.17 - * http://www.netbeans.org/cddl-gplv2.html
50.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
50.19 - * specific language governing permissions and limitations under the
50.20 - * License. When distributing the software, include this License Header
50.21 - * Notice in each file and include the License file at
50.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
50.23 - * particular file as subject to the "Classpath" exception as provided
50.24 - * by Oracle in the GPL Version 2 section of the License file that
50.25 - * accompanied this code. If applicable, add the following below the
50.26 - * License Header, with the fields enclosed by brackets [] replaced by
50.27 - * your own identifying information:
50.28 - * "Portions Copyrighted [year] [name of copyright owner]"
50.29 - *
50.30 - * Contributor(s):
50.31 - *
50.32 - * The Original Software is NetBeans. The Initial Developer of the Original
50.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
50.34 - *
50.35 - * If you wish your version of this file to be governed by only the CDDL
50.36 - * or only the GPL Version 2, indicate your decision by adding
50.37 - * "[Contributor] elects to include this software in this distribution
50.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
50.39 - * single choice of license, a recipient has the option to distribute
50.40 - * your version of this file under either the CDDL, the GPL Version 2 or
50.41 - * to extend the choice of license to its licensees as provided above.
50.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
50.43 - * Version 2 license, then the option applies only if the new code is
50.44 - * made subject to such option by the copyright holder.
50.45 - */
50.46 -package org.apidesign.html.json.tck;
50.47 -
50.48 -import java.lang.annotation.ElementType;
50.49 -import java.lang.annotation.Retention;
50.50 -import java.lang.annotation.RetentionPolicy;
50.51 -import java.lang.annotation.Target;
50.52 -
50.53 -/** Annotates method that is part of {@link KnockoutTCK test compatibility kit}
50.54 - * and should be executed in appropriate environment. The method annotated by
50.55 - * this annotation will be public instance method of its class
50.56 - * with no arguments.
50.57 - *
50.58 - * @author Jaroslav Tulach
50.59 - */
50.60 -@Retention(RetentionPolicy.RUNTIME)
50.61 -@Target(ElementType.METHOD)
50.62 -public @interface KOTest {
50.63 -}
51.1 --- a/json-tck/src/main/java/org/apidesign/html/json/tck/KnockoutTCK.java Tue Aug 26 17:43:37 2014 +0200
51.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
51.3 @@ -1,141 +0,0 @@
51.4 -/**
51.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
51.6 - *
51.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
51.8 - *
51.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
51.10 - * Other names may be trademarks of their respective owners.
51.11 - *
51.12 - * The contents of this file are subject to the terms of either the GNU
51.13 - * General Public License Version 2 only ("GPL") or the Common
51.14 - * Development and Distribution License("CDDL") (collectively, the
51.15 - * "License"). You may not use this file except in compliance with the
51.16 - * License. You can obtain a copy of the License at
51.17 - * http://www.netbeans.org/cddl-gplv2.html
51.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
51.19 - * specific language governing permissions and limitations under the
51.20 - * License. When distributing the software, include this License Header
51.21 - * Notice in each file and include the License file at
51.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
51.23 - * particular file as subject to the "Classpath" exception as provided
51.24 - * by Oracle in the GPL Version 2 section of the License file that
51.25 - * accompanied this code. If applicable, add the following below the
51.26 - * License Header, with the fields enclosed by brackets [] replaced by
51.27 - * your own identifying information:
51.28 - * "Portions Copyrighted [year] [name of copyright owner]"
51.29 - *
51.30 - * Contributor(s):
51.31 - *
51.32 - * The Original Software is NetBeans. The Initial Developer of the Original
51.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
51.34 - *
51.35 - * If you wish your version of this file to be governed by only the CDDL
51.36 - * or only the GPL Version 2, indicate your decision by adding
51.37 - * "[Contributor] elects to include this software in this distribution
51.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
51.39 - * single choice of license, a recipient has the option to distribute
51.40 - * your version of this file under either the CDDL, the GPL Version 2 or
51.41 - * to extend the choice of license to its licensees as provided above.
51.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
51.43 - * Version 2 license, then the option applies only if the new code is
51.44 - * made subject to such option by the copyright holder.
51.45 - */
51.46 -package org.apidesign.html.json.tck;
51.47 -
51.48 -import java.net.URI;
51.49 -import java.util.Map;
51.50 -import net.java.html.BrwsrCtx;
51.51 -import net.java.html.json.tests.ConvertTypesTest;
51.52 -import net.java.html.json.tests.JSONTest;
51.53 -import net.java.html.json.tests.KnockoutTest;
51.54 -import net.java.html.json.tests.MinesTest;
51.55 -import net.java.html.json.tests.OperationsTest;
51.56 -import net.java.html.json.tests.Utils;
51.57 -import net.java.html.json.tests.WebSocketTest;
51.58 -import org.apidesign.html.context.spi.Contexts.Builder;
51.59 -import org.openide.util.lookup.ServiceProvider;
51.60 -
51.61 -/** Entry point for providers of different HTML binding technologies (like
51.62 - * Knockout.js in JavaFX's WebView). Sample usage:
51.63 - *
51.64 -<pre>
51.65 -{@link ServiceProvider @ServiceProvider}(service = KnockoutTCK.class)
51.66 -public final class MyKnockoutBindingTest extends KnockoutTCK {
51.67 - {@link Override @Override}
51.68 - protected BrwsrCtx createContext() {
51.69 - // use {@link Builder}.{@link Builder#build() build}();
51.70 - }
51.71 -
51.72 - {@code @}{@link org.testng.annotations.Factory} public static Object[] create() {
51.73 - return VMTest.newTests().withClasses({@link KnockoutTCK#testClasses}()).build();
51.74 - }
51.75 -}
51.76 - * </pre>
51.77 - *
51.78 - * @author Jaroslav Tulach
51.79 - */
51.80 -public abstract class KnockoutTCK {
51.81 - protected KnockoutTCK() {
51.82 - Utils.registerTCK(this);
51.83 - }
51.84 -
51.85 - /** Implement to create new context for the test.
51.86 - * Use {@link Builder} to set context for your technology up.
51.87 - * @return the final context for the test
51.88 - */
51.89 - public abstract BrwsrCtx createContext();
51.90 -
51.91 - /** Create a JSON object as seen by the technology
51.92 - * @param values mapping from names to values of properties
51.93 - * @return the JSON object with filled in values
51.94 - */
51.95 - public abstract Object createJSON(Map<String,Object> values);
51.96 -
51.97 - /** Executes script in the context of current window
51.98 - *
51.99 - * @param script the JavaScript code to execute
51.100 - * @param arguments arguments sent to the script (can be referenced as <code>arguments[0]</code>)
51.101 - * @return the output of the execution
51.102 - */
51.103 - public abstract Object executeScript(String script, Object[] arguments);
51.104 -
51.105 - /** Creates a URL which later returns content with given
51.106 - * <code>mimeType</code> and <code>content</code>. The
51.107 - * content may be processed by the provided <code>parameters</code>.
51.108 - *
51.109 - * @param content what should be available on the URL. Can contain <code>$0</code>
51.110 - * <code>$1</code> to reference <code>parameters</code> by their position
51.111 - * @param mimeType the type of the resource
51.112 - * @param parameters names of parameters as reference by <code>content</code>
51.113 - * @return URI the test can connect to to obtain the (processed) content
51.114 - */
51.115 - public abstract URI prepareURL(String content, String mimeType, String[] parameters);
51.116 -
51.117 - /** Gives you list of classes included in the TCK. Their test methods
51.118 - * are annotated by {@link KOTest} annotation. The methods are public
51.119 - * instance methods that take no arguments.
51.120 - *
51.121 - * @return classes with methods annotated by {@link KOTest} annotation
51.122 - */
51.123 - protected static Class<?>[] testClasses() {
51.124 - return new Class[] {
51.125 - ConvertTypesTest.class,
51.126 - JSONTest.class,
51.127 - KnockoutTest.class,
51.128 - MinesTest.class,
51.129 - OperationsTest.class,
51.130 - WebSocketTest.class
51.131 - };
51.132 - }
51.133 -
51.134 - /** Some implementations cannot fully support web sockets and fail.
51.135 - *
51.136 - * @return true, if UnsupportedOperationException reported from a web
51.137 - * socket open operation is acceptable reply
51.138 - */
51.139 - public boolean canFailWebSocketTest() {
51.140 - return false;
51.141 - }
51.142 -
51.143 -
51.144 -}
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
52.2 +++ b/json-tck/src/main/java/org/netbeans/html/json/tck/JavaScriptTCK.java Tue Aug 26 18:13:30 2014 +0200
52.3 @@ -0,0 +1,72 @@
52.4 +/**
52.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
52.6 + *
52.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
52.8 + *
52.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
52.10 + * Other names may be trademarks of their respective owners.
52.11 + *
52.12 + * The contents of this file are subject to the terms of either the GNU
52.13 + * General Public License Version 2 only ("GPL") or the Common
52.14 + * Development and Distribution License("CDDL") (collectively, the
52.15 + * "License"). You may not use this file except in compliance with the
52.16 + * License. You can obtain a copy of the License at
52.17 + * http://www.netbeans.org/cddl-gplv2.html
52.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
52.19 + * specific language governing permissions and limitations under the
52.20 + * License. When distributing the software, include this License Header
52.21 + * Notice in each file and include the License file at
52.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
52.23 + * particular file as subject to the "Classpath" exception as provided
52.24 + * by Oracle in the GPL Version 2 section of the License file that
52.25 + * accompanied this code. If applicable, add the following below the
52.26 + * License Header, with the fields enclosed by brackets [] replaced by
52.27 + * your own identifying information:
52.28 + * "Portions Copyrighted [year] [name of copyright owner]"
52.29 + *
52.30 + * Contributor(s):
52.31 + *
52.32 + * The Original Software is NetBeans. The Initial Developer of the Original
52.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
52.34 + *
52.35 + * If you wish your version of this file to be governed by only the CDDL
52.36 + * or only the GPL Version 2, indicate your decision by adding
52.37 + * "[Contributor] elects to include this software in this distribution
52.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
52.39 + * single choice of license, a recipient has the option to distribute
52.40 + * your version of this file under either the CDDL, the GPL Version 2 or
52.41 + * to extend the choice of license to its licensees as provided above.
52.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
52.43 + * Version 2 license, then the option applies only if the new code is
52.44 + * made subject to such option by the copyright holder.
52.45 + */
52.46 +package org.netbeans.html.json.tck;
52.47 +
52.48 +import net.java.html.js.tests.JavaScriptBodyTest;
52.49 +import org.netbeans.html.boot.spi.Fn;
52.50 +import org.netbeans.html.boot.spi.Fn.Presenter;
52.51 +
52.52 +/** Entry point for those who want to verify that their implementation of
52.53 + * {@link Presenter} is good enough to support existing Java/JavaScript
52.54 + * communication use-cases. Subclass this class, get list of {@link #testClasses() classes}
52.55 + * find methods annotated by {@link KOTest} annotation and execute them.
52.56 + * <p>
52.57 + *
52.58 + * @author Jaroslav Tulach
52.59 + * @since 0.7
52.60 + */
52.61 +public abstract class JavaScriptTCK {
52.62 + /** Gives you list of classes included in the TCK. Their test methods
52.63 + * are annotated by {@link KOTest} annotation. The methods are public
52.64 + * instance methods that take no arguments. The method should be
52.65 + * invoke in a presenter context {@link Fn#activate(org.netbeans.html.boot.spi.Fn.Presenter)}.
52.66 + *
52.67 + * @return classes with methods annotated by {@link KOTest} annotation
52.68 + */
52.69 + protected static Class<?>[] testClasses() {
52.70 + return new Class[] {
52.71 + JavaScriptBodyTest.class
52.72 + };
52.73 + }
52.74 +
52.75 +}
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
53.2 +++ b/json-tck/src/main/java/org/netbeans/html/json/tck/KOTest.java Tue Aug 26 18:13:30 2014 +0200
53.3 @@ -0,0 +1,60 @@
53.4 +/**
53.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
53.6 + *
53.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
53.8 + *
53.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
53.10 + * Other names may be trademarks of their respective owners.
53.11 + *
53.12 + * The contents of this file are subject to the terms of either the GNU
53.13 + * General Public License Version 2 only ("GPL") or the Common
53.14 + * Development and Distribution License("CDDL") (collectively, the
53.15 + * "License"). You may not use this file except in compliance with the
53.16 + * License. You can obtain a copy of the License at
53.17 + * http://www.netbeans.org/cddl-gplv2.html
53.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
53.19 + * specific language governing permissions and limitations under the
53.20 + * License. When distributing the software, include this License Header
53.21 + * Notice in each file and include the License file at
53.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
53.23 + * particular file as subject to the "Classpath" exception as provided
53.24 + * by Oracle in the GPL Version 2 section of the License file that
53.25 + * accompanied this code. If applicable, add the following below the
53.26 + * License Header, with the fields enclosed by brackets [] replaced by
53.27 + * your own identifying information:
53.28 + * "Portions Copyrighted [year] [name of copyright owner]"
53.29 + *
53.30 + * Contributor(s):
53.31 + *
53.32 + * The Original Software is NetBeans. The Initial Developer of the Original
53.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
53.34 + *
53.35 + * If you wish your version of this file to be governed by only the CDDL
53.36 + * or only the GPL Version 2, indicate your decision by adding
53.37 + * "[Contributor] elects to include this software in this distribution
53.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
53.39 + * single choice of license, a recipient has the option to distribute
53.40 + * your version of this file under either the CDDL, the GPL Version 2 or
53.41 + * to extend the choice of license to its licensees as provided above.
53.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
53.43 + * Version 2 license, then the option applies only if the new code is
53.44 + * made subject to such option by the copyright holder.
53.45 + */
53.46 +package org.netbeans.html.json.tck;
53.47 +
53.48 +import java.lang.annotation.ElementType;
53.49 +import java.lang.annotation.Retention;
53.50 +import java.lang.annotation.RetentionPolicy;
53.51 +import java.lang.annotation.Target;
53.52 +
53.53 +/** Annotates method that is part of {@link KnockoutTCK test compatibility kit}
53.54 + * and should be executed in appropriate environment. The method annotated by
53.55 + * this annotation will be public instance method of its class
53.56 + * with no arguments.
53.57 + *
53.58 + * @author Jaroslav Tulach
53.59 + */
53.60 +@Retention(RetentionPolicy.RUNTIME)
53.61 +@Target(ElementType.METHOD)
53.62 +public @interface KOTest {
53.63 +}
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
54.2 +++ b/json-tck/src/main/java/org/netbeans/html/json/tck/KnockoutTCK.java Tue Aug 26 18:13:30 2014 +0200
54.3 @@ -0,0 +1,141 @@
54.4 +/**
54.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
54.6 + *
54.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
54.8 + *
54.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
54.10 + * Other names may be trademarks of their respective owners.
54.11 + *
54.12 + * The contents of this file are subject to the terms of either the GNU
54.13 + * General Public License Version 2 only ("GPL") or the Common
54.14 + * Development and Distribution License("CDDL") (collectively, the
54.15 + * "License"). You may not use this file except in compliance with the
54.16 + * License. You can obtain a copy of the License at
54.17 + * http://www.netbeans.org/cddl-gplv2.html
54.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
54.19 + * specific language governing permissions and limitations under the
54.20 + * License. When distributing the software, include this License Header
54.21 + * Notice in each file and include the License file at
54.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
54.23 + * particular file as subject to the "Classpath" exception as provided
54.24 + * by Oracle in the GPL Version 2 section of the License file that
54.25 + * accompanied this code. If applicable, add the following below the
54.26 + * License Header, with the fields enclosed by brackets [] replaced by
54.27 + * your own identifying information:
54.28 + * "Portions Copyrighted [year] [name of copyright owner]"
54.29 + *
54.30 + * Contributor(s):
54.31 + *
54.32 + * The Original Software is NetBeans. The Initial Developer of the Original
54.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
54.34 + *
54.35 + * If you wish your version of this file to be governed by only the CDDL
54.36 + * or only the GPL Version 2, indicate your decision by adding
54.37 + * "[Contributor] elects to include this software in this distribution
54.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
54.39 + * single choice of license, a recipient has the option to distribute
54.40 + * your version of this file under either the CDDL, the GPL Version 2 or
54.41 + * to extend the choice of license to its licensees as provided above.
54.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
54.43 + * Version 2 license, then the option applies only if the new code is
54.44 + * made subject to such option by the copyright holder.
54.45 + */
54.46 +package org.netbeans.html.json.tck;
54.47 +
54.48 +import java.net.URI;
54.49 +import java.util.Map;
54.50 +import net.java.html.BrwsrCtx;
54.51 +import net.java.html.json.tests.ConvertTypesTest;
54.52 +import net.java.html.json.tests.JSONTest;
54.53 +import net.java.html.json.tests.KnockoutTest;
54.54 +import net.java.html.json.tests.MinesTest;
54.55 +import net.java.html.json.tests.OperationsTest;
54.56 +import net.java.html.json.tests.Utils;
54.57 +import net.java.html.json.tests.WebSocketTest;
54.58 +import org.netbeans.html.context.spi.Contexts.Builder;
54.59 +import org.openide.util.lookup.ServiceProvider;
54.60 +
54.61 +/** Entry point for providers of different HTML binding technologies (like
54.62 + * Knockout.js in JavaFX's WebView). Sample usage:
54.63 + *
54.64 +<pre>
54.65 +{@link ServiceProvider @ServiceProvider}(service = KnockoutTCK.class)
54.66 +public final class MyKnockoutBindingTest extends KnockoutTCK {
54.67 + {@link Override @Override}
54.68 + protected BrwsrCtx createContext() {
54.69 + // use {@link Builder}.{@link Builder#build() build}();
54.70 + }
54.71 +
54.72 + {@code @}{@link org.testng.annotations.Factory} public static Object[] create() {
54.73 + return VMTest.newTests().withClasses({@link KnockoutTCK#testClasses}()).build();
54.74 + }
54.75 +}
54.76 + * </pre>
54.77 + *
54.78 + * @author Jaroslav Tulach
54.79 + */
54.80 +public abstract class KnockoutTCK {
54.81 + protected KnockoutTCK() {
54.82 + Utils.registerTCK(this);
54.83 + }
54.84 +
54.85 + /** Implement to create new context for the test.
54.86 + * Use {@link Builder} to set context for your technology up.
54.87 + * @return the final context for the test
54.88 + */
54.89 + public abstract BrwsrCtx createContext();
54.90 +
54.91 + /** Create a JSON object as seen by the technology
54.92 + * @param values mapping from names to values of properties
54.93 + * @return the JSON object with filled in values
54.94 + */
54.95 + public abstract Object createJSON(Map<String,Object> values);
54.96 +
54.97 + /** Executes script in the context of current window
54.98 + *
54.99 + * @param script the JavaScript code to execute
54.100 + * @param arguments arguments sent to the script (can be referenced as <code>arguments[0]</code>)
54.101 + * @return the output of the execution
54.102 + */
54.103 + public abstract Object executeScript(String script, Object[] arguments);
54.104 +
54.105 + /** Creates a URL which later returns content with given
54.106 + * <code>mimeType</code> and <code>content</code>. The
54.107 + * content may be processed by the provided <code>parameters</code>.
54.108 + *
54.109 + * @param content what should be available on the URL. Can contain <code>$0</code>
54.110 + * <code>$1</code> to reference <code>parameters</code> by their position
54.111 + * @param mimeType the type of the resource
54.112 + * @param parameters names of parameters as reference by <code>content</code>
54.113 + * @return URI the test can connect to to obtain the (processed) content
54.114 + */
54.115 + public abstract URI prepareURL(String content, String mimeType, String[] parameters);
54.116 +
54.117 + /** Gives you list of classes included in the TCK. Their test methods
54.118 + * are annotated by {@link KOTest} annotation. The methods are public
54.119 + * instance methods that take no arguments.
54.120 + *
54.121 + * @return classes with methods annotated by {@link KOTest} annotation
54.122 + */
54.123 + protected static Class<?>[] testClasses() {
54.124 + return new Class[] {
54.125 + ConvertTypesTest.class,
54.126 + JSONTest.class,
54.127 + KnockoutTest.class,
54.128 + MinesTest.class,
54.129 + OperationsTest.class,
54.130 + WebSocketTest.class
54.131 + };
54.132 + }
54.133 +
54.134 + /** Some implementations cannot fully support web sockets and fail.
54.135 + *
54.136 + * @return true, if UnsupportedOperationException reported from a web
54.137 + * socket open operation is acceptable reply
54.138 + */
54.139 + public boolean canFailWebSocketTest() {
54.140 + return false;
54.141 + }
54.142 +
54.143 +
54.144 +}
55.1 --- a/json-tck/src/main/resources/org/apidesign/html/json/tck/package.html Tue Aug 26 17:43:37 2014 +0200
55.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
55.3 @@ -1,56 +0,0 @@
55.4 -<!--
55.5 -
55.6 - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
55.7 -
55.8 - Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
55.9 -
55.10 - Oracle and Java are registered trademarks of Oracle and/or its affiliates.
55.11 - Other names may be trademarks of their respective owners.
55.12 -
55.13 - The contents of this file are subject to the terms of either the GNU
55.14 - General Public License Version 2 only ("GPL") or the Common
55.15 - Development and Distribution License("CDDL") (collectively, the
55.16 - "License"). You may not use this file except in compliance with the
55.17 - License. You can obtain a copy of the License at
55.18 - http://www.netbeans.org/cddl-gplv2.html
55.19 - or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
55.20 - specific language governing permissions and limitations under the
55.21 - License. When distributing the software, include this License Header
55.22 - Notice in each file and include the License file at
55.23 - nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
55.24 - particular file as subject to the "Classpath" exception as provided
55.25 - by Oracle in the GPL Version 2 section of the License file that
55.26 - accompanied this code. If applicable, add the following below the
55.27 - License Header, with the fields enclosed by brackets [] replaced by
55.28 - your own identifying information:
55.29 - "Portions Copyrighted [year] [name of copyright owner]"
55.30 -
55.31 - Contributor(s):
55.32 -
55.33 - The Original Software is NetBeans. The Initial Developer of the Original
55.34 - Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
55.35 -
55.36 - If you wish your version of this file to be governed by only the CDDL
55.37 - or only the GPL Version 2, indicate your decision by adding
55.38 - "[Contributor] elects to include this software in this distribution
55.39 - under the [CDDL or GPL Version 2] license." If you do not indicate a
55.40 - single choice of license, a recipient has the option to distribute
55.41 - your version of this file under either the CDDL, the GPL Version 2 or
55.42 - to extend the choice of license to its licensees as provided above.
55.43 - However, if you add GPL Version 2 code and therefore, elected the GPL
55.44 - Version 2 license, then the option applies only if the new code is
55.45 - made subject to such option by the copyright holder.
55.46 -
55.47 --->
55.48 -<!DOCTYPE html>
55.49 -<html>
55.50 - <head>
55.51 - <title></title>
55.52 - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
55.53 - </head>
55.54 - <body>
55.55 - <div>Entry point to the
55.56 - <a href="KnockoutTCK.html">test compatibility kit</a>.
55.57 - </div>
55.58 - </body>
55.59 -</html>
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
56.2 +++ b/json-tck/src/main/resources/org/netbeans/html/json/tck/package.html Tue Aug 26 18:13:30 2014 +0200
56.3 @@ -0,0 +1,56 @@
56.4 +<!--
56.5 +
56.6 + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
56.7 +
56.8 + Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
56.9 +
56.10 + Oracle and Java are registered trademarks of Oracle and/or its affiliates.
56.11 + Other names may be trademarks of their respective owners.
56.12 +
56.13 + The contents of this file are subject to the terms of either the GNU
56.14 + General Public License Version 2 only ("GPL") or the Common
56.15 + Development and Distribution License("CDDL") (collectively, the
56.16 + "License"). You may not use this file except in compliance with the
56.17 + License. You can obtain a copy of the License at
56.18 + http://www.netbeans.org/cddl-gplv2.html
56.19 + or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
56.20 + specific language governing permissions and limitations under the
56.21 + License. When distributing the software, include this License Header
56.22 + Notice in each file and include the License file at
56.23 + nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
56.24 + particular file as subject to the "Classpath" exception as provided
56.25 + by Oracle in the GPL Version 2 section of the License file that
56.26 + accompanied this code. If applicable, add the following below the
56.27 + License Header, with the fields enclosed by brackets [] replaced by
56.28 + your own identifying information:
56.29 + "Portions Copyrighted [year] [name of copyright owner]"
56.30 +
56.31 + Contributor(s):
56.32 +
56.33 + The Original Software is NetBeans. The Initial Developer of the Original
56.34 + Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
56.35 +
56.36 + If you wish your version of this file to be governed by only the CDDL
56.37 + or only the GPL Version 2, indicate your decision by adding
56.38 + "[Contributor] elects to include this software in this distribution
56.39 + under the [CDDL or GPL Version 2] license." If you do not indicate a
56.40 + single choice of license, a recipient has the option to distribute
56.41 + your version of this file under either the CDDL, the GPL Version 2 or
56.42 + to extend the choice of license to its licensees as provided above.
56.43 + However, if you add GPL Version 2 code and therefore, elected the GPL
56.44 + Version 2 license, then the option applies only if the new code is
56.45 + made subject to such option by the copyright holder.
56.46 +
56.47 +-->
56.48 +<!DOCTYPE html>
56.49 +<html>
56.50 + <head>
56.51 + <title></title>
56.52 + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
56.53 + </head>
56.54 + <body>
56.55 + <div>Entry point to the
56.56 + <a href="KnockoutTCK.html">test compatibility kit</a>.
56.57 + </div>
56.58 + </body>
56.59 +</html>
57.1 --- a/json/pom.xml Tue Aug 26 17:43:37 2014 +0200
57.2 +++ b/json/pom.xml Tue Aug 26 18:13:30 2014 +0200
57.3 @@ -14,7 +14,7 @@
57.4 <url>http://maven.apache.org</url>
57.5 <properties>
57.6 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
57.7 - <publicPackages>net.java.html.json,org.apidesign.html.json.spi</publicPackages>
57.8 + <publicPackages>net.java.html.json,org.netbeans.html.json.spi</publicPackages>
57.9 </properties>
57.10 <build>
57.11 <plugins>
58.1 --- a/json/src/main/java/org/apidesign/html/json/spi/FunctionBinding.java Tue Aug 26 17:43:37 2014 +0200
58.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
58.3 @@ -1,110 +0,0 @@
58.4 -/**
58.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
58.6 - *
58.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
58.8 - *
58.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
58.10 - * Other names may be trademarks of their respective owners.
58.11 - *
58.12 - * The contents of this file are subject to the terms of either the GNU
58.13 - * General Public License Version 2 only ("GPL") or the Common
58.14 - * Development and Distribution License("CDDL") (collectively, the
58.15 - * "License"). You may not use this file except in compliance with the
58.16 - * License. You can obtain a copy of the License at
58.17 - * http://www.netbeans.org/cddl-gplv2.html
58.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
58.19 - * specific language governing permissions and limitations under the
58.20 - * License. When distributing the software, include this License Header
58.21 - * Notice in each file and include the License file at
58.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
58.23 - * particular file as subject to the "Classpath" exception as provided
58.24 - * by Oracle in the GPL Version 2 section of the License file that
58.25 - * accompanied this code. If applicable, add the following below the
58.26 - * License Header, with the fields enclosed by brackets [] replaced by
58.27 - * your own identifying information:
58.28 - * "Portions Copyrighted [year] [name of copyright owner]"
58.29 - *
58.30 - * Contributor(s):
58.31 - *
58.32 - * The Original Software is NetBeans. The Initial Developer of the Original
58.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
58.34 - *
58.35 - * If you wish your version of this file to be governed by only the CDDL
58.36 - * or only the GPL Version 2, indicate your decision by adding
58.37 - * "[Contributor] elects to include this software in this distribution
58.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
58.39 - * single choice of license, a recipient has the option to distribute
58.40 - * your version of this file under either the CDDL, the GPL Version 2 or
58.41 - * to extend the choice of license to its licensees as provided above.
58.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
58.43 - * Version 2 license, then the option applies only if the new code is
58.44 - * made subject to such option by the copyright holder.
58.45 - */
58.46 -package org.apidesign.html.json.spi;
58.47 -
58.48 -import net.java.html.BrwsrCtx;
58.49 -import net.java.html.json.Function;
58.50 -import net.java.html.json.Model;
58.51 -
58.52 -/** Describes a function provided by the {@link Model} and
58.53 - * annotated by {@link Function} annotation.
58.54 - *
58.55 - * @author Jaroslav Tulach
58.56 - */
58.57 -public abstract class FunctionBinding {
58.58 - FunctionBinding() {
58.59 - }
58.60 -
58.61 - /** Returns name of the function.
58.62 - * @return function name
58.63 - */
58.64 - public abstract String getFunctionName();
58.65 -
58.66 - /**
58.67 - * Calls the function provided data associated with current element, as well
58.68 - * as information about the event that triggered the event.
58.69 - *
58.70 - * @param data data associated with selected element
58.71 - * @param ev event (with additional properties) that triggered the event
58.72 - */
58.73 - public abstract void call(Object data, Object ev);
58.74 -
58.75 - static <M> FunctionBinding registerFunction(String name, int index, M model, Proto.Type<M> access) {
58.76 - return new Impl<M>(name, index, model, access);
58.77 - }
58.78 -
58.79 - private static final class Impl<M> extends FunctionBinding {
58.80 - final String name;
58.81 - private final M model;
58.82 - private final Proto.Type<M> access;
58.83 - private final int index;
58.84 -
58.85 - public Impl(String name, int index, M model, Proto.Type<M> access) {
58.86 - this.name = name;
58.87 - this.index = index;
58.88 - this.model = model;
58.89 - this.access = access;
58.90 - }
58.91 -
58.92 - @Override
58.93 - public String getFunctionName() {
58.94 - return name;
58.95 - }
58.96 -
58.97 - @Override
58.98 - public void call(final Object data, final Object ev) {
58.99 - BrwsrCtx ctx = access.protoFor(model).getContext();
58.100 - class Dispatch implements Runnable {
58.101 - @Override
58.102 - public void run() {
58.103 - try {
58.104 - access.call(model, index, data, ev);
58.105 - } catch (Throwable ex) {
58.106 - ex.printStackTrace();
58.107 - }
58.108 - }
58.109 - }
58.110 - ctx.execute(new Dispatch());
58.111 - }
58.112 - }
58.113 -}
59.1 --- a/json/src/main/java/org/apidesign/html/json/spi/JSONCall.java Tue Aug 26 17:43:37 2014 +0200
59.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
59.3 @@ -1,136 +0,0 @@
59.4 -/**
59.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
59.6 - *
59.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
59.8 - *
59.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
59.10 - * Other names may be trademarks of their respective owners.
59.11 - *
59.12 - * The contents of this file are subject to the terms of either the GNU
59.13 - * General Public License Version 2 only ("GPL") or the Common
59.14 - * Development and Distribution License("CDDL") (collectively, the
59.15 - * "License"). You may not use this file except in compliance with the
59.16 - * License. You can obtain a copy of the License at
59.17 - * http://www.netbeans.org/cddl-gplv2.html
59.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
59.19 - * specific language governing permissions and limitations under the
59.20 - * License. When distributing the software, include this License Header
59.21 - * Notice in each file and include the License file at
59.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
59.23 - * particular file as subject to the "Classpath" exception as provided
59.24 - * by Oracle in the GPL Version 2 section of the License file that
59.25 - * accompanied this code. If applicable, add the following below the
59.26 - * License Header, with the fields enclosed by brackets [] replaced by
59.27 - * your own identifying information:
59.28 - * "Portions Copyrighted [year] [name of copyright owner]"
59.29 - *
59.30 - * Contributor(s):
59.31 - *
59.32 - * The Original Software is NetBeans. The Initial Developer of the Original
59.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
59.34 - *
59.35 - * If you wish your version of this file to be governed by only the CDDL
59.36 - * or only the GPL Version 2, indicate your decision by adding
59.37 - * "[Contributor] elects to include this software in this distribution
59.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
59.39 - * single choice of license, a recipient has the option to distribute
59.40 - * your version of this file under either the CDDL, the GPL Version 2 or
59.41 - * to extend the choice of license to its licensees as provided above.
59.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
59.43 - * Version 2 license, then the option applies only if the new code is
59.44 - * made subject to such option by the copyright holder.
59.45 - */
59.46 -package org.apidesign.html.json.spi;
59.47 -
59.48 -import java.io.IOException;
59.49 -import java.io.OutputStream;
59.50 -import net.java.html.BrwsrCtx;
59.51 -import org.netbeans.html.json.impl.RcvrJSON;
59.52 -
59.53 -/** Description of a JSON call request that is supposed to be processed
59.54 - * by {@link Transfer#loadJSON(org.apidesign.html.json.spi.JSONCall)} implementors.
59.55 - *
59.56 - * @author Jaroslav Tulach
59.57 - */
59.58 -public final class JSONCall {
59.59 - private final RcvrJSON whenDone;
59.60 - private final String urlBefore;
59.61 - private final String urlAfter;
59.62 - private final String method;
59.63 - private final Object data;
59.64 - private final BrwsrCtx ctx;
59.65 -
59.66 - JSONCall(BrwsrCtx ctx, RcvrJSON whenDone, String urlBefore, String urlAfter, String method, Object data) {
59.67 - this.ctx = ctx;
59.68 - this.whenDone = whenDone;
59.69 - this.urlBefore = urlBefore;
59.70 - this.urlAfter = urlAfter;
59.71 - this.method = method;
59.72 - this.data = data;
59.73 - }
59.74 -
59.75 - /** Do we have some data to send? Can the {@link #writeData(java.io.OutputStream)} method be
59.76 - * called?
59.77 - *
59.78 - * @return true, if the call has some data to send
59.79 - */
59.80 - public boolean isDoOutput() {
59.81 - return this.data != null;
59.82 - }
59.83 -
59.84 - public void writeData(OutputStream os) throws IOException {
59.85 - if (this.data == null) {
59.86 - throw new IOException("No data!");
59.87 - }
59.88 - os.write(this.data.toString().getBytes("UTF-8"));
59.89 - os.flush();
59.90 - }
59.91 -
59.92 - public String getMethod() {
59.93 - return method;
59.94 - }
59.95 -
59.96 - public boolean isJSONP() {
59.97 - return urlAfter != null;
59.98 - }
59.99 -
59.100 - public String composeURL(String jsonpCallback) {
59.101 - if ((urlAfter == null) != (jsonpCallback == null)) {
59.102 - throw new IllegalStateException();
59.103 - }
59.104 - if (urlAfter != null) {
59.105 - return urlBefore + jsonpCallback + urlAfter;
59.106 - } else {
59.107 - return urlBefore;
59.108 - }
59.109 - }
59.110 -
59.111 - public void notifySuccess(Object result) {
59.112 - if (result == null) {
59.113 - dispatch(RcvrJSON.MsgEvnt.createOpen());
59.114 - } else {
59.115 - dispatch(RcvrJSON.MsgEvnt.createMessage(result));
59.116 - }
59.117 - }
59.118 -
59.119 - public void notifyError(Throwable error) {
59.120 - if (error == null) {
59.121 - dispatch(RcvrJSON.MsgEvnt.createClose());
59.122 - } else {
59.123 - dispatch(RcvrJSON.MsgEvnt.createError(error));
59.124 - }
59.125 - }
59.126 -
59.127 - private void dispatch(final RcvrJSON.MsgEvnt ev) {
59.128 - ctx.execute(new Runnable() {
59.129 - @Override
59.130 - public void run() {
59.131 - ev.dispatch(whenDone);
59.132 - }
59.133 - });
59.134 - }
59.135 -
59.136 - public String getMessage() {
59.137 - return this.data.toString();
59.138 - }
59.139 -}
60.1 --- a/json/src/main/java/org/apidesign/html/json/spi/Observers.java Tue Aug 26 17:43:37 2014 +0200
60.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
60.3 @@ -1,221 +0,0 @@
60.4 -/**
60.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
60.6 - *
60.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
60.8 - *
60.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
60.10 - * Other names may be trademarks of their respective owners.
60.11 - *
60.12 - * The contents of this file are subject to the terms of either the GNU
60.13 - * General Public License Version 2 only ("GPL") or the Common
60.14 - * Development and Distribution License("CDDL") (collectively, the
60.15 - * "License"). You may not use this file except in compliance with the
60.16 - * License. You can obtain a copy of the License at
60.17 - * http://www.netbeans.org/cddl-gplv2.html
60.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
60.19 - * specific language governing permissions and limitations under the
60.20 - * License. When distributing the software, include this License Header
60.21 - * Notice in each file and include the License file at
60.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
60.23 - * particular file as subject to the "Classpath" exception as provided
60.24 - * by Oracle in the GPL Version 2 section of the License file that
60.25 - * accompanied this code. If applicable, add the following below the
60.26 - * License Header, with the fields enclosed by brackets [] replaced by
60.27 - * your own identifying information:
60.28 - * "Portions Copyrighted [year] [name of copyright owner]"
60.29 - *
60.30 - * Contributor(s):
60.31 - *
60.32 - * The Original Software is NetBeans. The Initial Developer of the Original
60.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
60.34 - *
60.35 - * If you wish your version of this file to be governed by only the CDDL
60.36 - * or only the GPL Version 2, indicate your decision by adding
60.37 - * "[Contributor] elects to include this software in this distribution
60.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
60.39 - * single choice of license, a recipient has the option to distribute
60.40 - * your version of this file under either the CDDL, the GPL Version 2 or
60.41 - * to extend the choice of license to its licensees as provided above.
60.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
60.43 - * Version 2 license, then the option applies only if the new code is
60.44 - * made subject to such option by the copyright holder.
60.45 - */
60.46 -package org.apidesign.html.json.spi;
60.47 -
60.48 -import java.lang.ref.WeakReference;
60.49 -import java.util.ArrayList;
60.50 -import java.util.Iterator;
60.51 -import java.util.LinkedList;
60.52 -import java.util.List;
60.53 -
60.54 -/**
60.55 - *
60.56 - * @author Jaroslav Tulach
60.57 - */
60.58 -final class Observers {
60.59 - private static final LinkedList<Watcher> GLOBAL = new LinkedList<Watcher>();
60.60 - private final List<Watcher> watchers = new ArrayList<Watcher>();
60.61 - private final List<Ref> observers = new ArrayList<Ref>();
60.62 -
60.63 - Observers() {
60.64 - assert Thread.holdsLock(GLOBAL);
60.65 - }
60.66 -
60.67 - static void beginComputing(Proto p, String name) {
60.68 - synchronized (GLOBAL) {
60.69 - verifyUnlocked(p);
60.70 - final Watcher nw = new Watcher(p, name);
60.71 - GLOBAL.push(nw);
60.72 - }
60.73 - }
60.74 -
60.75 - static void verifyUnlocked(Proto p) {
60.76 - synchronized (GLOBAL) {
60.77 - for (Watcher w : GLOBAL) {
60.78 - if (w.proto == p) {
60.79 - throw new IllegalStateException("Re-entrant attempt to access " + p);
60.80 - }
60.81 - }
60.82 - }
60.83 - }
60.84 -
60.85 - static void accessingValue(Proto p, String propName) {
60.86 - synchronized (GLOBAL) {
60.87 - verifyUnlocked(p);
60.88 - for (Watcher w : GLOBAL) {
60.89 - Observers mine = p.observers(true);
60.90 - mine.add(w, new Ref(w, propName));
60.91 - }
60.92 - }
60.93 - }
60.94 -
60.95 - static void finishComputing(Proto p) {
60.96 - synchronized (GLOBAL) {
60.97 - Watcher w = GLOBAL.pop();
60.98 - if (w.proto != p) {
60.99 - throw new IllegalStateException("Inconsistency: " + w.proto + " != " + p);
60.100 - }
60.101 - if (w.prop != null) {
60.102 - Observers mine = p.observers(true);
60.103 - mine.add(w);
60.104 - }
60.105 - }
60.106 - }
60.107 -
60.108 - private static final class Ref extends WeakReference<Watcher> {
60.109 - private final String prop;
60.110 -
60.111 - public Ref(Watcher ref, String prop) {
60.112 - super(ref);
60.113 - this.prop = prop;
60.114 - }
60.115 -
60.116 - final Watcher watcher() {
60.117 - Watcher w = get();
60.118 - if (w == null) {
60.119 - return null;
60.120 - }
60.121 - final Observers o = w.proto.observers(false);
60.122 - if (o == null) {
60.123 - return null;
60.124 - }
60.125 - if (o.find(w.prop) == w) {
60.126 - return w;
60.127 - }
60.128 - return null;
60.129 - }
60.130 - }
60.131 -
60.132 - private Watcher find(String prop) {
60.133 - if (prop == null) {
60.134 - return null;
60.135 - }
60.136 - for (Watcher w : watchers) {
60.137 - if (prop.equals(w.prop)) {
60.138 - return w;
60.139 - }
60.140 - }
60.141 - return null;
60.142 - }
60.143 -
60.144 - final void add(Watcher w) {
60.145 - for (int i = 0; i < watchers.size(); i++) {
60.146 - Watcher ith = watchers.get(i);
60.147 - if (w.prop == null) {
60.148 - if (ith.prop == null) {
60.149 - watchers.set(i, w);
60.150 - return;
60.151 - }
60.152 - } else if (w.prop.equals(ith.prop)) {
60.153 - watchers.set(i, w);
60.154 - return;
60.155 - }
60.156 - }
60.157 - watchers.add(w);
60.158 - }
60.159 -
60.160 - static final void valueHasMutated(Proto p, String propName) {
60.161 - List<Watcher> mutated = new LinkedList<Watcher>();
60.162 - synchronized (GLOBAL) {
60.163 - Observers mine = p.observers(false);
60.164 - if (mine == null) {
60.165 - return;
60.166 - }
60.167 - Iterator<Ref> it = mine.observers.iterator();
60.168 - while (it.hasNext()) {
60.169 - Ref ref = it.next();
60.170 - if (ref.get() == null) {
60.171 - it.remove();
60.172 - continue;
60.173 - }
60.174 - if (ref.prop.equals(propName)) {
60.175 - Watcher w = ref.watcher();
60.176 - if (w != null) {
60.177 - mutated.add(w);
60.178 - }
60.179 - }
60.180 - }
60.181 - }
60.182 - for (Watcher w : mutated) {
60.183 - w.proto.valueHasMutated(w.prop);
60.184 - }
60.185 - }
60.186 -
60.187 - void add(Watcher w, Ref r) {
60.188 - Thread.holdsLock(GLOBAL);
60.189 - if (w == null) {
60.190 - return;
60.191 - }
60.192 - Iterator<Ref> it = observers.iterator();
60.193 - while (it.hasNext()) {
60.194 - Ref ref = it.next();
60.195 - if (r == ref) {
60.196 - return;
60.197 - }
60.198 - final Watcher rw = ref.get();
60.199 - if (rw == null) {
60.200 - it.remove();
60.201 - continue;
60.202 - }
60.203 - if (rw == w && r.prop.equals(r.prop)) {
60.204 - return;
60.205 - }
60.206 - }
60.207 - observers.add(r);
60.208 - }
60.209 -
60.210 - private static final class Watcher {
60.211 - final Proto proto;
60.212 - final String prop;
60.213 -
60.214 - Watcher(Proto proto, String prop) {
60.215 - this.proto = proto;
60.216 - this.prop = prop;
60.217 - }
60.218 -
60.219 - @Override
60.220 - public String toString() {
60.221 - return "Watcher: " + proto + ", " + prop;
60.222 - }
60.223 - }
60.224 -}
61.1 --- a/json/src/main/java/org/apidesign/html/json/spi/PropertyBinding.java Tue Aug 26 17:43:37 2014 +0200
61.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
61.3 @@ -1,168 +0,0 @@
61.4 -/**
61.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
61.6 - *
61.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
61.8 - *
61.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
61.10 - * Other names may be trademarks of their respective owners.
61.11 - *
61.12 - * The contents of this file are subject to the terms of either the GNU
61.13 - * General Public License Version 2 only ("GPL") or the Common
61.14 - * Development and Distribution License("CDDL") (collectively, the
61.15 - * "License"). You may not use this file except in compliance with the
61.16 - * License. You can obtain a copy of the License at
61.17 - * http://www.netbeans.org/cddl-gplv2.html
61.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
61.19 - * specific language governing permissions and limitations under the
61.20 - * License. When distributing the software, include this License Header
61.21 - * Notice in each file and include the License file at
61.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
61.23 - * particular file as subject to the "Classpath" exception as provided
61.24 - * by Oracle in the GPL Version 2 section of the License file that
61.25 - * accompanied this code. If applicable, add the following below the
61.26 - * License Header, with the fields enclosed by brackets [] replaced by
61.27 - * your own identifying information:
61.28 - * "Portions Copyrighted [year] [name of copyright owner]"
61.29 - *
61.30 - * Contributor(s):
61.31 - *
61.32 - * The Original Software is NetBeans. The Initial Developer of the Original
61.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
61.34 - *
61.35 - * If you wish your version of this file to be governed by only the CDDL
61.36 - * or only the GPL Version 2, indicate your decision by adding
61.37 - * "[Contributor] elects to include this software in this distribution
61.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
61.39 - * single choice of license, a recipient has the option to distribute
61.40 - * your version of this file under either the CDDL, the GPL Version 2 or
61.41 - * to extend the choice of license to its licensees as provided above.
61.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
61.43 - * Version 2 license, then the option applies only if the new code is
61.44 - * made subject to such option by the copyright holder.
61.45 - */
61.46 -package org.apidesign.html.json.spi;
61.47 -
61.48 -import net.java.html.BrwsrCtx;
61.49 -import org.netbeans.html.json.impl.Bindings;
61.50 -import org.netbeans.html.json.impl.JSON;
61.51 -import org.netbeans.html.json.impl.PropertyBindingAccessor;
61.52 -import org.netbeans.html.json.impl.RcvrJSON;
61.53 -
61.54 -/** Describes a property when one is asked to
61.55 - * bind it
61.56 - *
61.57 - * @author Jaroslav Tulach
61.58 - */
61.59 -public abstract class PropertyBinding {
61.60 - PropertyBinding() {
61.61 - }
61.62 -
61.63 - static {
61.64 - new PropertyBindingAccessor() {
61.65 - @Override
61.66 - protected JSONCall newCall(BrwsrCtx ctx, RcvrJSON callback, String urlBefore, String urlAfter, String method, Object data) {
61.67 - return new JSONCall(ctx, callback, urlBefore, urlAfter, method, data);
61.68 - }
61.69 -
61.70 - @Override
61.71 - protected Bindings bindings(Proto proto, boolean initialize) {
61.72 - return initialize ? proto.initBindings() : proto.getBindings();
61.73 - }
61.74 -
61.75 - @Override
61.76 - protected void notifyChange(Proto proto, int propIndex) {
61.77 - proto.onChange(propIndex);
61.78 - }
61.79 -
61.80 - @Override
61.81 - protected Proto findProto(Proto.Type<?> type, Object object) {
61.82 - return type.protoFor(object);
61.83 - }
61.84 -
61.85 - @Override
61.86 - protected <Model> Model cloneTo(Proto.Type<Model> type, Model model, BrwsrCtx c) {
61.87 - return type.cloneTo(model, c);
61.88 - }
61.89 -
61.90 - @Override
61.91 - protected Object read(Proto.Type<?> from, BrwsrCtx c, Object data) {
61.92 - return from.read(c, data);
61.93 - }
61.94 -
61.95 - @Override
61.96 - protected <M> PropertyBinding newBinding(
61.97 - Proto.Type<M> access, Bindings<?> bindings, String name,
61.98 - int index, M model, boolean readOnly
61.99 - ) {
61.100 - return new Impl(bindings, name, index, model, access, readOnly);
61.101 - }
61.102 - };
61.103 - }
61.104 -
61.105 - /** Name of the property this binding represents.
61.106 - * @return name of the property
61.107 - */
61.108 - public abstract String getPropertyName();
61.109 -
61.110 - /** Changes value of the property. Can be called only on dedicated
61.111 - * thread. See {@link Technology#runSafe(java.lang.Runnable)}.
61.112 - *
61.113 - * @param v new value of the property
61.114 - */
61.115 - public abstract void setValue(Object v);
61.116 -
61.117 - /** Obtains current value of the property this binding represents.
61.118 - * Can be called only on dedicated
61.119 - * thread. See {@link Technology#runSafe(java.lang.Runnable)}.
61.120 - *
61.121 - * @return the value or <code>null</code>
61.122 - */
61.123 - public abstract Object getValue();
61.124 -
61.125 - /** Is this property read only? Or can one call {@link #setValue(java.lang.Object)}?
61.126 - *
61.127 - * @return true, if this property is read only
61.128 - */
61.129 - public abstract boolean isReadOnly();
61.130 -
61.131 - private static final class Impl<M> extends PropertyBinding {
61.132 - public final String name;
61.133 - public final boolean readOnly;
61.134 - private final M model;
61.135 - private final Proto.Type<M> access;
61.136 - private final Bindings<?> bindings;
61.137 - private final int index;
61.138 -
61.139 - public Impl(Bindings<?> bindings, String name, int index, M model, Proto.Type<M> access, boolean readOnly) {
61.140 - this.bindings = bindings;
61.141 - this.name = name;
61.142 - this.index = index;
61.143 - this.model = model;
61.144 - this.access = access;
61.145 - this.readOnly = readOnly;
61.146 - }
61.147 -
61.148 - @Override
61.149 - public void setValue(Object v) {
61.150 - access.setValue(model, index, v);
61.151 - }
61.152 -
61.153 - @Override
61.154 - public Object getValue() {
61.155 - Object v = access.getValue(model, index);
61.156 - Object r = JSON.find(v, bindings);
61.157 - return r == null ? v : r;
61.158 - }
61.159 -
61.160 - @Override
61.161 - public boolean isReadOnly() {
61.162 - return readOnly;
61.163 - }
61.164 -
61.165 - @Override
61.166 - public String getPropertyName() {
61.167 - return name;
61.168 - }
61.169 - } // end of PBData
61.170 -
61.171 -}
62.1 --- a/json/src/main/java/org/apidesign/html/json/spi/Proto.java Tue Aug 26 17:43:37 2014 +0200
62.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
62.3 @@ -1,843 +0,0 @@
62.4 -/**
62.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
62.6 - *
62.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
62.8 - *
62.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
62.10 - * Other names may be trademarks of their respective owners.
62.11 - *
62.12 - * The contents of this file are subject to the terms of either the GNU
62.13 - * General Public License Version 2 only ("GPL") or the Common
62.14 - * Development and Distribution License("CDDL") (collectively, the
62.15 - * "License"). You may not use this file except in compliance with the
62.16 - * License. You can obtain a copy of the License at
62.17 - * http://www.netbeans.org/cddl-gplv2.html
62.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
62.19 - * specific language governing permissions and limitations under the
62.20 - * License. When distributing the software, include this License Header
62.21 - * Notice in each file and include the License file at
62.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
62.23 - * particular file as subject to the "Classpath" exception as provided
62.24 - * by Oracle in the GPL Version 2 section of the License file that
62.25 - * accompanied this code. If applicable, add the following below the
62.26 - * License Header, with the fields enclosed by brackets [] replaced by
62.27 - * your own identifying information:
62.28 - * "Portions Copyrighted [year] [name of copyright owner]"
62.29 - *
62.30 - * Contributor(s):
62.31 - *
62.32 - * The Original Software is NetBeans. The Initial Developer of the Original
62.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
62.34 - *
62.35 - * If you wish your version of this file to be governed by only the CDDL
62.36 - * or only the GPL Version 2, indicate your decision by adding
62.37 - * "[Contributor] elects to include this software in this distribution
62.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
62.39 - * single choice of license, a recipient has the option to distribute
62.40 - * your version of this file under either the CDDL, the GPL Version 2 or
62.41 - * to extend the choice of license to its licensees as provided above.
62.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
62.43 - * Version 2 license, then the option applies only if the new code is
62.44 - * made subject to such option by the copyright holder.
62.45 - */
62.46 -package org.apidesign.html.json.spi;
62.47 -
62.48 -import java.util.Collection;
62.49 -import java.util.List;
62.50 -import net.java.html.BrwsrCtx;
62.51 -import net.java.html.json.ComputedProperty;
62.52 -import net.java.html.json.Model;
62.53 -import org.netbeans.html.json.impl.Bindings;
62.54 -import org.netbeans.html.json.impl.JSON;
62.55 -import org.netbeans.html.json.impl.JSONList;
62.56 -import org.netbeans.html.json.impl.RcvrJSON;
62.57 -import org.netbeans.html.json.impl.RcvrJSON.MsgEvnt;
62.58 -
62.59 -/** Object associated with one instance of a model generated by the
62.60 - * {@link Model} annotation. Contains methods the generated class can
62.61 - * use to communicate with behind the scene associated {@link Technology}.
62.62 - * Each {@link Proto} object is associated with <a href="http://wiki.apidesign.org/wiki/Singletonizer">
62.63 - * singletonizer</a>-like interface {@link Type} which provides the
62.64 - * associated {@link Technology} the necessary information about the
62.65 - * generated {@link Model} class.
62.66 - *
62.67 - * @author Jaroslav Tulach
62.68 - * @since 0.7
62.69 - */
62.70 -public final class Proto {
62.71 - private final Object obj;
62.72 - private final Type type;
62.73 - private final net.java.html.BrwsrCtx context;
62.74 - private org.netbeans.html.json.impl.Bindings ko;
62.75 - private Observers observers;
62.76 -
62.77 - Proto(Object obj, Type type, BrwsrCtx context) {
62.78 - this.obj = obj;
62.79 - this.type = type;
62.80 - this.context = context;
62.81 - }
62.82 -
62.83 - /** Browser context this proto object and its associated model
62.84 - * are operating-in.
62.85 - *
62.86 - * @return the associated context
62.87 - */
62.88 - public BrwsrCtx getContext() {
62.89 - return context;
62.90 - }
62.91 -
62.92 - /** Acquires global lock to compute a {@link ComputedProperty derived property}
62.93 - * on this proto object. This proto object must not be locked yet. No
62.94 - * dependency tracking is performed.
62.95 - *
62.96 - * @throws IllegalStateException if already locked
62.97 - */
62.98 - public void acquireLock() throws IllegalStateException {
62.99 - acquireLock(null);
62.100 - }
62.101 -
62.102 - /** Acquires global lock to compute a {@link ComputedProperty derived property}
62.103 - * on this proto object. This proto object must not be locked yet. The
62.104 - * name of the property is used to track dependencies on own
62.105 - * properties of other proto objects - when they are changed, this
62.106 - * {@link #valueHasMutated(java.lang.String) property is changed too}.
62.107 - *
62.108 - * @param propName name of property we are about to compute
62.109 - * @throws IllegalStateException thrown when there is a cyclic
62.110 - * call is detected
62.111 - * @since 0.9
62.112 - */
62.113 - public void acquireLock(String propName) throws IllegalStateException {
62.114 - Observers.beginComputing(this, propName);
62.115 - }
62.116 -
62.117 - /** A property on this proto object is about to be accessed. Verifies
62.118 - * whether this proto object is accessible - e.g. it has not been
62.119 - * {@link #acquireLock() locked yet}. If everything is OK, the
62.120 - * <code>propName</code> is recorded in the chain of dependencies
62.121 - * tracked by {@link #acquireLock(java.lang.String)} and watched by
62.122 - * {@link #valueHasMutated(java.lang.String)}.
62.123 - *
62.124 - * @param propName name of the property that is requested
62.125 - * @throws IllegalStateException if the model is locked
62.126 - * @since 0.9
62.127 - */
62.128 - public void accessProperty(String propName) throws IllegalStateException {
62.129 - Observers.accessingValue(this, propName);
62.130 - }
62.131 -
62.132 - /** Verifies the model is not locked otherwise throws an exception.
62.133 - * @throws IllegalStateException if the model is locked
62.134 - */
62.135 - public void verifyUnlocked() throws IllegalStateException {
62.136 - Observers.verifyUnlocked(this);
62.137 - }
62.138 -
62.139 - /** When modifications are over, the model is switched into
62.140 - * unlocked state by calling this method.
62.141 - */
62.142 - public void releaseLock() {
62.143 - Observers.finishComputing(this);
62.144 - }
62.145 -
62.146 - /** Whenever model changes a property. It should notify the
62.147 - * associated technology by calling this method.
62.148 - * Since 0.8.3: This method may be called by any thread - it reschedules
62.149 - * its actual execution into appropriate one by using
62.150 - * {@link BrwsrCtx#execute(java.lang.Runnable)}.
62.151 - *
62.152 - * @param propName name of the changed property
62.153 - */
62.154 - public void valueHasMutated(final String propName) {
62.155 - context.execute(new Runnable() {
62.156 - @Override
62.157 - public void run() {
62.158 - if (ko != null) {
62.159 - ko.valueHasMutated(propName, null, null);
62.160 - }
62.161 - Observers.valueHasMutated(Proto.this, propName);
62.162 - }
62.163 - });
62.164 - }
62.165 -
62.166 - /** Whenever model changes a propertyit should notify the
62.167 - * associated technology. Either by calling this method
62.168 - * (if the new value is known and different to the old one) or
62.169 - * via (slightly ineffective) {@link #valueHasMutated(java.lang.String)}
62.170 - * method.
62.171 - * Since 0.8.3: This method may be called by any thread - it reschedules
62.172 - * its actual execution into appropriate one by using
62.173 - * {@link BrwsrCtx#execute(java.lang.Runnable)}.
62.174 - *
62.175 - * @param propName name of the changed property
62.176 - * @param oldValue provides previous value of the property
62.177 - * @param newValue provides new value of the property
62.178 - * @since 0.7.6
62.179 - */
62.180 - public void valueHasMutated(
62.181 - final String propName, final Object oldValue, final Object newValue
62.182 - ) {
62.183 - context.execute(new Runnable() {
62.184 - @Override
62.185 - public void run() {
62.186 - if (ko != null) {
62.187 - ko.valueHasMutated(propName, oldValue, newValue);
62.188 - }
62.189 - Observers.valueHasMutated(Proto.this, propName);
62.190 - }
62.191 - });
62.192 - }
62.193 -
62.194 - /** Initializes the associated model in the current {@link #getContext() context}.
62.195 - * In case of <em>knockout.js</em> technology, applies given bindings
62.196 - * of the current model to the <em>body</em> element of the page.
62.197 - */
62.198 - public void applyBindings() {
62.199 - initBindings().applyBindings();
62.200 - }
62.201 -
62.202 - /** Invokes the provided runnable in the {@link #getContext() context}
62.203 - * of the browser. If the caller is already on the right thread, the
62.204 - * <code>run.run()</code> is invoked immediately and synchronously.
62.205 - * Otherwise the method returns immediately and the <code>run()</code>
62.206 - * method is performed later
62.207 - *
62.208 - * @param run the action to execute
62.209 - */
62.210 - public void runInBrowser(Runnable run) {
62.211 - context.execute(run);
62.212 - }
62.213 -
62.214 - /** Invokes the specified function index in the {@link #getContext() context}
62.215 - * of the browser. If the caller is already on the right thread, the
62.216 - * index-th function is invoked immediately and synchronously.
62.217 - * Otherwise the method returns immediately and the function is invoked
62.218 - * later.
62.219 - *
62.220 - * @param index the index of the function as will be passed to
62.221 - * {@link Type#call(java.lang.Object, int, java.lang.Object, java.lang.Object)}
62.222 - * method
62.223 - * @param args array of arguments that will be passed as
62.224 - * <code>data</code> argument of the <code>call</code> method.
62.225 - * @since 0.7.6
62.226 - */
62.227 - public void runInBrowser(final int index, final Object... args) {
62.228 - context.execute(new Runnable() {
62.229 - @Override
62.230 - public void run() {
62.231 - try {
62.232 - type.call(obj, index, args, null);
62.233 - } catch (Exception ex) {
62.234 - ex.printStackTrace();
62.235 - }
62.236 - }
62.237 - });
62.238 - }
62.239 -
62.240 - /** Initializes the provided collection with a content of the <code>array</code>.
62.241 - * The initialization can only be done soon after the the collection
62.242 - * is created, otherwise an exception is throw
62.243 - *
62.244 - * @param to the collection to initialize (assumed to be empty)
62.245 - * @param array the array to add to the collection
62.246 - * @throws IllegalStateException if the system has already been initialized
62.247 - */
62.248 - public void initTo(Collection<?> to, Object array) {
62.249 - if (ko != null) {
62.250 - throw new IllegalStateException();
62.251 - }
62.252 - if (to instanceof JSONList) {
62.253 - ((JSONList)to).init(array);
62.254 - } else {
62.255 - JSONList.init(to, array);
62.256 - }
62.257 - }
62.258 -
62.259 - /** Takes an object representing JSON result and extract some of its
62.260 - * properties. It is assumed that the <code>props</code> and
62.261 - * <code>values</code> arrays have the same length.
62.262 - *
62.263 - * @param json the JSON object (actual type depends on the associated
62.264 - * {@link Technology})
62.265 - * @param props list of properties to extract
62.266 - * @param values array that will be filled with extracted values
62.267 - */
62.268 - public void extract(Object json, String[] props, Object[] values) {
62.269 - JSON.extract(context, json, props, values);
62.270 - }
62.271 -
62.272 - /** Converts raw JSON <code>data</code> into a Java {@link Model} class.
62.273 - *
62.274 - * @param <T> type of the model class
62.275 - * @param modelClass the type of the class to create
62.276 - * @param data the raw JSON data
62.277 - * @return newly created instance of the model class
62.278 - */
62.279 - public <T> T read(Class<T> modelClass, Object data) {
62.280 - return JSON.read(context, modelClass, data);
62.281 - }
62.282 -
62.283 - /** Initializes asynchronous JSON connection to specified URL. Delegates
62.284 - * to {@link #loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...) }
62.285 - * with no extra parameters.
62.286 - *
62.287 - * @param index the callback index to be used when a reply is received
62.288 - * to call {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)}.
62.289 - *
62.290 - * @param urlBefore the part of the URL before JSON-P callback parameter
62.291 - * @param urlAfter the rest of the URL or <code>null</code> if no JSON-P is used
62.292 - * @param method method to use for connection to the server
62.293 - * @param data string, number or a {@link Model} generated class to send to
62.294 - * the server when doing a query
62.295 - */
62.296 - public void loadJSON(final int index,
62.297 - String urlBefore, String urlAfter, String method,
62.298 - final Object data
62.299 - ) {
62.300 - loadJSON(index, urlBefore, urlAfter, method, data, new Object[0]);
62.301 - }
62.302 -
62.303 - /** Initializes asynchronous JSON connection to specified URL. The
62.304 - * method returns immediately and later does callback later.
62.305 - *
62.306 - * @param index the callback index to be used when a reply is received
62.307 - * to call {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)}.
62.308 - *
62.309 - * @param urlBefore the part of the URL before JSON-P callback parameter
62.310 - * @param urlAfter the rest of the URL or <code>null</code> if no JSON-P is used
62.311 - * @param method method to use for connection to the server
62.312 - * @param data string, number or a {@link Model} generated class to send to
62.313 - * the server when doing a query
62.314 - * @param params extra params to pass back when calling
62.315 - * {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object, java.lang.Object[])}
62.316 - * @since 0.8.1
62.317 - */
62.318 - public void loadJSON(final int index,
62.319 - String urlBefore, String urlAfter, String method,
62.320 - final Object data, final Object... params
62.321 - ) {
62.322 - class Rcvr extends RcvrJSON {
62.323 - @Override
62.324 - protected void onMessage(MsgEvnt msg) {
62.325 - type.onMessage(obj, index, 1, msg.getValues(), params);
62.326 - }
62.327 -
62.328 - @Override
62.329 - protected void onError(MsgEvnt msg) {
62.330 - type.onMessage(obj, index, 2, msg.getException(), params);
62.331 - }
62.332 - }
62.333 - JSON.loadJSON(context, new Rcvr(), urlBefore, urlAfter, method, data);
62.334 - }
62.335 -
62.336 - /** Opens new WebSocket connection to the specified URL.
62.337 - *
62.338 - * @param index the index to use later during callbacks to
62.339 - * {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)}
62.340 - * @param url the <code>ws://</code> or <code>wss://</code> URL to connect to
62.341 - * @param data data to send to server (usually <code>null</code>)
62.342 - * @return returns a non-null object representing the socket
62.343 - * which can be used when calling {@link #wsSend(java.lang.Object, java.lang.String, java.lang.Object) }
62.344 - */
62.345 - public Object wsOpen(final int index, String url, Object data) {
62.346 - class WSrcvr extends RcvrJSON {
62.347 - @Override
62.348 - protected void onError(MsgEvnt msg) {
62.349 - type.onMessage(obj, index, 2, msg.getException());
62.350 - }
62.351 -
62.352 - @Override
62.353 - protected void onMessage(MsgEvnt msg) {
62.354 - type.onMessage(obj, index, 1, msg.getValues());
62.355 - }
62.356 -
62.357 - @Override
62.358 - protected void onClose(MsgEvnt msg) {
62.359 - type.onMessage(obj, index, 3, null);
62.360 - }
62.361 -
62.362 - @Override
62.363 - protected void onOpen(MsgEvnt msg) {
62.364 - type.onMessage(obj, index, 0, null);
62.365 - }
62.366 - }
62.367 - return JSON.openWS(context, new WSrcvr(), url, data);
62.368 - }
62.369 -
62.370 - /** Sends a message to existing socket.
62.371 - *
62.372 - * @param webSocket the socket to send message to
62.373 - * @param url the <code>ws://</code> or <code>wss://</code> URL to connect to,
62.374 - * preferably the same as the one used when the socket was
62.375 - * {@link #wsOpen(int, java.lang.String, java.lang.Object) opened}
62.376 - * @param data the data to send or <code>null</code> if the socket is
62.377 - * supposed to be closed
62.378 - */
62.379 - public void wsSend(Object webSocket, String url, Object data) {
62.380 - ((JSON.WS)webSocket).send(context, url, data);
62.381 - }
62.382 -
62.383 - /** Converts raw data (one of its properties) to string representation.
62.384 - *
62.385 - * @param data the object
62.386 - * @param propName the name of object property or <code>null</code>
62.387 - * if the whole object should be converted
62.388 - * @return the string representation of the object or its property
62.389 - */
62.390 - public String toString(Object data, String propName) {
62.391 - return JSON.toString(context, data, propName);
62.392 - }
62.393 -
62.394 - /** Converts raw data (one of its properties) to a number representation.
62.395 - *
62.396 - * @param data the object
62.397 - * @param propName the name of object property or <code>null</code>
62.398 - * if the whole object should be converted
62.399 - * @return the number representation of the object or its property
62.400 - */
62.401 - public Number toNumber(Object data, String propName) {
62.402 - return JSON.toNumber(context, data, propName);
62.403 - }
62.404 -
62.405 - /** Converts raw JSON data into a {@link Model} class representation.
62.406 - *
62.407 - * @param <T> type of the model to create
62.408 - * @param type class of the model to create
62.409 - * @param data raw JSON data (depends on associated {@link Technology})
62.410 - * @return new instances of the model class filled with values from the
62.411 - * <code>data</code> object
62.412 - */
62.413 - public <T> T toModel(Class<T> type, Object data) {
62.414 - return JSON.toModel(context, type, data, null);
62.415 - }
62.416 -
62.417 - /** Creates new JSON like observable list.
62.418 - *
62.419 - * @param <T> the type of the list elements
62.420 - * @param propName name of a property this list is associated with
62.421 - * @param onChange index of the property to use when the list is modified
62.422 - * during callback to {@link Type#onChange(java.lang.Object, int)}
62.423 - * @param dependingProps the array of {@link ComputedProperty derived properties}
62.424 - * that depend on the value of the list
62.425 - * @return new, empty list associated with this proto-object and its model
62.426 - */
62.427 - public <T> List<T> createList(String propName, int onChange, String... dependingProps) {
62.428 - return new JSONList<T>(this, propName, onChange, dependingProps);
62.429 - }
62.430 -
62.431 - /** Copies content of one collection to another, re-assigning all its
62.432 - * elements from their current context to the new <code>ctx</code>.
62.433 - *
62.434 - * @param <T> type of the collections
62.435 - * @param to the target collection to be filled with cloned values
62.436 - * @param ctx context for the new collection
62.437 - * @param from original collection with its data
62.438 - */
62.439 - public <T> void cloneList(Collection<T> to, BrwsrCtx ctx, Collection<T> from) {
62.440 - Boolean isModel = null;
62.441 - for (T t : from) {
62.442 - if (isModel == null) {
62.443 - isModel = JSON.isModel(t.getClass());
62.444 - }
62.445 - if (isModel) {
62.446 - to.add(JSON.bindTo(t, ctx));
62.447 - } else {
62.448 - to.add(t);
62.449 - }
62.450 - }
62.451 - }
62.452 -
62.453 - //
62.454 - // internal state
62.455 - //
62.456 -
62.457 - final String toStr() {
62.458 - return "Proto[" + obj + "]@" + Integer.toHexString(System.identityHashCode(this));
62.459 - }
62.460 -
62.461 - final Bindings initBindings() {
62.462 - if (ko == null) {
62.463 - Bindings b = Bindings.apply(context, obj);
62.464 - PropertyBinding[] pb = new PropertyBinding[type.propertyNames.length];
62.465 - for (int i = 0; i < pb.length; i++) {
62.466 - pb[i] = b.registerProperty(
62.467 - type.propertyNames[i], i, obj, type, type.propertyReadOnly[i]
62.468 - );
62.469 - }
62.470 - FunctionBinding[] fb = new FunctionBinding[type.functions.length];
62.471 - for (int i = 0; i < fb.length; i++) {
62.472 - fb[i] = FunctionBinding.registerFunction(
62.473 - type.functions[i], i, obj, type
62.474 - );
62.475 - }
62.476 - ko = b;
62.477 - b.finish(obj, pb, fb);
62.478 - }
62.479 - return ko;
62.480 - }
62.481 -
62.482 - final Bindings getBindings() {
62.483 - return ko;
62.484 - }
62.485 -
62.486 - final void onChange(int index) {
62.487 - type.onChange(obj, index);
62.488 - }
62.489 -
62.490 - final Observers observers(boolean create) {
62.491 - if (create && observers == null) {
62.492 - observers = new Observers();
62.493 - }
62.494 - return observers;
62.495 - }
62.496 -
62.497 - /** Functionality used by the code generated by annotation
62.498 - * processor for the {@link net.java.html.json.Model} annotation.
62.499 - *
62.500 - * @param <Model> the generated class
62.501 - * @since 0.7
62.502 - */
62.503 - public static abstract class Type<Model> {
62.504 - private final Class<Model> clazz;
62.505 - private final String[] propertyNames;
62.506 - private final boolean[] propertyReadOnly;
62.507 - private final String[] functions;
62.508 -
62.509 - /** Constructor for subclasses generated by the annotation processor
62.510 - * associated with {@link net.java.html.json.Model} annotation.
62.511 - *
62.512 - * @param clazz the generated model class
62.513 - * @param modelFor the original class annotated by the {@link net.java.html.json.Model} annotation.
62.514 - * @param properties number of properties the class has
62.515 - * @param functions number of functions the class has
62.516 - */
62.517 - protected Type(
62.518 - Class<Model> clazz, Class<?> modelFor, int properties, int functions
62.519 - ) {
62.520 - assert getClass().getName().endsWith("$Html4JavaType");
62.521 - try {
62.522 - assert getClass().getDeclaringClass() == clazz;
62.523 - } catch (SecurityException ex) {
62.524 - // OK, no check
62.525 - }
62.526 - this.clazz = clazz;
62.527 - this.propertyNames = new String[properties];
62.528 - this.propertyReadOnly = new boolean[properties];
62.529 - this.functions = new String[functions];
62.530 - JSON.register(clazz, this);
62.531 - }
62.532 -
62.533 - /** Registers property for the type. It is expected each index
62.534 - * is initialized only once.
62.535 - *
62.536 - * @param name name of the property
62.537 - * @param index index of the property
62.538 - * @param readOnly is the property read only?
62.539 - */
62.540 - protected final void registerProperty(String name, int index, boolean readOnly) {
62.541 - assert propertyNames[index] == null;
62.542 - propertyNames[index] = name;
62.543 - propertyReadOnly[index] = readOnly;
62.544 - }
62.545 -
62.546 - /** Registers function of given name at given index.
62.547 - *
62.548 - * @param name name of the function
62.549 - * @param index name of the type
62.550 - */
62.551 - protected final void registerFunction(String name, int index) {
62.552 - assert functions[index] == null;
62.553 - functions[index] = name;
62.554 - }
62.555 -
62.556 - /** Creates new proto-object for given {@link Model} class bound to
62.557 - * provided context.
62.558 - *
62.559 - * @param obj instance of appropriate {@link Model} class
62.560 - * @param context the browser context
62.561 - * @return new proto-object that the generated class can use for
62.562 - * communication with the infrastructure
62.563 - */
62.564 - public Proto createProto(Object obj, BrwsrCtx context) {
62.565 - return new Proto(obj, this, context);
62.566 - }
62.567 -
62.568 - //
62.569 - // Implemented by subclasses
62.570 - //
62.571 -
62.572 - /** Sets value of a {@link #registerProperty(java.lang.String, int, boolean) registered property}
62.573 - * to new value.
62.574 - *
62.575 - * @param model the instance of {@link Model model class}
62.576 - * @param index index of the property used during registration
62.577 - * @param value the value to set the property to
62.578 - */
62.579 - protected abstract void setValue(Model model, int index, Object value);
62.580 -
62.581 - /** Obtains and returns value of a
62.582 - * {@link #registerProperty(java.lang.String, int, boolean) registered property}.
62.583 - *
62.584 - * @param model the instance of {@link Model model class}
62.585 - * @param index index of the property used during registration
62.586 - * @return current value of the property
62.587 - */
62.588 - protected abstract Object getValue(Model model, int index);
62.589 -
62.590 - /** Invokes a {@link #registerFunction(java.lang.String, int)} registered function
62.591 - * on given object.
62.592 - *
62.593 - * @param model the instance of {@link Model model class}
62.594 - * @param index index of the property used during registration
62.595 - * @param data the currently selected object the function is about to operate on
62.596 - * @param event the event that triggered the event
62.597 - * @throws Exception the method can throw exception which is then logged
62.598 - */
62.599 - protected abstract void call(Model model, int index, Object data, Object event)
62.600 - throws Exception;
62.601 -
62.602 - /** Re-binds the model object to new browser context.
62.603 - *
62.604 - * @param model the instance of {@link Model model class}
62.605 - * @param ctx browser context to clone the object to
62.606 - * @return new instance of the model suitable for new context
62.607 - */
62.608 - protected abstract Model cloneTo(Model model, BrwsrCtx ctx);
62.609 -
62.610 - /** Reads raw JSON data and converts them to our model class.
62.611 - *
62.612 - * @param c the browser context to work in
62.613 - * @param json raw JSON data to get values from
62.614 - * @return new instance of model class filled by the data
62.615 - */
62.616 - protected abstract Model read(BrwsrCtx c, Object json);
62.617 -
62.618 - /** Called when a {@link #registerProperty(java.lang.String, int, boolean) registered property}
62.619 - * changes its value.
62.620 - *
62.621 - * @param model the object that has the property
62.622 - * @param index the index of the property during registration
62.623 - */
62.624 - protected abstract void onChange(Model model, int index);
62.625 -
62.626 - /** Finds out if there is an associated proto-object for given
62.627 - * object.
62.628 - *
62.629 - * @param object an object, presumably (but not necessarily) instance of Model class
62.630 - * @return associated proto-object or <code>null</code>
62.631 - */
62.632 - protected abstract Proto protoFor(Object object);
62.633 -
62.634 - /** Called to report results of asynchronous over-the-wire
62.635 - * communication. Result of calling {@link Proto#wsOpen(int, java.lang.String, java.lang.Object)}
62.636 - * or {@link Proto#loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)}.
62.637 - *
62.638 - * @param model the instance of the model class
62.639 - * @param index index used during initiating the communication (via <code>loadJSON</code> or <code>wsOpen</code> calls)
62.640 - * @param type type of the message: 0 - onOpen, 1 - onMessage, 2 - onError, 3 - onClose -
62.641 - * not all messages are applicable to all communication protocols (JSON has only 1 and 2).
62.642 - * @param data <code>null</code> or string, number or a {@link Model} class
62.643 - * obtained to the server as a response
62.644 - */
62.645 - protected void onMessage(Model model, int index, int type, Object data) {
62.646 - onMessage(model, index, type, data, new Object[0]);
62.647 - }
62.648 -
62.649 - /** Called to report results of asynchronous over-the-wire
62.650 - * communication. Result of calling {@link Proto#wsOpen(int, java.lang.String, java.lang.Object)}
62.651 - * or {@link Proto#loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)}.
62.652 - *
62.653 - * @param model the instance of the model class
62.654 - * @param index index used during initiating the communication (via <code>loadJSON</code> or <code>wsOpen</code> calls)
62.655 - * @param type type of the message: 0 - onOpen, 1 - onMessage, 2 - onError, 3 - onClose -
62.656 - * not all messages are applicable to all communication protocols (JSON has only 1 and 2).
62.657 - * @param data <code>null</code> or string, number or a {@link Model} class
62.658 - * obtained to the server as a response
62.659 - * @param params extra parameters as passed for example to
62.660 - * {@link Proto#loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)}
62.661 - * method
62.662 - * @since 0.8.1
62.663 - */
62.664 - protected void onMessage(Model model, int index, int type, Object data, Object[] params) {
62.665 - onMessage(model, index, type, data);
62.666 - }
62.667 -
62.668 - //
62.669 - // Various support methods the generated classes use
62.670 - //
62.671 -
62.672 - /** Converts and array of raw JSON objects into an array of typed
62.673 - * Java {@link Model} classes.
62.674 - *
62.675 - * @param <T> the type of the destination array
62.676 - * @param context browser context to use
62.677 - * @param src array of raw JSON objects
62.678 - * @param destType type of the individual array elements
62.679 - * @param dest array to be filled with read type instances
62.680 - */
62.681 - public <T> void copyJSON(BrwsrCtx context, Object[] src, Class<T> destType, T[] dest) {
62.682 - for (int i = 0; i < src.length && i < dest.length; i++) {
62.683 - dest[i] = org.netbeans.html.json.impl.JSON.read(context, destType, src[i]);
62.684 - }
62.685 - }
62.686 -
62.687 - /** Compares two objects that can be converted to integers.
62.688 - * @param a first value
62.689 - * @param b second value
62.690 - * @return true if they are the same
62.691 - */
62.692 - public final boolean isSame(int a, int b) {
62.693 - return a == b;
62.694 - }
62.695 -
62.696 - /** Compares two objects that can be converted to (floating point)
62.697 - * numbers.
62.698 - * @param a first value
62.699 - * @param b second value
62.700 - * @return true if they are the same
62.701 - */
62.702 - public final boolean isSame(double a, double b) {
62.703 - return a == b;
62.704 - }
62.705 -
62.706 - /** Compares two objects for being the same - e.g. either <code>==</code>
62.707 - * or <code>equals</code>.
62.708 - * @param a first value
62.709 - * @param b second value
62.710 - * @return true if they are equals
62.711 - */
62.712 - public final boolean isSame(Object a, Object b) {
62.713 - if (a == b) {
62.714 - return true;
62.715 - }
62.716 - if (a == null || b == null) {
62.717 - return false;
62.718 - }
62.719 - return a.equals(b);
62.720 - }
62.721 -
62.722 - /** Cumulative hash function. Adds hashcode of the object to the
62.723 - * previous value.
62.724 - * @param o the object (or <code>null</code>)
62.725 - * @param h the previous value of the hash
62.726 - * @return new hash - the old one xor the object's one
62.727 - */
62.728 - public final int hashPlus(Object o, int h) {
62.729 - return o == null ? h : h ^ o.hashCode();
62.730 - }
62.731 -
62.732 - /** Converts an object to its JSON value.
62.733 - *
62.734 - * @param obj the object to convert
62.735 - * @return JSON representation of the object
62.736 - */
62.737 - public final String toJSON(Object obj) {
62.738 - return JSON.toJSON(obj);
62.739 - }
62.740 -
62.741 - /** Converts the value to string.
62.742 - *
62.743 - * @param val the value
62.744 - * @return the converted value
62.745 - */
62.746 - public final String stringValue(Object val) {
62.747 - return JSON.stringValue(val);
62.748 - }
62.749 -
62.750 - /** Converts the value to number.
62.751 - *
62.752 - * @param val the value
62.753 - * @return the converted value
62.754 - */
62.755 - public final Number numberValue(Object val) {
62.756 - return JSON.numberValue(val);
62.757 - }
62.758 -
62.759 - /** Converts the value to character.
62.760 - *
62.761 - * @param val the value
62.762 - * @return the converted value
62.763 - */
62.764 - public final Character charValue(Object val) {
62.765 - return JSON.charValue(val);
62.766 - }
62.767 -
62.768 - /** Converts the value to boolean.
62.769 - *
62.770 - * @param val the value
62.771 - * @return the converted value
62.772 - */
62.773 - public final Boolean boolValue(Object val) {
62.774 - return JSON.boolValue(val);
62.775 - }
62.776 -
62.777 - /** Extracts value of specific type from given object.
62.778 - *
62.779 - * @param <T> the type of object one is interested in
62.780 - * @param type the type
62.781 - * @param val the object to convert to type
62.782 - * @return the converted value
62.783 - */
62.784 - public final <T> T extractValue(Class<T> type, Object val) {
62.785 - if (Number.class.isAssignableFrom(type)) {
62.786 - val = numberValue(val);
62.787 - }
62.788 - if (Boolean.class == type) {
62.789 - val = boolValue(val);
62.790 - }
62.791 - if (String.class == type) {
62.792 - val = stringValue(val);
62.793 - }
62.794 - if (Character.class == type) {
62.795 - val = charValue(val);
62.796 - }
62.797 - if (Integer.class == type) {
62.798 - val = val instanceof Number ? ((Number) val).intValue() : 0;
62.799 - }
62.800 - if (Long.class == type) {
62.801 - val = val instanceof Number ? ((Number) val).longValue() : 0;
62.802 - }
62.803 - if (Short.class == type) {
62.804 - val = val instanceof Number ? ((Number) val).shortValue() : 0;
62.805 - }
62.806 - if (Byte.class == type) {
62.807 - val = val instanceof Number ? ((Number) val).byteValue() : 0;
62.808 - }
62.809 - if (Double.class == type) {
62.810 - val = val instanceof Number ? ((Number) val).doubleValue() : Double.NaN;
62.811 - }
62.812 - if (Float.class == type) {
62.813 - val = val instanceof Number ? ((Number) val).floatValue() : Float.NaN;
62.814 - }
62.815 - if (type.isEnum() && val instanceof String) {
62.816 - val = Enum.valueOf(type.asSubclass(Enum.class), (String)val);
62.817 - }
62.818 - return type.cast(val);
62.819 - }
62.820 -
62.821 - /** Special dealing with array & {@link List} values. This method
62.822 - * takes the provided collection, empties it and fills it again
62.823 - * with values extracted from <code>value</code> (which is supposed
62.824 - * to be an array).
62.825 - *
62.826 - * @param <T> the type of list elements
62.827 - * @param arr collection to fill with elements in value
62.828 - * @param type the type of elements in the collection
62.829 - * @param value array of elements to put into the collecition. If
62.830 - * value is not an array it is wrapped into array with only element
62.831 - * @since 1.0
62.832 - */
62.833 - public final <T> void replaceValue(Collection<? super T> arr, Class<T> type, Object value) {
62.834 - Object[] newArr;
62.835 - if (value instanceof Object[]) {
62.836 - newArr = (Object[]) value;
62.837 - } else {
62.838 - newArr = new Object[] { value };
62.839 - }
62.840 - arr.clear();
62.841 - for (Object e : newArr) {
62.842 - arr.add(extractValue(type, e));
62.843 - }
62.844 - }
62.845 - }
62.846 -}
63.1 --- a/json/src/main/java/org/apidesign/html/json/spi/Technology.java Tue Aug 26 17:43:37 2014 +0200
63.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
63.3 @@ -1,169 +0,0 @@
63.4 -/**
63.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
63.6 - *
63.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
63.8 - *
63.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
63.10 - * Other names may be trademarks of their respective owners.
63.11 - *
63.12 - * The contents of this file are subject to the terms of either the GNU
63.13 - * General Public License Version 2 only ("GPL") or the Common
63.14 - * Development and Distribution License("CDDL") (collectively, the
63.15 - * "License"). You may not use this file except in compliance with the
63.16 - * License. You can obtain a copy of the License at
63.17 - * http://www.netbeans.org/cddl-gplv2.html
63.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
63.19 - * specific language governing permissions and limitations under the
63.20 - * License. When distributing the software, include this License Header
63.21 - * Notice in each file and include the License file at
63.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
63.23 - * particular file as subject to the "Classpath" exception as provided
63.24 - * by Oracle in the GPL Version 2 section of the License file that
63.25 - * accompanied this code. If applicable, add the following below the
63.26 - * License Header, with the fields enclosed by brackets [] replaced by
63.27 - * your own identifying information:
63.28 - * "Portions Copyrighted [year] [name of copyright owner]"
63.29 - *
63.30 - * Contributor(s):
63.31 - *
63.32 - * The Original Software is NetBeans. The Initial Developer of the Original
63.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
63.34 - *
63.35 - * If you wish your version of this file to be governed by only the CDDL
63.36 - * or only the GPL Version 2, indicate your decision by adding
63.37 - * "[Contributor] elects to include this software in this distribution
63.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
63.39 - * single choice of license, a recipient has the option to distribute
63.40 - * your version of this file under either the CDDL, the GPL Version 2 or
63.41 - * to extend the choice of license to its licensees as provided above.
63.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
63.43 - * Version 2 license, then the option applies only if the new code is
63.44 - * made subject to such option by the copyright holder.
63.45 - */
63.46 -package org.apidesign.html.json.spi;
63.47 -
63.48 -import net.java.html.BrwsrCtx;
63.49 -import net.java.html.json.Model;
63.50 -import net.java.html.json.Models;
63.51 -
63.52 -/** An implementation of a binding between model classes (see {@link Model})
63.53 - * and particular technology like <a href="http://knockoutjs.com">knockout.js</a>
63.54 - * in a browser window, etc.
63.55 - *
63.56 - * @author Jaroslav Tulach
63.57 - */
63.58 -public interface Technology<Data> {
63.59 - /** Creates an object to wrap the provided model object. The model
63.60 - * has previously been generated by annotation processor associated
63.61 - * with {@link Model} annotation.
63.62 - *
63.63 - * @param model the model generated from {@link Model}
63.64 - * @return internal object representing the model
63.65 - */
63.66 - public Data wrapModel(Object model);
63.67 -
63.68 - /** Converts an element potentially representing a model into the model.
63.69 - * @param <M> the type of the <code>modelClass</code>
63.70 - * @param modelClass expected class to convert the data to
63.71 - * @param data the current data provided from the browser
63.72 - * @return the instance of modelClass somehow extracted from the data, may return <code>null</code>
63.73 - */
63.74 - public <M> M toModel(Class<M> modelClass, Object data);
63.75 -
63.76 - /** Binds a property between the model and the data as used by the technology.
63.77 - *
63.78 - * @param b the description of the requested binding
63.79 - * @param model the original instance of the model
63.80 - * @param data the data to bind with the model
63.81 - */
63.82 - public void bind(PropertyBinding b, Object model, Data data);
63.83 -
63.84 - /** Model for given data has changed its value. The technology is
63.85 - * supposed to update its state (for example DOM nodes associated
63.86 - * with the model). The update usually happens asynchronously.
63.87 - *
63.88 - * @param data technology's own representation of the model
63.89 - * @param propertyName name of the model property that changed
63.90 - */
63.91 - public void valueHasMutated(Data data, String propertyName);
63.92 -
63.93 - public void expose(FunctionBinding fb, Object model, Data d);
63.94 -
63.95 - /** Applies given data to current context (usually an HTML page).
63.96 - * @param data the data to apply
63.97 - */
63.98 - public void applyBindings(Data data);
63.99 -
63.100 - /**
63.101 - * Some technologies may require wrapping a Java array into a special
63.102 - * object. In such case they may return it from this method.
63.103 - *
63.104 - * @param arr original array
63.105 - * @return wrapped array
63.106 - */
63.107 - public Object wrapArray(Object[] arr);
63.108 -
63.109 - /**
63.110 - * Run given runnable in a safe mode. If the runnable can be executed
63.111 - * immediately, do it. If we need to switch to some other thread, do it
63.112 - * and invoke r asynchronously immediately returning from the call to
63.113 - * runSafe method.
63.114 - *
63.115 - * @param r the runnable to execute
63.116 - * @deprecated Use {@link BrwsrCtx#execute(java.lang.Runnable)}
63.117 - */
63.118 - @Deprecated
63.119 - public void runSafe(Runnable r);
63.120 -
63.121 - /** For certain rendering technologies it may be more efficient to register
63.122 - * property and function bindings for one instance of the model at once,
63.123 - * rather then doing it incrementally via
63.124 - * {@link Technology#expose(org.apidesign.html.json.spi.FunctionBinding, java.lang.Object, java.lang.Object) }
63.125 - * and
63.126 - * {@link Technology#bind(org.apidesign.html.json.spi.PropertyBinding, java.lang.Object, java.lang.Object) }.
63.127 - * In such case implement the {@link #wrapModel(java.lang.Object, org.apidesign.html.json.spi.PropertyBinding[], org.apidesign.html.json.spi.FunctionBinding[]) }
63.128 - * method of this interface and it will be called instead of the
63.129 - * previous two ones.
63.130 - *
63.131 - * @since 0.6
63.132 - */
63.133 - public static interface BatchInit<D> extends Technology<D> {
63.134 - /** Wrap the given model into redering technology appropriate object
63.135 - * <code>D</code> and expose given properties and functions on it.
63.136 - *
63.137 - * @param model the {@link Models#isModel(java.lang.Class) model} in Java
63.138 - * @param propArr array of property bindings to expose
63.139 - * @param funcArr array of functions to expose
63.140 - * @return appropriate wrapper around the model
63.141 - */
63.142 - public D wrapModel(Object model, PropertyBinding[] propArr, FunctionBinding[] funcArr);
63.143 - }
63.144 -
63.145 - /** Some technologies are more effective when number of calls between
63.146 - * Java and JavaScript is limited - to do that when a value of property
63.147 - * is changed they should implement this additional interface.
63.148 - *
63.149 - * @param <D> internal type of the technology
63.150 - * @since 0.7.6
63.151 - */
63.152 - public static interface ValueMutated<D> extends Technology<D> {
63.153 - /** Model for given data has changed its value. The technology is
63.154 - * supposed to update its state (for example DOM nodes associated
63.155 - * with the model). The update usually happens asynchronously.
63.156 - * <p>
63.157 - * If both <code>oldValue</code> and <code>newValue</code> are
63.158 - * <code>null</code> then the real value of the technology is
63.159 - * not known.
63.160 - * <p>
63.161 - * If this method is present, then it is called instead of
63.162 - * old, plain {@link #valueHasMutated(java.lang.Object, java.lang.String)}
63.163 - * which is never called by the infrastructure then.
63.164 - *
63.165 - * @param data technology's own representation of the model
63.166 - * @param propertyName name of the model property that changed
63.167 - * @param oldValue provides previous value of the property
63.168 - * @param newValue provides new value of the property
63.169 - */
63.170 - public void valueHasMutated(D data, String propertyName, Object oldValue, Object newValue);
63.171 - }
63.172 -}
64.1 --- a/json/src/main/java/org/apidesign/html/json/spi/Transfer.java Tue Aug 26 17:43:37 2014 +0200
64.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
64.3 @@ -1,88 +0,0 @@
64.4 -/**
64.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
64.6 - *
64.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
64.8 - *
64.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
64.10 - * Other names may be trademarks of their respective owners.
64.11 - *
64.12 - * The contents of this file are subject to the terms of either the GNU
64.13 - * General Public License Version 2 only ("GPL") or the Common
64.14 - * Development and Distribution License("CDDL") (collectively, the
64.15 - * "License"). You may not use this file except in compliance with the
64.16 - * License. You can obtain a copy of the License at
64.17 - * http://www.netbeans.org/cddl-gplv2.html
64.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
64.19 - * specific language governing permissions and limitations under the
64.20 - * License. When distributing the software, include this License Header
64.21 - * Notice in each file and include the License file at
64.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
64.23 - * particular file as subject to the "Classpath" exception as provided
64.24 - * by Oracle in the GPL Version 2 section of the License file that
64.25 - * accompanied this code. If applicable, add the following below the
64.26 - * License Header, with the fields enclosed by brackets [] replaced by
64.27 - * your own identifying information:
64.28 - * "Portions Copyrighted [year] [name of copyright owner]"
64.29 - *
64.30 - * Contributor(s):
64.31 - *
64.32 - * The Original Software is NetBeans. The Initial Developer of the Original
64.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
64.34 - *
64.35 - * If you wish your version of this file to be governed by only the CDDL
64.36 - * or only the GPL Version 2, indicate your decision by adding
64.37 - * "[Contributor] elects to include this software in this distribution
64.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
64.39 - * single choice of license, a recipient has the option to distribute
64.40 - * your version of this file under either the CDDL, the GPL Version 2 or
64.41 - * to extend the choice of license to its licensees as provided above.
64.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
64.43 - * Version 2 license, then the option applies only if the new code is
64.44 - * made subject to such option by the copyright holder.
64.45 - */
64.46 -package org.apidesign.html.json.spi;
64.47 -
64.48 -import java.io.IOException;
64.49 -import java.io.InputStream;
64.50 -import org.apidesign.html.context.spi.Contexts.Builder;
64.51 -
64.52 -/** A {@link Builder service provider interface} responsible for
64.53 - * conversion of JSON objects to Java ones and vice-versa.
64.54 - *
64.55 - * @author Jaroslav Tulach
64.56 - */
64.57 -public interface Transfer {
64.58 - /**
64.59 - * Called to inspect properties of an object (usually a JSON or JavaScript
64.60 - * wrapper).
64.61 - *
64.62 - * @param obj the object to inspect
64.63 - * @param props the names of properties to check on the object
64.64 - * <code>obj</code>
64.65 - * @param values array of the same length as <code>props</code> should be
64.66 - * filled by values of properties on the <code>obj</code>. If a property is
64.67 - * not defined, a <code>null</code> value should be stored in the array
64.68 - */
64.69 - public void extract(Object obj, String[] props, Object[] values);
64.70 -
64.71 - /** Reads content of a stream and creates its JSON representation.
64.72 - * The returned object is implementation dependant. It however needs
64.73 - * to be acceptable as first argument of {@link #extract(java.lang.Object, java.lang.String[], java.lang.Object[]) extract}
64.74 - * method. If the stream contains representation or a JSON array,
64.75 - * an Object[] should be returned - each of its members should, by itself
64.76 - * be acceptable argument to
64.77 - * the {@link #extract(java.lang.Object, java.lang.String[], java.lang.Object[]) extract} method.
64.78 - *
64.79 - * @param is input stream to read data from
64.80 - * @return an object representing the JSON data
64.81 - * @throws IOException if something goes wrong
64.82 - */
64.83 - public Object toJSON(InputStream is) throws IOException;
64.84 -
64.85 - /** Starts the JSON or JSONP query.
64.86 - *
64.87 - * @param call description of the call to make
64.88 - */
64.89 - public void loadJSON(JSONCall call);
64.90 -
64.91 -}
65.1 --- a/json/src/main/java/org/apidesign/html/json/spi/WSTransfer.java Tue Aug 26 17:43:37 2014 +0200
65.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
65.3 @@ -1,84 +0,0 @@
65.4 -/**
65.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
65.6 - *
65.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
65.8 - *
65.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
65.10 - * Other names may be trademarks of their respective owners.
65.11 - *
65.12 - * The contents of this file are subject to the terms of either the GNU
65.13 - * General Public License Version 2 only ("GPL") or the Common
65.14 - * Development and Distribution License("CDDL") (collectively, the
65.15 - * "License"). You may not use this file except in compliance with the
65.16 - * License. You can obtain a copy of the License at
65.17 - * http://www.netbeans.org/cddl-gplv2.html
65.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
65.19 - * specific language governing permissions and limitations under the
65.20 - * License. When distributing the software, include this License Header
65.21 - * Notice in each file and include the License file at
65.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
65.23 - * particular file as subject to the "Classpath" exception as provided
65.24 - * by Oracle in the GPL Version 2 section of the License file that
65.25 - * accompanied this code. If applicable, add the following below the
65.26 - * License Header, with the fields enclosed by brackets [] replaced by
65.27 - * your own identifying information:
65.28 - * "Portions Copyrighted [year] [name of copyright owner]"
65.29 - *
65.30 - * Contributor(s):
65.31 - *
65.32 - * The Original Software is NetBeans. The Initial Developer of the Original
65.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
65.34 - *
65.35 - * If you wish your version of this file to be governed by only the CDDL
65.36 - * or only the GPL Version 2, indicate your decision by adding
65.37 - * "[Contributor] elects to include this software in this distribution
65.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
65.39 - * single choice of license, a recipient has the option to distribute
65.40 - * your version of this file under either the CDDL, the GPL Version 2 or
65.41 - * to extend the choice of license to its licensees as provided above.
65.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
65.43 - * Version 2 license, then the option applies only if the new code is
65.44 - * made subject to such option by the copyright holder.
65.45 - */
65.46 -package org.apidesign.html.json.spi;
65.47 -
65.48 -import net.java.html.BrwsrCtx;
65.49 -import org.apidesign.html.context.spi.Contexts.Provider;
65.50 -
65.51 -/** Interface for providers of WebSocket protocol. Register into a
65.52 - * {@link BrwsrCtx context} in your own {@link Provider}
65.53 - *
65.54 - * @author Jaroslav Tulach
65.55 - * @param <WebSocket> internal implementation type representing the socket
65.56 - * @since 0.5
65.57 - */
65.58 -public interface WSTransfer<WebSocket> {
65.59 - /** Initializes a web socket. The <code>callback</code> object should
65.60 - * have mostly empty values: {@link JSONCall#isDoOutput()} should be
65.61 - * <code>false</code> and thus there should be no {@link JSONCall#getMessage()}.
65.62 - * The method of connection {@link JSONCall#getMethod()} is "WebSocket".
65.63 - * Once the connection is open call {@link JSONCall#notifySuccess(java.lang.Object) notifySuccess(null)}.
65.64 - * When the server sends some data then, pass them to
65.65 - * {@link JSONCall#notifySuccess(java.lang.Object) notifySuccess} method
65.66 - * as well. If there is an error call {@link JSONCall#notifyError(java.lang.Throwable)}.
65.67 - *
65.68 - * @param url the URL to connect to
65.69 - * @param callback a way to provide results back to the client
65.70 - * @return your object representing the established web socket
65.71 - */
65.72 - public WebSocket open(String url, JSONCall callback);
65.73 -
65.74 - /** Sends data to the server. The most important value
65.75 - * of the <code>data</code> parameter is {@link JSONCall#getMessage()},
65.76 - * rest can be ignored.
65.77 - *
65.78 - * @param socket internal representation of the socket
65.79 - * @param data the message to be sent
65.80 - */
65.81 - public void send(WebSocket socket, JSONCall data);
65.82 -
65.83 - /** A request to close the socket.
65.84 - * @param socket internal representation of the socket
65.85 - */
65.86 - public void close(WebSocket socket);
65.87 -}
66.1 --- a/json/src/main/java/org/apidesign/html/json/spi/package.html Tue Aug 26 17:43:37 2014 +0200
66.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
66.3 @@ -1,51 +0,0 @@
66.4 -<!--
66.5 -
66.6 - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
66.7 -
66.8 - Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
66.9 -
66.10 - Oracle and Java are registered trademarks of Oracle and/or its affiliates.
66.11 - Other names may be trademarks of their respective owners.
66.12 -
66.13 - The contents of this file are subject to the terms of either the GNU
66.14 - General Public License Version 2 only ("GPL") or the Common
66.15 - Development and Distribution License("CDDL") (collectively, the
66.16 - "License"). You may not use this file except in compliance with the
66.17 - License. You can obtain a copy of the License at
66.18 - http://www.netbeans.org/cddl-gplv2.html
66.19 - or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
66.20 - specific language governing permissions and limitations under the
66.21 - License. When distributing the software, include this License Header
66.22 - Notice in each file and include the License file at
66.23 - nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
66.24 - particular file as subject to the "Classpath" exception as provided
66.25 - by Oracle in the GPL Version 2 section of the License file that
66.26 - accompanied this code. If applicable, add the following below the
66.27 - License Header, with the fields enclosed by brackets [] replaced by
66.28 - your own identifying information:
66.29 - "Portions Copyrighted [year] [name of copyright owner]"
66.30 -
66.31 - Contributor(s):
66.32 -
66.33 - The Original Software is NetBeans. The Initial Developer of the Original
66.34 - Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
66.35 -
66.36 - If you wish your version of this file to be governed by only the CDDL
66.37 - or only the GPL Version 2, indicate your decision by adding
66.38 - "[Contributor] elects to include this software in this distribution
66.39 - under the [CDDL or GPL Version 2] license." If you do not indicate a
66.40 - single choice of license, a recipient has the option to distribute
66.41 - your version of this file under either the CDDL, the GPL Version 2 or
66.42 - to extend the choice of license to its licensees as provided above.
66.43 - However, if you add GPL Version 2 code and therefore, elected the GPL
66.44 - Version 2 license, then the option applies only if the new code is
66.45 - made subject to such option by the copyright holder.
66.46 -
66.47 --->
66.48 -<html>
66.49 - <body>
66.50 - <div>Service Provider Interfaces for those who wish to integrate own
66.51 - <a href="Technology.html">technology</a> with the HTML for Java API.
66.52 - </div>
66.53 - </body>
66.54 -</html>
67.1 --- a/json/src/main/java/org/netbeans/html/json/impl/Bindings.java Tue Aug 26 17:43:37 2014 +0200
67.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/Bindings.java Tue Aug 26 18:13:30 2014 +0200
67.3 @@ -43,10 +43,10 @@
67.4 package org.netbeans.html.json.impl;
67.5
67.6 import net.java.html.BrwsrCtx;
67.7 -import org.apidesign.html.json.spi.FunctionBinding;
67.8 -import org.apidesign.html.json.spi.PropertyBinding;
67.9 -import org.apidesign.html.json.spi.Proto;
67.10 -import org.apidesign.html.json.spi.Technology;
67.11 +import org.netbeans.html.json.spi.FunctionBinding;
67.12 +import org.netbeans.html.json.spi.PropertyBinding;
67.13 +import org.netbeans.html.json.spi.Proto;
67.14 +import org.netbeans.html.json.spi.Technology;
67.15
67.16 /**
67.17 *
68.1 --- a/json/src/main/java/org/netbeans/html/json/impl/JSON.java Tue Aug 26 17:43:37 2014 +0200
68.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/JSON.java Tue Aug 26 18:13:30 2014 +0200
68.3 @@ -49,14 +49,14 @@
68.4 import java.util.HashMap;
68.5 import java.util.Map;
68.6 import net.java.html.BrwsrCtx;
68.7 -import org.apidesign.html.context.spi.Contexts;
68.8 -import org.apidesign.html.json.spi.FunctionBinding;
68.9 -import org.apidesign.html.json.spi.JSONCall;
68.10 -import org.apidesign.html.json.spi.PropertyBinding;
68.11 -import org.apidesign.html.json.spi.Proto;
68.12 -import org.apidesign.html.json.spi.Technology;
68.13 -import org.apidesign.html.json.spi.Transfer;
68.14 -import org.apidesign.html.json.spi.WSTransfer;
68.15 +import org.netbeans.html.context.spi.Contexts;
68.16 +import org.netbeans.html.json.spi.FunctionBinding;
68.17 +import org.netbeans.html.json.spi.JSONCall;
68.18 +import org.netbeans.html.json.spi.PropertyBinding;
68.19 +import org.netbeans.html.json.spi.Proto;
68.20 +import org.netbeans.html.json.spi.Technology;
68.21 +import org.netbeans.html.json.spi.Transfer;
68.22 +import org.netbeans.html.json.spi.WSTransfer;
68.23
68.24 /**
68.25 *
69.1 --- a/json/src/main/java/org/netbeans/html/json/impl/JSONList.java Tue Aug 26 17:43:37 2014 +0200
69.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/JSONList.java Tue Aug 26 18:13:30 2014 +0200
69.3 @@ -46,7 +46,7 @@
69.4 import java.util.ArrayList;
69.5 import java.util.Collection;
69.6 import java.util.Iterator;
69.7 -import org.apidesign.html.json.spi.Proto;
69.8 +import org.netbeans.html.json.spi.Proto;
69.9
69.10 /**
69.11 *
70.1 --- a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Tue Aug 26 17:43:37 2014 +0200
70.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Tue Aug 26 18:13:30 2014 +0200
70.3 @@ -224,7 +224,7 @@
70.4 w.append("import net.java.html.json.*;\n");
70.5 w.append("public final class ").append(className).append(" implements Cloneable {\n");
70.6 w.append(" private static final Html4JavaType TYPE = new Html4JavaType();\n");
70.7 - w.append(" private final org.apidesign.html.json.spi.Proto proto;\n");
70.8 + w.append(" private final org.netbeans.html.json.spi.Proto proto;\n");
70.9 w.append(body.toString());
70.10 w.append(" private static Class<" + inPckName(e) + "> modelFor() { return null; }\n");
70.11 w.append(" private ").append(className).append("(net.java.html.BrwsrCtx context) {\n");
70.12 @@ -309,7 +309,7 @@
70.13 }
70.14 w.append(" };\n");
70.15 }
70.16 - w.append(" private static class Html4JavaType extends org.apidesign.html.json.spi.Proto.Type<").append(className).append("> {\n");
70.17 + w.append(" private static class Html4JavaType extends org.netbeans.html.json.spi.Proto.Type<").append(className).append("> {\n");
70.18 w.append(" private Html4JavaType() {\n super(").append(className).append(".class, ").
70.19 append(inPckName(e)).append(".class, " + propsGetSet.size() + ", "
70.20 + functionsCount + ");\n");
70.21 @@ -383,7 +383,7 @@
70.22 w.append(" }\n");
70.23 w.append(" throw new UnsupportedOperationException();\n");
70.24 w.append(" }\n");
70.25 - w.append(" @Override public org.apidesign.html.json.spi.Proto protoFor(Object obj) {\n");
70.26 + w.append(" @Override public org.netbeans.html.json.spi.Proto protoFor(Object obj) {\n");
70.27 w.append(" return ((" + className + ")obj).proto;");
70.28 w.append(" }\n");
70.29 w.append(" @Override public void onChange(" + className + " model, int type) {\n");
71.1 --- a/json/src/main/java/org/netbeans/html/json/impl/PropertyBindingAccessor.java Tue Aug 26 17:43:37 2014 +0200
71.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/PropertyBindingAccessor.java Tue Aug 26 18:13:30 2014 +0200
71.3 @@ -43,10 +43,10 @@
71.4 package org.netbeans.html.json.impl;
71.5
71.6 import net.java.html.BrwsrCtx;
71.7 -import org.apidesign.html.json.spi.FunctionBinding;
71.8 -import org.apidesign.html.json.spi.JSONCall;
71.9 -import org.apidesign.html.json.spi.PropertyBinding;
71.10 -import org.apidesign.html.json.spi.Proto;
71.11 +import org.netbeans.html.json.spi.FunctionBinding;
71.12 +import org.netbeans.html.json.spi.JSONCall;
71.13 +import org.netbeans.html.json.spi.PropertyBinding;
71.14 +import org.netbeans.html.json.spi.Proto;
71.15
71.16 /**
71.17 *
72.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
72.2 +++ b/json/src/main/java/org/netbeans/html/json/spi/FunctionBinding.java Tue Aug 26 18:13:30 2014 +0200
72.3 @@ -0,0 +1,110 @@
72.4 +/**
72.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
72.6 + *
72.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
72.8 + *
72.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
72.10 + * Other names may be trademarks of their respective owners.
72.11 + *
72.12 + * The contents of this file are subject to the terms of either the GNU
72.13 + * General Public License Version 2 only ("GPL") or the Common
72.14 + * Development and Distribution License("CDDL") (collectively, the
72.15 + * "License"). You may not use this file except in compliance with the
72.16 + * License. You can obtain a copy of the License at
72.17 + * http://www.netbeans.org/cddl-gplv2.html
72.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
72.19 + * specific language governing permissions and limitations under the
72.20 + * License. When distributing the software, include this License Header
72.21 + * Notice in each file and include the License file at
72.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
72.23 + * particular file as subject to the "Classpath" exception as provided
72.24 + * by Oracle in the GPL Version 2 section of the License file that
72.25 + * accompanied this code. If applicable, add the following below the
72.26 + * License Header, with the fields enclosed by brackets [] replaced by
72.27 + * your own identifying information:
72.28 + * "Portions Copyrighted [year] [name of copyright owner]"
72.29 + *
72.30 + * Contributor(s):
72.31 + *
72.32 + * The Original Software is NetBeans. The Initial Developer of the Original
72.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
72.34 + *
72.35 + * If you wish your version of this file to be governed by only the CDDL
72.36 + * or only the GPL Version 2, indicate your decision by adding
72.37 + * "[Contributor] elects to include this software in this distribution
72.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
72.39 + * single choice of license, a recipient has the option to distribute
72.40 + * your version of this file under either the CDDL, the GPL Version 2 or
72.41 + * to extend the choice of license to its licensees as provided above.
72.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
72.43 + * Version 2 license, then the option applies only if the new code is
72.44 + * made subject to such option by the copyright holder.
72.45 + */
72.46 +package org.netbeans.html.json.spi;
72.47 +
72.48 +import net.java.html.BrwsrCtx;
72.49 +import net.java.html.json.Function;
72.50 +import net.java.html.json.Model;
72.51 +
72.52 +/** Describes a function provided by the {@link Model} and
72.53 + * annotated by {@link Function} annotation.
72.54 + *
72.55 + * @author Jaroslav Tulach
72.56 + */
72.57 +public abstract class FunctionBinding {
72.58 + FunctionBinding() {
72.59 + }
72.60 +
72.61 + /** Returns name of the function.
72.62 + * @return function name
72.63 + */
72.64 + public abstract String getFunctionName();
72.65 +
72.66 + /**
72.67 + * Calls the function provided data associated with current element, as well
72.68 + * as information about the event that triggered the event.
72.69 + *
72.70 + * @param data data associated with selected element
72.71 + * @param ev event (with additional properties) that triggered the event
72.72 + */
72.73 + public abstract void call(Object data, Object ev);
72.74 +
72.75 + static <M> FunctionBinding registerFunction(String name, int index, M model, Proto.Type<M> access) {
72.76 + return new Impl<M>(name, index, model, access);
72.77 + }
72.78 +
72.79 + private static final class Impl<M> extends FunctionBinding {
72.80 + final String name;
72.81 + private final M model;
72.82 + private final Proto.Type<M> access;
72.83 + private final int index;
72.84 +
72.85 + public Impl(String name, int index, M model, Proto.Type<M> access) {
72.86 + this.name = name;
72.87 + this.index = index;
72.88 + this.model = model;
72.89 + this.access = access;
72.90 + }
72.91 +
72.92 + @Override
72.93 + public String getFunctionName() {
72.94 + return name;
72.95 + }
72.96 +
72.97 + @Override
72.98 + public void call(final Object data, final Object ev) {
72.99 + BrwsrCtx ctx = access.protoFor(model).getContext();
72.100 + class Dispatch implements Runnable {
72.101 + @Override
72.102 + public void run() {
72.103 + try {
72.104 + access.call(model, index, data, ev);
72.105 + } catch (Throwable ex) {
72.106 + ex.printStackTrace();
72.107 + }
72.108 + }
72.109 + }
72.110 + ctx.execute(new Dispatch());
72.111 + }
72.112 + }
72.113 +}
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
73.2 +++ b/json/src/main/java/org/netbeans/html/json/spi/JSONCall.java Tue Aug 26 18:13:30 2014 +0200
73.3 @@ -0,0 +1,136 @@
73.4 +/**
73.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
73.6 + *
73.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
73.8 + *
73.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
73.10 + * Other names may be trademarks of their respective owners.
73.11 + *
73.12 + * The contents of this file are subject to the terms of either the GNU
73.13 + * General Public License Version 2 only ("GPL") or the Common
73.14 + * Development and Distribution License("CDDL") (collectively, the
73.15 + * "License"). You may not use this file except in compliance with the
73.16 + * License. You can obtain a copy of the License at
73.17 + * http://www.netbeans.org/cddl-gplv2.html
73.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
73.19 + * specific language governing permissions and limitations under the
73.20 + * License. When distributing the software, include this License Header
73.21 + * Notice in each file and include the License file at
73.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
73.23 + * particular file as subject to the "Classpath" exception as provided
73.24 + * by Oracle in the GPL Version 2 section of the License file that
73.25 + * accompanied this code. If applicable, add the following below the
73.26 + * License Header, with the fields enclosed by brackets [] replaced by
73.27 + * your own identifying information:
73.28 + * "Portions Copyrighted [year] [name of copyright owner]"
73.29 + *
73.30 + * Contributor(s):
73.31 + *
73.32 + * The Original Software is NetBeans. The Initial Developer of the Original
73.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
73.34 + *
73.35 + * If you wish your version of this file to be governed by only the CDDL
73.36 + * or only the GPL Version 2, indicate your decision by adding
73.37 + * "[Contributor] elects to include this software in this distribution
73.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
73.39 + * single choice of license, a recipient has the option to distribute
73.40 + * your version of this file under either the CDDL, the GPL Version 2 or
73.41 + * to extend the choice of license to its licensees as provided above.
73.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
73.43 + * Version 2 license, then the option applies only if the new code is
73.44 + * made subject to such option by the copyright holder.
73.45 + */
73.46 +package org.netbeans.html.json.spi;
73.47 +
73.48 +import java.io.IOException;
73.49 +import java.io.OutputStream;
73.50 +import net.java.html.BrwsrCtx;
73.51 +import org.netbeans.html.json.impl.RcvrJSON;
73.52 +
73.53 +/** Description of a JSON call request that is supposed to be processed
73.54 + * by {@link Transfer#loadJSON(org.netbeans.html.json.spi.JSONCall)} implementors.
73.55 + *
73.56 + * @author Jaroslav Tulach
73.57 + */
73.58 +public final class JSONCall {
73.59 + private final RcvrJSON whenDone;
73.60 + private final String urlBefore;
73.61 + private final String urlAfter;
73.62 + private final String method;
73.63 + private final Object data;
73.64 + private final BrwsrCtx ctx;
73.65 +
73.66 + JSONCall(BrwsrCtx ctx, RcvrJSON whenDone, String urlBefore, String urlAfter, String method, Object data) {
73.67 + this.ctx = ctx;
73.68 + this.whenDone = whenDone;
73.69 + this.urlBefore = urlBefore;
73.70 + this.urlAfter = urlAfter;
73.71 + this.method = method;
73.72 + this.data = data;
73.73 + }
73.74 +
73.75 + /** Do we have some data to send? Can the {@link #writeData(java.io.OutputStream)} method be
73.76 + * called?
73.77 + *
73.78 + * @return true, if the call has some data to send
73.79 + */
73.80 + public boolean isDoOutput() {
73.81 + return this.data != null;
73.82 + }
73.83 +
73.84 + public void writeData(OutputStream os) throws IOException {
73.85 + if (this.data == null) {
73.86 + throw new IOException("No data!");
73.87 + }
73.88 + os.write(this.data.toString().getBytes("UTF-8"));
73.89 + os.flush();
73.90 + }
73.91 +
73.92 + public String getMethod() {
73.93 + return method;
73.94 + }
73.95 +
73.96 + public boolean isJSONP() {
73.97 + return urlAfter != null;
73.98 + }
73.99 +
73.100 + public String composeURL(String jsonpCallback) {
73.101 + if ((urlAfter == null) != (jsonpCallback == null)) {
73.102 + throw new IllegalStateException();
73.103 + }
73.104 + if (urlAfter != null) {
73.105 + return urlBefore + jsonpCallback + urlAfter;
73.106 + } else {
73.107 + return urlBefore;
73.108 + }
73.109 + }
73.110 +
73.111 + public void notifySuccess(Object result) {
73.112 + if (result == null) {
73.113 + dispatch(RcvrJSON.MsgEvnt.createOpen());
73.114 + } else {
73.115 + dispatch(RcvrJSON.MsgEvnt.createMessage(result));
73.116 + }
73.117 + }
73.118 +
73.119 + public void notifyError(Throwable error) {
73.120 + if (error == null) {
73.121 + dispatch(RcvrJSON.MsgEvnt.createClose());
73.122 + } else {
73.123 + dispatch(RcvrJSON.MsgEvnt.createError(error));
73.124 + }
73.125 + }
73.126 +
73.127 + private void dispatch(final RcvrJSON.MsgEvnt ev) {
73.128 + ctx.execute(new Runnable() {
73.129 + @Override
73.130 + public void run() {
73.131 + ev.dispatch(whenDone);
73.132 + }
73.133 + });
73.134 + }
73.135 +
73.136 + public String getMessage() {
73.137 + return this.data.toString();
73.138 + }
73.139 +}
74.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
74.2 +++ b/json/src/main/java/org/netbeans/html/json/spi/Observers.java Tue Aug 26 18:13:30 2014 +0200
74.3 @@ -0,0 +1,221 @@
74.4 +/**
74.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
74.6 + *
74.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
74.8 + *
74.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
74.10 + * Other names may be trademarks of their respective owners.
74.11 + *
74.12 + * The contents of this file are subject to the terms of either the GNU
74.13 + * General Public License Version 2 only ("GPL") or the Common
74.14 + * Development and Distribution License("CDDL") (collectively, the
74.15 + * "License"). You may not use this file except in compliance with the
74.16 + * License. You can obtain a copy of the License at
74.17 + * http://www.netbeans.org/cddl-gplv2.html
74.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
74.19 + * specific language governing permissions and limitations under the
74.20 + * License. When distributing the software, include this License Header
74.21 + * Notice in each file and include the License file at
74.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
74.23 + * particular file as subject to the "Classpath" exception as provided
74.24 + * by Oracle in the GPL Version 2 section of the License file that
74.25 + * accompanied this code. If applicable, add the following below the
74.26 + * License Header, with the fields enclosed by brackets [] replaced by
74.27 + * your own identifying information:
74.28 + * "Portions Copyrighted [year] [name of copyright owner]"
74.29 + *
74.30 + * Contributor(s):
74.31 + *
74.32 + * The Original Software is NetBeans. The Initial Developer of the Original
74.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
74.34 + *
74.35 + * If you wish your version of this file to be governed by only the CDDL
74.36 + * or only the GPL Version 2, indicate your decision by adding
74.37 + * "[Contributor] elects to include this software in this distribution
74.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
74.39 + * single choice of license, a recipient has the option to distribute
74.40 + * your version of this file under either the CDDL, the GPL Version 2 or
74.41 + * to extend the choice of license to its licensees as provided above.
74.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
74.43 + * Version 2 license, then the option applies only if the new code is
74.44 + * made subject to such option by the copyright holder.
74.45 + */
74.46 +package org.netbeans.html.json.spi;
74.47 +
74.48 +import java.lang.ref.WeakReference;
74.49 +import java.util.ArrayList;
74.50 +import java.util.Iterator;
74.51 +import java.util.LinkedList;
74.52 +import java.util.List;
74.53 +
74.54 +/**
74.55 + *
74.56 + * @author Jaroslav Tulach
74.57 + */
74.58 +final class Observers {
74.59 + private static final LinkedList<Watcher> GLOBAL = new LinkedList<Watcher>();
74.60 + private final List<Watcher> watchers = new ArrayList<Watcher>();
74.61 + private final List<Ref> observers = new ArrayList<Ref>();
74.62 +
74.63 + Observers() {
74.64 + assert Thread.holdsLock(GLOBAL);
74.65 + }
74.66 +
74.67 + static void beginComputing(Proto p, String name) {
74.68 + synchronized (GLOBAL) {
74.69 + verifyUnlocked(p);
74.70 + final Watcher nw = new Watcher(p, name);
74.71 + GLOBAL.push(nw);
74.72 + }
74.73 + }
74.74 +
74.75 + static void verifyUnlocked(Proto p) {
74.76 + synchronized (GLOBAL) {
74.77 + for (Watcher w : GLOBAL) {
74.78 + if (w.proto == p) {
74.79 + throw new IllegalStateException("Re-entrant attempt to access " + p);
74.80 + }
74.81 + }
74.82 + }
74.83 + }
74.84 +
74.85 + static void accessingValue(Proto p, String propName) {
74.86 + synchronized (GLOBAL) {
74.87 + verifyUnlocked(p);
74.88 + for (Watcher w : GLOBAL) {
74.89 + Observers mine = p.observers(true);
74.90 + mine.add(w, new Ref(w, propName));
74.91 + }
74.92 + }
74.93 + }
74.94 +
74.95 + static void finishComputing(Proto p) {
74.96 + synchronized (GLOBAL) {
74.97 + Watcher w = GLOBAL.pop();
74.98 + if (w.proto != p) {
74.99 + throw new IllegalStateException("Inconsistency: " + w.proto + " != " + p);
74.100 + }
74.101 + if (w.prop != null) {
74.102 + Observers mine = p.observers(true);
74.103 + mine.add(w);
74.104 + }
74.105 + }
74.106 + }
74.107 +
74.108 + private static final class Ref extends WeakReference<Watcher> {
74.109 + private final String prop;
74.110 +
74.111 + public Ref(Watcher ref, String prop) {
74.112 + super(ref);
74.113 + this.prop = prop;
74.114 + }
74.115 +
74.116 + final Watcher watcher() {
74.117 + Watcher w = get();
74.118 + if (w == null) {
74.119 + return null;
74.120 + }
74.121 + final Observers o = w.proto.observers(false);
74.122 + if (o == null) {
74.123 + return null;
74.124 + }
74.125 + if (o.find(w.prop) == w) {
74.126 + return w;
74.127 + }
74.128 + return null;
74.129 + }
74.130 + }
74.131 +
74.132 + private Watcher find(String prop) {
74.133 + if (prop == null) {
74.134 + return null;
74.135 + }
74.136 + for (Watcher w : watchers) {
74.137 + if (prop.equals(w.prop)) {
74.138 + return w;
74.139 + }
74.140 + }
74.141 + return null;
74.142 + }
74.143 +
74.144 + final void add(Watcher w) {
74.145 + for (int i = 0; i < watchers.size(); i++) {
74.146 + Watcher ith = watchers.get(i);
74.147 + if (w.prop == null) {
74.148 + if (ith.prop == null) {
74.149 + watchers.set(i, w);
74.150 + return;
74.151 + }
74.152 + } else if (w.prop.equals(ith.prop)) {
74.153 + watchers.set(i, w);
74.154 + return;
74.155 + }
74.156 + }
74.157 + watchers.add(w);
74.158 + }
74.159 +
74.160 + static final void valueHasMutated(Proto p, String propName) {
74.161 + List<Watcher> mutated = new LinkedList<Watcher>();
74.162 + synchronized (GLOBAL) {
74.163 + Observers mine = p.observers(false);
74.164 + if (mine == null) {
74.165 + return;
74.166 + }
74.167 + Iterator<Ref> it = mine.observers.iterator();
74.168 + while (it.hasNext()) {
74.169 + Ref ref = it.next();
74.170 + if (ref.get() == null) {
74.171 + it.remove();
74.172 + continue;
74.173 + }
74.174 + if (ref.prop.equals(propName)) {
74.175 + Watcher w = ref.watcher();
74.176 + if (w != null) {
74.177 + mutated.add(w);
74.178 + }
74.179 + }
74.180 + }
74.181 + }
74.182 + for (Watcher w : mutated) {
74.183 + w.proto.valueHasMutated(w.prop);
74.184 + }
74.185 + }
74.186 +
74.187 + void add(Watcher w, Ref r) {
74.188 + Thread.holdsLock(GLOBAL);
74.189 + if (w == null) {
74.190 + return;
74.191 + }
74.192 + Iterator<Ref> it = observers.iterator();
74.193 + while (it.hasNext()) {
74.194 + Ref ref = it.next();
74.195 + if (r == ref) {
74.196 + return;
74.197 + }
74.198 + final Watcher rw = ref.get();
74.199 + if (rw == null) {
74.200 + it.remove();
74.201 + continue;
74.202 + }
74.203 + if (rw == w && r.prop.equals(r.prop)) {
74.204 + return;
74.205 + }
74.206 + }
74.207 + observers.add(r);
74.208 + }
74.209 +
74.210 + private static final class Watcher {
74.211 + final Proto proto;
74.212 + final String prop;
74.213 +
74.214 + Watcher(Proto proto, String prop) {
74.215 + this.proto = proto;
74.216 + this.prop = prop;
74.217 + }
74.218 +
74.219 + @Override
74.220 + public String toString() {
74.221 + return "Watcher: " + proto + ", " + prop;
74.222 + }
74.223 + }
74.224 +}
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
75.2 +++ b/json/src/main/java/org/netbeans/html/json/spi/PropertyBinding.java Tue Aug 26 18:13:30 2014 +0200
75.3 @@ -0,0 +1,168 @@
75.4 +/**
75.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
75.6 + *
75.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
75.8 + *
75.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
75.10 + * Other names may be trademarks of their respective owners.
75.11 + *
75.12 + * The contents of this file are subject to the terms of either the GNU
75.13 + * General Public License Version 2 only ("GPL") or the Common
75.14 + * Development and Distribution License("CDDL") (collectively, the
75.15 + * "License"). You may not use this file except in compliance with the
75.16 + * License. You can obtain a copy of the License at
75.17 + * http://www.netbeans.org/cddl-gplv2.html
75.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
75.19 + * specific language governing permissions and limitations under the
75.20 + * License. When distributing the software, include this License Header
75.21 + * Notice in each file and include the License file at
75.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
75.23 + * particular file as subject to the "Classpath" exception as provided
75.24 + * by Oracle in the GPL Version 2 section of the License file that
75.25 + * accompanied this code. If applicable, add the following below the
75.26 + * License Header, with the fields enclosed by brackets [] replaced by
75.27 + * your own identifying information:
75.28 + * "Portions Copyrighted [year] [name of copyright owner]"
75.29 + *
75.30 + * Contributor(s):
75.31 + *
75.32 + * The Original Software is NetBeans. The Initial Developer of the Original
75.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
75.34 + *
75.35 + * If you wish your version of this file to be governed by only the CDDL
75.36 + * or only the GPL Version 2, indicate your decision by adding
75.37 + * "[Contributor] elects to include this software in this distribution
75.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
75.39 + * single choice of license, a recipient has the option to distribute
75.40 + * your version of this file under either the CDDL, the GPL Version 2 or
75.41 + * to extend the choice of license to its licensees as provided above.
75.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
75.43 + * Version 2 license, then the option applies only if the new code is
75.44 + * made subject to such option by the copyright holder.
75.45 + */
75.46 +package org.netbeans.html.json.spi;
75.47 +
75.48 +import net.java.html.BrwsrCtx;
75.49 +import org.netbeans.html.json.impl.Bindings;
75.50 +import org.netbeans.html.json.impl.JSON;
75.51 +import org.netbeans.html.json.impl.PropertyBindingAccessor;
75.52 +import org.netbeans.html.json.impl.RcvrJSON;
75.53 +
75.54 +/** Describes a property when one is asked to
75.55 + * bind it
75.56 + *
75.57 + * @author Jaroslav Tulach
75.58 + */
75.59 +public abstract class PropertyBinding {
75.60 + PropertyBinding() {
75.61 + }
75.62 +
75.63 + static {
75.64 + new PropertyBindingAccessor() {
75.65 + @Override
75.66 + protected JSONCall newCall(BrwsrCtx ctx, RcvrJSON callback, String urlBefore, String urlAfter, String method, Object data) {
75.67 + return new JSONCall(ctx, callback, urlBefore, urlAfter, method, data);
75.68 + }
75.69 +
75.70 + @Override
75.71 + protected Bindings bindings(Proto proto, boolean initialize) {
75.72 + return initialize ? proto.initBindings() : proto.getBindings();
75.73 + }
75.74 +
75.75 + @Override
75.76 + protected void notifyChange(Proto proto, int propIndex) {
75.77 + proto.onChange(propIndex);
75.78 + }
75.79 +
75.80 + @Override
75.81 + protected Proto findProto(Proto.Type<?> type, Object object) {
75.82 + return type.protoFor(object);
75.83 + }
75.84 +
75.85 + @Override
75.86 + protected <Model> Model cloneTo(Proto.Type<Model> type, Model model, BrwsrCtx c) {
75.87 + return type.cloneTo(model, c);
75.88 + }
75.89 +
75.90 + @Override
75.91 + protected Object read(Proto.Type<?> from, BrwsrCtx c, Object data) {
75.92 + return from.read(c, data);
75.93 + }
75.94 +
75.95 + @Override
75.96 + protected <M> PropertyBinding newBinding(
75.97 + Proto.Type<M> access, Bindings<?> bindings, String name,
75.98 + int index, M model, boolean readOnly
75.99 + ) {
75.100 + return new Impl(bindings, name, index, model, access, readOnly);
75.101 + }
75.102 + };
75.103 + }
75.104 +
75.105 + /** Name of the property this binding represents.
75.106 + * @return name of the property
75.107 + */
75.108 + public abstract String getPropertyName();
75.109 +
75.110 + /** Changes value of the property. Can be called only on dedicated
75.111 + * thread. See {@link Technology#runSafe(java.lang.Runnable)}.
75.112 + *
75.113 + * @param v new value of the property
75.114 + */
75.115 + public abstract void setValue(Object v);
75.116 +
75.117 + /** Obtains current value of the property this binding represents.
75.118 + * Can be called only on dedicated
75.119 + * thread. See {@link Technology#runSafe(java.lang.Runnable)}.
75.120 + *
75.121 + * @return the value or <code>null</code>
75.122 + */
75.123 + public abstract Object getValue();
75.124 +
75.125 + /** Is this property read only? Or can one call {@link #setValue(java.lang.Object)}?
75.126 + *
75.127 + * @return true, if this property is read only
75.128 + */
75.129 + public abstract boolean isReadOnly();
75.130 +
75.131 + private static final class Impl<M> extends PropertyBinding {
75.132 + public final String name;
75.133 + public final boolean readOnly;
75.134 + private final M model;
75.135 + private final Proto.Type<M> access;
75.136 + private final Bindings<?> bindings;
75.137 + private final int index;
75.138 +
75.139 + public Impl(Bindings<?> bindings, String name, int index, M model, Proto.Type<M> access, boolean readOnly) {
75.140 + this.bindings = bindings;
75.141 + this.name = name;
75.142 + this.index = index;
75.143 + this.model = model;
75.144 + this.access = access;
75.145 + this.readOnly = readOnly;
75.146 + }
75.147 +
75.148 + @Override
75.149 + public void setValue(Object v) {
75.150 + access.setValue(model, index, v);
75.151 + }
75.152 +
75.153 + @Override
75.154 + public Object getValue() {
75.155 + Object v = access.getValue(model, index);
75.156 + Object r = JSON.find(v, bindings);
75.157 + return r == null ? v : r;
75.158 + }
75.159 +
75.160 + @Override
75.161 + public boolean isReadOnly() {
75.162 + return readOnly;
75.163 + }
75.164 +
75.165 + @Override
75.166 + public String getPropertyName() {
75.167 + return name;
75.168 + }
75.169 + } // end of PBData
75.170 +
75.171 +}
76.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
76.2 +++ b/json/src/main/java/org/netbeans/html/json/spi/Proto.java Tue Aug 26 18:13:30 2014 +0200
76.3 @@ -0,0 +1,843 @@
76.4 +/**
76.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
76.6 + *
76.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
76.8 + *
76.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
76.10 + * Other names may be trademarks of their respective owners.
76.11 + *
76.12 + * The contents of this file are subject to the terms of either the GNU
76.13 + * General Public License Version 2 only ("GPL") or the Common
76.14 + * Development and Distribution License("CDDL") (collectively, the
76.15 + * "License"). You may not use this file except in compliance with the
76.16 + * License. You can obtain a copy of the License at
76.17 + * http://www.netbeans.org/cddl-gplv2.html
76.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
76.19 + * specific language governing permissions and limitations under the
76.20 + * License. When distributing the software, include this License Header
76.21 + * Notice in each file and include the License file at
76.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
76.23 + * particular file as subject to the "Classpath" exception as provided
76.24 + * by Oracle in the GPL Version 2 section of the License file that
76.25 + * accompanied this code. If applicable, add the following below the
76.26 + * License Header, with the fields enclosed by brackets [] replaced by
76.27 + * your own identifying information:
76.28 + * "Portions Copyrighted [year] [name of copyright owner]"
76.29 + *
76.30 + * Contributor(s):
76.31 + *
76.32 + * The Original Software is NetBeans. The Initial Developer of the Original
76.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
76.34 + *
76.35 + * If you wish your version of this file to be governed by only the CDDL
76.36 + * or only the GPL Version 2, indicate your decision by adding
76.37 + * "[Contributor] elects to include this software in this distribution
76.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
76.39 + * single choice of license, a recipient has the option to distribute
76.40 + * your version of this file under either the CDDL, the GPL Version 2 or
76.41 + * to extend the choice of license to its licensees as provided above.
76.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
76.43 + * Version 2 license, then the option applies only if the new code is
76.44 + * made subject to such option by the copyright holder.
76.45 + */
76.46 +package org.netbeans.html.json.spi;
76.47 +
76.48 +import java.util.Collection;
76.49 +import java.util.List;
76.50 +import net.java.html.BrwsrCtx;
76.51 +import net.java.html.json.ComputedProperty;
76.52 +import net.java.html.json.Model;
76.53 +import org.netbeans.html.json.impl.Bindings;
76.54 +import org.netbeans.html.json.impl.JSON;
76.55 +import org.netbeans.html.json.impl.JSONList;
76.56 +import org.netbeans.html.json.impl.RcvrJSON;
76.57 +import org.netbeans.html.json.impl.RcvrJSON.MsgEvnt;
76.58 +
76.59 +/** Object associated with one instance of a model generated by the
76.60 + * {@link Model} annotation. Contains methods the generated class can
76.61 + * use to communicate with behind the scene associated {@link Technology}.
76.62 + * Each {@link Proto} object is associated with <a href="http://wiki.apidesign.org/wiki/Singletonizer">
76.63 + * singletonizer</a>-like interface {@link Type} which provides the
76.64 + * associated {@link Technology} the necessary information about the
76.65 + * generated {@link Model} class.
76.66 + *
76.67 + * @author Jaroslav Tulach
76.68 + * @since 0.7
76.69 + */
76.70 +public final class Proto {
76.71 + private final Object obj;
76.72 + private final Type type;
76.73 + private final net.java.html.BrwsrCtx context;
76.74 + private org.netbeans.html.json.impl.Bindings ko;
76.75 + private Observers observers;
76.76 +
76.77 + Proto(Object obj, Type type, BrwsrCtx context) {
76.78 + this.obj = obj;
76.79 + this.type = type;
76.80 + this.context = context;
76.81 + }
76.82 +
76.83 + /** Browser context this proto object and its associated model
76.84 + * are operating-in.
76.85 + *
76.86 + * @return the associated context
76.87 + */
76.88 + public BrwsrCtx getContext() {
76.89 + return context;
76.90 + }
76.91 +
76.92 + /** Acquires global lock to compute a {@link ComputedProperty derived property}
76.93 + * on this proto object. This proto object must not be locked yet. No
76.94 + * dependency tracking is performed.
76.95 + *
76.96 + * @throws IllegalStateException if already locked
76.97 + */
76.98 + public void acquireLock() throws IllegalStateException {
76.99 + acquireLock(null);
76.100 + }
76.101 +
76.102 + /** Acquires global lock to compute a {@link ComputedProperty derived property}
76.103 + * on this proto object. This proto object must not be locked yet. The
76.104 + * name of the property is used to track dependencies on own
76.105 + * properties of other proto objects - when they are changed, this
76.106 + * {@link #valueHasMutated(java.lang.String) property is changed too}.
76.107 + *
76.108 + * @param propName name of property we are about to compute
76.109 + * @throws IllegalStateException thrown when there is a cyclic
76.110 + * call is detected
76.111 + * @since 0.9
76.112 + */
76.113 + public void acquireLock(String propName) throws IllegalStateException {
76.114 + Observers.beginComputing(this, propName);
76.115 + }
76.116 +
76.117 + /** A property on this proto object is about to be accessed. Verifies
76.118 + * whether this proto object is accessible - e.g. it has not been
76.119 + * {@link #acquireLock() locked yet}. If everything is OK, the
76.120 + * <code>propName</code> is recorded in the chain of dependencies
76.121 + * tracked by {@link #acquireLock(java.lang.String)} and watched by
76.122 + * {@link #valueHasMutated(java.lang.String)}.
76.123 + *
76.124 + * @param propName name of the property that is requested
76.125 + * @throws IllegalStateException if the model is locked
76.126 + * @since 0.9
76.127 + */
76.128 + public void accessProperty(String propName) throws IllegalStateException {
76.129 + Observers.accessingValue(this, propName);
76.130 + }
76.131 +
76.132 + /** Verifies the model is not locked otherwise throws an exception.
76.133 + * @throws IllegalStateException if the model is locked
76.134 + */
76.135 + public void verifyUnlocked() throws IllegalStateException {
76.136 + Observers.verifyUnlocked(this);
76.137 + }
76.138 +
76.139 + /** When modifications are over, the model is switched into
76.140 + * unlocked state by calling this method.
76.141 + */
76.142 + public void releaseLock() {
76.143 + Observers.finishComputing(this);
76.144 + }
76.145 +
76.146 + /** Whenever model changes a property. It should notify the
76.147 + * associated technology by calling this method.
76.148 + * Since 0.8.3: This method may be called by any thread - it reschedules
76.149 + * its actual execution into appropriate one by using
76.150 + * {@link BrwsrCtx#execute(java.lang.Runnable)}.
76.151 + *
76.152 + * @param propName name of the changed property
76.153 + */
76.154 + public void valueHasMutated(final String propName) {
76.155 + context.execute(new Runnable() {
76.156 + @Override
76.157 + public void run() {
76.158 + if (ko != null) {
76.159 + ko.valueHasMutated(propName, null, null);
76.160 + }
76.161 + Observers.valueHasMutated(Proto.this, propName);
76.162 + }
76.163 + });
76.164 + }
76.165 +
76.166 + /** Whenever model changes a propertyit should notify the
76.167 + * associated technology. Either by calling this method
76.168 + * (if the new value is known and different to the old one) or
76.169 + * via (slightly ineffective) {@link #valueHasMutated(java.lang.String)}
76.170 + * method.
76.171 + * Since 0.8.3: This method may be called by any thread - it reschedules
76.172 + * its actual execution into appropriate one by using
76.173 + * {@link BrwsrCtx#execute(java.lang.Runnable)}.
76.174 + *
76.175 + * @param propName name of the changed property
76.176 + * @param oldValue provides previous value of the property
76.177 + * @param newValue provides new value of the property
76.178 + * @since 0.7.6
76.179 + */
76.180 + public void valueHasMutated(
76.181 + final String propName, final Object oldValue, final Object newValue
76.182 + ) {
76.183 + context.execute(new Runnable() {
76.184 + @Override
76.185 + public void run() {
76.186 + if (ko != null) {
76.187 + ko.valueHasMutated(propName, oldValue, newValue);
76.188 + }
76.189 + Observers.valueHasMutated(Proto.this, propName);
76.190 + }
76.191 + });
76.192 + }
76.193 +
76.194 + /** Initializes the associated model in the current {@link #getContext() context}.
76.195 + * In case of <em>knockout.js</em> technology, applies given bindings
76.196 + * of the current model to the <em>body</em> element of the page.
76.197 + */
76.198 + public void applyBindings() {
76.199 + initBindings().applyBindings();
76.200 + }
76.201 +
76.202 + /** Invokes the provided runnable in the {@link #getContext() context}
76.203 + * of the browser. If the caller is already on the right thread, the
76.204 + * <code>run.run()</code> is invoked immediately and synchronously.
76.205 + * Otherwise the method returns immediately and the <code>run()</code>
76.206 + * method is performed later
76.207 + *
76.208 + * @param run the action to execute
76.209 + */
76.210 + public void runInBrowser(Runnable run) {
76.211 + context.execute(run);
76.212 + }
76.213 +
76.214 + /** Invokes the specified function index in the {@link #getContext() context}
76.215 + * of the browser. If the caller is already on the right thread, the
76.216 + * index-th function is invoked immediately and synchronously.
76.217 + * Otherwise the method returns immediately and the function is invoked
76.218 + * later.
76.219 + *
76.220 + * @param index the index of the function as will be passed to
76.221 + * {@link Type#call(java.lang.Object, int, java.lang.Object, java.lang.Object)}
76.222 + * method
76.223 + * @param args array of arguments that will be passed as
76.224 + * <code>data</code> argument of the <code>call</code> method.
76.225 + * @since 0.7.6
76.226 + */
76.227 + public void runInBrowser(final int index, final Object... args) {
76.228 + context.execute(new Runnable() {
76.229 + @Override
76.230 + public void run() {
76.231 + try {
76.232 + type.call(obj, index, args, null);
76.233 + } catch (Exception ex) {
76.234 + ex.printStackTrace();
76.235 + }
76.236 + }
76.237 + });
76.238 + }
76.239 +
76.240 + /** Initializes the provided collection with a content of the <code>array</code>.
76.241 + * The initialization can only be done soon after the the collection
76.242 + * is created, otherwise an exception is throw
76.243 + *
76.244 + * @param to the collection to initialize (assumed to be empty)
76.245 + * @param array the array to add to the collection
76.246 + * @throws IllegalStateException if the system has already been initialized
76.247 + */
76.248 + public void initTo(Collection<?> to, Object array) {
76.249 + if (ko != null) {
76.250 + throw new IllegalStateException();
76.251 + }
76.252 + if (to instanceof JSONList) {
76.253 + ((JSONList)to).init(array);
76.254 + } else {
76.255 + JSONList.init(to, array);
76.256 + }
76.257 + }
76.258 +
76.259 + /** Takes an object representing JSON result and extract some of its
76.260 + * properties. It is assumed that the <code>props</code> and
76.261 + * <code>values</code> arrays have the same length.
76.262 + *
76.263 + * @param json the JSON object (actual type depends on the associated
76.264 + * {@link Technology})
76.265 + * @param props list of properties to extract
76.266 + * @param values array that will be filled with extracted values
76.267 + */
76.268 + public void extract(Object json, String[] props, Object[] values) {
76.269 + JSON.extract(context, json, props, values);
76.270 + }
76.271 +
76.272 + /** Converts raw JSON <code>data</code> into a Java {@link Model} class.
76.273 + *
76.274 + * @param <T> type of the model class
76.275 + * @param modelClass the type of the class to create
76.276 + * @param data the raw JSON data
76.277 + * @return newly created instance of the model class
76.278 + */
76.279 + public <T> T read(Class<T> modelClass, Object data) {
76.280 + return JSON.read(context, modelClass, data);
76.281 + }
76.282 +
76.283 + /** Initializes asynchronous JSON connection to specified URL. Delegates
76.284 + * to {@link #loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...) }
76.285 + * with no extra parameters.
76.286 + *
76.287 + * @param index the callback index to be used when a reply is received
76.288 + * to call {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)}.
76.289 + *
76.290 + * @param urlBefore the part of the URL before JSON-P callback parameter
76.291 + * @param urlAfter the rest of the URL or <code>null</code> if no JSON-P is used
76.292 + * @param method method to use for connection to the server
76.293 + * @param data string, number or a {@link Model} generated class to send to
76.294 + * the server when doing a query
76.295 + */
76.296 + public void loadJSON(final int index,
76.297 + String urlBefore, String urlAfter, String method,
76.298 + final Object data
76.299 + ) {
76.300 + loadJSON(index, urlBefore, urlAfter, method, data, new Object[0]);
76.301 + }
76.302 +
76.303 + /** Initializes asynchronous JSON connection to specified URL. The
76.304 + * method returns immediately and later does callback later.
76.305 + *
76.306 + * @param index the callback index to be used when a reply is received
76.307 + * to call {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)}.
76.308 + *
76.309 + * @param urlBefore the part of the URL before JSON-P callback parameter
76.310 + * @param urlAfter the rest of the URL or <code>null</code> if no JSON-P is used
76.311 + * @param method method to use for connection to the server
76.312 + * @param data string, number or a {@link Model} generated class to send to
76.313 + * the server when doing a query
76.314 + * @param params extra params to pass back when calling
76.315 + * {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object, java.lang.Object[])}
76.316 + * @since 0.8.1
76.317 + */
76.318 + public void loadJSON(final int index,
76.319 + String urlBefore, String urlAfter, String method,
76.320 + final Object data, final Object... params
76.321 + ) {
76.322 + class Rcvr extends RcvrJSON {
76.323 + @Override
76.324 + protected void onMessage(MsgEvnt msg) {
76.325 + type.onMessage(obj, index, 1, msg.getValues(), params);
76.326 + }
76.327 +
76.328 + @Override
76.329 + protected void onError(MsgEvnt msg) {
76.330 + type.onMessage(obj, index, 2, msg.getException(), params);
76.331 + }
76.332 + }
76.333 + JSON.loadJSON(context, new Rcvr(), urlBefore, urlAfter, method, data);
76.334 + }
76.335 +
76.336 + /** Opens new WebSocket connection to the specified URL.
76.337 + *
76.338 + * @param index the index to use later during callbacks to
76.339 + * {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)}
76.340 + * @param url the <code>ws://</code> or <code>wss://</code> URL to connect to
76.341 + * @param data data to send to server (usually <code>null</code>)
76.342 + * @return returns a non-null object representing the socket
76.343 + * which can be used when calling {@link #wsSend(java.lang.Object, java.lang.String, java.lang.Object) }
76.344 + */
76.345 + public Object wsOpen(final int index, String url, Object data) {
76.346 + class WSrcvr extends RcvrJSON {
76.347 + @Override
76.348 + protected void onError(MsgEvnt msg) {
76.349 + type.onMessage(obj, index, 2, msg.getException());
76.350 + }
76.351 +
76.352 + @Override
76.353 + protected void onMessage(MsgEvnt msg) {
76.354 + type.onMessage(obj, index, 1, msg.getValues());
76.355 + }
76.356 +
76.357 + @Override
76.358 + protected void onClose(MsgEvnt msg) {
76.359 + type.onMessage(obj, index, 3, null);
76.360 + }
76.361 +
76.362 + @Override
76.363 + protected void onOpen(MsgEvnt msg) {
76.364 + type.onMessage(obj, index, 0, null);
76.365 + }
76.366 + }
76.367 + return JSON.openWS(context, new WSrcvr(), url, data);
76.368 + }
76.369 +
76.370 + /** Sends a message to existing socket.
76.371 + *
76.372 + * @param webSocket the socket to send message to
76.373 + * @param url the <code>ws://</code> or <code>wss://</code> URL to connect to,
76.374 + * preferably the same as the one used when the socket was
76.375 + * {@link #wsOpen(int, java.lang.String, java.lang.Object) opened}
76.376 + * @param data the data to send or <code>null</code> if the socket is
76.377 + * supposed to be closed
76.378 + */
76.379 + public void wsSend(Object webSocket, String url, Object data) {
76.380 + ((JSON.WS)webSocket).send(context, url, data);
76.381 + }
76.382 +
76.383 + /** Converts raw data (one of its properties) to string representation.
76.384 + *
76.385 + * @param data the object
76.386 + * @param propName the name of object property or <code>null</code>
76.387 + * if the whole object should be converted
76.388 + * @return the string representation of the object or its property
76.389 + */
76.390 + public String toString(Object data, String propName) {
76.391 + return JSON.toString(context, data, propName);
76.392 + }
76.393 +
76.394 + /** Converts raw data (one of its properties) to a number representation.
76.395 + *
76.396 + * @param data the object
76.397 + * @param propName the name of object property or <code>null</code>
76.398 + * if the whole object should be converted
76.399 + * @return the number representation of the object or its property
76.400 + */
76.401 + public Number toNumber(Object data, String propName) {
76.402 + return JSON.toNumber(context, data, propName);
76.403 + }
76.404 +
76.405 + /** Converts raw JSON data into a {@link Model} class representation.
76.406 + *
76.407 + * @param <T> type of the model to create
76.408 + * @param type class of the model to create
76.409 + * @param data raw JSON data (depends on associated {@link Technology})
76.410 + * @return new instances of the model class filled with values from the
76.411 + * <code>data</code> object
76.412 + */
76.413 + public <T> T toModel(Class<T> type, Object data) {
76.414 + return JSON.toModel(context, type, data, null);
76.415 + }
76.416 +
76.417 + /** Creates new JSON like observable list.
76.418 + *
76.419 + * @param <T> the type of the list elements
76.420 + * @param propName name of a property this list is associated with
76.421 + * @param onChange index of the property to use when the list is modified
76.422 + * during callback to {@link Type#onChange(java.lang.Object, int)}
76.423 + * @param dependingProps the array of {@link ComputedProperty derived properties}
76.424 + * that depend on the value of the list
76.425 + * @return new, empty list associated with this proto-object and its model
76.426 + */
76.427 + public <T> List<T> createList(String propName, int onChange, String... dependingProps) {
76.428 + return new JSONList<T>(this, propName, onChange, dependingProps);
76.429 + }
76.430 +
76.431 + /** Copies content of one collection to another, re-assigning all its
76.432 + * elements from their current context to the new <code>ctx</code>.
76.433 + *
76.434 + * @param <T> type of the collections
76.435 + * @param to the target collection to be filled with cloned values
76.436 + * @param ctx context for the new collection
76.437 + * @param from original collection with its data
76.438 + */
76.439 + public <T> void cloneList(Collection<T> to, BrwsrCtx ctx, Collection<T> from) {
76.440 + Boolean isModel = null;
76.441 + for (T t : from) {
76.442 + if (isModel == null) {
76.443 + isModel = JSON.isModel(t.getClass());
76.444 + }
76.445 + if (isModel) {
76.446 + to.add(JSON.bindTo(t, ctx));
76.447 + } else {
76.448 + to.add(t);
76.449 + }
76.450 + }
76.451 + }
76.452 +
76.453 + //
76.454 + // internal state
76.455 + //
76.456 +
76.457 + final String toStr() {
76.458 + return "Proto[" + obj + "]@" + Integer.toHexString(System.identityHashCode(this));
76.459 + }
76.460 +
76.461 + final Bindings initBindings() {
76.462 + if (ko == null) {
76.463 + Bindings b = Bindings.apply(context, obj);
76.464 + PropertyBinding[] pb = new PropertyBinding[type.propertyNames.length];
76.465 + for (int i = 0; i < pb.length; i++) {
76.466 + pb[i] = b.registerProperty(
76.467 + type.propertyNames[i], i, obj, type, type.propertyReadOnly[i]
76.468 + );
76.469 + }
76.470 + FunctionBinding[] fb = new FunctionBinding[type.functions.length];
76.471 + for (int i = 0; i < fb.length; i++) {
76.472 + fb[i] = FunctionBinding.registerFunction(
76.473 + type.functions[i], i, obj, type
76.474 + );
76.475 + }
76.476 + ko = b;
76.477 + b.finish(obj, pb, fb);
76.478 + }
76.479 + return ko;
76.480 + }
76.481 +
76.482 + final Bindings getBindings() {
76.483 + return ko;
76.484 + }
76.485 +
76.486 + final void onChange(int index) {
76.487 + type.onChange(obj, index);
76.488 + }
76.489 +
76.490 + final Observers observers(boolean create) {
76.491 + if (create && observers == null) {
76.492 + observers = new Observers();
76.493 + }
76.494 + return observers;
76.495 + }
76.496 +
76.497 + /** Functionality used by the code generated by annotation
76.498 + * processor for the {@link net.java.html.json.Model} annotation.
76.499 + *
76.500 + * @param <Model> the generated class
76.501 + * @since 0.7
76.502 + */
76.503 + public static abstract class Type<Model> {
76.504 + private final Class<Model> clazz;
76.505 + private final String[] propertyNames;
76.506 + private final boolean[] propertyReadOnly;
76.507 + private final String[] functions;
76.508 +
76.509 + /** Constructor for subclasses generated by the annotation processor
76.510 + * associated with {@link net.java.html.json.Model} annotation.
76.511 + *
76.512 + * @param clazz the generated model class
76.513 + * @param modelFor the original class annotated by the {@link net.java.html.json.Model} annotation.
76.514 + * @param properties number of properties the class has
76.515 + * @param functions number of functions the class has
76.516 + */
76.517 + protected Type(
76.518 + Class<Model> clazz, Class<?> modelFor, int properties, int functions
76.519 + ) {
76.520 + assert getClass().getName().endsWith("$Html4JavaType");
76.521 + try {
76.522 + assert getClass().getDeclaringClass() == clazz;
76.523 + } catch (SecurityException ex) {
76.524 + // OK, no check
76.525 + }
76.526 + this.clazz = clazz;
76.527 + this.propertyNames = new String[properties];
76.528 + this.propertyReadOnly = new boolean[properties];
76.529 + this.functions = new String[functions];
76.530 + JSON.register(clazz, this);
76.531 + }
76.532 +
76.533 + /** Registers property for the type. It is expected each index
76.534 + * is initialized only once.
76.535 + *
76.536 + * @param name name of the property
76.537 + * @param index index of the property
76.538 + * @param readOnly is the property read only?
76.539 + */
76.540 + protected final void registerProperty(String name, int index, boolean readOnly) {
76.541 + assert propertyNames[index] == null;
76.542 + propertyNames[index] = name;
76.543 + propertyReadOnly[index] = readOnly;
76.544 + }
76.545 +
76.546 + /** Registers function of given name at given index.
76.547 + *
76.548 + * @param name name of the function
76.549 + * @param index name of the type
76.550 + */
76.551 + protected final void registerFunction(String name, int index) {
76.552 + assert functions[index] == null;
76.553 + functions[index] = name;
76.554 + }
76.555 +
76.556 + /** Creates new proto-object for given {@link Model} class bound to
76.557 + * provided context.
76.558 + *
76.559 + * @param obj instance of appropriate {@link Model} class
76.560 + * @param context the browser context
76.561 + * @return new proto-object that the generated class can use for
76.562 + * communication with the infrastructure
76.563 + */
76.564 + public Proto createProto(Object obj, BrwsrCtx context) {
76.565 + return new Proto(obj, this, context);
76.566 + }
76.567 +
76.568 + //
76.569 + // Implemented by subclasses
76.570 + //
76.571 +
76.572 + /** Sets value of a {@link #registerProperty(java.lang.String, int, boolean) registered property}
76.573 + * to new value.
76.574 + *
76.575 + * @param model the instance of {@link Model model class}
76.576 + * @param index index of the property used during registration
76.577 + * @param value the value to set the property to
76.578 + */
76.579 + protected abstract void setValue(Model model, int index, Object value);
76.580 +
76.581 + /** Obtains and returns value of a
76.582 + * {@link #registerProperty(java.lang.String, int, boolean) registered property}.
76.583 + *
76.584 + * @param model the instance of {@link Model model class}
76.585 + * @param index index of the property used during registration
76.586 + * @return current value of the property
76.587 + */
76.588 + protected abstract Object getValue(Model model, int index);
76.589 +
76.590 + /** Invokes a {@link #registerFunction(java.lang.String, int)} registered function
76.591 + * on given object.
76.592 + *
76.593 + * @param model the instance of {@link Model model class}
76.594 + * @param index index of the property used during registration
76.595 + * @param data the currently selected object the function is about to operate on
76.596 + * @param event the event that triggered the event
76.597 + * @throws Exception the method can throw exception which is then logged
76.598 + */
76.599 + protected abstract void call(Model model, int index, Object data, Object event)
76.600 + throws Exception;
76.601 +
76.602 + /** Re-binds the model object to new browser context.
76.603 + *
76.604 + * @param model the instance of {@link Model model class}
76.605 + * @param ctx browser context to clone the object to
76.606 + * @return new instance of the model suitable for new context
76.607 + */
76.608 + protected abstract Model cloneTo(Model model, BrwsrCtx ctx);
76.609 +
76.610 + /** Reads raw JSON data and converts them to our model class.
76.611 + *
76.612 + * @param c the browser context to work in
76.613 + * @param json raw JSON data to get values from
76.614 + * @return new instance of model class filled by the data
76.615 + */
76.616 + protected abstract Model read(BrwsrCtx c, Object json);
76.617 +
76.618 + /** Called when a {@link #registerProperty(java.lang.String, int, boolean) registered property}
76.619 + * changes its value.
76.620 + *
76.621 + * @param model the object that has the property
76.622 + * @param index the index of the property during registration
76.623 + */
76.624 + protected abstract void onChange(Model model, int index);
76.625 +
76.626 + /** Finds out if there is an associated proto-object for given
76.627 + * object.
76.628 + *
76.629 + * @param object an object, presumably (but not necessarily) instance of Model class
76.630 + * @return associated proto-object or <code>null</code>
76.631 + */
76.632 + protected abstract Proto protoFor(Object object);
76.633 +
76.634 + /** Called to report results of asynchronous over-the-wire
76.635 + * communication. Result of calling {@link Proto#wsOpen(int, java.lang.String, java.lang.Object)}
76.636 + * or {@link Proto#loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)}.
76.637 + *
76.638 + * @param model the instance of the model class
76.639 + * @param index index used during initiating the communication (via <code>loadJSON</code> or <code>wsOpen</code> calls)
76.640 + * @param type type of the message: 0 - onOpen, 1 - onMessage, 2 - onError, 3 - onClose -
76.641 + * not all messages are applicable to all communication protocols (JSON has only 1 and 2).
76.642 + * @param data <code>null</code> or string, number or a {@link Model} class
76.643 + * obtained to the server as a response
76.644 + */
76.645 + protected void onMessage(Model model, int index, int type, Object data) {
76.646 + onMessage(model, index, type, data, new Object[0]);
76.647 + }
76.648 +
76.649 + /** Called to report results of asynchronous over-the-wire
76.650 + * communication. Result of calling {@link Proto#wsOpen(int, java.lang.String, java.lang.Object)}
76.651 + * or {@link Proto#loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)}.
76.652 + *
76.653 + * @param model the instance of the model class
76.654 + * @param index index used during initiating the communication (via <code>loadJSON</code> or <code>wsOpen</code> calls)
76.655 + * @param type type of the message: 0 - onOpen, 1 - onMessage, 2 - onError, 3 - onClose -
76.656 + * not all messages are applicable to all communication protocols (JSON has only 1 and 2).
76.657 + * @param data <code>null</code> or string, number or a {@link Model} class
76.658 + * obtained to the server as a response
76.659 + * @param params extra parameters as passed for example to
76.660 + * {@link Proto#loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)}
76.661 + * method
76.662 + * @since 0.8.1
76.663 + */
76.664 + protected void onMessage(Model model, int index, int type, Object data, Object[] params) {
76.665 + onMessage(model, index, type, data);
76.666 + }
76.667 +
76.668 + //
76.669 + // Various support methods the generated classes use
76.670 + //
76.671 +
76.672 + /** Converts and array of raw JSON objects into an array of typed
76.673 + * Java {@link Model} classes.
76.674 + *
76.675 + * @param <T> the type of the destination array
76.676 + * @param context browser context to use
76.677 + * @param src array of raw JSON objects
76.678 + * @param destType type of the individual array elements
76.679 + * @param dest array to be filled with read type instances
76.680 + */
76.681 + public <T> void copyJSON(BrwsrCtx context, Object[] src, Class<T> destType, T[] dest) {
76.682 + for (int i = 0; i < src.length && i < dest.length; i++) {
76.683 + dest[i] = org.netbeans.html.json.impl.JSON.read(context, destType, src[i]);
76.684 + }
76.685 + }
76.686 +
76.687 + /** Compares two objects that can be converted to integers.
76.688 + * @param a first value
76.689 + * @param b second value
76.690 + * @return true if they are the same
76.691 + */
76.692 + public final boolean isSame(int a, int b) {
76.693 + return a == b;
76.694 + }
76.695 +
76.696 + /** Compares two objects that can be converted to (floating point)
76.697 + * numbers.
76.698 + * @param a first value
76.699 + * @param b second value
76.700 + * @return true if they are the same
76.701 + */
76.702 + public final boolean isSame(double a, double b) {
76.703 + return a == b;
76.704 + }
76.705 +
76.706 + /** Compares two objects for being the same - e.g. either <code>==</code>
76.707 + * or <code>equals</code>.
76.708 + * @param a first value
76.709 + * @param b second value
76.710 + * @return true if they are equals
76.711 + */
76.712 + public final boolean isSame(Object a, Object b) {
76.713 + if (a == b) {
76.714 + return true;
76.715 + }
76.716 + if (a == null || b == null) {
76.717 + return false;
76.718 + }
76.719 + return a.equals(b);
76.720 + }
76.721 +
76.722 + /** Cumulative hash function. Adds hashcode of the object to the
76.723 + * previous value.
76.724 + * @param o the object (or <code>null</code>)
76.725 + * @param h the previous value of the hash
76.726 + * @return new hash - the old one xor the object's one
76.727 + */
76.728 + public final int hashPlus(Object o, int h) {
76.729 + return o == null ? h : h ^ o.hashCode();
76.730 + }
76.731 +
76.732 + /** Converts an object to its JSON value.
76.733 + *
76.734 + * @param obj the object to convert
76.735 + * @return JSON representation of the object
76.736 + */
76.737 + public final String toJSON(Object obj) {
76.738 + return JSON.toJSON(obj);
76.739 + }
76.740 +
76.741 + /** Converts the value to string.
76.742 + *
76.743 + * @param val the value
76.744 + * @return the converted value
76.745 + */
76.746 + public final String stringValue(Object val) {
76.747 + return JSON.stringValue(val);
76.748 + }
76.749 +
76.750 + /** Converts the value to number.
76.751 + *
76.752 + * @param val the value
76.753 + * @return the converted value
76.754 + */
76.755 + public final Number numberValue(Object val) {
76.756 + return JSON.numberValue(val);
76.757 + }
76.758 +
76.759 + /** Converts the value to character.
76.760 + *
76.761 + * @param val the value
76.762 + * @return the converted value
76.763 + */
76.764 + public final Character charValue(Object val) {
76.765 + return JSON.charValue(val);
76.766 + }
76.767 +
76.768 + /** Converts the value to boolean.
76.769 + *
76.770 + * @param val the value
76.771 + * @return the converted value
76.772 + */
76.773 + public final Boolean boolValue(Object val) {
76.774 + return JSON.boolValue(val);
76.775 + }
76.776 +
76.777 + /** Extracts value of specific type from given object.
76.778 + *
76.779 + * @param <T> the type of object one is interested in
76.780 + * @param type the type
76.781 + * @param val the object to convert to type
76.782 + * @return the converted value
76.783 + */
76.784 + public final <T> T extractValue(Class<T> type, Object val) {
76.785 + if (Number.class.isAssignableFrom(type)) {
76.786 + val = numberValue(val);
76.787 + }
76.788 + if (Boolean.class == type) {
76.789 + val = boolValue(val);
76.790 + }
76.791 + if (String.class == type) {
76.792 + val = stringValue(val);
76.793 + }
76.794 + if (Character.class == type) {
76.795 + val = charValue(val);
76.796 + }
76.797 + if (Integer.class == type) {
76.798 + val = val instanceof Number ? ((Number) val).intValue() : 0;
76.799 + }
76.800 + if (Long.class == type) {
76.801 + val = val instanceof Number ? ((Number) val).longValue() : 0;
76.802 + }
76.803 + if (Short.class == type) {
76.804 + val = val instanceof Number ? ((Number) val).shortValue() : 0;
76.805 + }
76.806 + if (Byte.class == type) {
76.807 + val = val instanceof Number ? ((Number) val).byteValue() : 0;
76.808 + }
76.809 + if (Double.class == type) {
76.810 + val = val instanceof Number ? ((Number) val).doubleValue() : Double.NaN;
76.811 + }
76.812 + if (Float.class == type) {
76.813 + val = val instanceof Number ? ((Number) val).floatValue() : Float.NaN;
76.814 + }
76.815 + if (type.isEnum() && val instanceof String) {
76.816 + val = Enum.valueOf(type.asSubclass(Enum.class), (String)val);
76.817 + }
76.818 + return type.cast(val);
76.819 + }
76.820 +
76.821 + /** Special dealing with array & {@link List} values. This method
76.822 + * takes the provided collection, empties it and fills it again
76.823 + * with values extracted from <code>value</code> (which is supposed
76.824 + * to be an array).
76.825 + *
76.826 + * @param <T> the type of list elements
76.827 + * @param arr collection to fill with elements in value
76.828 + * @param type the type of elements in the collection
76.829 + * @param value array of elements to put into the collecition. If
76.830 + * value is not an array it is wrapped into array with only element
76.831 + * @since 1.0
76.832 + */
76.833 + public final <T> void replaceValue(Collection<? super T> arr, Class<T> type, Object value) {
76.834 + Object[] newArr;
76.835 + if (value instanceof Object[]) {
76.836 + newArr = (Object[]) value;
76.837 + } else {
76.838 + newArr = new Object[] { value };
76.839 + }
76.840 + arr.clear();
76.841 + for (Object e : newArr) {
76.842 + arr.add(extractValue(type, e));
76.843 + }
76.844 + }
76.845 + }
76.846 +}
77.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
77.2 +++ b/json/src/main/java/org/netbeans/html/json/spi/Technology.java Tue Aug 26 18:13:30 2014 +0200
77.3 @@ -0,0 +1,169 @@
77.4 +/**
77.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
77.6 + *
77.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
77.8 + *
77.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
77.10 + * Other names may be trademarks of their respective owners.
77.11 + *
77.12 + * The contents of this file are subject to the terms of either the GNU
77.13 + * General Public License Version 2 only ("GPL") or the Common
77.14 + * Development and Distribution License("CDDL") (collectively, the
77.15 + * "License"). You may not use this file except in compliance with the
77.16 + * License. You can obtain a copy of the License at
77.17 + * http://www.netbeans.org/cddl-gplv2.html
77.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
77.19 + * specific language governing permissions and limitations under the
77.20 + * License. When distributing the software, include this License Header
77.21 + * Notice in each file and include the License file at
77.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
77.23 + * particular file as subject to the "Classpath" exception as provided
77.24 + * by Oracle in the GPL Version 2 section of the License file that
77.25 + * accompanied this code. If applicable, add the following below the
77.26 + * License Header, with the fields enclosed by brackets [] replaced by
77.27 + * your own identifying information:
77.28 + * "Portions Copyrighted [year] [name of copyright owner]"
77.29 + *
77.30 + * Contributor(s):
77.31 + *
77.32 + * The Original Software is NetBeans. The Initial Developer of the Original
77.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
77.34 + *
77.35 + * If you wish your version of this file to be governed by only the CDDL
77.36 + * or only the GPL Version 2, indicate your decision by adding
77.37 + * "[Contributor] elects to include this software in this distribution
77.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
77.39 + * single choice of license, a recipient has the option to distribute
77.40 + * your version of this file under either the CDDL, the GPL Version 2 or
77.41 + * to extend the choice of license to its licensees as provided above.
77.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
77.43 + * Version 2 license, then the option applies only if the new code is
77.44 + * made subject to such option by the copyright holder.
77.45 + */
77.46 +package org.netbeans.html.json.spi;
77.47 +
77.48 +import net.java.html.BrwsrCtx;
77.49 +import net.java.html.json.Model;
77.50 +import net.java.html.json.Models;
77.51 +
77.52 +/** An implementation of a binding between model classes (see {@link Model})
77.53 + * and particular technology like <a href="http://knockoutjs.com">knockout.js</a>
77.54 + * in a browser window, etc.
77.55 + *
77.56 + * @author Jaroslav Tulach
77.57 + */
77.58 +public interface Technology<Data> {
77.59 + /** Creates an object to wrap the provided model object. The model
77.60 + * has previously been generated by annotation processor associated
77.61 + * with {@link Model} annotation.
77.62 + *
77.63 + * @param model the model generated from {@link Model}
77.64 + * @return internal object representing the model
77.65 + */
77.66 + public Data wrapModel(Object model);
77.67 +
77.68 + /** Converts an element potentially representing a model into the model.
77.69 + * @param <M> the type of the <code>modelClass</code>
77.70 + * @param modelClass expected class to convert the data to
77.71 + * @param data the current data provided from the browser
77.72 + * @return the instance of modelClass somehow extracted from the data, may return <code>null</code>
77.73 + */
77.74 + public <M> M toModel(Class<M> modelClass, Object data);
77.75 +
77.76 + /** Binds a property between the model and the data as used by the technology.
77.77 + *
77.78 + * @param b the description of the requested binding
77.79 + * @param model the original instance of the model
77.80 + * @param data the data to bind with the model
77.81 + */
77.82 + public void bind(PropertyBinding b, Object model, Data data);
77.83 +
77.84 + /** Model for given data has changed its value. The technology is
77.85 + * supposed to update its state (for example DOM nodes associated
77.86 + * with the model). The update usually happens asynchronously.
77.87 + *
77.88 + * @param data technology's own representation of the model
77.89 + * @param propertyName name of the model property that changed
77.90 + */
77.91 + public void valueHasMutated(Data data, String propertyName);
77.92 +
77.93 + public void expose(FunctionBinding fb, Object model, Data d);
77.94 +
77.95 + /** Applies given data to current context (usually an HTML page).
77.96 + * @param data the data to apply
77.97 + */
77.98 + public void applyBindings(Data data);
77.99 +
77.100 + /**
77.101 + * Some technologies may require wrapping a Java array into a special
77.102 + * object. In such case they may return it from this method.
77.103 + *
77.104 + * @param arr original array
77.105 + * @return wrapped array
77.106 + */
77.107 + public Object wrapArray(Object[] arr);
77.108 +
77.109 + /**
77.110 + * Run given runnable in a safe mode. If the runnable can be executed
77.111 + * immediately, do it. If we need to switch to some other thread, do it
77.112 + * and invoke r asynchronously immediately returning from the call to
77.113 + * runSafe method.
77.114 + *
77.115 + * @param r the runnable to execute
77.116 + * @deprecated Use {@link BrwsrCtx#execute(java.lang.Runnable)}
77.117 + */
77.118 + @Deprecated
77.119 + public void runSafe(Runnable r);
77.120 +
77.121 + /** For certain rendering technologies it may be more efficient to register
77.122 + * property and function bindings for one instance of the model at once,
77.123 + * rather then doing it incrementally via
77.124 + * {@link Technology#expose(org.netbeans.html.json.spi.FunctionBinding, java.lang.Object, java.lang.Object) }
77.125 + * and
77.126 + * {@link Technology#bind(org.netbeans.html.json.spi.PropertyBinding, java.lang.Object, java.lang.Object) }.
77.127 + * In such case implement the {@link #wrapModel(java.lang.Object, org.netbeans.html.json.spi.PropertyBinding[], org.netbeans.html.json.spi.FunctionBinding[]) }
77.128 + * method of this interface and it will be called instead of the
77.129 + * previous two ones.
77.130 + *
77.131 + * @since 0.6
77.132 + */
77.133 + public static interface BatchInit<D> extends Technology<D> {
77.134 + /** Wrap the given model into redering technology appropriate object
77.135 + * <code>D</code> and expose given properties and functions on it.
77.136 + *
77.137 + * @param model the {@link Models#isModel(java.lang.Class) model} in Java
77.138 + * @param propArr array of property bindings to expose
77.139 + * @param funcArr array of functions to expose
77.140 + * @return appropriate wrapper around the model
77.141 + */
77.142 + public D wrapModel(Object model, PropertyBinding[] propArr, FunctionBinding[] funcArr);
77.143 + }
77.144 +
77.145 + /** Some technologies are more effective when number of calls between
77.146 + * Java and JavaScript is limited - to do that when a value of property
77.147 + * is changed they should implement this additional interface.
77.148 + *
77.149 + * @param <D> internal type of the technology
77.150 + * @since 0.7.6
77.151 + */
77.152 + public static interface ValueMutated<D> extends Technology<D> {
77.153 + /** Model for given data has changed its value. The technology is
77.154 + * supposed to update its state (for example DOM nodes associated
77.155 + * with the model). The update usually happens asynchronously.
77.156 + * <p>
77.157 + * If both <code>oldValue</code> and <code>newValue</code> are
77.158 + * <code>null</code> then the real value of the technology is
77.159 + * not known.
77.160 + * <p>
77.161 + * If this method is present, then it is called instead of
77.162 + * old, plain {@link #valueHasMutated(java.lang.Object, java.lang.String)}
77.163 + * which is never called by the infrastructure then.
77.164 + *
77.165 + * @param data technology's own representation of the model
77.166 + * @param propertyName name of the model property that changed
77.167 + * @param oldValue provides previous value of the property
77.168 + * @param newValue provides new value of the property
77.169 + */
77.170 + public void valueHasMutated(D data, String propertyName, Object oldValue, Object newValue);
77.171 + }
77.172 +}
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
78.2 +++ b/json/src/main/java/org/netbeans/html/json/spi/Transfer.java Tue Aug 26 18:13:30 2014 +0200
78.3 @@ -0,0 +1,88 @@
78.4 +/**
78.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
78.6 + *
78.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
78.8 + *
78.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
78.10 + * Other names may be trademarks of their respective owners.
78.11 + *
78.12 + * The contents of this file are subject to the terms of either the GNU
78.13 + * General Public License Version 2 only ("GPL") or the Common
78.14 + * Development and Distribution License("CDDL") (collectively, the
78.15 + * "License"). You may not use this file except in compliance with the
78.16 + * License. You can obtain a copy of the License at
78.17 + * http://www.netbeans.org/cddl-gplv2.html
78.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
78.19 + * specific language governing permissions and limitations under the
78.20 + * License. When distributing the software, include this License Header
78.21 + * Notice in each file and include the License file at
78.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
78.23 + * particular file as subject to the "Classpath" exception as provided
78.24 + * by Oracle in the GPL Version 2 section of the License file that
78.25 + * accompanied this code. If applicable, add the following below the
78.26 + * License Header, with the fields enclosed by brackets [] replaced by
78.27 + * your own identifying information:
78.28 + * "Portions Copyrighted [year] [name of copyright owner]"
78.29 + *
78.30 + * Contributor(s):
78.31 + *
78.32 + * The Original Software is NetBeans. The Initial Developer of the Original
78.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
78.34 + *
78.35 + * If you wish your version of this file to be governed by only the CDDL
78.36 + * or only the GPL Version 2, indicate your decision by adding
78.37 + * "[Contributor] elects to include this software in this distribution
78.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
78.39 + * single choice of license, a recipient has the option to distribute
78.40 + * your version of this file under either the CDDL, the GPL Version 2 or
78.41 + * to extend the choice of license to its licensees as provided above.
78.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
78.43 + * Version 2 license, then the option applies only if the new code is
78.44 + * made subject to such option by the copyright holder.
78.45 + */
78.46 +package org.netbeans.html.json.spi;
78.47 +
78.48 +import java.io.IOException;
78.49 +import java.io.InputStream;
78.50 +import org.netbeans.html.context.spi.Contexts.Builder;
78.51 +
78.52 +/** A {@link Builder service provider interface} responsible for
78.53 + * conversion of JSON objects to Java ones and vice-versa.
78.54 + *
78.55 + * @author Jaroslav Tulach
78.56 + */
78.57 +public interface Transfer {
78.58 + /**
78.59 + * Called to inspect properties of an object (usually a JSON or JavaScript
78.60 + * wrapper).
78.61 + *
78.62 + * @param obj the object to inspect
78.63 + * @param props the names of properties to check on the object
78.64 + * <code>obj</code>
78.65 + * @param values array of the same length as <code>props</code> should be
78.66 + * filled by values of properties on the <code>obj</code>. If a property is
78.67 + * not defined, a <code>null</code> value should be stored in the array
78.68 + */
78.69 + public void extract(Object obj, String[] props, Object[] values);
78.70 +
78.71 + /** Reads content of a stream and creates its JSON representation.
78.72 + * The returned object is implementation dependant. It however needs
78.73 + * to be acceptable as first argument of {@link #extract(java.lang.Object, java.lang.String[], java.lang.Object[]) extract}
78.74 + * method. If the stream contains representation or a JSON array,
78.75 + * an Object[] should be returned - each of its members should, by itself
78.76 + * be acceptable argument to
78.77 + * the {@link #extract(java.lang.Object, java.lang.String[], java.lang.Object[]) extract} method.
78.78 + *
78.79 + * @param is input stream to read data from
78.80 + * @return an object representing the JSON data
78.81 + * @throws IOException if something goes wrong
78.82 + */
78.83 + public Object toJSON(InputStream is) throws IOException;
78.84 +
78.85 + /** Starts the JSON or JSONP query.
78.86 + *
78.87 + * @param call description of the call to make
78.88 + */
78.89 + public void loadJSON(JSONCall call);
78.90 +
78.91 +}
79.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
79.2 +++ b/json/src/main/java/org/netbeans/html/json/spi/WSTransfer.java Tue Aug 26 18:13:30 2014 +0200
79.3 @@ -0,0 +1,84 @@
79.4 +/**
79.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
79.6 + *
79.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
79.8 + *
79.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
79.10 + * Other names may be trademarks of their respective owners.
79.11 + *
79.12 + * The contents of this file are subject to the terms of either the GNU
79.13 + * General Public License Version 2 only ("GPL") or the Common
79.14 + * Development and Distribution License("CDDL") (collectively, the
79.15 + * "License"). You may not use this file except in compliance with the
79.16 + * License. You can obtain a copy of the License at
79.17 + * http://www.netbeans.org/cddl-gplv2.html
79.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
79.19 + * specific language governing permissions and limitations under the
79.20 + * License. When distributing the software, include this License Header
79.21 + * Notice in each file and include the License file at
79.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
79.23 + * particular file as subject to the "Classpath" exception as provided
79.24 + * by Oracle in the GPL Version 2 section of the License file that
79.25 + * accompanied this code. If applicable, add the following below the
79.26 + * License Header, with the fields enclosed by brackets [] replaced by
79.27 + * your own identifying information:
79.28 + * "Portions Copyrighted [year] [name of copyright owner]"
79.29 + *
79.30 + * Contributor(s):
79.31 + *
79.32 + * The Original Software is NetBeans. The Initial Developer of the Original
79.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
79.34 + *
79.35 + * If you wish your version of this file to be governed by only the CDDL
79.36 + * or only the GPL Version 2, indicate your decision by adding
79.37 + * "[Contributor] elects to include this software in this distribution
79.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
79.39 + * single choice of license, a recipient has the option to distribute
79.40 + * your version of this file under either the CDDL, the GPL Version 2 or
79.41 + * to extend the choice of license to its licensees as provided above.
79.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
79.43 + * Version 2 license, then the option applies only if the new code is
79.44 + * made subject to such option by the copyright holder.
79.45 + */
79.46 +package org.netbeans.html.json.spi;
79.47 +
79.48 +import net.java.html.BrwsrCtx;
79.49 +import org.netbeans.html.context.spi.Contexts.Provider;
79.50 +
79.51 +/** Interface for providers of WebSocket protocol. Register into a
79.52 + * {@link BrwsrCtx context} in your own {@link Provider}
79.53 + *
79.54 + * @author Jaroslav Tulach
79.55 + * @param <WebSocket> internal implementation type representing the socket
79.56 + * @since 0.5
79.57 + */
79.58 +public interface WSTransfer<WebSocket> {
79.59 + /** Initializes a web socket. The <code>callback</code> object should
79.60 + * have mostly empty values: {@link JSONCall#isDoOutput()} should be
79.61 + * <code>false</code> and thus there should be no {@link JSONCall#getMessage()}.
79.62 + * The method of connection {@link JSONCall#getMethod()} is "WebSocket".
79.63 + * Once the connection is open call {@link JSONCall#notifySuccess(java.lang.Object) notifySuccess(null)}.
79.64 + * When the server sends some data then, pass them to
79.65 + * {@link JSONCall#notifySuccess(java.lang.Object) notifySuccess} method
79.66 + * as well. If there is an error call {@link JSONCall#notifyError(java.lang.Throwable)}.
79.67 + *
79.68 + * @param url the URL to connect to
79.69 + * @param callback a way to provide results back to the client
79.70 + * @return your object representing the established web socket
79.71 + */
79.72 + public WebSocket open(String url, JSONCall callback);
79.73 +
79.74 + /** Sends data to the server. The most important value
79.75 + * of the <code>data</code> parameter is {@link JSONCall#getMessage()},
79.76 + * rest can be ignored.
79.77 + *
79.78 + * @param socket internal representation of the socket
79.79 + * @param data the message to be sent
79.80 + */
79.81 + public void send(WebSocket socket, JSONCall data);
79.82 +
79.83 + /** A request to close the socket.
79.84 + * @param socket internal representation of the socket
79.85 + */
79.86 + public void close(WebSocket socket);
79.87 +}
80.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
80.2 +++ b/json/src/main/java/org/netbeans/html/json/spi/package.html Tue Aug 26 18:13:30 2014 +0200
80.3 @@ -0,0 +1,51 @@
80.4 +<!--
80.5 +
80.6 + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
80.7 +
80.8 + Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
80.9 +
80.10 + Oracle and Java are registered trademarks of Oracle and/or its affiliates.
80.11 + Other names may be trademarks of their respective owners.
80.12 +
80.13 + The contents of this file are subject to the terms of either the GNU
80.14 + General Public License Version 2 only ("GPL") or the Common
80.15 + Development and Distribution License("CDDL") (collectively, the
80.16 + "License"). You may not use this file except in compliance with the
80.17 + License. You can obtain a copy of the License at
80.18 + http://www.netbeans.org/cddl-gplv2.html
80.19 + or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
80.20 + specific language governing permissions and limitations under the
80.21 + License. When distributing the software, include this License Header
80.22 + Notice in each file and include the License file at
80.23 + nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
80.24 + particular file as subject to the "Classpath" exception as provided
80.25 + by Oracle in the GPL Version 2 section of the License file that
80.26 + accompanied this code. If applicable, add the following below the
80.27 + License Header, with the fields enclosed by brackets [] replaced by
80.28 + your own identifying information:
80.29 + "Portions Copyrighted [year] [name of copyright owner]"
80.30 +
80.31 + Contributor(s):
80.32 +
80.33 + The Original Software is NetBeans. The Initial Developer of the Original
80.34 + Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
80.35 +
80.36 + If you wish your version of this file to be governed by only the CDDL
80.37 + or only the GPL Version 2, indicate your decision by adding
80.38 + "[Contributor] elects to include this software in this distribution
80.39 + under the [CDDL or GPL Version 2] license." If you do not indicate a
80.40 + single choice of license, a recipient has the option to distribute
80.41 + your version of this file under either the CDDL, the GPL Version 2 or
80.42 + to extend the choice of license to its licensees as provided above.
80.43 + However, if you add GPL Version 2 code and therefore, elected the GPL
80.44 + Version 2 license, then the option applies only if the new code is
80.45 + made subject to such option by the copyright holder.
80.46 +
80.47 +-->
80.48 +<html>
80.49 + <body>
80.50 + <div>Service Provider Interfaces for those who wish to integrate own
80.51 + <a href="Technology.html">technology</a> with the HTML for Java API.
80.52 + </div>
80.53 + </body>
80.54 +</html>
81.1 --- a/json/src/test/java/net/java/html/json/MapModelTest.java Tue Aug 26 17:43:37 2014 +0200
81.2 +++ b/json/src/test/java/net/java/html/json/MapModelTest.java Tue Aug 26 18:13:30 2014 +0200
81.3 @@ -48,12 +48,12 @@
81.4 import java.lang.reflect.InvocationTargetException;
81.5 import java.util.HashMap;
81.6 import java.util.Map;
81.7 -import org.apidesign.html.context.spi.Contexts;
81.8 -import org.apidesign.html.json.spi.FunctionBinding;
81.9 -import org.apidesign.html.json.spi.JSONCall;
81.10 -import org.apidesign.html.json.spi.PropertyBinding;
81.11 -import org.apidesign.html.json.spi.Technology;
81.12 -import org.apidesign.html.json.spi.Transfer;
81.13 +import org.netbeans.html.context.spi.Contexts;
81.14 +import org.netbeans.html.json.spi.FunctionBinding;
81.15 +import org.netbeans.html.json.spi.JSONCall;
81.16 +import org.netbeans.html.json.spi.PropertyBinding;
81.17 +import org.netbeans.html.json.spi.Technology;
81.18 +import org.netbeans.html.json.spi.Transfer;
81.19 import org.testng.annotations.BeforeMethod;
81.20 import org.testng.annotations.Test;
81.21 import static org.testng.Assert.*;
82.1 --- a/json/src/test/java/net/java/html/json/ModelTest.java Tue Aug 26 17:43:37 2014 +0200
82.2 +++ b/json/src/test/java/net/java/html/json/ModelTest.java Tue Aug 26 18:13:30 2014 +0200
82.3 @@ -48,10 +48,10 @@
82.4 import java.util.Iterator;
82.5 import java.util.List;
82.6 import java.util.ListIterator;
82.7 -import org.apidesign.html.context.spi.Contexts;
82.8 -import org.apidesign.html.json.spi.FunctionBinding;
82.9 -import org.apidesign.html.json.spi.PropertyBinding;
82.10 -import org.apidesign.html.json.spi.Technology;
82.11 +import org.netbeans.html.context.spi.Contexts;
82.12 +import org.netbeans.html.json.spi.FunctionBinding;
82.13 +import org.netbeans.html.json.spi.PropertyBinding;
82.14 +import org.netbeans.html.json.spi.Technology;
82.15 import static org.testng.Assert.*;
82.16 import org.testng.annotations.BeforeMethod;
82.17 import org.testng.annotations.Test;
83.1 --- a/json/src/test/java/net/java/html/json/OperationTest.java Tue Aug 26 17:43:37 2014 +0200
83.2 +++ b/json/src/test/java/net/java/html/json/OperationTest.java Tue Aug 26 18:13:30 2014 +0200
83.3 @@ -45,7 +45,7 @@
83.4 import java.io.IOException;
83.5 import java.util.Arrays;
83.6 import net.java.html.BrwsrCtx;
83.7 -import org.apidesign.html.context.spi.Contexts;
83.8 +import org.netbeans.html.context.spi.Contexts;
83.9 import static org.testng.Assert.*;
83.10 import org.testng.annotations.Test;
83.11
84.1 --- a/json/src/test/java/net/java/html/json/TypesTest.java Tue Aug 26 17:43:37 2014 +0200
84.2 +++ b/json/src/test/java/net/java/html/json/TypesTest.java Tue Aug 26 18:13:30 2014 +0200
84.3 @@ -45,9 +45,9 @@
84.4 import net.java.html.BrwsrCtx;
84.5 import java.util.Map;
84.6 import net.java.html.json.MapModelTest.One;
84.7 -import org.apidesign.html.context.spi.Contexts;
84.8 -import org.apidesign.html.json.spi.Technology;
84.9 -import org.apidesign.html.json.spi.Transfer;
84.10 +import org.netbeans.html.context.spi.Contexts;
84.11 +import org.netbeans.html.json.spi.Technology;
84.12 +import org.netbeans.html.json.spi.Transfer;
84.13 import org.netbeans.html.json.impl.JSON;
84.14 import org.testng.annotations.BeforeMethod;
84.15 import org.testng.annotations.Test;
85.1 --- a/json/src/test/java/org/netbeans/html/json/impl/DeepChangeTest.java Tue Aug 26 17:43:37 2014 +0200
85.2 +++ b/json/src/test/java/org/netbeans/html/json/impl/DeepChangeTest.java Tue Aug 26 18:13:30 2014 +0200
85.3 @@ -53,12 +53,12 @@
85.4 import net.java.html.json.Model;
85.5 import net.java.html.json.Models;
85.6 import net.java.html.json.Property;
85.7 -import org.apidesign.html.context.spi.Contexts;
85.8 -import org.apidesign.html.json.spi.FunctionBinding;
85.9 -import org.apidesign.html.json.spi.JSONCall;
85.10 -import org.apidesign.html.json.spi.PropertyBinding;
85.11 -import org.apidesign.html.json.spi.Technology;
85.12 -import org.apidesign.html.json.spi.Transfer;
85.13 +import org.netbeans.html.context.spi.Contexts;
85.14 +import org.netbeans.html.json.spi.FunctionBinding;
85.15 +import org.netbeans.html.json.spi.JSONCall;
85.16 +import org.netbeans.html.json.spi.PropertyBinding;
85.17 +import org.netbeans.html.json.spi.Technology;
85.18 +import org.netbeans.html.json.spi.Transfer;
85.19 import static org.testng.Assert.*;
85.20 import org.testng.annotations.BeforeMethod;
85.21 import org.testng.annotations.Test;
86.1 --- a/json/src/test/java/org/netbeans/html/json/impl/JSONListTest.java Tue Aug 26 17:43:37 2014 +0200
86.2 +++ b/json/src/test/java/org/netbeans/html/json/impl/JSONListTest.java Tue Aug 26 18:13:30 2014 +0200
86.3 @@ -51,10 +51,10 @@
86.4 import net.java.html.json.Person;
86.5 import net.java.html.json.Property;
86.6 import net.java.html.json.Sex;
86.7 -import org.apidesign.html.context.spi.Contexts;
86.8 -import org.apidesign.html.json.spi.FunctionBinding;
86.9 -import org.apidesign.html.json.spi.PropertyBinding;
86.10 -import org.apidesign.html.json.spi.Technology;
86.11 +import org.netbeans.html.context.spi.Contexts;
86.12 +import org.netbeans.html.json.spi.FunctionBinding;
86.13 +import org.netbeans.html.json.spi.PropertyBinding;
86.14 +import org.netbeans.html.json.spi.Technology;
86.15 import static org.testng.Assert.*;
86.16 import org.testng.annotations.BeforeMethod;
86.17 import org.testng.annotations.Test;
87.1 --- a/json/src/test/java/org/netbeans/html/json/impl/OnReceiveTest.java Tue Aug 26 17:43:37 2014 +0200
87.2 +++ b/json/src/test/java/org/netbeans/html/json/impl/OnReceiveTest.java Tue Aug 26 18:13:30 2014 +0200
87.3 @@ -49,9 +49,9 @@
87.4 import net.java.html.BrwsrCtx;
87.5 import net.java.html.json.Models;
87.6 import net.java.html.json.Person;
87.7 -import org.apidesign.html.context.spi.Contexts;
87.8 -import org.apidesign.html.json.spi.JSONCall;
87.9 -import org.apidesign.html.json.spi.Transfer;
87.10 +import org.netbeans.html.context.spi.Contexts;
87.11 +import org.netbeans.html.json.spi.JSONCall;
87.12 +import org.netbeans.html.json.spi.Transfer;
87.13 import static org.testng.Assert.*;
87.14 import org.testng.annotations.Test;
87.15
88.1 --- a/json/src/test/java/org/netbeans/html/json/impl/ToDoTest.java Tue Aug 26 17:43:37 2014 +0200
88.2 +++ b/json/src/test/java/org/netbeans/html/json/impl/ToDoTest.java Tue Aug 26 18:13:30 2014 +0200
88.3 @@ -49,9 +49,9 @@
88.4 import net.java.html.json.Model;
88.5 import net.java.html.json.Models;
88.6 import net.java.html.json.Property;
88.7 -import org.apidesign.html.context.spi.Contexts;
88.8 -import org.apidesign.html.json.spi.Technology;
88.9 -import org.apidesign.html.json.spi.Transfer;
88.10 +import org.netbeans.html.context.spi.Contexts;
88.11 +import org.netbeans.html.json.spi.Technology;
88.12 +import org.netbeans.html.json.spi.Transfer;
88.13 import org.netbeans.html.json.impl.DeepChangeTest.MapTechnology;
88.14 import org.netbeans.html.json.impl.DeepChangeTest.One;
88.15 import static org.testng.Assert.*;
89.1 --- a/ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java Tue Aug 26 17:43:37 2014 +0200
89.2 +++ b/ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java Tue Aug 26 18:13:30 2014 +0200
89.3 @@ -62,11 +62,11 @@
89.4 import net.java.html.BrwsrCtx;
89.5 import net.java.html.boot.BrowserBuilder;
89.6 import net.java.html.js.JavaScriptBody;
89.7 -import org.apidesign.html.boot.spi.Fn;
89.8 -import org.apidesign.html.context.spi.Contexts;
89.9 -import org.apidesign.html.json.spi.Technology;
89.10 -import org.apidesign.html.json.spi.Transfer;
89.11 -import org.apidesign.html.json.tck.KnockoutTCK;
89.12 +import org.netbeans.html.boot.spi.Fn;
89.13 +import org.netbeans.html.context.spi.Contexts;
89.14 +import org.netbeans.html.json.spi.Technology;
89.15 +import org.netbeans.html.json.spi.Transfer;
89.16 +import org.netbeans.html.json.tck.KnockoutTCK;
89.17 import org.json.JSONException;
89.18 import org.json.JSONObject;
89.19 import org.openide.util.lookup.ServiceProvider;
90.1 --- a/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KOFx.java Tue Aug 26 17:43:37 2014 +0200
90.2 +++ b/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KOFx.java Tue Aug 26 18:13:30 2014 +0200
90.3 @@ -49,7 +49,7 @@
90.4 import java.util.logging.Level;
90.5 import java.util.logging.Logger;
90.6 import javafx.application.Platform;
90.7 -import org.apidesign.html.boot.spi.Fn;
90.8 +import org.netbeans.html.boot.spi.Fn;
90.9 import org.testng.ITest;
90.10 import org.testng.annotations.Test;
90.11
91.1 --- a/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KnockoutFelixIT.java Tue Aug 26 17:43:37 2014 +0200
91.2 +++ b/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KnockoutFelixIT.java Tue Aug 26 18:13:30 2014 +0200
91.3 @@ -58,9 +58,9 @@
91.4 import java.util.jar.JarFile;
91.5 import java.util.logging.Level;
91.6 import java.util.logging.Logger;
91.7 -import org.apidesign.html.boot.spi.Fn;
91.8 -import org.apidesign.html.json.tck.KOTest;
91.9 -import org.apidesign.html.json.tck.KnockoutTCK;
91.10 +import org.netbeans.html.boot.spi.Fn;
91.11 +import org.netbeans.html.json.tck.KOTest;
91.12 +import org.netbeans.html.json.tck.KnockoutTCK;
91.13 import org.osgi.framework.Bundle;
91.14 import org.osgi.framework.BundleException;
91.15 import org.osgi.framework.Constants;
92.1 --- a/ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java Tue Aug 26 17:43:37 2014 +0200
92.2 +++ b/ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java Tue Aug 26 18:13:30 2014 +0200
92.3 @@ -58,11 +58,11 @@
92.4 import net.java.html.BrwsrCtx;
92.5 import net.java.html.boot.BrowserBuilder;
92.6 import net.java.html.js.JavaScriptBody;
92.7 -import org.apidesign.html.boot.spi.Fn;
92.8 -import org.apidesign.html.context.spi.Contexts;
92.9 -import org.apidesign.html.json.spi.Technology;
92.10 -import org.apidesign.html.json.spi.Transfer;
92.11 -import org.apidesign.html.json.tck.KnockoutTCK;
92.12 +import org.netbeans.html.boot.spi.Fn;
92.13 +import org.netbeans.html.context.spi.Contexts;
92.14 +import org.netbeans.html.json.spi.Technology;
92.15 +import org.netbeans.html.json.spi.Transfer;
92.16 +import org.netbeans.html.json.tck.KnockoutTCK;
92.17 import org.json.JSONException;
92.18 import org.json.JSONObject;
92.19 import org.openide.util.lookup.ServiceProvider;
93.1 --- a/ko-osgi-test/src/test/java/org/netbeans/html/ko/osgi/test/KOFx.java Tue Aug 26 17:43:37 2014 +0200
93.2 +++ b/ko-osgi-test/src/test/java/org/netbeans/html/ko/osgi/test/KOFx.java Tue Aug 26 18:13:30 2014 +0200
93.3 @@ -49,7 +49,7 @@
93.4 import java.util.logging.Level;
93.5 import java.util.logging.Logger;
93.6 import javafx.application.Platform;
93.7 -import org.apidesign.html.boot.spi.Fn;
93.8 +import org.netbeans.html.boot.spi.Fn;
93.9 import org.testng.ITest;
93.10 import org.testng.annotations.Test;
93.11
94.1 --- a/ko-osgi-test/src/test/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxIT.java Tue Aug 26 17:43:37 2014 +0200
94.2 +++ b/ko-osgi-test/src/test/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxIT.java Tue Aug 26 18:13:30 2014 +0200
94.3 @@ -57,9 +57,9 @@
94.4 import java.util.jar.JarFile;
94.5 import java.util.logging.Level;
94.6 import java.util.logging.Logger;
94.7 -import org.apidesign.html.boot.spi.Fn;
94.8 -import org.apidesign.html.json.tck.KOTest;
94.9 -import org.apidesign.html.json.tck.KnockoutTCK;
94.10 +import org.netbeans.html.boot.spi.Fn;
94.11 +import org.netbeans.html.json.tck.KOTest;
94.12 +import org.netbeans.html.json.tck.KnockoutTCK;
94.13 import org.osgi.framework.Bundle;
94.14 import org.osgi.framework.BundleException;
94.15 import org.osgi.framework.Constants;
95.1 --- a/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/LoadJSON.java Tue Aug 26 17:43:37 2014 +0200
95.2 +++ b/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/LoadJSON.java Tue Aug 26 18:13:30 2014 +0200
95.3 @@ -59,7 +59,7 @@
95.4 import java.util.concurrent.ThreadFactory;
95.5 import java.util.logging.Logger;
95.6 import net.java.html.js.JavaScriptBody;
95.7 -import org.apidesign.html.json.spi.JSONCall;
95.8 +import org.netbeans.html.json.spi.JSONCall;
95.9 import org.json.JSONArray;
95.10 import org.json.JSONException;
95.11 import org.json.JSONObject;
96.1 --- a/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/TyrusContext.java Tue Aug 26 17:43:37 2014 +0200
96.2 +++ b/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/TyrusContext.java Tue Aug 26 18:13:30 2014 +0200
96.3 @@ -56,10 +56,10 @@
96.4 import javax.websocket.Session;
96.5 import javax.websocket.WebSocketContainer;
96.6 import net.java.html.json.OnReceive;
96.7 -import org.apidesign.html.context.spi.Contexts;
96.8 -import org.apidesign.html.json.spi.JSONCall;
96.9 -import org.apidesign.html.json.spi.Transfer;
96.10 -import org.apidesign.html.json.spi.WSTransfer;
96.11 +import org.netbeans.html.context.spi.Contexts;
96.12 +import org.netbeans.html.json.spi.JSONCall;
96.13 +import org.netbeans.html.json.spi.Transfer;
96.14 +import org.netbeans.html.json.spi.WSTransfer;
96.15 import org.netbeans.html.wstyrus.TyrusContext.Comm;
96.16 import org.json.JSONArray;
96.17 import org.json.JSONException;
96.18 @@ -78,7 +78,7 @@
96.19 * There is no need to include this module in your application if you are
96.20 * running on JDK8. JDK8 WebView provides its own implementation of the
96.21 * WebSocket API based on WebSocket object inside a browser. This is included
96.22 - * in the <code>org.apidesign.html:ko-fx:0.5</code> module.
96.23 + * in the <code>org.netbeans.html:ko4j:1.0</code> module.
96.24 *
96.25 * @author Jaroslav Tulach
96.26 */
97.1 --- a/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusFX.java Tue Aug 26 17:43:37 2014 +0200
97.2 +++ b/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusFX.java Tue Aug 26 18:13:30 2014 +0200
97.3 @@ -46,7 +46,7 @@
97.4 import java.lang.reflect.Method;
97.5 import javafx.application.Platform;
97.6 import org.netbeans.html.boot.impl.FnContext;
97.7 -import org.apidesign.html.boot.spi.Fn;
97.8 +import org.netbeans.html.boot.spi.Fn;
97.9 import org.testng.ITest;
97.10 import org.testng.annotations.Test;
97.11
98.1 --- a/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusKnockoutTest.java Tue Aug 26 17:43:37 2014 +0200
98.2 +++ b/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusKnockoutTest.java Tue Aug 26 18:13:30 2014 +0200
98.3 @@ -59,13 +59,13 @@
98.4 import net.java.html.BrwsrCtx;
98.5 import net.java.html.boot.BrowserBuilder;
98.6 import net.java.html.js.JavaScriptBody;
98.7 -import org.apidesign.html.boot.spi.Fn;
98.8 -import org.apidesign.html.context.spi.Contexts;
98.9 -import org.apidesign.html.json.spi.Technology;
98.10 -import org.apidesign.html.json.spi.Transfer;
98.11 -import org.apidesign.html.json.spi.WSTransfer;
98.12 -import org.apidesign.html.json.tck.KOTest;
98.13 -import org.apidesign.html.json.tck.KnockoutTCK;
98.14 +import org.netbeans.html.boot.spi.Fn;
98.15 +import org.netbeans.html.context.spi.Contexts;
98.16 +import org.netbeans.html.json.spi.Technology;
98.17 +import org.netbeans.html.json.spi.Transfer;
98.18 +import org.netbeans.html.json.spi.WSTransfer;
98.19 +import org.netbeans.html.json.tck.KOTest;
98.20 +import org.netbeans.html.json.tck.KnockoutTCK;
98.21 import org.json.JSONException;
98.22 import org.json.JSONObject;
98.23 import org.netbeans.html.boot.impl.FnContext;
99.1 --- a/ko4j/src/main/java/org/netbeans/html/ko4j/FXContext.java Tue Aug 26 17:43:37 2014 +0200
99.2 +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/FXContext.java Tue Aug 26 18:13:30 2014 +0200
99.3 @@ -50,13 +50,13 @@
99.4 import java.io.Reader;
99.5 import java.net.URL;
99.6 import java.util.logging.Logger;
99.7 -import org.apidesign.html.boot.spi.Fn;
99.8 -import org.apidesign.html.json.spi.FunctionBinding;
99.9 -import org.apidesign.html.json.spi.JSONCall;
99.10 -import org.apidesign.html.json.spi.PropertyBinding;
99.11 -import org.apidesign.html.json.spi.Technology;
99.12 -import org.apidesign.html.json.spi.Transfer;
99.13 -import org.apidesign.html.json.spi.WSTransfer;
99.14 +import org.netbeans.html.boot.spi.Fn;
99.15 +import org.netbeans.html.json.spi.FunctionBinding;
99.16 +import org.netbeans.html.json.spi.JSONCall;
99.17 +import org.netbeans.html.json.spi.PropertyBinding;
99.18 +import org.netbeans.html.json.spi.Technology;
99.19 +import org.netbeans.html.json.spi.Transfer;
99.20 +import org.netbeans.html.json.spi.WSTransfer;
99.21
99.22 /** This is an implementation package - just
99.23 * include its JAR on classpath and use official {@link Context} API
100.1 --- a/ko4j/src/main/java/org/netbeans/html/ko4j/KO4J.java Tue Aug 26 17:43:37 2014 +0200
100.2 +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/KO4J.java Tue Aug 26 18:13:30 2014 +0200
100.3 @@ -43,12 +43,12 @@
100.4 package org.netbeans.html.ko4j;
100.5
100.6 import net.java.html.json.Model;
100.7 -import org.apidesign.html.boot.spi.Fn;
100.8 -import org.apidesign.html.context.spi.Contexts;
100.9 -import org.apidesign.html.context.spi.Contexts.Provider;
100.10 -import org.apidesign.html.json.spi.Technology;
100.11 -import org.apidesign.html.json.spi.Transfer;
100.12 -import org.apidesign.html.json.spi.WSTransfer;
100.13 +import org.netbeans.html.boot.spi.Fn;
100.14 +import org.netbeans.html.context.spi.Contexts;
100.15 +import org.netbeans.html.context.spi.Contexts.Provider;
100.16 +import org.netbeans.html.json.spi.Technology;
100.17 +import org.netbeans.html.json.spi.Transfer;
100.18 +import org.netbeans.html.json.spi.WSTransfer;
100.19 import org.openide.util.lookup.ServiceProvider;
100.20
100.21 /** Support for <a href="http://knockoutjs.com">knockout.js</a>
101.1 --- a/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java Tue Aug 26 17:43:37 2014 +0200
101.2 +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java Tue Aug 26 18:13:30 2014 +0200
101.3 @@ -45,8 +45,8 @@
101.4 import net.java.html.js.JavaScriptBody;
101.5 import net.java.html.js.JavaScriptResource;
101.6 import net.java.html.json.Model;
101.7 -import org.apidesign.html.json.spi.FunctionBinding;
101.8 -import org.apidesign.html.json.spi.PropertyBinding;
101.9 +import org.netbeans.html.json.spi.FunctionBinding;
101.10 +import org.netbeans.html.json.spi.PropertyBinding;
101.11
101.12 /** This is an implementation package - just
101.13 * include its JAR on classpath and use official {@link Context} API
101.14 @@ -100,7 +100,7 @@
101.15 + " var trigger = ko.observable().extend({notify:'always'});"
101.16 + " function realGetter() {\n"
101.17 + " try {\n"
101.18 - + " var v = prop.@org.apidesign.html.json.spi.PropertyBinding::getValue()();\n"
101.19 + + " var v = prop.@org.netbeans.html.json.spi.PropertyBinding::getValue()();\n"
101.20 + " return v;\n"
101.21 + " } catch (e) {\n"
101.22 + " alert(\"Cannot call getValue on \" + model + \" prop: \" + name + \" error: \" + e);\n"
101.23 @@ -120,7 +120,7 @@
101.24 + " if (!readOnly) {\n"
101.25 + " bnd['write'] = function(val) {\n"
101.26 + " var model = val['ko-fx.model'];\n"
101.27 - + " prop.@org.apidesign.html.json.spi.PropertyBinding::setValue(Ljava/lang/Object;)(model ? model : val);\n"
101.28 + + " prop.@org.netbeans.html.json.spi.PropertyBinding::setValue(Ljava/lang/Object;)(model ? model : val);\n"
101.29 + " };\n"
101.30 + " };\n"
101.31 + " var cmpt = ko['computed'](bnd);\n"
101.32 @@ -135,7 +135,7 @@
101.33 + "}\n"
101.34 + "function koExpose(name, func) {\n"
101.35 + " ret[name] = function(data, ev) {\n"
101.36 - + " func.@org.apidesign.html.json.spi.FunctionBinding::call(Ljava/lang/Object;Ljava/lang/Object;)(data, ev);\n"
101.37 + + " func.@org.netbeans.html.json.spi.FunctionBinding::call(Ljava/lang/Object;Ljava/lang/Object;)(data, ev);\n"
101.38 + " };\n"
101.39 + "}\n"
101.40 + "for (var i = 0; i < funcNames.length; i++) {\n"
102.1 --- a/ko4j/src/main/java/org/netbeans/html/ko4j/LoadJSON.java Tue Aug 26 17:43:37 2014 +0200
102.2 +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/LoadJSON.java Tue Aug 26 18:13:30 2014 +0200
102.3 @@ -47,9 +47,9 @@
102.4 import java.io.InputStream;
102.5 import java.io.InputStreamReader;
102.6 import net.java.html.js.JavaScriptBody;
102.7 -import org.apidesign.html.json.spi.JSONCall;
102.8 -import org.apidesign.html.json.spi.Transfer;
102.9 -import org.apidesign.html.json.spi.WSTransfer;
102.10 +import org.netbeans.html.json.spi.JSONCall;
102.11 +import org.netbeans.html.json.spi.Transfer;
102.12 +import org.netbeans.html.json.spi.WSTransfer;
102.13
102.14 /**
102.15 *
102.16 @@ -144,7 +144,7 @@
102.17 + " delete window[name];\n"
102.18 + " var el = window.document.getElementById(name);\n"
102.19 + " el.parentNode.removeChild(el);\n"
102.20 - + " done.@org.apidesign.html.json.spi.JSONCall::notifySuccess(Ljava/lang/Object;)(data);\n"
102.21 + + " done.@org.netbeans.html.json.spi.JSONCall::notifySuccess(Ljava/lang/Object;)(data);\n"
102.22 + "};\n"
102.23 + "return true;\n"
102.24 )
102.25 @@ -168,7 +168,7 @@
102.26 + " try {\n"
102.27 + " if (request.status < 100 || request.status >= 400) throw request.status + ': ' + request.statusText;"
102.28 + " try { r = eval('(' + r + ')'); } catch (ignore) { }"
102.29 - + " done.@org.apidesign.html.json.spi.JSONCall::notifySuccess(Ljava/lang/Object;)(r);\n"
102.30 + + " done.@org.netbeans.html.json.spi.JSONCall::notifySuccess(Ljava/lang/Object;)(r);\n"
102.31 + " } catch (error) {;\n"
102.32 + " @org.netbeans.html.ko4j.LoadJSON::notifyError(Ljava/lang/Object;Ljava/lang/Object;)(done, error);\n"
102.33 + " }\n"
103.1 --- a/ko4j/src/main/java/org/netbeans/html/ko4j/LoadWS.java Tue Aug 26 17:43:37 2014 +0200
103.2 +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/LoadWS.java Tue Aug 26 18:13:30 2014 +0200
103.3 @@ -43,7 +43,7 @@
103.4 package org.netbeans.html.ko4j;
103.5
103.6 import net.java.html.js.JavaScriptBody;
103.7 -import org.apidesign.html.json.spi.JSONCall;
103.8 +import org.netbeans.html.json.spi.JSONCall;
103.9
103.10 /** Communication with WebSockets via browser's WebSocket object.
103.11 *
104.1 --- a/ko4j/src/test/java/org/netbeans/html/ko4j/KOFx.java Tue Aug 26 17:43:37 2014 +0200
104.2 +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/KOFx.java Tue Aug 26 18:13:30 2014 +0200
104.3 @@ -49,7 +49,7 @@
104.4 import java.util.logging.Level;
104.5 import java.util.logging.Logger;
104.6 import javafx.application.Platform;
104.7 -import org.apidesign.html.boot.spi.Fn;
104.8 +import org.netbeans.html.boot.spi.Fn;
104.9 import org.testng.ITest;
104.10 import org.testng.annotations.Test;
104.11
105.1 --- a/ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java Tue Aug 26 17:43:37 2014 +0200
105.2 +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java Tue Aug 26 18:13:30 2014 +0200
105.3 @@ -59,13 +59,13 @@
105.4 import net.java.html.BrwsrCtx;
105.5 import net.java.html.boot.BrowserBuilder;
105.6 import net.java.html.js.JavaScriptBody;
105.7 -import org.apidesign.html.boot.spi.Fn;
105.8 -import org.apidesign.html.context.spi.Contexts;
105.9 -import org.apidesign.html.json.spi.Technology;
105.10 -import org.apidesign.html.json.spi.Transfer;
105.11 -import org.apidesign.html.json.spi.WSTransfer;
105.12 -import org.apidesign.html.json.tck.KOTest;
105.13 -import org.apidesign.html.json.tck.KnockoutTCK;
105.14 +import org.netbeans.html.boot.spi.Fn;
105.15 +import org.netbeans.html.context.spi.Contexts;
105.16 +import org.netbeans.html.json.spi.Technology;
105.17 +import org.netbeans.html.json.spi.Transfer;
105.18 +import org.netbeans.html.json.spi.WSTransfer;
105.19 +import org.netbeans.html.json.tck.KOTest;
105.20 +import org.netbeans.html.json.tck.KnockoutTCK;
105.21 import org.netbeans.html.boot.impl.FnContext;
105.22 import org.openide.util.lookup.ServiceProvider;
105.23 import org.testng.Assert;
106.1 --- a/ko4j/src/test/java/org/netbeans/html/ko4j/LessCallbacksCheck.java Tue Aug 26 17:43:37 2014 +0200
106.2 +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/LessCallbacksCheck.java Tue Aug 26 18:13:30 2014 +0200
106.3 @@ -47,7 +47,7 @@
106.4 import net.java.html.json.ComputedProperty;
106.5 import net.java.html.json.Model;
106.6 import net.java.html.json.Property;
106.7 -import org.apidesign.html.json.tck.KOTest;
106.8 +import org.netbeans.html.json.tck.KOTest;
106.9
106.10 /**
106.11 *
107.1 --- a/pom.xml Tue Aug 26 17:43:37 2014 +0200
107.2 +++ b/pom.xml Tue Aug 26 18:13:30 2014 +0200
107.3 @@ -143,7 +143,7 @@
107.4 </group>
107.5 <group>
107.6 <title>Service Provider APIs (not commonly interesting)</title>
107.7 - <packages>org.apidesign.html.*</packages>
107.8 + <packages>org.netbeans.html.*</packages>
107.9 </group>
107.10 </groups>
107.11 <links>
108.1 --- a/sound/src/main/java/net/java/html/sound/AudioClip.java Tue Aug 26 17:43:37 2014 +0200
108.2 +++ b/sound/src/main/java/net/java/html/sound/AudioClip.java Tue Aug 26 18:13:30 2014 +0200
108.3 @@ -44,8 +44,8 @@
108.4
108.5 import java.util.ServiceLoader;
108.6 import net.java.html.BrwsrCtx;
108.7 -import org.apidesign.html.context.spi.Contexts;
108.8 -import org.apidesign.html.sound.spi.AudioEnvironment;
108.9 +import org.netbeans.html.context.spi.Contexts;
108.10 +import org.netbeans.html.sound.spi.AudioEnvironment;
108.11 import org.netbeans.html.sound.impl.BrowserAudioEnv;
108.12
108.13 /** Handle to an audio clip which can be {@link #play() played}, {@link #pause() paused}
109.1 --- a/sound/src/main/java/org/apidesign/html/sound/spi/AudioEnvironment.java Tue Aug 26 17:43:37 2014 +0200
109.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
109.3 @@ -1,94 +0,0 @@
109.4 -/**
109.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
109.6 - *
109.7 - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
109.8 - *
109.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
109.10 - * Other names may be trademarks of their respective owners.
109.11 - *
109.12 - * The contents of this file are subject to the terms of either the GNU
109.13 - * General Public License Version 2 only ("GPL") or the Common
109.14 - * Development and Distribution License("CDDL") (collectively, the
109.15 - * "License"). You may not use this file except in compliance with the
109.16 - * License. You can obtain a copy of the License at
109.17 - * http://www.netbeans.org/cddl-gplv2.html
109.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
109.19 - * specific language governing permissions and limitations under the
109.20 - * License. When distributing the software, include this License Header
109.21 - * Notice in each file and include the License file at
109.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
109.23 - * particular file as subject to the "Classpath" exception as provided
109.24 - * by Oracle in the GPL Version 2 section of the License file that
109.25 - * accompanied this code. If applicable, add the following below the
109.26 - * License Header, with the fields enclosed by brackets [] replaced by
109.27 - * your own identifying information:
109.28 - * "Portions Copyrighted [year] [name of copyright owner]"
109.29 - *
109.30 - * Contributor(s):
109.31 - *
109.32 - * The Original Software is NetBeans. The Initial Developer of the Original
109.33 - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
109.34 - *
109.35 - * If you wish your version of this file to be governed by only the CDDL
109.36 - * or only the GPL Version 2, indicate your decision by adding
109.37 - * "[Contributor] elects to include this software in this distribution
109.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
109.39 - * single choice of license, a recipient has the option to distribute
109.40 - * your version of this file under either the CDDL, the GPL Version 2 or
109.41 - * to extend the choice of license to its licensees as provided above.
109.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
109.43 - * Version 2 license, then the option applies only if the new code is
109.44 - * made subject to such option by the copyright holder.
109.45 - */
109.46 -package org.apidesign.html.sound.spi;
109.47 -
109.48 -import net.java.html.BrwsrCtx;
109.49 -import org.apidesign.html.context.spi.Contexts;
109.50 -
109.51 -/** Basic interface for sound playback providers. Register your implementation
109.52 - * in a way {@link java.util.ServiceLoader} can find it - e.g. use
109.53 - * {@link org.openide.util.lookup.ServiceProvider} annotation. Possibly
109.54 - * one can register the provider into {@link Contexts#newBuilder()}, in
109.55 - * case the implementation is somehow associated
109.56 - * with the actual {@link BrwsrCtx} (works since version 0.8.3).
109.57 - *
109.58 - * @author antonepple
109.59 - * @param <Audio> custom type representing the internal audio state
109.60 - */
109.61 -public interface AudioEnvironment<Audio> {
109.62 - /** Checks if the provided URL can be a supported audio stream
109.63 - * and if so, it create an object to represent it. The created object
109.64 - * will be used in future callbacks to other methods of this interface
109.65 - * (like {@link #play(java.lang.Object)}).
109.66 - * @param src the URL pointing to the media stream
109.67 - * @return an internal representation object or <code>null</code> if this
109.68 - * environment does not know how to handle such stream
109.69 - */
109.70 - public Audio create(String src);
109.71 -
109.72 - /** Starts playback of the audio.
109.73 - *
109.74 - * @param a the internal representation of the audio as created by {@link #create(java.lang.String)} method.
109.75 - */
109.76 - public void play(Audio a);
109.77 -
109.78 - /** Pauses playback of the audio.
109.79 - *
109.80 - * @param a the internal representation of the audio as created by {@link #create(java.lang.String)} method.
109.81 - */
109.82 - public void pause(Audio a);
109.83 -
109.84 - /** Changes volume for the playback of the audio.
109.85 - *
109.86 - * @param a the internal representation of the audio as created by {@link #create(java.lang.String)} method.
109.87 - * @param volume value between 0.0 and 1.0
109.88 - */
109.89 - public void setVolume(Audio a, double volume);
109.90 -
109.91 - /** Checks whether given audio is supported
109.92 - *
109.93 - * @param a the internal representation of the audio as created by {@link #create(java.lang.String)} method.
109.94 - * @return <code>true</code> or <code>false</code>
109.95 - */
109.96 - public boolean isSupported(Audio a);
109.97 -}
110.1 --- a/sound/src/main/java/org/apidesign/html/sound/spi/package.html Tue Aug 26 17:43:37 2014 +0200
110.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
110.3 @@ -1,49 +0,0 @@
110.4 -<!--
110.5 -
110.6 - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
110.7 -
110.8 - Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
110.9 -
110.10 - Oracle and Java are registered trademarks of Oracle and/or its affiliates.
110.11 - Other names may be trademarks of their respective owners.
110.12 -
110.13 - The contents of this file are subject to the terms of either the GNU
110.14 - General Public License Version 2 only ("GPL") or the Common
110.15 - Development and Distribution License("CDDL") (collectively, the
110.16 - "License"). You may not use this file except in compliance with the
110.17 - License. You can obtain a copy of the License at
110.18 - http://www.netbeans.org/cddl-gplv2.html
110.19 - or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
110.20 - specific language governing permissions and limitations under the
110.21 - License. When distributing the software, include this License Header
110.22 - Notice in each file and include the License file at
110.23 - nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
110.24 - particular file as subject to the "Classpath" exception as provided
110.25 - by Oracle in the GPL Version 2 section of the License file that
110.26 - accompanied this code. If applicable, add the following below the
110.27 - License Header, with the fields enclosed by brackets [] replaced by
110.28 - your own identifying information:
110.29 - "Portions Copyrighted [year] [name of copyright owner]"
110.30 -
110.31 - Contributor(s):
110.32 -
110.33 - The Original Software is NetBeans. The Initial Developer of the Original
110.34 - Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
110.35 -
110.36 - If you wish your version of this file to be governed by only the CDDL
110.37 - or only the GPL Version 2, indicate your decision by adding
110.38 - "[Contributor] elects to include this software in this distribution
110.39 - under the [CDDL or GPL Version 2] license." If you do not indicate a
110.40 - single choice of license, a recipient has the option to distribute
110.41 - your version of this file under either the CDDL, the GPL Version 2 or
110.42 - to extend the choice of license to its licensees as provided above.
110.43 - However, if you add GPL Version 2 code and therefore, elected the GPL
110.44 - Version 2 license, then the option applies only if the new code is
110.45 - made subject to such option by the copyright holder.
110.46 -
110.47 --->
110.48 -<body>
110.49 - <p>
110.50 - Give your {@link net.java.html.sound.AudioClip} real behavior!
110.51 - </p>
110.52 -</body>
111.1 --- a/sound/src/main/java/org/netbeans/html/sound/impl/BrowserAudioEnv.java Tue Aug 26 17:43:37 2014 +0200
111.2 +++ b/sound/src/main/java/org/netbeans/html/sound/impl/BrowserAudioEnv.java Tue Aug 26 18:13:30 2014 +0200
111.3 @@ -43,7 +43,7 @@
111.4 package org.netbeans.html.sound.impl;
111.5
111.6 import net.java.html.js.JavaScriptBody;
111.7 -import org.apidesign.html.sound.spi.AudioEnvironment;
111.8 +import org.netbeans.html.sound.spi.AudioEnvironment;
111.9
111.10 /** The default audio provider that delegates to HTML5 Audio tag
111.11 * it is used if no other {@link AudioEnvironment} is found.
112.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
112.2 +++ b/sound/src/main/java/org/netbeans/html/sound/spi/AudioEnvironment.java Tue Aug 26 18:13:30 2014 +0200
112.3 @@ -0,0 +1,94 @@
112.4 +/**
112.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
112.6 + *
112.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
112.8 + *
112.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
112.10 + * Other names may be trademarks of their respective owners.
112.11 + *
112.12 + * The contents of this file are subject to the terms of either the GNU
112.13 + * General Public License Version 2 only ("GPL") or the Common
112.14 + * Development and Distribution License("CDDL") (collectively, the
112.15 + * "License"). You may not use this file except in compliance with the
112.16 + * License. You can obtain a copy of the License at
112.17 + * http://www.netbeans.org/cddl-gplv2.html
112.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
112.19 + * specific language governing permissions and limitations under the
112.20 + * License. When distributing the software, include this License Header
112.21 + * Notice in each file and include the License file at
112.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
112.23 + * particular file as subject to the "Classpath" exception as provided
112.24 + * by Oracle in the GPL Version 2 section of the License file that
112.25 + * accompanied this code. If applicable, add the following below the
112.26 + * License Header, with the fields enclosed by brackets [] replaced by
112.27 + * your own identifying information:
112.28 + * "Portions Copyrighted [year] [name of copyright owner]"
112.29 + *
112.30 + * Contributor(s):
112.31 + *
112.32 + * The Original Software is NetBeans. The Initial Developer of the Original
112.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
112.34 + *
112.35 + * If you wish your version of this file to be governed by only the CDDL
112.36 + * or only the GPL Version 2, indicate your decision by adding
112.37 + * "[Contributor] elects to include this software in this distribution
112.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
112.39 + * single choice of license, a recipient has the option to distribute
112.40 + * your version of this file under either the CDDL, the GPL Version 2 or
112.41 + * to extend the choice of license to its licensees as provided above.
112.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
112.43 + * Version 2 license, then the option applies only if the new code is
112.44 + * made subject to such option by the copyright holder.
112.45 + */
112.46 +package org.netbeans.html.sound.spi;
112.47 +
112.48 +import net.java.html.BrwsrCtx;
112.49 +import org.netbeans.html.context.spi.Contexts;
112.50 +
112.51 +/** Basic interface for sound playback providers. Register your implementation
112.52 + * in a way {@link java.util.ServiceLoader} can find it - e.g. use
112.53 + * {@link org.openide.util.lookup.ServiceProvider} annotation. Possibly
112.54 + * one can register the provider into {@link Contexts#newBuilder()}, in
112.55 + * case the implementation is somehow associated
112.56 + * with the actual {@link BrwsrCtx} (works since version 0.8.3).
112.57 + *
112.58 + * @author antonepple
112.59 + * @param <Audio> custom type representing the internal audio state
112.60 + */
112.61 +public interface AudioEnvironment<Audio> {
112.62 + /** Checks if the provided URL can be a supported audio stream
112.63 + * and if so, it create an object to represent it. The created object
112.64 + * will be used in future callbacks to other methods of this interface
112.65 + * (like {@link #play(java.lang.Object)}).
112.66 + * @param src the URL pointing to the media stream
112.67 + * @return an internal representation object or <code>null</code> if this
112.68 + * environment does not know how to handle such stream
112.69 + */
112.70 + public Audio create(String src);
112.71 +
112.72 + /** Starts playback of the audio.
112.73 + *
112.74 + * @param a the internal representation of the audio as created by {@link #create(java.lang.String)} method.
112.75 + */
112.76 + public void play(Audio a);
112.77 +
112.78 + /** Pauses playback of the audio.
112.79 + *
112.80 + * @param a the internal representation of the audio as created by {@link #create(java.lang.String)} method.
112.81 + */
112.82 + public void pause(Audio a);
112.83 +
112.84 + /** Changes volume for the playback of the audio.
112.85 + *
112.86 + * @param a the internal representation of the audio as created by {@link #create(java.lang.String)} method.
112.87 + * @param volume value between 0.0 and 1.0
112.88 + */
112.89 + public void setVolume(Audio a, double volume);
112.90 +
112.91 + /** Checks whether given audio is supported
112.92 + *
112.93 + * @param a the internal representation of the audio as created by {@link #create(java.lang.String)} method.
112.94 + * @return <code>true</code> or <code>false</code>
112.95 + */
112.96 + public boolean isSupported(Audio a);
112.97 +}
113.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
113.2 +++ b/sound/src/main/java/org/netbeans/html/sound/spi/package.html Tue Aug 26 18:13:30 2014 +0200
113.3 @@ -0,0 +1,49 @@
113.4 +<!--
113.5 +
113.6 + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
113.7 +
113.8 + Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
113.9 +
113.10 + Oracle and Java are registered trademarks of Oracle and/or its affiliates.
113.11 + Other names may be trademarks of their respective owners.
113.12 +
113.13 + The contents of this file are subject to the terms of either the GNU
113.14 + General Public License Version 2 only ("GPL") or the Common
113.15 + Development and Distribution License("CDDL") (collectively, the
113.16 + "License"). You may not use this file except in compliance with the
113.17 + License. You can obtain a copy of the License at
113.18 + http://www.netbeans.org/cddl-gplv2.html
113.19 + or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
113.20 + specific language governing permissions and limitations under the
113.21 + License. When distributing the software, include this License Header
113.22 + Notice in each file and include the License file at
113.23 + nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
113.24 + particular file as subject to the "Classpath" exception as provided
113.25 + by Oracle in the GPL Version 2 section of the License file that
113.26 + accompanied this code. If applicable, add the following below the
113.27 + License Header, with the fields enclosed by brackets [] replaced by
113.28 + your own identifying information:
113.29 + "Portions Copyrighted [year] [name of copyright owner]"
113.30 +
113.31 + Contributor(s):
113.32 +
113.33 + The Original Software is NetBeans. The Initial Developer of the Original
113.34 + Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
113.35 +
113.36 + If you wish your version of this file to be governed by only the CDDL
113.37 + or only the GPL Version 2, indicate your decision by adding
113.38 + "[Contributor] elects to include this software in this distribution
113.39 + under the [CDDL or GPL Version 2] license." If you do not indicate a
113.40 + single choice of license, a recipient has the option to distribute
113.41 + your version of this file under either the CDDL, the GPL Version 2 or
113.42 + to extend the choice of license to its licensees as provided above.
113.43 + However, if you add GPL Version 2 code and therefore, elected the GPL
113.44 + Version 2 license, then the option applies only if the new code is
113.45 + made subject to such option by the copyright holder.
113.46 +
113.47 +-->
113.48 +<body>
113.49 + <p>
113.50 + Give your {@link net.java.html.sound.AudioClip} real behavior!
113.51 + </p>
113.52 +</body>
114.1 --- a/src/main/javadoc/overview.html Tue Aug 26 17:43:37 2014 +0200
114.2 +++ b/src/main/javadoc/overview.html Tue Aug 26 18:13:30 2014 +0200
114.3 @@ -80,7 +80,7 @@
114.4 <p>
114.5 {@link net.java.html.json.Property#array() Array properties} are now
114.6 mutable from the <a href="http://knockoutjs.com">knockout.js</a>
114.7 - point of view (required {@link org.apidesign.html.json.spi.Proto.Type#replaceValue one SPI change}).
114.8 + point of view (required {@link org.netbeans.html.json.spi.Proto.Type#replaceValue one SPI change}).
114.9 The page lookup mechanism can use {@link net.java.html.boot.BrowserBuilder#locale(java.util.Locale) locale}
114.10 to load localized a page with appropriate suffix.
114.11 </p>
114.12 @@ -100,7 +100,7 @@
114.13
114.14 <p>
114.15 Setters or array properties on classes generated by {@link net.java.html.json.Model}
114.16 - annotation can be accessed from any thread. {@link org.apidesign.html.sound.spi.AudioEnvironment}
114.17 + annotation can be accessed from any thread. {@link org.netbeans.html.sound.spi.AudioEnvironment}
114.18 can be registered into {@link net.java.html.BrwsrCtx}. There is
114.19 a {@link net.java.html.json.Models#parse(net.java.html.BrwsrCtx, java.lang.Class, java.io.InputStream, java.util.Collection) method}
114.20 to parse a JSON array and convert it into
114.21 @@ -412,7 +412,7 @@
114.22 environment which is not supported? In such case you can bring
114.23 <a href="http://html.java.net">HTML for Java</a>
114.24 to your environment yourself. Just implement your own
114.25 - {@link org.apidesign.html.boot.spi.Fn.Presenter}!
114.26 + {@link org.netbeans.html.boot.spi.Fn.Presenter}!
114.27 </p>
114.28
114.29 <h2>Other Resources</h2>