# HG changeset patch # User Jaroslav Tulach # Date 1409069610 -7200 # Node ID bdc3d696dd4aedee93e8f84df1244e5795a3aaa6 # Parent 892b0a823f46d08c7f49c7703322a9655b353c97 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. diff -r 892b0a823f46 -r bdc3d696dd4a boot-fx/src/main/java/org/netbeans/html/boot/fx/AbstractFXPresenter.java --- a/boot-fx/src/main/java/org/netbeans/html/boot/fx/AbstractFXPresenter.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot-fx/src/main/java/org/netbeans/html/boot/fx/AbstractFXPresenter.java Tue Aug 26 18:13:30 2014 +0200 @@ -61,7 +61,7 @@ import javafx.scene.web.WebEngine; import javafx.scene.web.WebView; import netscape.javascript.JSObject; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; /** * diff -r 892b0a823f46 -r bdc3d696dd4a boot-fx/src/main/java/org/netbeans/html/boot/fx/FXPresenter.java --- a/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXPresenter.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXPresenter.java Tue Aug 26 18:13:30 2014 +0200 @@ -48,7 +48,7 @@ import java.net.URLClassLoader; import javafx.scene.web.WebView; import net.java.html.boot.BrowserBuilder; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import org.openide.util.lookup.ServiceProvider; /** This is an implementation class, use {@link BrowserBuilder} API. Just diff -r 892b0a823f46 -r bdc3d696dd4a boot-fx/src/test/java/org/netbeans/html/boot/fx/BootstrapTest.java --- a/boot-fx/src/test/java/org/netbeans/html/boot/fx/BootstrapTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/BootstrapTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -49,9 +49,9 @@ import java.util.concurrent.Executors; import net.java.html.BrwsrCtx; import net.java.html.boot.BrowserBuilder; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.tck.KOTest; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.tck.KOTest; import org.openide.util.lookup.ServiceProvider; import org.testng.Assert; import static org.testng.Assert.assertNotSame; diff -r 892b0a823f46 -r bdc3d696dd4a boot-fx/src/test/java/org/netbeans/html/boot/fx/FXJavaScriptTest.java --- a/boot-fx/src/test/java/org/netbeans/html/boot/fx/FXJavaScriptTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/FXJavaScriptTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -48,8 +48,8 @@ import java.util.List; import java.util.concurrent.Executors; import net.java.html.boot.BrowserBuilder; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.json.tck.KOTest; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.json.tck.KOTest; import org.testng.Assert; import org.testng.annotations.Factory; diff -r 892b0a823f46 -r bdc3d696dd4a boot-fx/src/test/java/org/netbeans/html/boot/fx/FxJavaScriptTst.java --- a/boot-fx/src/test/java/org/netbeans/html/boot/fx/FxJavaScriptTst.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/FxJavaScriptTst.java Tue Aug 26 18:13:30 2014 +0200 @@ -42,7 +42,7 @@ */ package org.netbeans.html.boot.fx; -import org.apidesign.html.json.tck.JavaScriptTCK; +import org.netbeans.html.json.tck.JavaScriptTCK; /** * diff -r 892b0a823f46 -r bdc3d696dd4a boot-fx/src/test/java/org/netbeans/html/boot/fx/KOFx.java --- a/boot-fx/src/test/java/org/netbeans/html/boot/fx/KOFx.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/KOFx.java Tue Aug 26 18:13:30 2014 +0200 @@ -46,7 +46,7 @@ import java.lang.reflect.Method; import javafx.application.Platform; import org.netbeans.html.boot.impl.FnContext; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import org.testng.IHookCallBack; import org.testng.IHookable; import org.testng.ITest; diff -r 892b0a823f46 -r bdc3d696dd4a boot-fx/src/test/java/org/netbeans/html/boot/fx/ReloadTest.java --- a/boot-fx/src/test/java/org/netbeans/html/boot/fx/ReloadTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/ReloadTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -48,7 +48,7 @@ import net.java.html.BrwsrCtx; import net.java.html.boot.BrowserBuilder; import net.java.html.js.JavaScriptBody; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import static org.testng.Assert.*; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a boot-fx/src/test/java/org/netbeans/html/boot/fx/TestingProvider.java --- a/boot-fx/src/test/java/org/netbeans/html/boot/fx/TestingProvider.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/TestingProvider.java Tue Aug 26 18:13:30 2014 +0200 @@ -42,7 +42,7 @@ */ package org.netbeans.html.boot.fx; -import org.apidesign.html.context.spi.Contexts; +import org.netbeans.html.context.spi.Contexts; import org.openide.util.lookup.ServiceProvider; import static org.testng.Assert.assertTrue; diff -r 892b0a823f46 -r bdc3d696dd4a boot-script/src/main/java/net/java/html/boot/script/ScriptPresenter.java --- a/boot-script/src/main/java/net/java/html/boot/script/ScriptPresenter.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot-script/src/main/java/net/java/html/boot/script/ScriptPresenter.java Tue Aug 26 18:13:30 2014 +0200 @@ -55,8 +55,8 @@ import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.boot.spi.Fn.Presenter; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn.Presenter; /** Implementation of {@link Presenter} that delegates * to Java {@link ScriptEngine scripting} API. The presenter runs headless diff -r 892b0a823f46 -r bdc3d696dd4a boot-script/src/main/java/net/java/html/boot/script/Scripts.java --- a/boot-script/src/main/java/net/java/html/boot/script/Scripts.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot-script/src/main/java/net/java/html/boot/script/Scripts.java Tue Aug 26 18:13:30 2014 +0200 @@ -47,8 +47,8 @@ import javax.script.ScriptEngine; import net.java.html.boot.BrowserBuilder; import net.java.html.js.JavaScriptBody; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.boot.spi.Fn.Presenter; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn.Presenter; /** Implementations of {@link Presenter}s that delegate * to Java {@link ScriptEngine scripting} API. Initialize your presenter @@ -71,7 +71,7 @@ *
  * {@code @Test} public void runInASimulatedBrowser() throws Exception {
  *   {@link Presenter Fn.Presenter} p = Scripts.{@link Scripts#createPresenter()};
- *   try ({@link Closeable} c = {@link Fn#activate(org.apidesign.html.boot.spi.Fn.Presenter) Fn.activate}(p)) {
+ *   try ({@link Closeable} c = {@link Fn#activate(org.netbeans.html.boot.spi.Fn.Presenter) Fn.activate}(p)) {
  *     // your code operating in context of p
  *   }
  * }
diff -r 892b0a823f46 -r bdc3d696dd4a boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java
--- a/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java	Tue Aug 26 17:43:37 2014 +0200
+++ b/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java	Tue Aug 26 18:13:30 2014 +0200
@@ -48,8 +48,8 @@
 import java.util.List;
 import java.util.concurrent.Executors;
 import net.java.html.boot.BrowserBuilder;
-import org.apidesign.html.boot.spi.Fn;
-import org.apidesign.html.json.tck.KOTest;
+import org.netbeans.html.boot.spi.Fn;
+import org.netbeans.html.json.tck.KOTest;
 import org.testng.Assert;
 import org.testng.annotations.Factory;
 
diff -r 892b0a823f46 -r bdc3d696dd4a boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTst.java
--- a/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTst.java	Tue Aug 26 17:43:37 2014 +0200
+++ b/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTst.java	Tue Aug 26 18:13:30 2014 +0200
@@ -42,7 +42,7 @@
  */
 package net.java.html.boot.script;
 
-import org.apidesign.html.json.tck.JavaScriptTCK;
+import org.netbeans.html.json.tck.JavaScriptTCK;
 
 /**
  *
diff -r 892b0a823f46 -r bdc3d696dd4a boot-script/src/test/java/net/java/html/boot/script/SingleCase.java
--- a/boot-script/src/test/java/net/java/html/boot/script/SingleCase.java	Tue Aug 26 17:43:37 2014 +0200
+++ b/boot-script/src/test/java/net/java/html/boot/script/SingleCase.java	Tue Aug 26 18:13:30 2014 +0200
@@ -46,7 +46,7 @@
 import java.lang.reflect.Method;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
-import org.apidesign.html.boot.spi.Fn;
+import org.netbeans.html.boot.spi.Fn;
 import org.netbeans.html.boot.impl.FnContext;
 import org.testng.IHookCallBack;
 import org.testng.IHookable;
diff -r 892b0a823f46 -r bdc3d696dd4a boot-script/src/test/java/net/java/html/boot/script/ko4j/KOCase.java
--- a/boot-script/src/test/java/net/java/html/boot/script/ko4j/KOCase.java	Tue Aug 26 17:43:37 2014 +0200
+++ b/boot-script/src/test/java/net/java/html/boot/script/ko4j/KOCase.java	Tue Aug 26 18:13:30 2014 +0200
@@ -50,7 +50,7 @@
 import java.util.concurrent.Executors;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import org.apidesign.html.boot.spi.Fn;
+import org.netbeans.html.boot.spi.Fn;
 import org.testng.ITest;
 import org.testng.SkipException;
 import org.testng.annotations.Test;
diff -r 892b0a823f46 -r bdc3d696dd4a boot-script/src/test/java/net/java/html/boot/script/ko4j/KnockoutEnvJSTest.java
--- a/boot-script/src/test/java/net/java/html/boot/script/ko4j/KnockoutEnvJSTest.java	Tue Aug 26 17:43:37 2014 +0200
+++ b/boot-script/src/test/java/net/java/html/boot/script/ko4j/KnockoutEnvJSTest.java	Tue Aug 26 18:13:30 2014 +0200
@@ -61,12 +61,12 @@
 import net.java.html.boot.BrowserBuilder;
 import net.java.html.boot.script.Scripts;
 import net.java.html.js.JavaScriptBody;
-import org.apidesign.html.boot.spi.Fn;
-import org.apidesign.html.context.spi.Contexts;
-import org.apidesign.html.json.spi.Technology;
-import org.apidesign.html.json.spi.Transfer;
-import org.apidesign.html.json.tck.KOTest;
-import org.apidesign.html.json.tck.KnockoutTCK;
+import org.netbeans.html.boot.spi.Fn;
+import org.netbeans.html.context.spi.Contexts;
+import org.netbeans.html.json.spi.Technology;
+import org.netbeans.html.json.spi.Transfer;
+import org.netbeans.html.json.tck.KOTest;
+import org.netbeans.html.json.tck.KnockoutTCK;
 import org.netbeans.html.ko4j.KO4J;
 import org.netbeans.html.wstyrus.TyrusContext;
 import org.openide.util.lookup.ServiceProvider;
diff -r 892b0a823f46 -r bdc3d696dd4a boot/pom.xml
--- a/boot/pom.xml	Tue Aug 26 17:43:37 2014 +0200
+++ b/boot/pom.xml	Tue Aug 26 18:13:30 2014 +0200
@@ -14,7 +14,7 @@
   http://maven.apache.org
   
     UTF-8
-    net.java.html.js,net.java.html.boot,org.apidesign.html.boot.spi
+    net.java.html.js,net.java.html.boot,org.netbeans.html.boot.spi
   
   
       
diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/main/java/net/java/html/boot/BrowserBuilder.java
--- a/boot/src/main/java/net/java/html/boot/BrowserBuilder.java	Tue Aug 26 17:43:37 2014 +0200
+++ b/boot/src/main/java/net/java/html/boot/BrowserBuilder.java	Tue Aug 26 18:13:30 2014 +0200
@@ -62,8 +62,8 @@
 import java.util.logging.Logger;
 import net.java.html.BrwsrCtx;
 import net.java.html.js.JavaScriptBody;
-import org.apidesign.html.boot.spi.Fn;
-import org.apidesign.html.context.spi.Contexts;
+import org.netbeans.html.boot.spi.Fn;
+import org.netbeans.html.context.spi.Contexts;
 import org.netbeans.html.boot.impl.FindResources;
 import org.netbeans.html.boot.impl.FnContext;
 import org.netbeans.html.boot.impl.FnUtils;
@@ -211,7 +211,7 @@
 
     /** Loader to use when searching for classes to initialize. 
      * If specified, this loader is going to be used to load {@link Fn.Presenter}
-     * and {@link Contexts#fillInByProviders(java.lang.Class, org.apidesign.html.context.spi.Contexts.Builder) fill} {@link BrwsrCtx} in.
+     * and {@link Contexts#fillInByProviders(java.lang.Class, org.netbeans.html.context.spi.Contexts.Builder) fill} {@link BrwsrCtx} in.
      * Specifying special classloader may be useful in modular systems, 
      * like OSGi, where one needs to load classes from many otherwise independent
      * modules.
diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/main/java/net/java/html/js/package.html
--- a/boot/src/main/java/net/java/html/js/package.html	Tue Aug 26 17:43:37 2014 +0200
+++ b/boot/src/main/java/net/java/html/js/package.html	Tue Aug 26 18:13:30 2014 +0200
@@ -202,7 +202,7 @@
         Classes with {@link net.java.html.js.JavaScriptBody} annotated methods need to
         be post processed before they can be used - e.g. their native
         body needs to be generated to call into JavaScript (btw. the code is performed
-        via {@link org.apidesign.html.boot.spi.Fn}). There are three ways
+        via {@link org.netbeans.html.boot.spi.Fn}). There are three ways
         such post processing can happen.
         

Compile time processing - this is the preferred method that diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/main/java/org/apidesign/html/boot/spi/Fn.java --- a/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,332 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.boot.spi; - -import java.io.Closeable; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URL; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.Executor; -import net.java.html.js.JavaScriptBody; -import org.netbeans.html.boot.impl.FnContext; - -/** Represents single JavaScript function that can be invoked. - * Created via {@link Presenter#defineFn(java.lang.String, java.lang.String...)}. - * - * @author Jaroslav Tulach - */ -public abstract class Fn { - private final Presenter presenter; - - /** - * @deprecated Ineffective as of 0.6. - * Provide a presenter via {@link #Fn(org.apidesign.html.boot.spi.Fn.Presenter)} - * constructor - */ - @Deprecated - protected Fn() { - this(null); - } - - /** Creates new function object and associates it with given presenter. - * - * @param presenter the browser presenter associated with this function - * @since 0.6 - */ - protected Fn(Presenter presenter) { - this.presenter = presenter; - } - - /** True, if currently active presenter is the same as presenter this - * function has been created for via {@link #Fn(org.apidesign.html.boot.spi.Fn.Presenter)}. - * - * @return true, if proper presenter is used - */ - public final boolean isValid() { - return presenter != null && FnContext.currentPresenter(false) == presenter; - } - - /** Helper method to check if the provided instance is valid function. - * Checks if the parameter is non-null and if so, does {@link #isValid()} - * check. - * - * @param fnOrNull function or null - * @return true if the parameter is non-null and valid - * @since 0.7 - */ - public static boolean isValid(Fn fnOrNull) { - return fnOrNull != null && fnOrNull.isValid(); - } - - /** Helper method to find current presenter and ask it to define new - * function by calling {@link Presenter#defineFn(java.lang.String, java.lang.String...)}. - * - * @param caller the class who wishes to define the function - * @param code the body of the function (can reference this and names variables) - * @param names names of individual parameters - * @return the function object that can be {@link Fn#invoke(java.lang.Object, java.lang.Object...) invoked} - * - can return null if there is {@link #activePresenter() no presenter} - * @since 0.7 - */ - public static Fn define(Class caller, String code, String... names) { - final Presenter p = FnContext.currentPresenter(false); - return p == null ? null : p.defineFn(code, names); - } - - private static final Map> LOADED = new HashMap>(); - - /** Wraps function to ensure that the script represented by resource - * gets loaded into the browser environment before the function fn - * is executed. - * - * @param fn original function to call (if null returns null) - * @param caller the class who wishes to define/call the function - * @param resource resources (accessible via {@link ClassLoader#getResource(java.lang.String)}) - * with a JavaScript that is supposed to loaded into the browser - * environment - * @return function that ensures the script is loaded and then delegates - * to fn. Returns null if the input fn is null - * @since 0.7 - */ - public static Fn preload(final Fn fn, final Class caller, final String resource) { - if (fn == null) { - return null; - } - return new Fn(fn.presenter()) { - @Override - public Object invoke(Object thiz, Object... args) throws Exception { - loadResource(); - return fn.invoke(thiz, args); - } - - @Override - public void invokeLater(Object thiz, Object... args) throws Exception { - loadResource(); - fn.invokeLater(thiz, args); - } - - private void loadResource() throws Exception { - Presenter p = presenter(); - if (p == null) { - p = FnContext.currentPresenter(false); - } - if (p != null) { - Set there = LOADED.get(resource); - if (there == null) { - there = new HashSet(); - LOADED.put(resource, there); - } - if (there.add(p)) { - final ClassLoader l = caller.getClassLoader(); - InputStream is = l.getResourceAsStream(resource); - if (is == null && resource.startsWith("/")) { - is = l.getResourceAsStream(resource.substring(1)); - } - if (is == null) { - throw new IOException("Cannot find " + resource + " in " + l); - } - try { - InputStreamReader r = new InputStreamReader(is, "UTF-8"); - p.loadScript(r); - } finally { - is.close(); - } - } - } - } - }; - } - - - /** The currently active presenter. - * - * @return the currently active presenter or null - * @since 0.7 - */ - public static Presenter activePresenter() { - return FnContext.currentPresenter(false); - } - - /** Activates given presenter. Used to associate the native - * JavaScript code specified by - * {@link JavaScriptBody} annotation with certain presenter: - *
-     * try ({@link Closeable} c = Fn.activate(presenter)) {
-     *   doCallsInPresenterContext();
-     * }
-     * 
- * - * @param p the presenter that should be active until closable is closed - * @return the closable to close - * @since 0.7 - */ - public static Closeable activate(Presenter p) { - return FnContext.activate(p); - } - - /** Invokes the defined function with specified this and - * appropriate arguments. - * - * @param thiz the meaning of this inside of the JavaScript - * function - can be null - * @param args arguments for the function - * @return return value from the function - * @throws Exception if something goes wrong, as exception may be thrown - */ - public abstract Object invoke(Object thiz, Object... args) throws Exception; - - /** Invokes the defined function with specified this and - * appropriate arguments asynchronously. The invocation may be - * happen "later". - * - * @param thiz the meaning of this inside of the JavaScript - * function - can be null - * @param args arguments for the function - * @throws Exception if something goes wrong, as exception may be thrown - * @since 0.7.6 - */ - public void invokeLater(Object thiz, Object... args) throws Exception { - invoke(this, args); - } - - /** Provides the function implementation access to the presenter provided - * in {@link #Fn(org.apidesign.html.boot.spi.Fn.Presenter) the constructor}. - * - * @return presenter passed in the constructor (may be, but should not be null) - * @since 0.7 - */ - protected final Presenter presenter() { - return presenter; - } - - /** The representation of a presenter - usually a browser window. - * Should be provided by a library included in the application and registered - * in META-INF/services, for example with - * @ServiceProvider(service = Fn.Presenter.class) annotation. - *

- * Since 0.7 a presenter may implement {@link Executor} interface, in case - * it supports single threaded execution environment. The executor's - * {@link Executor#execute(java.lang.Runnable)} method is then supposed - * to invoke the runnable immediately (in case we are on the right thread - * already) or return and asynchronously invoke the runnable later on the - * right thread (if we are on wrong thread). - */ - public interface Presenter { - /** Creates new function with given parameter names and provided body. - * - * @param code the body of the function. Can refer to variables named - * as names - * @param names names of parameters of the function - these will be - * available when the code body executes - * - * @return function that can be later invoked - */ - public Fn defineFn(String code, String... names); - - /** Opens the browser, loads provided page and when the - * page is ready, it calls back to the provider runnable. - * - * @param page the URL for the page to display - * @param onPageLoad callback when the page is ready - */ - public void displayPage(URL page, Runnable onPageLoad); - - /** Loads a script into the browser JavaScript interpreter and - * executes it. - * @param code the script to execute - * @throws Exception if something goes wrong, throw an exception - */ - public void loadScript(Reader code) throws Exception; - } - - /** Additional interface to be implemented by {@link Presenter}s that - * wish to control what objects are passed into the JavaScript virtual - * machine. - *

- * If a JavaScript engine makes callback to Java method that returns - * a value, the {@link #toJavaScript(java.lang.Object)} method is - * consulted to convert the Java value to something reasonable inside - * JavaScript VM. - *

- * Note: The implementation based on JavaFX WebView - * uses this interface to convert Java arrays to JavaScript ones. - * - * @see Presenter - * @since 0.7 - */ - public interface ToJavaScript { - /** Convert a Java return value into some object suitable for - * JavaScript virtual machine. - * - * @param toReturn the Java object to be returned - * @return the replacement value to return instead - */ - public Object toJavaScript(Object toReturn); - } - - /** Additional interface to be implemented by {@link Presenter}s that - * need to convert JavaScript object (usually array) to Java object - * when calling back from JavaScript to Java. - *

- * Note: The implementation based on JavaFX - * WebView uses this interface to convert JavaScript arrays to - * Java ones. - * - * @since 0.7 - */ - public interface FromJavaScript { - /** Convert a JavaScript object into suitable Java representation - * before a Java method is called with this object as an argument. - * - * @param js the JavaScript object - * @return replacement object for - */ - public Object toJava(Object js); - } -} diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/main/java/org/apidesign/html/boot/spi/package.html --- a/boot/src/main/java/org/apidesign/html/boot/spi/package.html Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ - - - - -

Interfaces for integrators of various execution environments.
- Not really interesting for clients. The clients should rather use - {@link net.java.html.boot.BrowserBuilder} to launch their applications, - or (if they need to do some JavaScript calls themselves) look at - {@link net.java.html.js.JavaScriptBody} annotation and its usage. - - diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/main/java/org/netbeans/html/boot/impl/FnContext.java --- a/boot/src/main/java/org/netbeans/html/boot/impl/FnContext.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/FnContext.java Tue Aug 26 18:13:30 2014 +0200 @@ -46,7 +46,7 @@ import java.io.Flushable; import java.io.IOException; import java.util.logging.Logger; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; /** * diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java --- a/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java Tue Aug 26 18:13:30 2014 +0200 @@ -52,7 +52,7 @@ import java.util.List; import net.java.html.js.JavaScriptBody; import net.java.html.js.JavaScriptResource; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; @@ -292,13 +292,13 @@ super.visitFieldInsn( Opcodes.GETSTATIC, FindInClass.this.name, "$$fn$$" + name + "_" + found, - "Lorg/apidesign/html/boot/spi/Fn;" + "Lorg/netbeans/html/boot/spi/Fn;" ); super.visitInsn(Opcodes.DUP); super.visitMethodInsn( Opcodes.INVOKESTATIC, - "org/apidesign/html/boot/spi/Fn", "isValid", - "(Lorg/apidesign/html/boot/spi/Fn;)Z" + "org/netbeans/html/boot/spi/Fn", "isValid", + "(Lorg/netbeans/html/boot/spi/Fn;)Z" ); Label ifNotNull = new Label(); super.visitJumpInsn(Opcodes.IFNE, ifNotNull); @@ -320,8 +320,8 @@ super.visitInsn(Opcodes.AASTORE); } super.visitMethodInsn(Opcodes.INVOKESTATIC, - "org/apidesign/html/boot/spi/Fn", "define", - "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Lorg/apidesign/html/boot/spi/Fn;" + "org/netbeans/html/boot/spi/Fn", "define", + "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Lorg/netbeans/html/boot/spi/Fn;" ); Label noPresenter = new Label(); if (hasCode) { @@ -332,15 +332,15 @@ super.visitLdcInsn(Type.getObjectType(FindInClass.this.name)); super.visitLdcInsn(resource); super.visitMethodInsn(Opcodes.INVOKESTATIC, - "org/apidesign/html/boot/spi/Fn", "preload", - "(Lorg/apidesign/html/boot/spi/Fn;Ljava/lang/Class;Ljava/lang/String;)Lorg/apidesign/html/boot/spi/Fn;" + "org/netbeans/html/boot/spi/Fn", "preload", + "(Lorg/netbeans/html/boot/spi/Fn;Ljava/lang/Class;Ljava/lang/String;)Lorg/netbeans/html/boot/spi/Fn;" ); } super.visitInsn(Opcodes.DUP); super.visitFieldInsn( Opcodes.PUTSTATIC, FindInClass.this.name, "$$fn$$" + name + "_" + found, - "Lorg/apidesign/html/boot/spi/Fn;" + "Lorg/netbeans/html/boot/spi/Fn;" ); // end of Fn init @@ -469,7 +469,7 @@ if (fia.wait4js) { super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, - "org/apidesign/html/boot/spi/Fn", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;" + "org/netbeans/html/boot/spi/Fn", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;" ); switch (sv.returnType.getSort()) { case Type.VOID: @@ -496,7 +496,7 @@ } } else { super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, - "org/apidesign/html/boot/spi/Fn", "invokeLater", "(Ljava/lang/Object;[Ljava/lang/Object;)V" + "org/netbeans/html/boot/spi/Fn", "invokeLater", "(Ljava/lang/Object;[Ljava/lang/Object;)V" ); super.visitInsn(Opcodes.RETURN); } @@ -518,7 +518,7 @@ FindInClass.this.visitField( Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, "$$fn$$" + name + "_" + found, - "Lorg/apidesign/html/boot/spi/Fn;", + "Lorg/netbeans/html/boot/spi/Fn;", null, null ); } diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java --- a/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java Tue Aug 26 18:13:30 2014 +0200 @@ -353,13 +353,13 @@ source.append("package ").append(pkgName).append(";\n"); source.append("public final class $JsCallbacks$ {\n"); source.append(" static final $JsCallbacks$ VM = new $JsCallbacks$(null);\n"); - source.append(" private final org.apidesign.html.boot.spi.Fn.Presenter p;\n"); + source.append(" private final org.netbeans.html.boot.spi.Fn.Presenter p;\n"); source.append(" private $JsCallbacks$ last;\n"); - source.append(" private $JsCallbacks$(org.apidesign.html.boot.spi.Fn.Presenter p) {\n"); + source.append(" private $JsCallbacks$(org.netbeans.html.boot.spi.Fn.Presenter p) {\n"); source.append(" this.p = p;\n"); source.append(" }\n"); source.append(" final $JsCallbacks$ current() {\n"); - source.append(" org.apidesign.html.boot.spi.Fn.Presenter now = org.apidesign.html.boot.spi.Fn.activePresenter();\n"); + source.append(" org.netbeans.html.boot.spi.Fn.Presenter now = org.netbeans.html.boot.spi.Fn.activePresenter();\n"); source.append(" if (now == p) return this;\n"); source.append(" if (last != null && now == last.p) return last;\n"); source.append(" return last = new $JsCallbacks$(now);\n"); @@ -388,9 +388,9 @@ final TypeMirror t = ve.asType(); if (!t.getKind().isPrimitive()) { source.append("Object"); - convert.append(" if (p instanceof org.apidesign.html.boot.spi.Fn.FromJavaScript) {\n"); + convert.append(" if (p instanceof org.netbeans.html.boot.spi.Fn.FromJavaScript) {\n"); convert.append(" arg").append(cnt). - append(" = ((org.apidesign.html.boot.spi.Fn.FromJavaScript)p).toJava(arg").append(cnt). + append(" = ((org.netbeans.html.boot.spi.Fn.FromJavaScript)p).toJava(arg").append(cnt). append(");\n"); convert.append(" }\n"); } else { @@ -402,9 +402,9 @@ source.append(") throws Throwable {\n"); source.append(convert); if (useTryResources()) { - source.append(" try (java.io.Closeable a = org.apidesign.html.boot.spi.Fn.activate(p)) { \n"); + source.append(" try (java.io.Closeable a = org.netbeans.html.boot.spi.Fn.activate(p)) { \n"); } else { - source.append(" java.io.Closeable a = org.apidesign.html.boot.spi.Fn.activate(p); try {\n"); + source.append(" java.io.Closeable a = org.netbeans.html.boot.spi.Fn.activate(p); try {\n"); } source.append(" "); if (m.getReturnType().getKind() != TypeKind.VOID) { @@ -430,8 +430,8 @@ if (m.getReturnType().getKind() == TypeKind.VOID) { source.append(" return null;\n"); } else { - source.append(" if (p instanceof org.apidesign.html.boot.spi.Fn.ToJavaScript) {\n"); - source.append(" $ret = ((org.apidesign.html.boot.spi.Fn.ToJavaScript)p).toJavaScript($ret);\n"); + source.append(" if (p instanceof org.netbeans.html.boot.spi.Fn.ToJavaScript) {\n"); + source.append(" $ret = ((org.netbeans.html.boot.spi.Fn.ToJavaScript)p).toJavaScript($ret);\n"); source.append(" }\n"); source.append(" return $ret;\n"); } diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/main/java/org/netbeans/html/boot/impl/JsClassLoader.java --- a/boot/src/main/java/org/netbeans/html/boot/impl/JsClassLoader.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/JsClassLoader.java Tue Aug 26 18:13:30 2014 +0200 @@ -42,7 +42,7 @@ */ package org.netbeans.html.boot.impl; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -76,7 +76,7 @@ if (name.startsWith("com.sun")) { return Class.forName(name); } - if (name.startsWith("org.apidesign.html.context.spi")) { + if (name.startsWith("org.netbeans.html.context.spi")) { return Class.forName(name); } if (name.startsWith("net.java.html.BrwsrCtx")) { @@ -101,7 +101,7 @@ return FnUtils.class; } if ( - name.equals("org.apidesign.html.boot.spi.Fn") || + name.equals("org.netbeans.html.boot.spi.Fn") || name.equals("org.netbeans.html.boot.impl.FnUtils") || name.equals("org.netbeans.html.boot.impl.FnContext") ) { diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/main/java/org/netbeans/html/boot/spi/Fn.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/boot/src/main/java/org/netbeans/html/boot/spi/Fn.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,332 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.boot.spi; + +import java.io.Closeable; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Executor; +import net.java.html.js.JavaScriptBody; +import org.netbeans.html.boot.impl.FnContext; + +/** Represents single JavaScript function that can be invoked. + * Created via {@link Presenter#defineFn(java.lang.String, java.lang.String...)}. + * + * @author Jaroslav Tulach + */ +public abstract class Fn { + private final Presenter presenter; + + /** + * @deprecated Ineffective as of 0.6. + * Provide a presenter via {@link #Fn(org.netbeans.html.boot.spi.Fn.Presenter)} + * constructor + */ + @Deprecated + protected Fn() { + this(null); + } + + /** Creates new function object and associates it with given presenter. + * + * @param presenter the browser presenter associated with this function + * @since 0.6 + */ + protected Fn(Presenter presenter) { + this.presenter = presenter; + } + + /** True, if currently active presenter is the same as presenter this + * function has been created for via {@link #Fn(org.netbeans.html.boot.spi.Fn.Presenter)}. + * + * @return true, if proper presenter is used + */ + public final boolean isValid() { + return presenter != null && FnContext.currentPresenter(false) == presenter; + } + + /** Helper method to check if the provided instance is valid function. + * Checks if the parameter is non-null and if so, does {@link #isValid()} + * check. + * + * @param fnOrNull function or null + * @return true if the parameter is non-null and valid + * @since 0.7 + */ + public static boolean isValid(Fn fnOrNull) { + return fnOrNull != null && fnOrNull.isValid(); + } + + /** Helper method to find current presenter and ask it to define new + * function by calling {@link Presenter#defineFn(java.lang.String, java.lang.String...)}. + * + * @param caller the class who wishes to define the function + * @param code the body of the function (can reference this and names variables) + * @param names names of individual parameters + * @return the function object that can be {@link Fn#invoke(java.lang.Object, java.lang.Object...) invoked} + * - can return null if there is {@link #activePresenter() no presenter} + * @since 0.7 + */ + public static Fn define(Class caller, String code, String... names) { + final Presenter p = FnContext.currentPresenter(false); + return p == null ? null : p.defineFn(code, names); + } + + private static final Map> LOADED = new HashMap>(); + + /** Wraps function to ensure that the script represented by resource + * gets loaded into the browser environment before the function fn + * is executed. + * + * @param fn original function to call (if null returns null) + * @param caller the class who wishes to define/call the function + * @param resource resources (accessible via {@link ClassLoader#getResource(java.lang.String)}) + * with a JavaScript that is supposed to loaded into the browser + * environment + * @return function that ensures the script is loaded and then delegates + * to fn. Returns null if the input fn is null + * @since 0.7 + */ + public static Fn preload(final Fn fn, final Class caller, final String resource) { + if (fn == null) { + return null; + } + return new Fn(fn.presenter()) { + @Override + public Object invoke(Object thiz, Object... args) throws Exception { + loadResource(); + return fn.invoke(thiz, args); + } + + @Override + public void invokeLater(Object thiz, Object... args) throws Exception { + loadResource(); + fn.invokeLater(thiz, args); + } + + private void loadResource() throws Exception { + Presenter p = presenter(); + if (p == null) { + p = FnContext.currentPresenter(false); + } + if (p != null) { + Set there = LOADED.get(resource); + if (there == null) { + there = new HashSet(); + LOADED.put(resource, there); + } + if (there.add(p)) { + final ClassLoader l = caller.getClassLoader(); + InputStream is = l.getResourceAsStream(resource); + if (is == null && resource.startsWith("/")) { + is = l.getResourceAsStream(resource.substring(1)); + } + if (is == null) { + throw new IOException("Cannot find " + resource + " in " + l); + } + try { + InputStreamReader r = new InputStreamReader(is, "UTF-8"); + p.loadScript(r); + } finally { + is.close(); + } + } + } + } + }; + } + + + /** The currently active presenter. + * + * @return the currently active presenter or null + * @since 0.7 + */ + public static Presenter activePresenter() { + return FnContext.currentPresenter(false); + } + + /** Activates given presenter. Used to associate the native + * JavaScript code specified by + * {@link JavaScriptBody} annotation with certain presenter: + *
+     * try ({@link Closeable} c = Fn.activate(presenter)) {
+     *   doCallsInPresenterContext();
+     * }
+     * 
+ * + * @param p the presenter that should be active until closable is closed + * @return the closable to close + * @since 0.7 + */ + public static Closeable activate(Presenter p) { + return FnContext.activate(p); + } + + /** Invokes the defined function with specified this and + * appropriate arguments. + * + * @param thiz the meaning of this inside of the JavaScript + * function - can be null + * @param args arguments for the function + * @return return value from the function + * @throws Exception if something goes wrong, as exception may be thrown + */ + public abstract Object invoke(Object thiz, Object... args) throws Exception; + + /** Invokes the defined function with specified this and + * appropriate arguments asynchronously. The invocation may be + * happen "later". + * + * @param thiz the meaning of this inside of the JavaScript + * function - can be null + * @param args arguments for the function + * @throws Exception if something goes wrong, as exception may be thrown + * @since 0.7.6 + */ + public void invokeLater(Object thiz, Object... args) throws Exception { + invoke(this, args); + } + + /** Provides the function implementation access to the presenter provided + * in {@link #Fn(org.netbeans.html.boot.spi.Fn.Presenter) the constructor}. + * + * @return presenter passed in the constructor (may be, but should not be null) + * @since 0.7 + */ + protected final Presenter presenter() { + return presenter; + } + + /** The representation of a presenter - usually a browser window. + * Should be provided by a library included in the application and registered + * in META-INF/services, for example with + * @ServiceProvider(service = Fn.Presenter.class) annotation. + *

+ * Since 0.7 a presenter may implement {@link Executor} interface, in case + * it supports single threaded execution environment. The executor's + * {@link Executor#execute(java.lang.Runnable)} method is then supposed + * to invoke the runnable immediately (in case we are on the right thread + * already) or return and asynchronously invoke the runnable later on the + * right thread (if we are on wrong thread). + */ + public interface Presenter { + /** Creates new function with given parameter names and provided body. + * + * @param code the body of the function. Can refer to variables named + * as names + * @param names names of parameters of the function - these will be + * available when the code body executes + * + * @return function that can be later invoked + */ + public Fn defineFn(String code, String... names); + + /** Opens the browser, loads provided page and when the + * page is ready, it calls back to the provider runnable. + * + * @param page the URL for the page to display + * @param onPageLoad callback when the page is ready + */ + public void displayPage(URL page, Runnable onPageLoad); + + /** Loads a script into the browser JavaScript interpreter and + * executes it. + * @param code the script to execute + * @throws Exception if something goes wrong, throw an exception + */ + public void loadScript(Reader code) throws Exception; + } + + /** Additional interface to be implemented by {@link Presenter}s that + * wish to control what objects are passed into the JavaScript virtual + * machine. + *

+ * If a JavaScript engine makes callback to Java method that returns + * a value, the {@link #toJavaScript(java.lang.Object)} method is + * consulted to convert the Java value to something reasonable inside + * JavaScript VM. + *

+ * Note: The implementation based on JavaFX WebView + * uses this interface to convert Java arrays to JavaScript ones. + * + * @see Presenter + * @since 0.7 + */ + public interface ToJavaScript { + /** Convert a Java return value into some object suitable for + * JavaScript virtual machine. + * + * @param toReturn the Java object to be returned + * @return the replacement value to return instead + */ + public Object toJavaScript(Object toReturn); + } + + /** Additional interface to be implemented by {@link Presenter}s that + * need to convert JavaScript object (usually array) to Java object + * when calling back from JavaScript to Java. + *

+ * Note: The implementation based on JavaFX + * WebView uses this interface to convert JavaScript arrays to + * Java ones. + * + * @since 0.7 + */ + public interface FromJavaScript { + /** Convert a JavaScript object into suitable Java representation + * before a Java method is called with this object as an argument. + * + * @param js the JavaScript object + * @return replacement object for + */ + public Object toJava(Object js); + } +} diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/main/java/org/netbeans/html/boot/spi/package.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/boot/src/main/java/org/netbeans/html/boot/spi/package.html Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,54 @@ + + + + +

Interfaces for integrators of various execution environments.
+ Not really interesting for clients. The clients should rather use + {@link net.java.html.boot.BrowserBuilder} to launch their applications, + or (if they need to do some JavaScript calls themselves) look at + {@link net.java.html.js.JavaScriptBody} annotation and its usage. + + diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/test/java/org/netbeans/html/boot/impl/CountFnCreationTest.java --- a/boot/src/test/java/org/netbeans/html/boot/impl/CountFnCreationTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/CountFnCreationTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -53,7 +53,7 @@ import java.util.logging.Logger; import net.java.html.js.JavaScriptBody; import net.java.html.js.JavaScriptResource; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import static org.testng.Assert.assertEquals; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java --- a/boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -56,7 +56,7 @@ import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import static org.testng.Assert.assertEquals; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/test/java/org/netbeans/html/boot/impl/JsCallbackTest.java --- a/boot/src/test/java/org/netbeans/html/boot/impl/JsCallbackTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsCallbackTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -55,7 +55,7 @@ } @Test public void missingTypeSpecification() { String body = "console[attr] = function(msg) {\n" - + " @org.apidesign.html.charts.Main::log(msg);\n" + + " @org.netbeans.html.charts.Main::log(msg);\n" + "};\n"; JsCallback instance = new JsCallbackImpl(); try { diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java --- a/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java Tue Aug 26 18:13:30 2014 +0200 @@ -46,7 +46,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import static org.testng.Assert.*; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderTest.java --- a/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -44,7 +44,7 @@ import java.io.Closeable; import java.io.Reader; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; diff -r 892b0a823f46 -r bdc3d696dd4a context/pom.xml --- a/context/pom.xml Tue Aug 26 17:43:37 2014 +0200 +++ b/context/pom.xml Tue Aug 26 18:13:30 2014 +0200 @@ -14,7 +14,7 @@ http://maven.apache.org UTF-8 - net.java.html,org.apidesign.html.context.spi + net.java.html,org.netbeans.html.context.spi diff -r 892b0a823f46 -r bdc3d696dd4a context/src/main/java/net/java/html/BrwsrCtx.java --- a/context/src/main/java/net/java/html/BrwsrCtx.java Tue Aug 26 17:43:37 2014 +0200 +++ b/context/src/main/java/net/java/html/BrwsrCtx.java Tue Aug 26 18:13:30 2014 +0200 @@ -46,7 +46,7 @@ import java.util.logging.Logger; import org.netbeans.html.context.impl.CtxAccssr; import org.netbeans.html.context.impl.CtxImpl; -import org.apidesign.html.context.spi.Contexts; +import org.netbeans.html.context.spi.Contexts; /** Represents context where the net.java.html.json.Model * and other objects @@ -100,7 +100,7 @@ return brwsr; } - org.apidesign.html.context.spi.Contexts.Builder cb = Contexts.newBuilder(); + org.netbeans.html.context.spi.Contexts.Builder cb = Contexts.newBuilder(); boolean found = Contexts.fillInByProviders(requestor, cb); if (!found) { LOG.warning("No browser context found. Returning empty technology!"); diff -r 892b0a823f46 -r bdc3d696dd4a context/src/main/java/org/apidesign/html/context/spi/Contexts.java --- a/context/src/main/java/org/apidesign/html/context/spi/Contexts.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,192 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.context.spi; - -import java.util.ServiceLoader; -import net.java.html.BrwsrCtx; -import org.netbeans.html.context.impl.CtxImpl; - -/** Factory class to assign various technologies - * to a {@link BrwsrCtx browser context}. Start with {@link #newBuilder()} - * and then assign technologies with {@link Builder#register(java.lang.Class, java.lang.Object, int)} - * method. - * - * @author Jaroslav Tulach - */ -public final class Contexts { - private Contexts() { - } - - /** Creates new, empty builder for creation of {@link BrwsrCtx}. At the - * end call the {@link Builder#build()} method to generate the context. - * - * @return new instance of the builder - */ - public static Builder newBuilder() { - return new Builder(); - } - - /** Seeks for the specified technology in the provided context. - * - * @param type of the technology - * @param context the context to seek in - * (previously filled with ({@link Builder#register(java.lang.Class, java.lang.Object, int)}) - * @param technology class that identifies the technology - * @return the technology in the context or null - */ - public static Tech find(BrwsrCtx context, Class technology) { - return CtxImpl.find(context, technology); - } - - /** Seeks {@link ServiceLoader} for all registered instances of - * {@link Provider} and asks them to {@link Provider#fillContext(org.apidesign.html.context.spi.Contexts.Builder, java.lang.Class) fill - * the builder}. - * - * @param requestor the application class for which to find the context - * @param cb the context builder to register technologies into - * @return true, if some instances of the provider were - * found, false otherwise - * @since 0.7.6 - */ - public static boolean fillInByProviders(Class requestor, Contexts.Builder cb) { - boolean found = false; - ClassLoader l; - try { - l = requestor.getClassLoader(); - } catch (SecurityException ex) { - l = null; - } - for (Provider cp : ServiceLoader.load(Provider.class, l)) { - cp.fillContext(cb, requestor); - found = true; - } - try { - for (Provider cp : ServiceLoader.load(Provider.class, Provider.class.getClassLoader())) { - cp.fillContext(cb, requestor); - found = true; - } - } catch (SecurityException ex) { - if (!found) { - throw ex; - } - } - if (!found) { - for (Provider cp : ServiceLoader.load(Provider.class)) { - cp.fillContext(cb, requestor); - found = true; - } - } - return found; - } - - /** Implementors of various HTML technologies should - * register their implementation via org.openide.util.lookup.ServiceProvider, so - * {@link ServiceLoader} can find them, when their JARs are included - * on the classpath of the running application. - * - * @author Jaroslav Tulach - */ - public static interface Provider { - - /** Register into the context if suitable technology is - * available for the requesting class. - * The provider should check if its own technology is available in current - * scope (e.g. proper JDK, proper browser, etc.). The provider - * can also find the right context depending on requestor's classloader, etc. - *

- * Providers should use {@link Builder} to enrich appropriately - * the context. - * - * @param context the context builder to fill with technologies - * @param requestor the application class requesting access the the HTML page - * @see BrwsrCtx#findDefault(java.lang.Class) - */ - void fillContext(Builder context, Class requestor); - } - - /** Support for providers of new {@link BrwsrCtx}. Providers of different - * technologies should be of particular interest in this class. End users - * designing their application with existing technologies should rather - * point their attention to {@link BrwsrCtx} and co. - * - * @author Jaroslav Tulach - */ - public static final class Builder { - private final CtxImpl impl = new CtxImpl(); - - Builder() { - } - - /** Registers new technology into the context. Each technology is - * exactly identified by its implementation class and can be associated - * with (positive) priority. In case of presence of multiple technologies - * with the same class, the one with higher lower priority takes precedence. - * @param type of technology to register - * @param type the real class of the technology type - * @param impl an instance of the technology class - * @param position the lower position, the more important implementation - * which will be consulted sooner when seeking for a {@link Contexts#find(net.java.html.BrwsrCtx, java.lang.Class)} - * an implementation - * @return this builder - */ - public Builder register(Class type, Tech impl, int position) { - if (impl == null) { - return this; - } - if (position <= 0) { - throw new IllegalStateException(); - } - this.impl.register(type, impl, position); - return this; - } - - /** Generates context based on values previously inserted into - * this builder. - * - * @return new, immutable instance of {@link BrwsrCtx} - */ - public BrwsrCtx build() { - return impl.build(); - } - } -} diff -r 892b0a823f46 -r bdc3d696dd4a context/src/main/java/org/apidesign/html/context/spi/package.html --- a/context/src/main/java/org/apidesign/html/context/spi/package.html Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ - - -

- Service provider classes to build {@link net.java.html.BrwsrCtx} - instances. -

- diff -r 892b0a823f46 -r bdc3d696dd4a context/src/main/java/org/netbeans/html/context/impl/CtxAccssr.java --- a/context/src/main/java/org/netbeans/html/context/impl/CtxAccssr.java Tue Aug 26 17:43:37 2014 +0200 +++ b/context/src/main/java/org/netbeans/html/context/impl/CtxAccssr.java Tue Aug 26 18:13:30 2014 +0200 @@ -43,7 +43,7 @@ package org.netbeans.html.context.impl; import net.java.html.BrwsrCtx; -import org.apidesign.html.context.spi.Contexts.Builder; +import org.netbeans.html.context.spi.Contexts.Builder; /** Internal communication between API (e.g. {@link BrwsrCtx}), SPI * (e.g. {@link Builder}) and the implementation package. diff -r 892b0a823f46 -r bdc3d696dd4a context/src/main/java/org/netbeans/html/context/spi/Contexts.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/context/src/main/java/org/netbeans/html/context/spi/Contexts.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,192 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.context.spi; + +import java.util.ServiceLoader; +import net.java.html.BrwsrCtx; +import org.netbeans.html.context.impl.CtxImpl; + +/** Factory class to assign various technologies + * to a {@link BrwsrCtx browser context}. Start with {@link #newBuilder()} + * and then assign technologies with {@link Builder#register(java.lang.Class, java.lang.Object, int)} + * method. + * + * @author Jaroslav Tulach + */ +public final class Contexts { + private Contexts() { + } + + /** Creates new, empty builder for creation of {@link BrwsrCtx}. At the + * end call the {@link Builder#build()} method to generate the context. + * + * @return new instance of the builder + */ + public static Builder newBuilder() { + return new Builder(); + } + + /** Seeks for the specified technology in the provided context. + * + * @param type of the technology + * @param context the context to seek in + * (previously filled with ({@link Builder#register(java.lang.Class, java.lang.Object, int)}) + * @param technology class that identifies the technology + * @return the technology in the context or null + */ + public static Tech find(BrwsrCtx context, Class technology) { + return CtxImpl.find(context, technology); + } + + /** Seeks {@link ServiceLoader} for all registered instances of + * {@link Provider} and asks them to {@link Provider#fillContext(org.netbeans.html.context.spi.Contexts.Builder, java.lang.Class) fill + * the builder}. + * + * @param requestor the application class for which to find the context + * @param cb the context builder to register technologies into + * @return true, if some instances of the provider were + * found, false otherwise + * @since 0.7.6 + */ + public static boolean fillInByProviders(Class requestor, Contexts.Builder cb) { + boolean found = false; + ClassLoader l; + try { + l = requestor.getClassLoader(); + } catch (SecurityException ex) { + l = null; + } + for (Provider cp : ServiceLoader.load(Provider.class, l)) { + cp.fillContext(cb, requestor); + found = true; + } + try { + for (Provider cp : ServiceLoader.load(Provider.class, Provider.class.getClassLoader())) { + cp.fillContext(cb, requestor); + found = true; + } + } catch (SecurityException ex) { + if (!found) { + throw ex; + } + } + if (!found) { + for (Provider cp : ServiceLoader.load(Provider.class)) { + cp.fillContext(cb, requestor); + found = true; + } + } + return found; + } + + /** Implementors of various HTML technologies should + * register their implementation via org.openide.util.lookup.ServiceProvider, so + * {@link ServiceLoader} can find them, when their JARs are included + * on the classpath of the running application. + * + * @author Jaroslav Tulach + */ + public static interface Provider { + + /** Register into the context if suitable technology is + * available for the requesting class. + * The provider should check if its own technology is available in current + * scope (e.g. proper JDK, proper browser, etc.). The provider + * can also find the right context depending on requestor's classloader, etc. + *

+ * Providers should use {@link Builder} to enrich appropriately + * the context. + * + * @param context the context builder to fill with technologies + * @param requestor the application class requesting access the the HTML page + * @see BrwsrCtx#findDefault(java.lang.Class) + */ + void fillContext(Builder context, Class requestor); + } + + /** Support for providers of new {@link BrwsrCtx}. Providers of different + * technologies should be of particular interest in this class. End users + * designing their application with existing technologies should rather + * point their attention to {@link BrwsrCtx} and co. + * + * @author Jaroslav Tulach + */ + public static final class Builder { + private final CtxImpl impl = new CtxImpl(); + + Builder() { + } + + /** Registers new technology into the context. Each technology is + * exactly identified by its implementation class and can be associated + * with (positive) priority. In case of presence of multiple technologies + * with the same class, the one with higher lower priority takes precedence. + * @param type of technology to register + * @param type the real class of the technology type + * @param impl an instance of the technology class + * @param position the lower position, the more important implementation + * which will be consulted sooner when seeking for a {@link Contexts#find(net.java.html.BrwsrCtx, java.lang.Class)} + * an implementation + * @return this builder + */ + public Builder register(Class type, Tech impl, int position) { + if (impl == null) { + return this; + } + if (position <= 0) { + throw new IllegalStateException(); + } + this.impl.register(type, impl, position); + return this; + } + + /** Generates context based on values previously inserted into + * this builder. + * + * @return new, immutable instance of {@link BrwsrCtx} + */ + public BrwsrCtx build() { + return impl.build(); + } + } +} diff -r 892b0a823f46 -r bdc3d696dd4a context/src/main/java/org/netbeans/html/context/spi/package.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/context/src/main/java/org/netbeans/html/context/spi/package.html Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,50 @@ + + +

+ Service provider classes to build {@link net.java.html.BrwsrCtx} + instances. +

+ diff -r 892b0a823f46 -r bdc3d696dd4a context/src/test/java/net/java/html/BrwsrCtxTest.java --- a/context/src/test/java/net/java/html/BrwsrCtxTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/context/src/test/java/net/java/html/BrwsrCtxTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -42,7 +42,7 @@ */ package net.java.html; -import org.apidesign.html.context.spi.Contexts; +import org.netbeans.html.context.spi.Contexts; import static org.testng.Assert.*; /** diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/pom.xml --- a/json-tck/pom.xml Tue Aug 26 17:43:37 2014 +0200 +++ b/json-tck/pom.xml Tue Aug 26 18:13:30 2014 +0200 @@ -14,7 +14,7 @@ http://maven.apache.org UTF-8 - org.apidesign.html.json.tck + org.netbeans.html.json.tck @@ -30,7 +30,7 @@ org.apache.maven.plugins maven-javadoc-plugin - org.apidesign.html.json.tck,org.apidesign.html.json.spi + org.netbeans.html.json.tck,org.netbeans.html.json.spi false true diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java --- a/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -45,8 +45,8 @@ import java.io.StringReader; import java.util.Arrays; import java.util.concurrent.Callable; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.json.tck.KOTest; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.json.tck.KOTest; /** * diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/net/java/html/json/tests/ConvertTypesTest.java --- a/json-tck/src/main/java/net/java/html/json/tests/ConvertTypesTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json-tck/src/main/java/net/java/html/json/tests/ConvertTypesTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -52,7 +52,7 @@ import java.util.Map; import net.java.html.BrwsrCtx; import net.java.html.json.Models; -import org.apidesign.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KOTest; /** * diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/net/java/html/json/tests/JSONTest.java --- a/json-tck/src/main/java/net/java/html/json/tests/JSONTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json-tck/src/main/java/net/java/html/json/tests/JSONTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -51,7 +51,7 @@ import net.java.html.json.Models; import net.java.html.json.OnReceive; import net.java.html.json.Property; -import org.apidesign.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KOTest; /** Need to verify that models produce reasonable JSON objects. * diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java --- a/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -52,7 +52,7 @@ import net.java.html.json.Model; import net.java.html.json.Models; import net.java.html.json.Property; -import org.apidesign.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KOTest; /** * diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/net/java/html/json/tests/MinesTest.java --- a/json-tck/src/main/java/net/java/html/json/tests/MinesTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json-tck/src/main/java/net/java/html/json/tests/MinesTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -53,7 +53,7 @@ import net.java.html.json.ModelOperation; import net.java.html.json.Models; import net.java.html.json.Property; -import org.apidesign.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KOTest; /** Tests model of a mine field and its behavior in the browser. */ diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/net/java/html/json/tests/OperationsTest.java --- a/json-tck/src/main/java/net/java/html/json/tests/OperationsTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json-tck/src/main/java/net/java/html/json/tests/OperationsTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -43,7 +43,7 @@ package net.java.html.json.tests; import net.java.html.json.Models; -import org.apidesign.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KOTest; /** * diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/net/java/html/json/tests/Utils.java --- a/json-tck/src/main/java/net/java/html/json/tests/Utils.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json-tck/src/main/java/net/java/html/json/tests/Utils.java Tue Aug 26 18:13:30 2014 +0200 @@ -47,7 +47,7 @@ import java.util.Map; import java.util.ServiceLoader; import net.java.html.BrwsrCtx; -import org.apidesign.html.json.tck.KnockoutTCK; +import org.netbeans.html.json.tck.KnockoutTCK; /** * diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/net/java/html/json/tests/WebSocketTest.java --- a/json-tck/src/main/java/net/java/html/json/tests/WebSocketTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json-tck/src/main/java/net/java/html/json/tests/WebSocketTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -47,7 +47,7 @@ import net.java.html.json.Models; import net.java.html.json.OnReceive; import net.java.html.json.Property; -import org.apidesign.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KOTest; /** Testing support of WebSocket communication. * diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/org/apidesign/html/json/tck/JavaScriptTCK.java --- a/json-tck/src/main/java/org/apidesign/html/json/tck/JavaScriptTCK.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.json.tck; - -import net.java.html.js.tests.JavaScriptBodyTest; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.boot.spi.Fn.Presenter; - -/** Entry point for those who want to verify that their implementation of - * {@link Presenter} is good enough to support existing Java/JavaScript - * communication use-cases. Subclass this class, get list of {@link #testClasses() classes} - * find methods annotated by {@link KOTest} annotation and execute them. - *

- * - * @author Jaroslav Tulach - * @since 0.7 - */ -public abstract class JavaScriptTCK { - /** Gives you list of classes included in the TCK. Their test methods - * are annotated by {@link KOTest} annotation. The methods are public - * instance methods that take no arguments. The method should be - * invoke in a presenter context {@link Fn#activate(org.apidesign.html.boot.spi.Fn.Presenter)}. - * - * @return classes with methods annotated by {@link KOTest} annotation - */ - protected static Class[] testClasses() { - return new Class[] { - JavaScriptBodyTest.class - }; - } - -} diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/org/apidesign/html/json/tck/KOTest.java --- a/json-tck/src/main/java/org/apidesign/html/json/tck/KOTest.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.json.tck; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** Annotates method that is part of {@link KnockoutTCK test compatibility kit} - * and should be executed in appropriate environment. The method annotated by - * this annotation will be public instance method of its class - * with no arguments. - * - * @author Jaroslav Tulach - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface KOTest { -} diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/org/apidesign/html/json/tck/KnockoutTCK.java --- a/json-tck/src/main/java/org/apidesign/html/json/tck/KnockoutTCK.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,141 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.json.tck; - -import java.net.URI; -import java.util.Map; -import net.java.html.BrwsrCtx; -import net.java.html.json.tests.ConvertTypesTest; -import net.java.html.json.tests.JSONTest; -import net.java.html.json.tests.KnockoutTest; -import net.java.html.json.tests.MinesTest; -import net.java.html.json.tests.OperationsTest; -import net.java.html.json.tests.Utils; -import net.java.html.json.tests.WebSocketTest; -import org.apidesign.html.context.spi.Contexts.Builder; -import org.openide.util.lookup.ServiceProvider; - -/** Entry point for providers of different HTML binding technologies (like - * Knockout.js in JavaFX's WebView). Sample usage: - * -

-{@link ServiceProvider @ServiceProvider}(service = KnockoutTCK.class)
-public final class MyKnockoutBindingTest extends KnockoutTCK {
-    {@link Override @Override}
-    protected BrwsrCtx createContext() {
-        // use {@link Builder}.{@link Builder#build() build}();
-    }
-
-    {@code @}{@link org.testng.annotations.Factory} public static Object[] create() {
-        return VMTest.newTests().withClasses({@link KnockoutTCK#testClasses}()).build();
-    }
-}
- * 
- * - * @author Jaroslav Tulach - */ -public abstract class KnockoutTCK { - protected KnockoutTCK() { - Utils.registerTCK(this); - } - - /** Implement to create new context for the test. - * Use {@link Builder} to set context for your technology up. - * @return the final context for the test - */ - public abstract BrwsrCtx createContext(); - - /** Create a JSON object as seen by the technology - * @param values mapping from names to values of properties - * @return the JSON object with filled in values - */ - public abstract Object createJSON(Map values); - - /** Executes script in the context of current window - * - * @param script the JavaScript code to execute - * @param arguments arguments sent to the script (can be referenced as arguments[0]) - * @return the output of the execution - */ - public abstract Object executeScript(String script, Object[] arguments); - - /** Creates a URL which later returns content with given - * mimeType and content. The - * content may be processed by the provided parameters. - * - * @param content what should be available on the URL. Can contain $0 - * $1 to reference parameters by their position - * @param mimeType the type of the resource - * @param parameters names of parameters as reference by content - * @return URI the test can connect to to obtain the (processed) content - */ - public abstract URI prepareURL(String content, String mimeType, String[] parameters); - - /** Gives you list of classes included in the TCK. Their test methods - * are annotated by {@link KOTest} annotation. The methods are public - * instance methods that take no arguments. - * - * @return classes with methods annotated by {@link KOTest} annotation - */ - protected static Class[] testClasses() { - return new Class[] { - ConvertTypesTest.class, - JSONTest.class, - KnockoutTest.class, - MinesTest.class, - OperationsTest.class, - WebSocketTest.class - }; - } - - /** Some implementations cannot fully support web sockets and fail. - * - * @return true, if UnsupportedOperationException reported from a web - * socket open operation is acceptable reply - */ - public boolean canFailWebSocketTest() { - return false; - } - - -} diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/org/netbeans/html/json/tck/JavaScriptTCK.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json-tck/src/main/java/org/netbeans/html/json/tck/JavaScriptTCK.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,72 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.json.tck; + +import net.java.html.js.tests.JavaScriptBodyTest; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn.Presenter; + +/** Entry point for those who want to verify that their implementation of + * {@link Presenter} is good enough to support existing Java/JavaScript + * communication use-cases. Subclass this class, get list of {@link #testClasses() classes} + * find methods annotated by {@link KOTest} annotation and execute them. + *

+ * + * @author Jaroslav Tulach + * @since 0.7 + */ +public abstract class JavaScriptTCK { + /** Gives you list of classes included in the TCK. Their test methods + * are annotated by {@link KOTest} annotation. The methods are public + * instance methods that take no arguments. The method should be + * invoke in a presenter context {@link Fn#activate(org.netbeans.html.boot.spi.Fn.Presenter)}. + * + * @return classes with methods annotated by {@link KOTest} annotation + */ + protected static Class[] testClasses() { + return new Class[] { + JavaScriptBodyTest.class + }; + } + +} diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/org/netbeans/html/json/tck/KOTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json-tck/src/main/java/org/netbeans/html/json/tck/KOTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,60 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.json.tck; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** Annotates method that is part of {@link KnockoutTCK test compatibility kit} + * and should be executed in appropriate environment. The method annotated by + * this annotation will be public instance method of its class + * with no arguments. + * + * @author Jaroslav Tulach + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface KOTest { +} diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/java/org/netbeans/html/json/tck/KnockoutTCK.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json-tck/src/main/java/org/netbeans/html/json/tck/KnockoutTCK.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,141 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.json.tck; + +import java.net.URI; +import java.util.Map; +import net.java.html.BrwsrCtx; +import net.java.html.json.tests.ConvertTypesTest; +import net.java.html.json.tests.JSONTest; +import net.java.html.json.tests.KnockoutTest; +import net.java.html.json.tests.MinesTest; +import net.java.html.json.tests.OperationsTest; +import net.java.html.json.tests.Utils; +import net.java.html.json.tests.WebSocketTest; +import org.netbeans.html.context.spi.Contexts.Builder; +import org.openide.util.lookup.ServiceProvider; + +/** Entry point for providers of different HTML binding technologies (like + * Knockout.js in JavaFX's WebView). Sample usage: + * +

+{@link ServiceProvider @ServiceProvider}(service = KnockoutTCK.class)
+public final class MyKnockoutBindingTest extends KnockoutTCK {
+    {@link Override @Override}
+    protected BrwsrCtx createContext() {
+        // use {@link Builder}.{@link Builder#build() build}();
+    }
+
+    {@code @}{@link org.testng.annotations.Factory} public static Object[] create() {
+        return VMTest.newTests().withClasses({@link KnockoutTCK#testClasses}()).build();
+    }
+}
+ * 
+ * + * @author Jaroslav Tulach + */ +public abstract class KnockoutTCK { + protected KnockoutTCK() { + Utils.registerTCK(this); + } + + /** Implement to create new context for the test. + * Use {@link Builder} to set context for your technology up. + * @return the final context for the test + */ + public abstract BrwsrCtx createContext(); + + /** Create a JSON object as seen by the technology + * @param values mapping from names to values of properties + * @return the JSON object with filled in values + */ + public abstract Object createJSON(Map values); + + /** Executes script in the context of current window + * + * @param script the JavaScript code to execute + * @param arguments arguments sent to the script (can be referenced as arguments[0]) + * @return the output of the execution + */ + public abstract Object executeScript(String script, Object[] arguments); + + /** Creates a URL which later returns content with given + * mimeType and content. The + * content may be processed by the provided parameters. + * + * @param content what should be available on the URL. Can contain $0 + * $1 to reference parameters by their position + * @param mimeType the type of the resource + * @param parameters names of parameters as reference by content + * @return URI the test can connect to to obtain the (processed) content + */ + public abstract URI prepareURL(String content, String mimeType, String[] parameters); + + /** Gives you list of classes included in the TCK. Their test methods + * are annotated by {@link KOTest} annotation. The methods are public + * instance methods that take no arguments. + * + * @return classes with methods annotated by {@link KOTest} annotation + */ + protected static Class[] testClasses() { + return new Class[] { + ConvertTypesTest.class, + JSONTest.class, + KnockoutTest.class, + MinesTest.class, + OperationsTest.class, + WebSocketTest.class + }; + } + + /** Some implementations cannot fully support web sockets and fail. + * + * @return true, if UnsupportedOperationException reported from a web + * socket open operation is acceptable reply + */ + public boolean canFailWebSocketTest() { + return false; + } + + +} diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/resources/org/apidesign/html/json/tck/package.html --- a/json-tck/src/main/resources/org/apidesign/html/json/tck/package.html Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ - - - - - - - - -
Entry point to the - test compatibility kit. -
- - diff -r 892b0a823f46 -r bdc3d696dd4a json-tck/src/main/resources/org/netbeans/html/json/tck/package.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json-tck/src/main/resources/org/netbeans/html/json/tck/package.html Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,56 @@ + + + + + + + + +
Entry point to the + test compatibility kit. +
+ + diff -r 892b0a823f46 -r bdc3d696dd4a json/pom.xml --- a/json/pom.xml Tue Aug 26 17:43:37 2014 +0200 +++ b/json/pom.xml Tue Aug 26 18:13:30 2014 +0200 @@ -14,7 +14,7 @@ http://maven.apache.org UTF-8 - net.java.html.json,org.apidesign.html.json.spi + net.java.html.json,org.netbeans.html.json.spi diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/apidesign/html/json/spi/FunctionBinding.java --- a/json/src/main/java/org/apidesign/html/json/spi/FunctionBinding.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.json.spi; - -import net.java.html.BrwsrCtx; -import net.java.html.json.Function; -import net.java.html.json.Model; - -/** Describes a function provided by the {@link Model} and - * annotated by {@link Function} annotation. - * - * @author Jaroslav Tulach - */ -public abstract class FunctionBinding { - FunctionBinding() { - } - - /** Returns name of the function. - * @return function name - */ - public abstract String getFunctionName(); - - /** - * Calls the function provided data associated with current element, as well - * as information about the event that triggered the event. - * - * @param data data associated with selected element - * @param ev event (with additional properties) that triggered the event - */ - public abstract void call(Object data, Object ev); - - static FunctionBinding registerFunction(String name, int index, M model, Proto.Type access) { - return new Impl(name, index, model, access); - } - - private static final class Impl extends FunctionBinding { - final String name; - private final M model; - private final Proto.Type access; - private final int index; - - public Impl(String name, int index, M model, Proto.Type access) { - this.name = name; - this.index = index; - this.model = model; - this.access = access; - } - - @Override - public String getFunctionName() { - return name; - } - - @Override - public void call(final Object data, final Object ev) { - BrwsrCtx ctx = access.protoFor(model).getContext(); - class Dispatch implements Runnable { - @Override - public void run() { - try { - access.call(model, index, data, ev); - } catch (Throwable ex) { - ex.printStackTrace(); - } - } - } - ctx.execute(new Dispatch()); - } - } -} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/apidesign/html/json/spi/JSONCall.java --- a/json/src/main/java/org/apidesign/html/json/spi/JSONCall.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.json.spi; - -import java.io.IOException; -import java.io.OutputStream; -import net.java.html.BrwsrCtx; -import org.netbeans.html.json.impl.RcvrJSON; - -/** Description of a JSON call request that is supposed to be processed - * by {@link Transfer#loadJSON(org.apidesign.html.json.spi.JSONCall)} implementors. - * - * @author Jaroslav Tulach - */ -public final class JSONCall { - private final RcvrJSON whenDone; - private final String urlBefore; - private final String urlAfter; - private final String method; - private final Object data; - private final BrwsrCtx ctx; - - JSONCall(BrwsrCtx ctx, RcvrJSON whenDone, String urlBefore, String urlAfter, String method, Object data) { - this.ctx = ctx; - this.whenDone = whenDone; - this.urlBefore = urlBefore; - this.urlAfter = urlAfter; - this.method = method; - this.data = data; - } - - /** Do we have some data to send? Can the {@link #writeData(java.io.OutputStream)} method be - * called? - * - * @return true, if the call has some data to send - */ - public boolean isDoOutput() { - return this.data != null; - } - - public void writeData(OutputStream os) throws IOException { - if (this.data == null) { - throw new IOException("No data!"); - } - os.write(this.data.toString().getBytes("UTF-8")); - os.flush(); - } - - public String getMethod() { - return method; - } - - public boolean isJSONP() { - return urlAfter != null; - } - - public String composeURL(String jsonpCallback) { - if ((urlAfter == null) != (jsonpCallback == null)) { - throw new IllegalStateException(); - } - if (urlAfter != null) { - return urlBefore + jsonpCallback + urlAfter; - } else { - return urlBefore; - } - } - - public void notifySuccess(Object result) { - if (result == null) { - dispatch(RcvrJSON.MsgEvnt.createOpen()); - } else { - dispatch(RcvrJSON.MsgEvnt.createMessage(result)); - } - } - - public void notifyError(Throwable error) { - if (error == null) { - dispatch(RcvrJSON.MsgEvnt.createClose()); - } else { - dispatch(RcvrJSON.MsgEvnt.createError(error)); - } - } - - private void dispatch(final RcvrJSON.MsgEvnt ev) { - ctx.execute(new Runnable() { - @Override - public void run() { - ev.dispatch(whenDone); - } - }); - } - - public String getMessage() { - return this.data.toString(); - } -} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/apidesign/html/json/spi/Observers.java --- a/json/src/main/java/org/apidesign/html/json/spi/Observers.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,221 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.json.spi; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -/** - * - * @author Jaroslav Tulach - */ -final class Observers { - private static final LinkedList GLOBAL = new LinkedList(); - private final List watchers = new ArrayList(); - private final List observers = new ArrayList(); - - Observers() { - assert Thread.holdsLock(GLOBAL); - } - - static void beginComputing(Proto p, String name) { - synchronized (GLOBAL) { - verifyUnlocked(p); - final Watcher nw = new Watcher(p, name); - GLOBAL.push(nw); - } - } - - static void verifyUnlocked(Proto p) { - synchronized (GLOBAL) { - for (Watcher w : GLOBAL) { - if (w.proto == p) { - throw new IllegalStateException("Re-entrant attempt to access " + p); - } - } - } - } - - static void accessingValue(Proto p, String propName) { - synchronized (GLOBAL) { - verifyUnlocked(p); - for (Watcher w : GLOBAL) { - Observers mine = p.observers(true); - mine.add(w, new Ref(w, propName)); - } - } - } - - static void finishComputing(Proto p) { - synchronized (GLOBAL) { - Watcher w = GLOBAL.pop(); - if (w.proto != p) { - throw new IllegalStateException("Inconsistency: " + w.proto + " != " + p); - } - if (w.prop != null) { - Observers mine = p.observers(true); - mine.add(w); - } - } - } - - private static final class Ref extends WeakReference { - private final String prop; - - public Ref(Watcher ref, String prop) { - super(ref); - this.prop = prop; - } - - final Watcher watcher() { - Watcher w = get(); - if (w == null) { - return null; - } - final Observers o = w.proto.observers(false); - if (o == null) { - return null; - } - if (o.find(w.prop) == w) { - return w; - } - return null; - } - } - - private Watcher find(String prop) { - if (prop == null) { - return null; - } - for (Watcher w : watchers) { - if (prop.equals(w.prop)) { - return w; - } - } - return null; - } - - final void add(Watcher w) { - for (int i = 0; i < watchers.size(); i++) { - Watcher ith = watchers.get(i); - if (w.prop == null) { - if (ith.prop == null) { - watchers.set(i, w); - return; - } - } else if (w.prop.equals(ith.prop)) { - watchers.set(i, w); - return; - } - } - watchers.add(w); - } - - static final void valueHasMutated(Proto p, String propName) { - List mutated = new LinkedList(); - synchronized (GLOBAL) { - Observers mine = p.observers(false); - if (mine == null) { - return; - } - Iterator it = mine.observers.iterator(); - while (it.hasNext()) { - Ref ref = it.next(); - if (ref.get() == null) { - it.remove(); - continue; - } - if (ref.prop.equals(propName)) { - Watcher w = ref.watcher(); - if (w != null) { - mutated.add(w); - } - } - } - } - for (Watcher w : mutated) { - w.proto.valueHasMutated(w.prop); - } - } - - void add(Watcher w, Ref r) { - Thread.holdsLock(GLOBAL); - if (w == null) { - return; - } - Iterator it = observers.iterator(); - while (it.hasNext()) { - Ref ref = it.next(); - if (r == ref) { - return; - } - final Watcher rw = ref.get(); - if (rw == null) { - it.remove(); - continue; - } - if (rw == w && r.prop.equals(r.prop)) { - return; - } - } - observers.add(r); - } - - private static final class Watcher { - final Proto proto; - final String prop; - - Watcher(Proto proto, String prop) { - this.proto = proto; - this.prop = prop; - } - - @Override - public String toString() { - return "Watcher: " + proto + ", " + prop; - } - } -} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/apidesign/html/json/spi/PropertyBinding.java --- a/json/src/main/java/org/apidesign/html/json/spi/PropertyBinding.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,168 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.json.spi; - -import net.java.html.BrwsrCtx; -import org.netbeans.html.json.impl.Bindings; -import org.netbeans.html.json.impl.JSON; -import org.netbeans.html.json.impl.PropertyBindingAccessor; -import org.netbeans.html.json.impl.RcvrJSON; - -/** Describes a property when one is asked to - * bind it - * - * @author Jaroslav Tulach - */ -public abstract class PropertyBinding { - PropertyBinding() { - } - - static { - new PropertyBindingAccessor() { - @Override - protected JSONCall newCall(BrwsrCtx ctx, RcvrJSON callback, String urlBefore, String urlAfter, String method, Object data) { - return new JSONCall(ctx, callback, urlBefore, urlAfter, method, data); - } - - @Override - protected Bindings bindings(Proto proto, boolean initialize) { - return initialize ? proto.initBindings() : proto.getBindings(); - } - - @Override - protected void notifyChange(Proto proto, int propIndex) { - proto.onChange(propIndex); - } - - @Override - protected Proto findProto(Proto.Type type, Object object) { - return type.protoFor(object); - } - - @Override - protected Model cloneTo(Proto.Type type, Model model, BrwsrCtx c) { - return type.cloneTo(model, c); - } - - @Override - protected Object read(Proto.Type from, BrwsrCtx c, Object data) { - return from.read(c, data); - } - - @Override - protected PropertyBinding newBinding( - Proto.Type access, Bindings bindings, String name, - int index, M model, boolean readOnly - ) { - return new Impl(bindings, name, index, model, access, readOnly); - } - }; - } - - /** Name of the property this binding represents. - * @return name of the property - */ - public abstract String getPropertyName(); - - /** Changes value of the property. Can be called only on dedicated - * thread. See {@link Technology#runSafe(java.lang.Runnable)}. - * - * @param v new value of the property - */ - public abstract void setValue(Object v); - - /** Obtains current value of the property this binding represents. - * Can be called only on dedicated - * thread. See {@link Technology#runSafe(java.lang.Runnable)}. - * - * @return the value or null - */ - public abstract Object getValue(); - - /** Is this property read only? Or can one call {@link #setValue(java.lang.Object)}? - * - * @return true, if this property is read only - */ - public abstract boolean isReadOnly(); - - private static final class Impl extends PropertyBinding { - public final String name; - public final boolean readOnly; - private final M model; - private final Proto.Type access; - private final Bindings bindings; - private final int index; - - public Impl(Bindings bindings, String name, int index, M model, Proto.Type access, boolean readOnly) { - this.bindings = bindings; - this.name = name; - this.index = index; - this.model = model; - this.access = access; - this.readOnly = readOnly; - } - - @Override - public void setValue(Object v) { - access.setValue(model, index, v); - } - - @Override - public Object getValue() { - Object v = access.getValue(model, index); - Object r = JSON.find(v, bindings); - return r == null ? v : r; - } - - @Override - public boolean isReadOnly() { - return readOnly; - } - - @Override - public String getPropertyName() { - return name; - } - } // end of PBData - -} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/apidesign/html/json/spi/Proto.java --- a/json/src/main/java/org/apidesign/html/json/spi/Proto.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,843 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.json.spi; - -import java.util.Collection; -import java.util.List; -import net.java.html.BrwsrCtx; -import net.java.html.json.ComputedProperty; -import net.java.html.json.Model; -import org.netbeans.html.json.impl.Bindings; -import org.netbeans.html.json.impl.JSON; -import org.netbeans.html.json.impl.JSONList; -import org.netbeans.html.json.impl.RcvrJSON; -import org.netbeans.html.json.impl.RcvrJSON.MsgEvnt; - -/** Object associated with one instance of a model generated by the - * {@link Model} annotation. Contains methods the generated class can - * use to communicate with behind the scene associated {@link Technology}. - * Each {@link Proto} object is associated with - * singletonizer-like interface {@link Type} which provides the - * associated {@link Technology} the necessary information about the - * generated {@link Model} class. - * - * @author Jaroslav Tulach - * @since 0.7 - */ -public final class Proto { - private final Object obj; - private final Type type; - private final net.java.html.BrwsrCtx context; - private org.netbeans.html.json.impl.Bindings ko; - private Observers observers; - - Proto(Object obj, Type type, BrwsrCtx context) { - this.obj = obj; - this.type = type; - this.context = context; - } - - /** Browser context this proto object and its associated model - * are operating-in. - * - * @return the associated context - */ - public BrwsrCtx getContext() { - return context; - } - - /** Acquires global lock to compute a {@link ComputedProperty derived property} - * on this proto object. This proto object must not be locked yet. No - * dependency tracking is performed. - * - * @throws IllegalStateException if already locked - */ - public void acquireLock() throws IllegalStateException { - acquireLock(null); - } - - /** Acquires global lock to compute a {@link ComputedProperty derived property} - * on this proto object. This proto object must not be locked yet. The - * name of the property is used to track dependencies on own - * properties of other proto objects - when they are changed, this - * {@link #valueHasMutated(java.lang.String) property is changed too}. - * - * @param propName name of property we are about to compute - * @throws IllegalStateException thrown when there is a cyclic - * call is detected - * @since 0.9 - */ - public void acquireLock(String propName) throws IllegalStateException { - Observers.beginComputing(this, propName); - } - - /** A property on this proto object is about to be accessed. Verifies - * whether this proto object is accessible - e.g. it has not been - * {@link #acquireLock() locked yet}. If everything is OK, the - * propName is recorded in the chain of dependencies - * tracked by {@link #acquireLock(java.lang.String)} and watched by - * {@link #valueHasMutated(java.lang.String)}. - * - * @param propName name of the property that is requested - * @throws IllegalStateException if the model is locked - * @since 0.9 - */ - public void accessProperty(String propName) throws IllegalStateException { - Observers.accessingValue(this, propName); - } - - /** Verifies the model is not locked otherwise throws an exception. - * @throws IllegalStateException if the model is locked - */ - public void verifyUnlocked() throws IllegalStateException { - Observers.verifyUnlocked(this); - } - - /** When modifications are over, the model is switched into - * unlocked state by calling this method. - */ - public void releaseLock() { - Observers.finishComputing(this); - } - - /** Whenever model changes a property. It should notify the - * associated technology by calling this method. - * Since 0.8.3: This method may be called by any thread - it reschedules - * its actual execution into appropriate one by using - * {@link BrwsrCtx#execute(java.lang.Runnable)}. - * - * @param propName name of the changed property - */ - public void valueHasMutated(final String propName) { - context.execute(new Runnable() { - @Override - public void run() { - if (ko != null) { - ko.valueHasMutated(propName, null, null); - } - Observers.valueHasMutated(Proto.this, propName); - } - }); - } - - /** Whenever model changes a propertyit should notify the - * associated technology. Either by calling this method - * (if the new value is known and different to the old one) or - * via (slightly ineffective) {@link #valueHasMutated(java.lang.String)} - * method. - * Since 0.8.3: This method may be called by any thread - it reschedules - * its actual execution into appropriate one by using - * {@link BrwsrCtx#execute(java.lang.Runnable)}. - * - * @param propName name of the changed property - * @param oldValue provides previous value of the property - * @param newValue provides new value of the property - * @since 0.7.6 - */ - public void valueHasMutated( - final String propName, final Object oldValue, final Object newValue - ) { - context.execute(new Runnable() { - @Override - public void run() { - if (ko != null) { - ko.valueHasMutated(propName, oldValue, newValue); - } - Observers.valueHasMutated(Proto.this, propName); - } - }); - } - - /** Initializes the associated model in the current {@link #getContext() context}. - * In case of knockout.js technology, applies given bindings - * of the current model to the body element of the page. - */ - public void applyBindings() { - initBindings().applyBindings(); - } - - /** Invokes the provided runnable in the {@link #getContext() context} - * of the browser. If the caller is already on the right thread, the - * run.run() is invoked immediately and synchronously. - * Otherwise the method returns immediately and the run() - * method is performed later - * - * @param run the action to execute - */ - public void runInBrowser(Runnable run) { - context.execute(run); - } - - /** Invokes the specified function index in the {@link #getContext() context} - * of the browser. If the caller is already on the right thread, the - * index-th function is invoked immediately and synchronously. - * Otherwise the method returns immediately and the function is invoked - * later. - * - * @param index the index of the function as will be passed to - * {@link Type#call(java.lang.Object, int, java.lang.Object, java.lang.Object)} - * method - * @param args array of arguments that will be passed as - * data argument of the call method. - * @since 0.7.6 - */ - public void runInBrowser(final int index, final Object... args) { - context.execute(new Runnable() { - @Override - public void run() { - try { - type.call(obj, index, args, null); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }); - } - - /** Initializes the provided collection with a content of the array. - * The initialization can only be done soon after the the collection - * is created, otherwise an exception is throw - * - * @param to the collection to initialize (assumed to be empty) - * @param array the array to add to the collection - * @throws IllegalStateException if the system has already been initialized - */ - public void initTo(Collection to, Object array) { - if (ko != null) { - throw new IllegalStateException(); - } - if (to instanceof JSONList) { - ((JSONList)to).init(array); - } else { - JSONList.init(to, array); - } - } - - /** Takes an object representing JSON result and extract some of its - * properties. It is assumed that the props and - * values arrays have the same length. - * - * @param json the JSON object (actual type depends on the associated - * {@link Technology}) - * @param props list of properties to extract - * @param values array that will be filled with extracted values - */ - public void extract(Object json, String[] props, Object[] values) { - JSON.extract(context, json, props, values); - } - - /** Converts raw JSON data into a Java {@link Model} class. - * - * @param type of the model class - * @param modelClass the type of the class to create - * @param data the raw JSON data - * @return newly created instance of the model class - */ - public T read(Class modelClass, Object data) { - return JSON.read(context, modelClass, data); - } - - /** Initializes asynchronous JSON connection to specified URL. Delegates - * to {@link #loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...) } - * with no extra parameters. - * - * @param index the callback index to be used when a reply is received - * to call {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)}. - * - * @param urlBefore the part of the URL before JSON-P callback parameter - * @param urlAfter the rest of the URL or null if no JSON-P is used - * @param method method to use for connection to the server - * @param data string, number or a {@link Model} generated class to send to - * the server when doing a query - */ - public void loadJSON(final int index, - String urlBefore, String urlAfter, String method, - final Object data - ) { - loadJSON(index, urlBefore, urlAfter, method, data, new Object[0]); - } - - /** Initializes asynchronous JSON connection to specified URL. The - * method returns immediately and later does callback later. - * - * @param index the callback index to be used when a reply is received - * to call {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)}. - * - * @param urlBefore the part of the URL before JSON-P callback parameter - * @param urlAfter the rest of the URL or null if no JSON-P is used - * @param method method to use for connection to the server - * @param data string, number or a {@link Model} generated class to send to - * the server when doing a query - * @param params extra params to pass back when calling - * {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object, java.lang.Object[])} - * @since 0.8.1 - */ - public void loadJSON(final int index, - String urlBefore, String urlAfter, String method, - final Object data, final Object... params - ) { - class Rcvr extends RcvrJSON { - @Override - protected void onMessage(MsgEvnt msg) { - type.onMessage(obj, index, 1, msg.getValues(), params); - } - - @Override - protected void onError(MsgEvnt msg) { - type.onMessage(obj, index, 2, msg.getException(), params); - } - } - JSON.loadJSON(context, new Rcvr(), urlBefore, urlAfter, method, data); - } - - /** Opens new WebSocket connection to the specified URL. - * - * @param index the index to use later during callbacks to - * {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)} - * @param url the ws:// or wss:// URL to connect to - * @param data data to send to server (usually null) - * @return returns a non-null object representing the socket - * which can be used when calling {@link #wsSend(java.lang.Object, java.lang.String, java.lang.Object) } - */ - public Object wsOpen(final int index, String url, Object data) { - class WSrcvr extends RcvrJSON { - @Override - protected void onError(MsgEvnt msg) { - type.onMessage(obj, index, 2, msg.getException()); - } - - @Override - protected void onMessage(MsgEvnt msg) { - type.onMessage(obj, index, 1, msg.getValues()); - } - - @Override - protected void onClose(MsgEvnt msg) { - type.onMessage(obj, index, 3, null); - } - - @Override - protected void onOpen(MsgEvnt msg) { - type.onMessage(obj, index, 0, null); - } - } - return JSON.openWS(context, new WSrcvr(), url, data); - } - - /** Sends a message to existing socket. - * - * @param webSocket the socket to send message to - * @param url the ws:// or wss:// URL to connect to, - * preferably the same as the one used when the socket was - * {@link #wsOpen(int, java.lang.String, java.lang.Object) opened} - * @param data the data to send or null if the socket is - * supposed to be closed - */ - public void wsSend(Object webSocket, String url, Object data) { - ((JSON.WS)webSocket).send(context, url, data); - } - - /** Converts raw data (one of its properties) to string representation. - * - * @param data the object - * @param propName the name of object property or null - * if the whole object should be converted - * @return the string representation of the object or its property - */ - public String toString(Object data, String propName) { - return JSON.toString(context, data, propName); - } - - /** Converts raw data (one of its properties) to a number representation. - * - * @param data the object - * @param propName the name of object property or null - * if the whole object should be converted - * @return the number representation of the object or its property - */ - public Number toNumber(Object data, String propName) { - return JSON.toNumber(context, data, propName); - } - - /** Converts raw JSON data into a {@link Model} class representation. - * - * @param type of the model to create - * @param type class of the model to create - * @param data raw JSON data (depends on associated {@link Technology}) - * @return new instances of the model class filled with values from the - * data object - */ - public T toModel(Class type, Object data) { - return JSON.toModel(context, type, data, null); - } - - /** Creates new JSON like observable list. - * - * @param the type of the list elements - * @param propName name of a property this list is associated with - * @param onChange index of the property to use when the list is modified - * during callback to {@link Type#onChange(java.lang.Object, int)} - * @param dependingProps the array of {@link ComputedProperty derived properties} - * that depend on the value of the list - * @return new, empty list associated with this proto-object and its model - */ - public List createList(String propName, int onChange, String... dependingProps) { - return new JSONList(this, propName, onChange, dependingProps); - } - - /** Copies content of one collection to another, re-assigning all its - * elements from their current context to the new ctx. - * - * @param type of the collections - * @param to the target collection to be filled with cloned values - * @param ctx context for the new collection - * @param from original collection with its data - */ - public void cloneList(Collection to, BrwsrCtx ctx, Collection from) { - Boolean isModel = null; - for (T t : from) { - if (isModel == null) { - isModel = JSON.isModel(t.getClass()); - } - if (isModel) { - to.add(JSON.bindTo(t, ctx)); - } else { - to.add(t); - } - } - } - - // - // internal state - // - - final String toStr() { - return "Proto[" + obj + "]@" + Integer.toHexString(System.identityHashCode(this)); - } - - final Bindings initBindings() { - if (ko == null) { - Bindings b = Bindings.apply(context, obj); - PropertyBinding[] pb = new PropertyBinding[type.propertyNames.length]; - for (int i = 0; i < pb.length; i++) { - pb[i] = b.registerProperty( - type.propertyNames[i], i, obj, type, type.propertyReadOnly[i] - ); - } - FunctionBinding[] fb = new FunctionBinding[type.functions.length]; - for (int i = 0; i < fb.length; i++) { - fb[i] = FunctionBinding.registerFunction( - type.functions[i], i, obj, type - ); - } - ko = b; - b.finish(obj, pb, fb); - } - return ko; - } - - final Bindings getBindings() { - return ko; - } - - final void onChange(int index) { - type.onChange(obj, index); - } - - final Observers observers(boolean create) { - if (create && observers == null) { - observers = new Observers(); - } - return observers; - } - - /** Functionality used by the code generated by annotation - * processor for the {@link net.java.html.json.Model} annotation. - * - * @param the generated class - * @since 0.7 - */ - public static abstract class Type { - private final Class clazz; - private final String[] propertyNames; - private final boolean[] propertyReadOnly; - private final String[] functions; - - /** Constructor for subclasses generated by the annotation processor - * associated with {@link net.java.html.json.Model} annotation. - * - * @param clazz the generated model class - * @param modelFor the original class annotated by the {@link net.java.html.json.Model} annotation. - * @param properties number of properties the class has - * @param functions number of functions the class has - */ - protected Type( - Class clazz, Class modelFor, int properties, int functions - ) { - assert getClass().getName().endsWith("$Html4JavaType"); - try { - assert getClass().getDeclaringClass() == clazz; - } catch (SecurityException ex) { - // OK, no check - } - this.clazz = clazz; - this.propertyNames = new String[properties]; - this.propertyReadOnly = new boolean[properties]; - this.functions = new String[functions]; - JSON.register(clazz, this); - } - - /** Registers property for the type. It is expected each index - * is initialized only once. - * - * @param name name of the property - * @param index index of the property - * @param readOnly is the property read only? - */ - protected final void registerProperty(String name, int index, boolean readOnly) { - assert propertyNames[index] == null; - propertyNames[index] = name; - propertyReadOnly[index] = readOnly; - } - - /** Registers function of given name at given index. - * - * @param name name of the function - * @param index name of the type - */ - protected final void registerFunction(String name, int index) { - assert functions[index] == null; - functions[index] = name; - } - - /** Creates new proto-object for given {@link Model} class bound to - * provided context. - * - * @param obj instance of appropriate {@link Model} class - * @param context the browser context - * @return new proto-object that the generated class can use for - * communication with the infrastructure - */ - public Proto createProto(Object obj, BrwsrCtx context) { - return new Proto(obj, this, context); - } - - // - // Implemented by subclasses - // - - /** Sets value of a {@link #registerProperty(java.lang.String, int, boolean) registered property} - * to new value. - * - * @param model the instance of {@link Model model class} - * @param index index of the property used during registration - * @param value the value to set the property to - */ - protected abstract void setValue(Model model, int index, Object value); - - /** Obtains and returns value of a - * {@link #registerProperty(java.lang.String, int, boolean) registered property}. - * - * @param model the instance of {@link Model model class} - * @param index index of the property used during registration - * @return current value of the property - */ - protected abstract Object getValue(Model model, int index); - - /** Invokes a {@link #registerFunction(java.lang.String, int)} registered function - * on given object. - * - * @param model the instance of {@link Model model class} - * @param index index of the property used during registration - * @param data the currently selected object the function is about to operate on - * @param event the event that triggered the event - * @throws Exception the method can throw exception which is then logged - */ - protected abstract void call(Model model, int index, Object data, Object event) - throws Exception; - - /** Re-binds the model object to new browser context. - * - * @param model the instance of {@link Model model class} - * @param ctx browser context to clone the object to - * @return new instance of the model suitable for new context - */ - protected abstract Model cloneTo(Model model, BrwsrCtx ctx); - - /** Reads raw JSON data and converts them to our model class. - * - * @param c the browser context to work in - * @param json raw JSON data to get values from - * @return new instance of model class filled by the data - */ - protected abstract Model read(BrwsrCtx c, Object json); - - /** Called when a {@link #registerProperty(java.lang.String, int, boolean) registered property} - * changes its value. - * - * @param model the object that has the property - * @param index the index of the property during registration - */ - protected abstract void onChange(Model model, int index); - - /** Finds out if there is an associated proto-object for given - * object. - * - * @param object an object, presumably (but not necessarily) instance of Model class - * @return associated proto-object or null - */ - protected abstract Proto protoFor(Object object); - - /** Called to report results of asynchronous over-the-wire - * communication. Result of calling {@link Proto#wsOpen(int, java.lang.String, java.lang.Object)} - * or {@link Proto#loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)}. - * - * @param model the instance of the model class - * @param index index used during initiating the communication (via loadJSON or wsOpen calls) - * @param type type of the message: 0 - onOpen, 1 - onMessage, 2 - onError, 3 - onClose - - * not all messages are applicable to all communication protocols (JSON has only 1 and 2). - * @param data null or string, number or a {@link Model} class - * obtained to the server as a response - */ - protected void onMessage(Model model, int index, int type, Object data) { - onMessage(model, index, type, data, new Object[0]); - } - - /** Called to report results of asynchronous over-the-wire - * communication. Result of calling {@link Proto#wsOpen(int, java.lang.String, java.lang.Object)} - * or {@link Proto#loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)}. - * - * @param model the instance of the model class - * @param index index used during initiating the communication (via loadJSON or wsOpen calls) - * @param type type of the message: 0 - onOpen, 1 - onMessage, 2 - onError, 3 - onClose - - * not all messages are applicable to all communication protocols (JSON has only 1 and 2). - * @param data null or string, number or a {@link Model} class - * obtained to the server as a response - * @param params extra parameters as passed for example to - * {@link Proto#loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)} - * method - * @since 0.8.1 - */ - protected void onMessage(Model model, int index, int type, Object data, Object[] params) { - onMessage(model, index, type, data); - } - - // - // Various support methods the generated classes use - // - - /** Converts and array of raw JSON objects into an array of typed - * Java {@link Model} classes. - * - * @param the type of the destination array - * @param context browser context to use - * @param src array of raw JSON objects - * @param destType type of the individual array elements - * @param dest array to be filled with read type instances - */ - public void copyJSON(BrwsrCtx context, Object[] src, Class destType, T[] dest) { - for (int i = 0; i < src.length && i < dest.length; i++) { - dest[i] = org.netbeans.html.json.impl.JSON.read(context, destType, src[i]); - } - } - - /** Compares two objects that can be converted to integers. - * @param a first value - * @param b second value - * @return true if they are the same - */ - public final boolean isSame(int a, int b) { - return a == b; - } - - /** Compares two objects that can be converted to (floating point) - * numbers. - * @param a first value - * @param b second value - * @return true if they are the same - */ - public final boolean isSame(double a, double b) { - return a == b; - } - - /** Compares two objects for being the same - e.g. either == - * or equals. - * @param a first value - * @param b second value - * @return true if they are equals - */ - public final boolean isSame(Object a, Object b) { - if (a == b) { - return true; - } - if (a == null || b == null) { - return false; - } - return a.equals(b); - } - - /** Cumulative hash function. Adds hashcode of the object to the - * previous value. - * @param o the object (or null) - * @param h the previous value of the hash - * @return new hash - the old one xor the object's one - */ - public final int hashPlus(Object o, int h) { - return o == null ? h : h ^ o.hashCode(); - } - - /** Converts an object to its JSON value. - * - * @param obj the object to convert - * @return JSON representation of the object - */ - public final String toJSON(Object obj) { - return JSON.toJSON(obj); - } - - /** Converts the value to string. - * - * @param val the value - * @return the converted value - */ - public final String stringValue(Object val) { - return JSON.stringValue(val); - } - - /** Converts the value to number. - * - * @param val the value - * @return the converted value - */ - public final Number numberValue(Object val) { - return JSON.numberValue(val); - } - - /** Converts the value to character. - * - * @param val the value - * @return the converted value - */ - public final Character charValue(Object val) { - return JSON.charValue(val); - } - - /** Converts the value to boolean. - * - * @param val the value - * @return the converted value - */ - public final Boolean boolValue(Object val) { - return JSON.boolValue(val); - } - - /** Extracts value of specific type from given object. - * - * @param the type of object one is interested in - * @param type the type - * @param val the object to convert to type - * @return the converted value - */ - public final T extractValue(Class type, Object val) { - if (Number.class.isAssignableFrom(type)) { - val = numberValue(val); - } - if (Boolean.class == type) { - val = boolValue(val); - } - if (String.class == type) { - val = stringValue(val); - } - if (Character.class == type) { - val = charValue(val); - } - if (Integer.class == type) { - val = val instanceof Number ? ((Number) val).intValue() : 0; - } - if (Long.class == type) { - val = val instanceof Number ? ((Number) val).longValue() : 0; - } - if (Short.class == type) { - val = val instanceof Number ? ((Number) val).shortValue() : 0; - } - if (Byte.class == type) { - val = val instanceof Number ? ((Number) val).byteValue() : 0; - } - if (Double.class == type) { - val = val instanceof Number ? ((Number) val).doubleValue() : Double.NaN; - } - if (Float.class == type) { - val = val instanceof Number ? ((Number) val).floatValue() : Float.NaN; - } - if (type.isEnum() && val instanceof String) { - val = Enum.valueOf(type.asSubclass(Enum.class), (String)val); - } - return type.cast(val); - } - - /** Special dealing with array & {@link List} values. This method - * takes the provided collection, empties it and fills it again - * with values extracted from value (which is supposed - * to be an array). - * - * @param the type of list elements - * @param arr collection to fill with elements in value - * @param type the type of elements in the collection - * @param value array of elements to put into the collecition. If - * value is not an array it is wrapped into array with only element - * @since 1.0 - */ - public final void replaceValue(Collection arr, Class type, Object value) { - Object[] newArr; - if (value instanceof Object[]) { - newArr = (Object[]) value; - } else { - newArr = new Object[] { value }; - } - arr.clear(); - for (Object e : newArr) { - arr.add(extractValue(type, e)); - } - } - } -} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/apidesign/html/json/spi/Technology.java --- a/json/src/main/java/org/apidesign/html/json/spi/Technology.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,169 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.json.spi; - -import net.java.html.BrwsrCtx; -import net.java.html.json.Model; -import net.java.html.json.Models; - -/** An implementation of a binding between model classes (see {@link Model}) - * and particular technology like knockout.js - * in a browser window, etc. - * - * @author Jaroslav Tulach - */ -public interface Technology { - /** Creates an object to wrap the provided model object. The model - * has previously been generated by annotation processor associated - * with {@link Model} annotation. - * - * @param model the model generated from {@link Model} - * @return internal object representing the model - */ - public Data wrapModel(Object model); - - /** Converts an element potentially representing a model into the model. - * @param the type of the modelClass - * @param modelClass expected class to convert the data to - * @param data the current data provided from the browser - * @return the instance of modelClass somehow extracted from the data, may return null - */ - public M toModel(Class modelClass, Object data); - - /** Binds a property between the model and the data as used by the technology. - * - * @param b the description of the requested binding - * @param model the original instance of the model - * @param data the data to bind with the model - */ - public void bind(PropertyBinding b, Object model, Data data); - - /** Model for given data has changed its value. The technology is - * supposed to update its state (for example DOM nodes associated - * with the model). The update usually happens asynchronously. - * - * @param data technology's own representation of the model - * @param propertyName name of the model property that changed - */ - public void valueHasMutated(Data data, String propertyName); - - public void expose(FunctionBinding fb, Object model, Data d); - - /** Applies given data to current context (usually an HTML page). - * @param data the data to apply - */ - public void applyBindings(Data data); - - /** - * Some technologies may require wrapping a Java array into a special - * object. In such case they may return it from this method. - * - * @param arr original array - * @return wrapped array - */ - public Object wrapArray(Object[] arr); - - /** - * Run given runnable in a safe mode. If the runnable can be executed - * immediately, do it. If we need to switch to some other thread, do it - * and invoke r asynchronously immediately returning from the call to - * runSafe method. - * - * @param r the runnable to execute - * @deprecated Use {@link BrwsrCtx#execute(java.lang.Runnable)} - */ - @Deprecated - public void runSafe(Runnable r); - - /** For certain rendering technologies it may be more efficient to register - * property and function bindings for one instance of the model at once, - * rather then doing it incrementally via - * {@link Technology#expose(org.apidesign.html.json.spi.FunctionBinding, java.lang.Object, java.lang.Object) } - * and - * {@link Technology#bind(org.apidesign.html.json.spi.PropertyBinding, java.lang.Object, java.lang.Object) }. - * In such case implement the {@link #wrapModel(java.lang.Object, org.apidesign.html.json.spi.PropertyBinding[], org.apidesign.html.json.spi.FunctionBinding[]) } - * method of this interface and it will be called instead of the - * previous two ones. - * - * @since 0.6 - */ - public static interface BatchInit extends Technology { - /** Wrap the given model into redering technology appropriate object - * D and expose given properties and functions on it. - * - * @param model the {@link Models#isModel(java.lang.Class) model} in Java - * @param propArr array of property bindings to expose - * @param funcArr array of functions to expose - * @return appropriate wrapper around the model - */ - public D wrapModel(Object model, PropertyBinding[] propArr, FunctionBinding[] funcArr); - } - - /** Some technologies are more effective when number of calls between - * Java and JavaScript is limited - to do that when a value of property - * is changed they should implement this additional interface. - * - * @param internal type of the technology - * @since 0.7.6 - */ - public static interface ValueMutated extends Technology { - /** Model for given data has changed its value. The technology is - * supposed to update its state (for example DOM nodes associated - * with the model). The update usually happens asynchronously. - *

- * If both oldValue and newValue are - * null then the real value of the technology is - * not known. - *

- * If this method is present, then it is called instead of - * old, plain {@link #valueHasMutated(java.lang.Object, java.lang.String)} - * which is never called by the infrastructure then. - * - * @param data technology's own representation of the model - * @param propertyName name of the model property that changed - * @param oldValue provides previous value of the property - * @param newValue provides new value of the property - */ - public void valueHasMutated(D data, String propertyName, Object oldValue, Object newValue); - } -} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/apidesign/html/json/spi/Transfer.java --- a/json/src/main/java/org/apidesign/html/json/spi/Transfer.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.json.spi; - -import java.io.IOException; -import java.io.InputStream; -import org.apidesign.html.context.spi.Contexts.Builder; - -/** A {@link Builder service provider interface} responsible for - * conversion of JSON objects to Java ones and vice-versa. - * - * @author Jaroslav Tulach - */ -public interface Transfer { - /** - * Called to inspect properties of an object (usually a JSON or JavaScript - * wrapper). - * - * @param obj the object to inspect - * @param props the names of properties to check on the object - * obj - * @param values array of the same length as props should be - * filled by values of properties on the obj. If a property is - * not defined, a null value should be stored in the array - */ - public void extract(Object obj, String[] props, Object[] values); - - /** Reads content of a stream and creates its JSON representation. - * The returned object is implementation dependant. It however needs - * to be acceptable as first argument of {@link #extract(java.lang.Object, java.lang.String[], java.lang.Object[]) extract} - * method. If the stream contains representation or a JSON array, - * an Object[] should be returned - each of its members should, by itself - * be acceptable argument to - * the {@link #extract(java.lang.Object, java.lang.String[], java.lang.Object[]) extract} method. - * - * @param is input stream to read data from - * @return an object representing the JSON data - * @throws IOException if something goes wrong - */ - public Object toJSON(InputStream is) throws IOException; - - /** Starts the JSON or JSONP query. - * - * @param call description of the call to make - */ - public void loadJSON(JSONCall call); - -} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/apidesign/html/json/spi/WSTransfer.java --- a/json/src/main/java/org/apidesign/html/json/spi/WSTransfer.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.json.spi; - -import net.java.html.BrwsrCtx; -import org.apidesign.html.context.spi.Contexts.Provider; - -/** Interface for providers of WebSocket protocol. Register into a - * {@link BrwsrCtx context} in your own {@link Provider} - * - * @author Jaroslav Tulach - * @param internal implementation type representing the socket - * @since 0.5 - */ -public interface WSTransfer { - /** Initializes a web socket. The callback object should - * have mostly empty values: {@link JSONCall#isDoOutput()} should be - * false and thus there should be no {@link JSONCall#getMessage()}. - * The method of connection {@link JSONCall#getMethod()} is "WebSocket". - * Once the connection is open call {@link JSONCall#notifySuccess(java.lang.Object) notifySuccess(null)}. - * When the server sends some data then, pass them to - * {@link JSONCall#notifySuccess(java.lang.Object) notifySuccess} method - * as well. If there is an error call {@link JSONCall#notifyError(java.lang.Throwable)}. - * - * @param url the URL to connect to - * @param callback a way to provide results back to the client - * @return your object representing the established web socket - */ - public WebSocket open(String url, JSONCall callback); - - /** Sends data to the server. The most important value - * of the data parameter is {@link JSONCall#getMessage()}, - * rest can be ignored. - * - * @param socket internal representation of the socket - * @param data the message to be sent - */ - public void send(WebSocket socket, JSONCall data); - - /** A request to close the socket. - * @param socket internal representation of the socket - */ - public void close(WebSocket socket); -} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/apidesign/html/json/spi/package.html --- a/json/src/main/java/org/apidesign/html/json/spi/package.html Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ - - - -

Service Provider Interfaces for those who wish to integrate own - technology with the HTML for Java API. -
- - diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/impl/Bindings.java --- a/json/src/main/java/org/netbeans/html/json/impl/Bindings.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/main/java/org/netbeans/html/json/impl/Bindings.java Tue Aug 26 18:13:30 2014 +0200 @@ -43,10 +43,10 @@ package org.netbeans.html.json.impl; import net.java.html.BrwsrCtx; -import org.apidesign.html.json.spi.FunctionBinding; -import org.apidesign.html.json.spi.PropertyBinding; -import org.apidesign.html.json.spi.Proto; -import org.apidesign.html.json.spi.Technology; +import org.netbeans.html.json.spi.FunctionBinding; +import org.netbeans.html.json.spi.PropertyBinding; +import org.netbeans.html.json.spi.Proto; +import org.netbeans.html.json.spi.Technology; /** * diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/impl/JSON.java --- a/json/src/main/java/org/netbeans/html/json/impl/JSON.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/main/java/org/netbeans/html/json/impl/JSON.java Tue Aug 26 18:13:30 2014 +0200 @@ -49,14 +49,14 @@ import java.util.HashMap; import java.util.Map; import net.java.html.BrwsrCtx; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.FunctionBinding; -import org.apidesign.html.json.spi.JSONCall; -import org.apidesign.html.json.spi.PropertyBinding; -import org.apidesign.html.json.spi.Proto; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; -import org.apidesign.html.json.spi.WSTransfer; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.FunctionBinding; +import org.netbeans.html.json.spi.JSONCall; +import org.netbeans.html.json.spi.PropertyBinding; +import org.netbeans.html.json.spi.Proto; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; +import org.netbeans.html.json.spi.WSTransfer; /** * diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/impl/JSONList.java --- a/json/src/main/java/org/netbeans/html/json/impl/JSONList.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/main/java/org/netbeans/html/json/impl/JSONList.java Tue Aug 26 18:13:30 2014 +0200 @@ -46,7 +46,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; -import org.apidesign.html.json.spi.Proto; +import org.netbeans.html.json.spi.Proto; /** * diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java --- a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Tue Aug 26 18:13:30 2014 +0200 @@ -224,7 +224,7 @@ w.append("import net.java.html.json.*;\n"); w.append("public final class ").append(className).append(" implements Cloneable {\n"); w.append(" private static final Html4JavaType TYPE = new Html4JavaType();\n"); - w.append(" private final org.apidesign.html.json.spi.Proto proto;\n"); + w.append(" private final org.netbeans.html.json.spi.Proto proto;\n"); w.append(body.toString()); w.append(" private static Class<" + inPckName(e) + "> modelFor() { return null; }\n"); w.append(" private ").append(className).append("(net.java.html.BrwsrCtx context) {\n"); @@ -309,7 +309,7 @@ } w.append(" };\n"); } - w.append(" private static class Html4JavaType extends org.apidesign.html.json.spi.Proto.Type<").append(className).append("> {\n"); + w.append(" private static class Html4JavaType extends org.netbeans.html.json.spi.Proto.Type<").append(className).append("> {\n"); w.append(" private Html4JavaType() {\n super(").append(className).append(".class, "). append(inPckName(e)).append(".class, " + propsGetSet.size() + ", " + functionsCount + ");\n"); @@ -383,7 +383,7 @@ w.append(" }\n"); w.append(" throw new UnsupportedOperationException();\n"); w.append(" }\n"); - w.append(" @Override public org.apidesign.html.json.spi.Proto protoFor(Object obj) {\n"); + w.append(" @Override public org.netbeans.html.json.spi.Proto protoFor(Object obj) {\n"); w.append(" return ((" + className + ")obj).proto;"); w.append(" }\n"); w.append(" @Override public void onChange(" + className + " model, int type) {\n"); diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/impl/PropertyBindingAccessor.java --- a/json/src/main/java/org/netbeans/html/json/impl/PropertyBindingAccessor.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/main/java/org/netbeans/html/json/impl/PropertyBindingAccessor.java Tue Aug 26 18:13:30 2014 +0200 @@ -43,10 +43,10 @@ package org.netbeans.html.json.impl; import net.java.html.BrwsrCtx; -import org.apidesign.html.json.spi.FunctionBinding; -import org.apidesign.html.json.spi.JSONCall; -import org.apidesign.html.json.spi.PropertyBinding; -import org.apidesign.html.json.spi.Proto; +import org.netbeans.html.json.spi.FunctionBinding; +import org.netbeans.html.json.spi.JSONCall; +import org.netbeans.html.json.spi.PropertyBinding; +import org.netbeans.html.json.spi.Proto; /** * diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/spi/FunctionBinding.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json/src/main/java/org/netbeans/html/json/spi/FunctionBinding.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,110 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.json.spi; + +import net.java.html.BrwsrCtx; +import net.java.html.json.Function; +import net.java.html.json.Model; + +/** Describes a function provided by the {@link Model} and + * annotated by {@link Function} annotation. + * + * @author Jaroslav Tulach + */ +public abstract class FunctionBinding { + FunctionBinding() { + } + + /** Returns name of the function. + * @return function name + */ + public abstract String getFunctionName(); + + /** + * Calls the function provided data associated with current element, as well + * as information about the event that triggered the event. + * + * @param data data associated with selected element + * @param ev event (with additional properties) that triggered the event + */ + public abstract void call(Object data, Object ev); + + static FunctionBinding registerFunction(String name, int index, M model, Proto.Type access) { + return new Impl(name, index, model, access); + } + + private static final class Impl extends FunctionBinding { + final String name; + private final M model; + private final Proto.Type access; + private final int index; + + public Impl(String name, int index, M model, Proto.Type access) { + this.name = name; + this.index = index; + this.model = model; + this.access = access; + } + + @Override + public String getFunctionName() { + return name; + } + + @Override + public void call(final Object data, final Object ev) { + BrwsrCtx ctx = access.protoFor(model).getContext(); + class Dispatch implements Runnable { + @Override + public void run() { + try { + access.call(model, index, data, ev); + } catch (Throwable ex) { + ex.printStackTrace(); + } + } + } + ctx.execute(new Dispatch()); + } + } +} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/spi/JSONCall.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json/src/main/java/org/netbeans/html/json/spi/JSONCall.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,136 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.json.spi; + +import java.io.IOException; +import java.io.OutputStream; +import net.java.html.BrwsrCtx; +import org.netbeans.html.json.impl.RcvrJSON; + +/** Description of a JSON call request that is supposed to be processed + * by {@link Transfer#loadJSON(org.netbeans.html.json.spi.JSONCall)} implementors. + * + * @author Jaroslav Tulach + */ +public final class JSONCall { + private final RcvrJSON whenDone; + private final String urlBefore; + private final String urlAfter; + private final String method; + private final Object data; + private final BrwsrCtx ctx; + + JSONCall(BrwsrCtx ctx, RcvrJSON whenDone, String urlBefore, String urlAfter, String method, Object data) { + this.ctx = ctx; + this.whenDone = whenDone; + this.urlBefore = urlBefore; + this.urlAfter = urlAfter; + this.method = method; + this.data = data; + } + + /** Do we have some data to send? Can the {@link #writeData(java.io.OutputStream)} method be + * called? + * + * @return true, if the call has some data to send + */ + public boolean isDoOutput() { + return this.data != null; + } + + public void writeData(OutputStream os) throws IOException { + if (this.data == null) { + throw new IOException("No data!"); + } + os.write(this.data.toString().getBytes("UTF-8")); + os.flush(); + } + + public String getMethod() { + return method; + } + + public boolean isJSONP() { + return urlAfter != null; + } + + public String composeURL(String jsonpCallback) { + if ((urlAfter == null) != (jsonpCallback == null)) { + throw new IllegalStateException(); + } + if (urlAfter != null) { + return urlBefore + jsonpCallback + urlAfter; + } else { + return urlBefore; + } + } + + public void notifySuccess(Object result) { + if (result == null) { + dispatch(RcvrJSON.MsgEvnt.createOpen()); + } else { + dispatch(RcvrJSON.MsgEvnt.createMessage(result)); + } + } + + public void notifyError(Throwable error) { + if (error == null) { + dispatch(RcvrJSON.MsgEvnt.createClose()); + } else { + dispatch(RcvrJSON.MsgEvnt.createError(error)); + } + } + + private void dispatch(final RcvrJSON.MsgEvnt ev) { + ctx.execute(new Runnable() { + @Override + public void run() { + ev.dispatch(whenDone); + } + }); + } + + public String getMessage() { + return this.data.toString(); + } +} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/spi/Observers.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json/src/main/java/org/netbeans/html/json/spi/Observers.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,221 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.json.spi; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +/** + * + * @author Jaroslav Tulach + */ +final class Observers { + private static final LinkedList GLOBAL = new LinkedList(); + private final List watchers = new ArrayList(); + private final List observers = new ArrayList(); + + Observers() { + assert Thread.holdsLock(GLOBAL); + } + + static void beginComputing(Proto p, String name) { + synchronized (GLOBAL) { + verifyUnlocked(p); + final Watcher nw = new Watcher(p, name); + GLOBAL.push(nw); + } + } + + static void verifyUnlocked(Proto p) { + synchronized (GLOBAL) { + for (Watcher w : GLOBAL) { + if (w.proto == p) { + throw new IllegalStateException("Re-entrant attempt to access " + p); + } + } + } + } + + static void accessingValue(Proto p, String propName) { + synchronized (GLOBAL) { + verifyUnlocked(p); + for (Watcher w : GLOBAL) { + Observers mine = p.observers(true); + mine.add(w, new Ref(w, propName)); + } + } + } + + static void finishComputing(Proto p) { + synchronized (GLOBAL) { + Watcher w = GLOBAL.pop(); + if (w.proto != p) { + throw new IllegalStateException("Inconsistency: " + w.proto + " != " + p); + } + if (w.prop != null) { + Observers mine = p.observers(true); + mine.add(w); + } + } + } + + private static final class Ref extends WeakReference { + private final String prop; + + public Ref(Watcher ref, String prop) { + super(ref); + this.prop = prop; + } + + final Watcher watcher() { + Watcher w = get(); + if (w == null) { + return null; + } + final Observers o = w.proto.observers(false); + if (o == null) { + return null; + } + if (o.find(w.prop) == w) { + return w; + } + return null; + } + } + + private Watcher find(String prop) { + if (prop == null) { + return null; + } + for (Watcher w : watchers) { + if (prop.equals(w.prop)) { + return w; + } + } + return null; + } + + final void add(Watcher w) { + for (int i = 0; i < watchers.size(); i++) { + Watcher ith = watchers.get(i); + if (w.prop == null) { + if (ith.prop == null) { + watchers.set(i, w); + return; + } + } else if (w.prop.equals(ith.prop)) { + watchers.set(i, w); + return; + } + } + watchers.add(w); + } + + static final void valueHasMutated(Proto p, String propName) { + List mutated = new LinkedList(); + synchronized (GLOBAL) { + Observers mine = p.observers(false); + if (mine == null) { + return; + } + Iterator it = mine.observers.iterator(); + while (it.hasNext()) { + Ref ref = it.next(); + if (ref.get() == null) { + it.remove(); + continue; + } + if (ref.prop.equals(propName)) { + Watcher w = ref.watcher(); + if (w != null) { + mutated.add(w); + } + } + } + } + for (Watcher w : mutated) { + w.proto.valueHasMutated(w.prop); + } + } + + void add(Watcher w, Ref r) { + Thread.holdsLock(GLOBAL); + if (w == null) { + return; + } + Iterator it = observers.iterator(); + while (it.hasNext()) { + Ref ref = it.next(); + if (r == ref) { + return; + } + final Watcher rw = ref.get(); + if (rw == null) { + it.remove(); + continue; + } + if (rw == w && r.prop.equals(r.prop)) { + return; + } + } + observers.add(r); + } + + private static final class Watcher { + final Proto proto; + final String prop; + + Watcher(Proto proto, String prop) { + this.proto = proto; + this.prop = prop; + } + + @Override + public String toString() { + return "Watcher: " + proto + ", " + prop; + } + } +} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/spi/PropertyBinding.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json/src/main/java/org/netbeans/html/json/spi/PropertyBinding.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,168 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.json.spi; + +import net.java.html.BrwsrCtx; +import org.netbeans.html.json.impl.Bindings; +import org.netbeans.html.json.impl.JSON; +import org.netbeans.html.json.impl.PropertyBindingAccessor; +import org.netbeans.html.json.impl.RcvrJSON; + +/** Describes a property when one is asked to + * bind it + * + * @author Jaroslav Tulach + */ +public abstract class PropertyBinding { + PropertyBinding() { + } + + static { + new PropertyBindingAccessor() { + @Override + protected JSONCall newCall(BrwsrCtx ctx, RcvrJSON callback, String urlBefore, String urlAfter, String method, Object data) { + return new JSONCall(ctx, callback, urlBefore, urlAfter, method, data); + } + + @Override + protected Bindings bindings(Proto proto, boolean initialize) { + return initialize ? proto.initBindings() : proto.getBindings(); + } + + @Override + protected void notifyChange(Proto proto, int propIndex) { + proto.onChange(propIndex); + } + + @Override + protected Proto findProto(Proto.Type type, Object object) { + return type.protoFor(object); + } + + @Override + protected Model cloneTo(Proto.Type type, Model model, BrwsrCtx c) { + return type.cloneTo(model, c); + } + + @Override + protected Object read(Proto.Type from, BrwsrCtx c, Object data) { + return from.read(c, data); + } + + @Override + protected PropertyBinding newBinding( + Proto.Type access, Bindings bindings, String name, + int index, M model, boolean readOnly + ) { + return new Impl(bindings, name, index, model, access, readOnly); + } + }; + } + + /** Name of the property this binding represents. + * @return name of the property + */ + public abstract String getPropertyName(); + + /** Changes value of the property. Can be called only on dedicated + * thread. See {@link Technology#runSafe(java.lang.Runnable)}. + * + * @param v new value of the property + */ + public abstract void setValue(Object v); + + /** Obtains current value of the property this binding represents. + * Can be called only on dedicated + * thread. See {@link Technology#runSafe(java.lang.Runnable)}. + * + * @return the value or null + */ + public abstract Object getValue(); + + /** Is this property read only? Or can one call {@link #setValue(java.lang.Object)}? + * + * @return true, if this property is read only + */ + public abstract boolean isReadOnly(); + + private static final class Impl extends PropertyBinding { + public final String name; + public final boolean readOnly; + private final M model; + private final Proto.Type access; + private final Bindings bindings; + private final int index; + + public Impl(Bindings bindings, String name, int index, M model, Proto.Type access, boolean readOnly) { + this.bindings = bindings; + this.name = name; + this.index = index; + this.model = model; + this.access = access; + this.readOnly = readOnly; + } + + @Override + public void setValue(Object v) { + access.setValue(model, index, v); + } + + @Override + public Object getValue() { + Object v = access.getValue(model, index); + Object r = JSON.find(v, bindings); + return r == null ? v : r; + } + + @Override + public boolean isReadOnly() { + return readOnly; + } + + @Override + public String getPropertyName() { + return name; + } + } // end of PBData + +} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/spi/Proto.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json/src/main/java/org/netbeans/html/json/spi/Proto.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,843 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.json.spi; + +import java.util.Collection; +import java.util.List; +import net.java.html.BrwsrCtx; +import net.java.html.json.ComputedProperty; +import net.java.html.json.Model; +import org.netbeans.html.json.impl.Bindings; +import org.netbeans.html.json.impl.JSON; +import org.netbeans.html.json.impl.JSONList; +import org.netbeans.html.json.impl.RcvrJSON; +import org.netbeans.html.json.impl.RcvrJSON.MsgEvnt; + +/** Object associated with one instance of a model generated by the + * {@link Model} annotation. Contains methods the generated class can + * use to communicate with behind the scene associated {@link Technology}. + * Each {@link Proto} object is associated with + * singletonizer-like interface {@link Type} which provides the + * associated {@link Technology} the necessary information about the + * generated {@link Model} class. + * + * @author Jaroslav Tulach + * @since 0.7 + */ +public final class Proto { + private final Object obj; + private final Type type; + private final net.java.html.BrwsrCtx context; + private org.netbeans.html.json.impl.Bindings ko; + private Observers observers; + + Proto(Object obj, Type type, BrwsrCtx context) { + this.obj = obj; + this.type = type; + this.context = context; + } + + /** Browser context this proto object and its associated model + * are operating-in. + * + * @return the associated context + */ + public BrwsrCtx getContext() { + return context; + } + + /** Acquires global lock to compute a {@link ComputedProperty derived property} + * on this proto object. This proto object must not be locked yet. No + * dependency tracking is performed. + * + * @throws IllegalStateException if already locked + */ + public void acquireLock() throws IllegalStateException { + acquireLock(null); + } + + /** Acquires global lock to compute a {@link ComputedProperty derived property} + * on this proto object. This proto object must not be locked yet. The + * name of the property is used to track dependencies on own + * properties of other proto objects - when they are changed, this + * {@link #valueHasMutated(java.lang.String) property is changed too}. + * + * @param propName name of property we are about to compute + * @throws IllegalStateException thrown when there is a cyclic + * call is detected + * @since 0.9 + */ + public void acquireLock(String propName) throws IllegalStateException { + Observers.beginComputing(this, propName); + } + + /** A property on this proto object is about to be accessed. Verifies + * whether this proto object is accessible - e.g. it has not been + * {@link #acquireLock() locked yet}. If everything is OK, the + * propName is recorded in the chain of dependencies + * tracked by {@link #acquireLock(java.lang.String)} and watched by + * {@link #valueHasMutated(java.lang.String)}. + * + * @param propName name of the property that is requested + * @throws IllegalStateException if the model is locked + * @since 0.9 + */ + public void accessProperty(String propName) throws IllegalStateException { + Observers.accessingValue(this, propName); + } + + /** Verifies the model is not locked otherwise throws an exception. + * @throws IllegalStateException if the model is locked + */ + public void verifyUnlocked() throws IllegalStateException { + Observers.verifyUnlocked(this); + } + + /** When modifications are over, the model is switched into + * unlocked state by calling this method. + */ + public void releaseLock() { + Observers.finishComputing(this); + } + + /** Whenever model changes a property. It should notify the + * associated technology by calling this method. + * Since 0.8.3: This method may be called by any thread - it reschedules + * its actual execution into appropriate one by using + * {@link BrwsrCtx#execute(java.lang.Runnable)}. + * + * @param propName name of the changed property + */ + public void valueHasMutated(final String propName) { + context.execute(new Runnable() { + @Override + public void run() { + if (ko != null) { + ko.valueHasMutated(propName, null, null); + } + Observers.valueHasMutated(Proto.this, propName); + } + }); + } + + /** Whenever model changes a propertyit should notify the + * associated technology. Either by calling this method + * (if the new value is known and different to the old one) or + * via (slightly ineffective) {@link #valueHasMutated(java.lang.String)} + * method. + * Since 0.8.3: This method may be called by any thread - it reschedules + * its actual execution into appropriate one by using + * {@link BrwsrCtx#execute(java.lang.Runnable)}. + * + * @param propName name of the changed property + * @param oldValue provides previous value of the property + * @param newValue provides new value of the property + * @since 0.7.6 + */ + public void valueHasMutated( + final String propName, final Object oldValue, final Object newValue + ) { + context.execute(new Runnable() { + @Override + public void run() { + if (ko != null) { + ko.valueHasMutated(propName, oldValue, newValue); + } + Observers.valueHasMutated(Proto.this, propName); + } + }); + } + + /** Initializes the associated model in the current {@link #getContext() context}. + * In case of knockout.js technology, applies given bindings + * of the current model to the body element of the page. + */ + public void applyBindings() { + initBindings().applyBindings(); + } + + /** Invokes the provided runnable in the {@link #getContext() context} + * of the browser. If the caller is already on the right thread, the + * run.run() is invoked immediately and synchronously. + * Otherwise the method returns immediately and the run() + * method is performed later + * + * @param run the action to execute + */ + public void runInBrowser(Runnable run) { + context.execute(run); + } + + /** Invokes the specified function index in the {@link #getContext() context} + * of the browser. If the caller is already on the right thread, the + * index-th function is invoked immediately and synchronously. + * Otherwise the method returns immediately and the function is invoked + * later. + * + * @param index the index of the function as will be passed to + * {@link Type#call(java.lang.Object, int, java.lang.Object, java.lang.Object)} + * method + * @param args array of arguments that will be passed as + * data argument of the call method. + * @since 0.7.6 + */ + public void runInBrowser(final int index, final Object... args) { + context.execute(new Runnable() { + @Override + public void run() { + try { + type.call(obj, index, args, null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + }); + } + + /** Initializes the provided collection with a content of the array. + * The initialization can only be done soon after the the collection + * is created, otherwise an exception is throw + * + * @param to the collection to initialize (assumed to be empty) + * @param array the array to add to the collection + * @throws IllegalStateException if the system has already been initialized + */ + public void initTo(Collection to, Object array) { + if (ko != null) { + throw new IllegalStateException(); + } + if (to instanceof JSONList) { + ((JSONList)to).init(array); + } else { + JSONList.init(to, array); + } + } + + /** Takes an object representing JSON result and extract some of its + * properties. It is assumed that the props and + * values arrays have the same length. + * + * @param json the JSON object (actual type depends on the associated + * {@link Technology}) + * @param props list of properties to extract + * @param values array that will be filled with extracted values + */ + public void extract(Object json, String[] props, Object[] values) { + JSON.extract(context, json, props, values); + } + + /** Converts raw JSON data into a Java {@link Model} class. + * + * @param type of the model class + * @param modelClass the type of the class to create + * @param data the raw JSON data + * @return newly created instance of the model class + */ + public T read(Class modelClass, Object data) { + return JSON.read(context, modelClass, data); + } + + /** Initializes asynchronous JSON connection to specified URL. Delegates + * to {@link #loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...) } + * with no extra parameters. + * + * @param index the callback index to be used when a reply is received + * to call {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)}. + * + * @param urlBefore the part of the URL before JSON-P callback parameter + * @param urlAfter the rest of the URL or null if no JSON-P is used + * @param method method to use for connection to the server + * @param data string, number or a {@link Model} generated class to send to + * the server when doing a query + */ + public void loadJSON(final int index, + String urlBefore, String urlAfter, String method, + final Object data + ) { + loadJSON(index, urlBefore, urlAfter, method, data, new Object[0]); + } + + /** Initializes asynchronous JSON connection to specified URL. The + * method returns immediately and later does callback later. + * + * @param index the callback index to be used when a reply is received + * to call {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)}. + * + * @param urlBefore the part of the URL before JSON-P callback parameter + * @param urlAfter the rest of the URL or null if no JSON-P is used + * @param method method to use for connection to the server + * @param data string, number or a {@link Model} generated class to send to + * the server when doing a query + * @param params extra params to pass back when calling + * {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object, java.lang.Object[])} + * @since 0.8.1 + */ + public void loadJSON(final int index, + String urlBefore, String urlAfter, String method, + final Object data, final Object... params + ) { + class Rcvr extends RcvrJSON { + @Override + protected void onMessage(MsgEvnt msg) { + type.onMessage(obj, index, 1, msg.getValues(), params); + } + + @Override + protected void onError(MsgEvnt msg) { + type.onMessage(obj, index, 2, msg.getException(), params); + } + } + JSON.loadJSON(context, new Rcvr(), urlBefore, urlAfter, method, data); + } + + /** Opens new WebSocket connection to the specified URL. + * + * @param index the index to use later during callbacks to + * {@link Type#onMessage(java.lang.Object, int, int, java.lang.Object)} + * @param url the ws:// or wss:// URL to connect to + * @param data data to send to server (usually null) + * @return returns a non-null object representing the socket + * which can be used when calling {@link #wsSend(java.lang.Object, java.lang.String, java.lang.Object) } + */ + public Object wsOpen(final int index, String url, Object data) { + class WSrcvr extends RcvrJSON { + @Override + protected void onError(MsgEvnt msg) { + type.onMessage(obj, index, 2, msg.getException()); + } + + @Override + protected void onMessage(MsgEvnt msg) { + type.onMessage(obj, index, 1, msg.getValues()); + } + + @Override + protected void onClose(MsgEvnt msg) { + type.onMessage(obj, index, 3, null); + } + + @Override + protected void onOpen(MsgEvnt msg) { + type.onMessage(obj, index, 0, null); + } + } + return JSON.openWS(context, new WSrcvr(), url, data); + } + + /** Sends a message to existing socket. + * + * @param webSocket the socket to send message to + * @param url the ws:// or wss:// URL to connect to, + * preferably the same as the one used when the socket was + * {@link #wsOpen(int, java.lang.String, java.lang.Object) opened} + * @param data the data to send or null if the socket is + * supposed to be closed + */ + public void wsSend(Object webSocket, String url, Object data) { + ((JSON.WS)webSocket).send(context, url, data); + } + + /** Converts raw data (one of its properties) to string representation. + * + * @param data the object + * @param propName the name of object property or null + * if the whole object should be converted + * @return the string representation of the object or its property + */ + public String toString(Object data, String propName) { + return JSON.toString(context, data, propName); + } + + /** Converts raw data (one of its properties) to a number representation. + * + * @param data the object + * @param propName the name of object property or null + * if the whole object should be converted + * @return the number representation of the object or its property + */ + public Number toNumber(Object data, String propName) { + return JSON.toNumber(context, data, propName); + } + + /** Converts raw JSON data into a {@link Model} class representation. + * + * @param type of the model to create + * @param type class of the model to create + * @param data raw JSON data (depends on associated {@link Technology}) + * @return new instances of the model class filled with values from the + * data object + */ + public T toModel(Class type, Object data) { + return JSON.toModel(context, type, data, null); + } + + /** Creates new JSON like observable list. + * + * @param the type of the list elements + * @param propName name of a property this list is associated with + * @param onChange index of the property to use when the list is modified + * during callback to {@link Type#onChange(java.lang.Object, int)} + * @param dependingProps the array of {@link ComputedProperty derived properties} + * that depend on the value of the list + * @return new, empty list associated with this proto-object and its model + */ + public List createList(String propName, int onChange, String... dependingProps) { + return new JSONList(this, propName, onChange, dependingProps); + } + + /** Copies content of one collection to another, re-assigning all its + * elements from their current context to the new ctx. + * + * @param type of the collections + * @param to the target collection to be filled with cloned values + * @param ctx context for the new collection + * @param from original collection with its data + */ + public void cloneList(Collection to, BrwsrCtx ctx, Collection from) { + Boolean isModel = null; + for (T t : from) { + if (isModel == null) { + isModel = JSON.isModel(t.getClass()); + } + if (isModel) { + to.add(JSON.bindTo(t, ctx)); + } else { + to.add(t); + } + } + } + + // + // internal state + // + + final String toStr() { + return "Proto[" + obj + "]@" + Integer.toHexString(System.identityHashCode(this)); + } + + final Bindings initBindings() { + if (ko == null) { + Bindings b = Bindings.apply(context, obj); + PropertyBinding[] pb = new PropertyBinding[type.propertyNames.length]; + for (int i = 0; i < pb.length; i++) { + pb[i] = b.registerProperty( + type.propertyNames[i], i, obj, type, type.propertyReadOnly[i] + ); + } + FunctionBinding[] fb = new FunctionBinding[type.functions.length]; + for (int i = 0; i < fb.length; i++) { + fb[i] = FunctionBinding.registerFunction( + type.functions[i], i, obj, type + ); + } + ko = b; + b.finish(obj, pb, fb); + } + return ko; + } + + final Bindings getBindings() { + return ko; + } + + final void onChange(int index) { + type.onChange(obj, index); + } + + final Observers observers(boolean create) { + if (create && observers == null) { + observers = new Observers(); + } + return observers; + } + + /** Functionality used by the code generated by annotation + * processor for the {@link net.java.html.json.Model} annotation. + * + * @param the generated class + * @since 0.7 + */ + public static abstract class Type { + private final Class clazz; + private final String[] propertyNames; + private final boolean[] propertyReadOnly; + private final String[] functions; + + /** Constructor for subclasses generated by the annotation processor + * associated with {@link net.java.html.json.Model} annotation. + * + * @param clazz the generated model class + * @param modelFor the original class annotated by the {@link net.java.html.json.Model} annotation. + * @param properties number of properties the class has + * @param functions number of functions the class has + */ + protected Type( + Class clazz, Class modelFor, int properties, int functions + ) { + assert getClass().getName().endsWith("$Html4JavaType"); + try { + assert getClass().getDeclaringClass() == clazz; + } catch (SecurityException ex) { + // OK, no check + } + this.clazz = clazz; + this.propertyNames = new String[properties]; + this.propertyReadOnly = new boolean[properties]; + this.functions = new String[functions]; + JSON.register(clazz, this); + } + + /** Registers property for the type. It is expected each index + * is initialized only once. + * + * @param name name of the property + * @param index index of the property + * @param readOnly is the property read only? + */ + protected final void registerProperty(String name, int index, boolean readOnly) { + assert propertyNames[index] == null; + propertyNames[index] = name; + propertyReadOnly[index] = readOnly; + } + + /** Registers function of given name at given index. + * + * @param name name of the function + * @param index name of the type + */ + protected final void registerFunction(String name, int index) { + assert functions[index] == null; + functions[index] = name; + } + + /** Creates new proto-object for given {@link Model} class bound to + * provided context. + * + * @param obj instance of appropriate {@link Model} class + * @param context the browser context + * @return new proto-object that the generated class can use for + * communication with the infrastructure + */ + public Proto createProto(Object obj, BrwsrCtx context) { + return new Proto(obj, this, context); + } + + // + // Implemented by subclasses + // + + /** Sets value of a {@link #registerProperty(java.lang.String, int, boolean) registered property} + * to new value. + * + * @param model the instance of {@link Model model class} + * @param index index of the property used during registration + * @param value the value to set the property to + */ + protected abstract void setValue(Model model, int index, Object value); + + /** Obtains and returns value of a + * {@link #registerProperty(java.lang.String, int, boolean) registered property}. + * + * @param model the instance of {@link Model model class} + * @param index index of the property used during registration + * @return current value of the property + */ + protected abstract Object getValue(Model model, int index); + + /** Invokes a {@link #registerFunction(java.lang.String, int)} registered function + * on given object. + * + * @param model the instance of {@link Model model class} + * @param index index of the property used during registration + * @param data the currently selected object the function is about to operate on + * @param event the event that triggered the event + * @throws Exception the method can throw exception which is then logged + */ + protected abstract void call(Model model, int index, Object data, Object event) + throws Exception; + + /** Re-binds the model object to new browser context. + * + * @param model the instance of {@link Model model class} + * @param ctx browser context to clone the object to + * @return new instance of the model suitable for new context + */ + protected abstract Model cloneTo(Model model, BrwsrCtx ctx); + + /** Reads raw JSON data and converts them to our model class. + * + * @param c the browser context to work in + * @param json raw JSON data to get values from + * @return new instance of model class filled by the data + */ + protected abstract Model read(BrwsrCtx c, Object json); + + /** Called when a {@link #registerProperty(java.lang.String, int, boolean) registered property} + * changes its value. + * + * @param model the object that has the property + * @param index the index of the property during registration + */ + protected abstract void onChange(Model model, int index); + + /** Finds out if there is an associated proto-object for given + * object. + * + * @param object an object, presumably (but not necessarily) instance of Model class + * @return associated proto-object or null + */ + protected abstract Proto protoFor(Object object); + + /** Called to report results of asynchronous over-the-wire + * communication. Result of calling {@link Proto#wsOpen(int, java.lang.String, java.lang.Object)} + * or {@link Proto#loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)}. + * + * @param model the instance of the model class + * @param index index used during initiating the communication (via loadJSON or wsOpen calls) + * @param type type of the message: 0 - onOpen, 1 - onMessage, 2 - onError, 3 - onClose - + * not all messages are applicable to all communication protocols (JSON has only 1 and 2). + * @param data null or string, number or a {@link Model} class + * obtained to the server as a response + */ + protected void onMessage(Model model, int index, int type, Object data) { + onMessage(model, index, type, data, new Object[0]); + } + + /** Called to report results of asynchronous over-the-wire + * communication. Result of calling {@link Proto#wsOpen(int, java.lang.String, java.lang.Object)} + * or {@link Proto#loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)}. + * + * @param model the instance of the model class + * @param index index used during initiating the communication (via loadJSON or wsOpen calls) + * @param type type of the message: 0 - onOpen, 1 - onMessage, 2 - onError, 3 - onClose - + * not all messages are applicable to all communication protocols (JSON has only 1 and 2). + * @param data null or string, number or a {@link Model} class + * obtained to the server as a response + * @param params extra parameters as passed for example to + * {@link Proto#loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)} + * method + * @since 0.8.1 + */ + protected void onMessage(Model model, int index, int type, Object data, Object[] params) { + onMessage(model, index, type, data); + } + + // + // Various support methods the generated classes use + // + + /** Converts and array of raw JSON objects into an array of typed + * Java {@link Model} classes. + * + * @param the type of the destination array + * @param context browser context to use + * @param src array of raw JSON objects + * @param destType type of the individual array elements + * @param dest array to be filled with read type instances + */ + public void copyJSON(BrwsrCtx context, Object[] src, Class destType, T[] dest) { + for (int i = 0; i < src.length && i < dest.length; i++) { + dest[i] = org.netbeans.html.json.impl.JSON.read(context, destType, src[i]); + } + } + + /** Compares two objects that can be converted to integers. + * @param a first value + * @param b second value + * @return true if they are the same + */ + public final boolean isSame(int a, int b) { + return a == b; + } + + /** Compares two objects that can be converted to (floating point) + * numbers. + * @param a first value + * @param b second value + * @return true if they are the same + */ + public final boolean isSame(double a, double b) { + return a == b; + } + + /** Compares two objects for being the same - e.g. either == + * or equals. + * @param a first value + * @param b second value + * @return true if they are equals + */ + public final boolean isSame(Object a, Object b) { + if (a == b) { + return true; + } + if (a == null || b == null) { + return false; + } + return a.equals(b); + } + + /** Cumulative hash function. Adds hashcode of the object to the + * previous value. + * @param o the object (or null) + * @param h the previous value of the hash + * @return new hash - the old one xor the object's one + */ + public final int hashPlus(Object o, int h) { + return o == null ? h : h ^ o.hashCode(); + } + + /** Converts an object to its JSON value. + * + * @param obj the object to convert + * @return JSON representation of the object + */ + public final String toJSON(Object obj) { + return JSON.toJSON(obj); + } + + /** Converts the value to string. + * + * @param val the value + * @return the converted value + */ + public final String stringValue(Object val) { + return JSON.stringValue(val); + } + + /** Converts the value to number. + * + * @param val the value + * @return the converted value + */ + public final Number numberValue(Object val) { + return JSON.numberValue(val); + } + + /** Converts the value to character. + * + * @param val the value + * @return the converted value + */ + public final Character charValue(Object val) { + return JSON.charValue(val); + } + + /** Converts the value to boolean. + * + * @param val the value + * @return the converted value + */ + public final Boolean boolValue(Object val) { + return JSON.boolValue(val); + } + + /** Extracts value of specific type from given object. + * + * @param the type of object one is interested in + * @param type the type + * @param val the object to convert to type + * @return the converted value + */ + public final T extractValue(Class type, Object val) { + if (Number.class.isAssignableFrom(type)) { + val = numberValue(val); + } + if (Boolean.class == type) { + val = boolValue(val); + } + if (String.class == type) { + val = stringValue(val); + } + if (Character.class == type) { + val = charValue(val); + } + if (Integer.class == type) { + val = val instanceof Number ? ((Number) val).intValue() : 0; + } + if (Long.class == type) { + val = val instanceof Number ? ((Number) val).longValue() : 0; + } + if (Short.class == type) { + val = val instanceof Number ? ((Number) val).shortValue() : 0; + } + if (Byte.class == type) { + val = val instanceof Number ? ((Number) val).byteValue() : 0; + } + if (Double.class == type) { + val = val instanceof Number ? ((Number) val).doubleValue() : Double.NaN; + } + if (Float.class == type) { + val = val instanceof Number ? ((Number) val).floatValue() : Float.NaN; + } + if (type.isEnum() && val instanceof String) { + val = Enum.valueOf(type.asSubclass(Enum.class), (String)val); + } + return type.cast(val); + } + + /** Special dealing with array & {@link List} values. This method + * takes the provided collection, empties it and fills it again + * with values extracted from value (which is supposed + * to be an array). + * + * @param the type of list elements + * @param arr collection to fill with elements in value + * @param type the type of elements in the collection + * @param value array of elements to put into the collecition. If + * value is not an array it is wrapped into array with only element + * @since 1.0 + */ + public final void replaceValue(Collection arr, Class type, Object value) { + Object[] newArr; + if (value instanceof Object[]) { + newArr = (Object[]) value; + } else { + newArr = new Object[] { value }; + } + arr.clear(); + for (Object e : newArr) { + arr.add(extractValue(type, e)); + } + } + } +} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/spi/Technology.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json/src/main/java/org/netbeans/html/json/spi/Technology.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,169 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.json.spi; + +import net.java.html.BrwsrCtx; +import net.java.html.json.Model; +import net.java.html.json.Models; + +/** An implementation of a binding between model classes (see {@link Model}) + * and particular technology like knockout.js + * in a browser window, etc. + * + * @author Jaroslav Tulach + */ +public interface Technology { + /** Creates an object to wrap the provided model object. The model + * has previously been generated by annotation processor associated + * with {@link Model} annotation. + * + * @param model the model generated from {@link Model} + * @return internal object representing the model + */ + public Data wrapModel(Object model); + + /** Converts an element potentially representing a model into the model. + * @param the type of the modelClass + * @param modelClass expected class to convert the data to + * @param data the current data provided from the browser + * @return the instance of modelClass somehow extracted from the data, may return null + */ + public M toModel(Class modelClass, Object data); + + /** Binds a property between the model and the data as used by the technology. + * + * @param b the description of the requested binding + * @param model the original instance of the model + * @param data the data to bind with the model + */ + public void bind(PropertyBinding b, Object model, Data data); + + /** Model for given data has changed its value. The technology is + * supposed to update its state (for example DOM nodes associated + * with the model). The update usually happens asynchronously. + * + * @param data technology's own representation of the model + * @param propertyName name of the model property that changed + */ + public void valueHasMutated(Data data, String propertyName); + + public void expose(FunctionBinding fb, Object model, Data d); + + /** Applies given data to current context (usually an HTML page). + * @param data the data to apply + */ + public void applyBindings(Data data); + + /** + * Some technologies may require wrapping a Java array into a special + * object. In such case they may return it from this method. + * + * @param arr original array + * @return wrapped array + */ + public Object wrapArray(Object[] arr); + + /** + * Run given runnable in a safe mode. If the runnable can be executed + * immediately, do it. If we need to switch to some other thread, do it + * and invoke r asynchronously immediately returning from the call to + * runSafe method. + * + * @param r the runnable to execute + * @deprecated Use {@link BrwsrCtx#execute(java.lang.Runnable)} + */ + @Deprecated + public void runSafe(Runnable r); + + /** For certain rendering technologies it may be more efficient to register + * property and function bindings for one instance of the model at once, + * rather then doing it incrementally via + * {@link Technology#expose(org.netbeans.html.json.spi.FunctionBinding, java.lang.Object, java.lang.Object) } + * and + * {@link Technology#bind(org.netbeans.html.json.spi.PropertyBinding, java.lang.Object, java.lang.Object) }. + * In such case implement the {@link #wrapModel(java.lang.Object, org.netbeans.html.json.spi.PropertyBinding[], org.netbeans.html.json.spi.FunctionBinding[]) } + * method of this interface and it will be called instead of the + * previous two ones. + * + * @since 0.6 + */ + public static interface BatchInit extends Technology { + /** Wrap the given model into redering technology appropriate object + * D and expose given properties and functions on it. + * + * @param model the {@link Models#isModel(java.lang.Class) model} in Java + * @param propArr array of property bindings to expose + * @param funcArr array of functions to expose + * @return appropriate wrapper around the model + */ + public D wrapModel(Object model, PropertyBinding[] propArr, FunctionBinding[] funcArr); + } + + /** Some technologies are more effective when number of calls between + * Java and JavaScript is limited - to do that when a value of property + * is changed they should implement this additional interface. + * + * @param internal type of the technology + * @since 0.7.6 + */ + public static interface ValueMutated extends Technology { + /** Model for given data has changed its value. The technology is + * supposed to update its state (for example DOM nodes associated + * with the model). The update usually happens asynchronously. + *

+ * If both oldValue and newValue are + * null then the real value of the technology is + * not known. + *

+ * If this method is present, then it is called instead of + * old, plain {@link #valueHasMutated(java.lang.Object, java.lang.String)} + * which is never called by the infrastructure then. + * + * @param data technology's own representation of the model + * @param propertyName name of the model property that changed + * @param oldValue provides previous value of the property + * @param newValue provides new value of the property + */ + public void valueHasMutated(D data, String propertyName, Object oldValue, Object newValue); + } +} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/spi/Transfer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json/src/main/java/org/netbeans/html/json/spi/Transfer.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,88 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.json.spi; + +import java.io.IOException; +import java.io.InputStream; +import org.netbeans.html.context.spi.Contexts.Builder; + +/** A {@link Builder service provider interface} responsible for + * conversion of JSON objects to Java ones and vice-versa. + * + * @author Jaroslav Tulach + */ +public interface Transfer { + /** + * Called to inspect properties of an object (usually a JSON or JavaScript + * wrapper). + * + * @param obj the object to inspect + * @param props the names of properties to check on the object + * obj + * @param values array of the same length as props should be + * filled by values of properties on the obj. If a property is + * not defined, a null value should be stored in the array + */ + public void extract(Object obj, String[] props, Object[] values); + + /** Reads content of a stream and creates its JSON representation. + * The returned object is implementation dependant. It however needs + * to be acceptable as first argument of {@link #extract(java.lang.Object, java.lang.String[], java.lang.Object[]) extract} + * method. If the stream contains representation or a JSON array, + * an Object[] should be returned - each of its members should, by itself + * be acceptable argument to + * the {@link #extract(java.lang.Object, java.lang.String[], java.lang.Object[]) extract} method. + * + * @param is input stream to read data from + * @return an object representing the JSON data + * @throws IOException if something goes wrong + */ + public Object toJSON(InputStream is) throws IOException; + + /** Starts the JSON or JSONP query. + * + * @param call description of the call to make + */ + public void loadJSON(JSONCall call); + +} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/spi/WSTransfer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json/src/main/java/org/netbeans/html/json/spi/WSTransfer.java Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,84 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.json.spi; + +import net.java.html.BrwsrCtx; +import org.netbeans.html.context.spi.Contexts.Provider; + +/** Interface for providers of WebSocket protocol. Register into a + * {@link BrwsrCtx context} in your own {@link Provider} + * + * @author Jaroslav Tulach + * @param internal implementation type representing the socket + * @since 0.5 + */ +public interface WSTransfer { + /** Initializes a web socket. The callback object should + * have mostly empty values: {@link JSONCall#isDoOutput()} should be + * false and thus there should be no {@link JSONCall#getMessage()}. + * The method of connection {@link JSONCall#getMethod()} is "WebSocket". + * Once the connection is open call {@link JSONCall#notifySuccess(java.lang.Object) notifySuccess(null)}. + * When the server sends some data then, pass them to + * {@link JSONCall#notifySuccess(java.lang.Object) notifySuccess} method + * as well. If there is an error call {@link JSONCall#notifyError(java.lang.Throwable)}. + * + * @param url the URL to connect to + * @param callback a way to provide results back to the client + * @return your object representing the established web socket + */ + public WebSocket open(String url, JSONCall callback); + + /** Sends data to the server. The most important value + * of the data parameter is {@link JSONCall#getMessage()}, + * rest can be ignored. + * + * @param socket internal representation of the socket + * @param data the message to be sent + */ + public void send(WebSocket socket, JSONCall data); + + /** A request to close the socket. + * @param socket internal representation of the socket + */ + public void close(WebSocket socket); +} diff -r 892b0a823f46 -r bdc3d696dd4a json/src/main/java/org/netbeans/html/json/spi/package.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json/src/main/java/org/netbeans/html/json/spi/package.html Tue Aug 26 18:13:30 2014 +0200 @@ -0,0 +1,51 @@ + + + +

Service Provider Interfaces for those who wish to integrate own + technology with the HTML for Java API. +
+ + diff -r 892b0a823f46 -r bdc3d696dd4a json/src/test/java/net/java/html/json/MapModelTest.java --- a/json/src/test/java/net/java/html/json/MapModelTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/test/java/net/java/html/json/MapModelTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -48,12 +48,12 @@ import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.FunctionBinding; -import org.apidesign.html.json.spi.JSONCall; -import org.apidesign.html.json.spi.PropertyBinding; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.FunctionBinding; +import org.netbeans.html.json.spi.JSONCall; +import org.netbeans.html.json.spi.PropertyBinding; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static org.testng.Assert.*; diff -r 892b0a823f46 -r bdc3d696dd4a json/src/test/java/net/java/html/json/ModelTest.java --- a/json/src/test/java/net/java/html/json/ModelTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/test/java/net/java/html/json/ModelTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -48,10 +48,10 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.FunctionBinding; -import org.apidesign.html.json.spi.PropertyBinding; -import org.apidesign.html.json.spi.Technology; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.FunctionBinding; +import org.netbeans.html.json.spi.PropertyBinding; +import org.netbeans.html.json.spi.Technology; import static org.testng.Assert.*; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a json/src/test/java/net/java/html/json/OperationTest.java --- a/json/src/test/java/net/java/html/json/OperationTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/test/java/net/java/html/json/OperationTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -45,7 +45,7 @@ import java.io.IOException; import java.util.Arrays; import net.java.html.BrwsrCtx; -import org.apidesign.html.context.spi.Contexts; +import org.netbeans.html.context.spi.Contexts; import static org.testng.Assert.*; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a json/src/test/java/net/java/html/json/TypesTest.java --- a/json/src/test/java/net/java/html/json/TypesTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/test/java/net/java/html/json/TypesTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -45,9 +45,9 @@ import net.java.html.BrwsrCtx; import java.util.Map; import net.java.html.json.MapModelTest.One; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; import org.netbeans.html.json.impl.JSON; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a json/src/test/java/org/netbeans/html/json/impl/DeepChangeTest.java --- a/json/src/test/java/org/netbeans/html/json/impl/DeepChangeTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/test/java/org/netbeans/html/json/impl/DeepChangeTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -53,12 +53,12 @@ import net.java.html.json.Model; import net.java.html.json.Models; import net.java.html.json.Property; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.FunctionBinding; -import org.apidesign.html.json.spi.JSONCall; -import org.apidesign.html.json.spi.PropertyBinding; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.FunctionBinding; +import org.netbeans.html.json.spi.JSONCall; +import org.netbeans.html.json.spi.PropertyBinding; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; import static org.testng.Assert.*; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a json/src/test/java/org/netbeans/html/json/impl/JSONListTest.java --- a/json/src/test/java/org/netbeans/html/json/impl/JSONListTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/test/java/org/netbeans/html/json/impl/JSONListTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -51,10 +51,10 @@ import net.java.html.json.Person; import net.java.html.json.Property; import net.java.html.json.Sex; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.FunctionBinding; -import org.apidesign.html.json.spi.PropertyBinding; -import org.apidesign.html.json.spi.Technology; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.FunctionBinding; +import org.netbeans.html.json.spi.PropertyBinding; +import org.netbeans.html.json.spi.Technology; import static org.testng.Assert.*; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a json/src/test/java/org/netbeans/html/json/impl/OnReceiveTest.java --- a/json/src/test/java/org/netbeans/html/json/impl/OnReceiveTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/test/java/org/netbeans/html/json/impl/OnReceiveTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -49,9 +49,9 @@ import net.java.html.BrwsrCtx; import net.java.html.json.Models; import net.java.html.json.Person; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.JSONCall; -import org.apidesign.html.json.spi.Transfer; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.JSONCall; +import org.netbeans.html.json.spi.Transfer; import static org.testng.Assert.*; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a json/src/test/java/org/netbeans/html/json/impl/ToDoTest.java --- a/json/src/test/java/org/netbeans/html/json/impl/ToDoTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/json/src/test/java/org/netbeans/html/json/impl/ToDoTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -49,9 +49,9 @@ import net.java.html.json.Model; import net.java.html.json.Models; import net.java.html.json.Property; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; import org.netbeans.html.json.impl.DeepChangeTest.MapTechnology; import org.netbeans.html.json.impl.DeepChangeTest.One; import static org.testng.Assert.*; diff -r 892b0a823f46 -r bdc3d696dd4a ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java --- a/ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java Tue Aug 26 18:13:30 2014 +0200 @@ -62,11 +62,11 @@ import net.java.html.BrwsrCtx; import net.java.html.boot.BrowserBuilder; import net.java.html.js.JavaScriptBody; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; -import org.apidesign.html.json.tck.KnockoutTCK; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; +import org.netbeans.html.json.tck.KnockoutTCK; import org.json.JSONException; import org.json.JSONObject; import org.openide.util.lookup.ServiceProvider; diff -r 892b0a823f46 -r bdc3d696dd4a ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KOFx.java --- a/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KOFx.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KOFx.java Tue Aug 26 18:13:30 2014 +0200 @@ -49,7 +49,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import javafx.application.Platform; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import org.testng.ITest; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KnockoutFelixIT.java --- a/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KnockoutFelixIT.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KnockoutFelixIT.java Tue Aug 26 18:13:30 2014 +0200 @@ -58,9 +58,9 @@ import java.util.jar.JarFile; import java.util.logging.Level; import java.util.logging.Logger; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.json.tck.KOTest; -import org.apidesign.html.json.tck.KnockoutTCK; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KnockoutTCK; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; diff -r 892b0a823f46 -r bdc3d696dd4a ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java --- a/ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java Tue Aug 26 18:13:30 2014 +0200 @@ -58,11 +58,11 @@ import net.java.html.BrwsrCtx; import net.java.html.boot.BrowserBuilder; import net.java.html.js.JavaScriptBody; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; -import org.apidesign.html.json.tck.KnockoutTCK; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; +import org.netbeans.html.json.tck.KnockoutTCK; import org.json.JSONException; import org.json.JSONObject; import org.openide.util.lookup.ServiceProvider; diff -r 892b0a823f46 -r bdc3d696dd4a ko-osgi-test/src/test/java/org/netbeans/html/ko/osgi/test/KOFx.java --- a/ko-osgi-test/src/test/java/org/netbeans/html/ko/osgi/test/KOFx.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko-osgi-test/src/test/java/org/netbeans/html/ko/osgi/test/KOFx.java Tue Aug 26 18:13:30 2014 +0200 @@ -49,7 +49,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import javafx.application.Platform; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import org.testng.ITest; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a ko-osgi-test/src/test/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxIT.java --- a/ko-osgi-test/src/test/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxIT.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko-osgi-test/src/test/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxIT.java Tue Aug 26 18:13:30 2014 +0200 @@ -57,9 +57,9 @@ import java.util.jar.JarFile; import java.util.logging.Level; import java.util.logging.Logger; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.json.tck.KOTest; -import org.apidesign.html.json.tck.KnockoutTCK; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KnockoutTCK; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; diff -r 892b0a823f46 -r bdc3d696dd4a ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/LoadJSON.java --- a/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/LoadJSON.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/LoadJSON.java Tue Aug 26 18:13:30 2014 +0200 @@ -59,7 +59,7 @@ import java.util.concurrent.ThreadFactory; import java.util.logging.Logger; import net.java.html.js.JavaScriptBody; -import org.apidesign.html.json.spi.JSONCall; +import org.netbeans.html.json.spi.JSONCall; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; diff -r 892b0a823f46 -r bdc3d696dd4a ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/TyrusContext.java --- a/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/TyrusContext.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/TyrusContext.java Tue Aug 26 18:13:30 2014 +0200 @@ -56,10 +56,10 @@ import javax.websocket.Session; import javax.websocket.WebSocketContainer; import net.java.html.json.OnReceive; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.JSONCall; -import org.apidesign.html.json.spi.Transfer; -import org.apidesign.html.json.spi.WSTransfer; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.JSONCall; +import org.netbeans.html.json.spi.Transfer; +import org.netbeans.html.json.spi.WSTransfer; import org.netbeans.html.wstyrus.TyrusContext.Comm; import org.json.JSONArray; import org.json.JSONException; @@ -78,7 +78,7 @@ * There is no need to include this module in your application if you are * running on JDK8. JDK8 WebView provides its own implementation of the * WebSocket API based on WebSocket object inside a browser. This is included - * in the org.apidesign.html:ko-fx:0.5 module. + * in the org.netbeans.html:ko4j:1.0 module. * * @author Jaroslav Tulach */ diff -r 892b0a823f46 -r bdc3d696dd4a ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusFX.java --- a/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusFX.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusFX.java Tue Aug 26 18:13:30 2014 +0200 @@ -46,7 +46,7 @@ import java.lang.reflect.Method; import javafx.application.Platform; import org.netbeans.html.boot.impl.FnContext; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import org.testng.ITest; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusKnockoutTest.java --- a/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusKnockoutTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusKnockoutTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -59,13 +59,13 @@ import net.java.html.BrwsrCtx; import net.java.html.boot.BrowserBuilder; import net.java.html.js.JavaScriptBody; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; -import org.apidesign.html.json.spi.WSTransfer; -import org.apidesign.html.json.tck.KOTest; -import org.apidesign.html.json.tck.KnockoutTCK; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; +import org.netbeans.html.json.spi.WSTransfer; +import org.netbeans.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KnockoutTCK; import org.json.JSONException; import org.json.JSONObject; import org.netbeans.html.boot.impl.FnContext; diff -r 892b0a823f46 -r bdc3d696dd4a ko4j/src/main/java/org/netbeans/html/ko4j/FXContext.java --- a/ko4j/src/main/java/org/netbeans/html/ko4j/FXContext.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/FXContext.java Tue Aug 26 18:13:30 2014 +0200 @@ -50,13 +50,13 @@ import java.io.Reader; import java.net.URL; import java.util.logging.Logger; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.json.spi.FunctionBinding; -import org.apidesign.html.json.spi.JSONCall; -import org.apidesign.html.json.spi.PropertyBinding; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; -import org.apidesign.html.json.spi.WSTransfer; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.json.spi.FunctionBinding; +import org.netbeans.html.json.spi.JSONCall; +import org.netbeans.html.json.spi.PropertyBinding; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; +import org.netbeans.html.json.spi.WSTransfer; /** This is an implementation package - just * include its JAR on classpath and use official {@link Context} API diff -r 892b0a823f46 -r bdc3d696dd4a ko4j/src/main/java/org/netbeans/html/ko4j/KO4J.java --- a/ko4j/src/main/java/org/netbeans/html/ko4j/KO4J.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/KO4J.java Tue Aug 26 18:13:30 2014 +0200 @@ -43,12 +43,12 @@ package org.netbeans.html.ko4j; import net.java.html.json.Model; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.context.spi.Contexts.Provider; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; -import org.apidesign.html.json.spi.WSTransfer; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.context.spi.Contexts.Provider; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; +import org.netbeans.html.json.spi.WSTransfer; import org.openide.util.lookup.ServiceProvider; /** Support for knockout.js diff -r 892b0a823f46 -r bdc3d696dd4a ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java --- a/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java Tue Aug 26 18:13:30 2014 +0200 @@ -45,8 +45,8 @@ import net.java.html.js.JavaScriptBody; import net.java.html.js.JavaScriptResource; import net.java.html.json.Model; -import org.apidesign.html.json.spi.FunctionBinding; -import org.apidesign.html.json.spi.PropertyBinding; +import org.netbeans.html.json.spi.FunctionBinding; +import org.netbeans.html.json.spi.PropertyBinding; /** This is an implementation package - just * include its JAR on classpath and use official {@link Context} API @@ -100,7 +100,7 @@ + " var trigger = ko.observable().extend({notify:'always'});" + " function realGetter() {\n" + " try {\n" - + " var v = prop.@org.apidesign.html.json.spi.PropertyBinding::getValue()();\n" + + " var v = prop.@org.netbeans.html.json.spi.PropertyBinding::getValue()();\n" + " return v;\n" + " } catch (e) {\n" + " alert(\"Cannot call getValue on \" + model + \" prop: \" + name + \" error: \" + e);\n" @@ -120,7 +120,7 @@ + " if (!readOnly) {\n" + " bnd['write'] = function(val) {\n" + " var model = val['ko-fx.model'];\n" - + " prop.@org.apidesign.html.json.spi.PropertyBinding::setValue(Ljava/lang/Object;)(model ? model : val);\n" + + " prop.@org.netbeans.html.json.spi.PropertyBinding::setValue(Ljava/lang/Object;)(model ? model : val);\n" + " };\n" + " };\n" + " var cmpt = ko['computed'](bnd);\n" @@ -135,7 +135,7 @@ + "}\n" + "function koExpose(name, func) {\n" + " ret[name] = function(data, ev) {\n" - + " func.@org.apidesign.html.json.spi.FunctionBinding::call(Ljava/lang/Object;Ljava/lang/Object;)(data, ev);\n" + + " func.@org.netbeans.html.json.spi.FunctionBinding::call(Ljava/lang/Object;Ljava/lang/Object;)(data, ev);\n" + " };\n" + "}\n" + "for (var i = 0; i < funcNames.length; i++) {\n" diff -r 892b0a823f46 -r bdc3d696dd4a ko4j/src/main/java/org/netbeans/html/ko4j/LoadJSON.java --- a/ko4j/src/main/java/org/netbeans/html/ko4j/LoadJSON.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/LoadJSON.java Tue Aug 26 18:13:30 2014 +0200 @@ -47,9 +47,9 @@ import java.io.InputStream; import java.io.InputStreamReader; import net.java.html.js.JavaScriptBody; -import org.apidesign.html.json.spi.JSONCall; -import org.apidesign.html.json.spi.Transfer; -import org.apidesign.html.json.spi.WSTransfer; +import org.netbeans.html.json.spi.JSONCall; +import org.netbeans.html.json.spi.Transfer; +import org.netbeans.html.json.spi.WSTransfer; /** * @@ -144,7 +144,7 @@ + " delete window[name];\n" + " var el = window.document.getElementById(name);\n" + " el.parentNode.removeChild(el);\n" - + " done.@org.apidesign.html.json.spi.JSONCall::notifySuccess(Ljava/lang/Object;)(data);\n" + + " done.@org.netbeans.html.json.spi.JSONCall::notifySuccess(Ljava/lang/Object;)(data);\n" + "};\n" + "return true;\n" ) @@ -168,7 +168,7 @@ + " try {\n" + " if (request.status < 100 || request.status >= 400) throw request.status + ': ' + request.statusText;" + " try { r = eval('(' + r + ')'); } catch (ignore) { }" - + " done.@org.apidesign.html.json.spi.JSONCall::notifySuccess(Ljava/lang/Object;)(r);\n" + + " done.@org.netbeans.html.json.spi.JSONCall::notifySuccess(Ljava/lang/Object;)(r);\n" + " } catch (error) {;\n" + " @org.netbeans.html.ko4j.LoadJSON::notifyError(Ljava/lang/Object;Ljava/lang/Object;)(done, error);\n" + " }\n" diff -r 892b0a823f46 -r bdc3d696dd4a ko4j/src/main/java/org/netbeans/html/ko4j/LoadWS.java --- a/ko4j/src/main/java/org/netbeans/html/ko4j/LoadWS.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/LoadWS.java Tue Aug 26 18:13:30 2014 +0200 @@ -43,7 +43,7 @@ package org.netbeans.html.ko4j; import net.java.html.js.JavaScriptBody; -import org.apidesign.html.json.spi.JSONCall; +import org.netbeans.html.json.spi.JSONCall; /** Communication with WebSockets via browser's WebSocket object. * diff -r 892b0a823f46 -r bdc3d696dd4a ko4j/src/test/java/org/netbeans/html/ko4j/KOFx.java --- a/ko4j/src/test/java/org/netbeans/html/ko4j/KOFx.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/KOFx.java Tue Aug 26 18:13:30 2014 +0200 @@ -49,7 +49,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import javafx.application.Platform; -import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.spi.Fn; import org.testng.ITest; import org.testng.annotations.Test; diff -r 892b0a823f46 -r bdc3d696dd4a ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java --- a/ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java Tue Aug 26 18:13:30 2014 +0200 @@ -59,13 +59,13 @@ import net.java.html.BrwsrCtx; import net.java.html.boot.BrowserBuilder; import net.java.html.js.JavaScriptBody; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; -import org.apidesign.html.json.spi.WSTransfer; -import org.apidesign.html.json.tck.KOTest; -import org.apidesign.html.json.tck.KnockoutTCK; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; +import org.netbeans.html.json.spi.WSTransfer; +import org.netbeans.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KnockoutTCK; import org.netbeans.html.boot.impl.FnContext; import org.openide.util.lookup.ServiceProvider; import org.testng.Assert; diff -r 892b0a823f46 -r bdc3d696dd4a ko4j/src/test/java/org/netbeans/html/ko4j/LessCallbacksCheck.java --- a/ko4j/src/test/java/org/netbeans/html/ko4j/LessCallbacksCheck.java Tue Aug 26 17:43:37 2014 +0200 +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/LessCallbacksCheck.java Tue Aug 26 18:13:30 2014 +0200 @@ -47,7 +47,7 @@ import net.java.html.json.ComputedProperty; import net.java.html.json.Model; import net.java.html.json.Property; -import org.apidesign.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KOTest; /** * diff -r 892b0a823f46 -r bdc3d696dd4a pom.xml --- a/pom.xml Tue Aug 26 17:43:37 2014 +0200 +++ b/pom.xml Tue Aug 26 18:13:30 2014 +0200 @@ -143,7 +143,7 @@ Service Provider APIs (not commonly interesting) - org.apidesign.html.* + org.netbeans.html.* diff -r 892b0a823f46 -r bdc3d696dd4a sound/src/main/java/net/java/html/sound/AudioClip.java --- a/sound/src/main/java/net/java/html/sound/AudioClip.java Tue Aug 26 17:43:37 2014 +0200 +++ b/sound/src/main/java/net/java/html/sound/AudioClip.java Tue Aug 26 18:13:30 2014 +0200 @@ -44,8 +44,8 @@ import java.util.ServiceLoader; import net.java.html.BrwsrCtx; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.sound.spi.AudioEnvironment; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.sound.spi.AudioEnvironment; import org.netbeans.html.sound.impl.BrowserAudioEnv; /** Handle to an audio clip which can be {@link #play() played}, {@link #pause() paused} diff -r 892b0a823f46 -r bdc3d696dd4a sound/src/main/java/org/apidesign/html/sound/spi/AudioEnvironment.java --- a/sound/src/main/java/org/apidesign/html/sound/spi/AudioEnvironment.java Tue Aug 26 17:43:37 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -/** - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.apidesign.html.sound.spi; - -import net.java.html.BrwsrCtx; -import org.apidesign.html.context.spi.Contexts; - -/** Basic interface for sound playback providers. Register your implementation - * in a way {@link java.util.ServiceLoader} can find it - e.g. use - * {@link org.openide.util.lookup.ServiceProvider} annotation. Possibly - * one can register the provider into {@link Contexts#newBuilder()}, in - * case the implementation is somehow associated - * with the actual {@link BrwsrCtx} (works since version 0.8.3). - * - * @author antonepple - * @param