Updating references to ko4j UniversalKO
authorJaroslav Tulach <jaroslav.tulach@netbeans.org>
Thu, 09 Jan 2014 15:43:04 +0100
branchUniversalKO
changeset 44403eeeb863fa1
parent 443 cfaeaa98a0a6
child 445 491f5e97da6e
Updating references to ko4j
ko-archetype-test/pom.xml
ko-archetype/src/main/resources/archetype-resources/pom.xml
ko-osgi-test/pom.xml
ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java
ko-ws-tyrus/pom.xml
ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusKnockoutTest.java
ko4j/src/main/java/org/netbeans/html/ko4j/KO4J.java
     1.1 --- a/ko-archetype-test/pom.xml	Thu Jan 09 15:07:00 2014 +0100
     1.2 +++ b/ko-archetype-test/pom.xml	Thu Jan 09 15:43:04 2014 +0100
     1.3 @@ -34,7 +34,7 @@
     1.4          </dependency>
     1.5          <dependency>
     1.6              <groupId>${project.groupId}</groupId>
     1.7 -            <artifactId>ko-fx</artifactId>
     1.8 +            <artifactId>ko4j</artifactId>
     1.9              <version>${project.version}</version>
    1.10              <scope>provided</scope>
    1.11          </dependency>
     2.1 --- a/ko-archetype/src/main/resources/archetype-resources/pom.xml	Thu Jan 09 15:07:00 2014 +0100
     2.2 +++ b/ko-archetype/src/main/resources/archetype-resources/pom.xml	Thu Jan 09 15:43:04 2014 +0100
     2.3 @@ -112,7 +112,7 @@
     2.4      </dependency>
     2.5      <dependency>
     2.6          <groupId>org.netbeans.html</groupId>
     2.7 -        <artifactId>ko-fx</artifactId>
     2.8 +        <artifactId>ko4j</artifactId>
     2.9          <version>\${net.java.html.version}</version>
    2.10          <scope>runtime</scope>
    2.11      </dependency>
     3.1 --- a/ko-osgi-test/pom.xml	Thu Jan 09 15:07:00 2014 +0100
     3.2 +++ b/ko-osgi-test/pom.xml	Thu Jan 09 15:43:04 2014 +0100
     3.3 @@ -87,7 +87,7 @@
     3.4          </dependency>
     3.5          <dependency>
     3.6              <groupId>${project.groupId}</groupId>
     3.7 -            <artifactId>ko-fx</artifactId>
     3.8 +            <artifactId>ko4j</artifactId>
     3.9              <version>${project.version}</version>
    3.10          </dependency>
    3.11          <dependency>
     4.1 --- a/ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java	Thu Jan 09 15:07:00 2014 +0100
     4.2 +++ b/ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java	Thu Jan 09 15:43:04 2014 +0100
     4.3 @@ -45,6 +45,7 @@
     4.4  import java.io.BufferedReader;
     4.5  import java.io.IOException;
     4.6  import java.io.InputStreamReader;
     4.7 +import java.lang.reflect.Constructor;
     4.8  import java.lang.reflect.Method;
     4.9  import java.net.URI;
    4.10  import java.net.URISyntaxException;
    4.11 @@ -134,10 +135,12 @@
    4.12      public BrwsrCtx createContext() {
    4.13          try {
    4.14              Class<?> fxCls = loadOSGiClass(
    4.15 -                "org.netbeans.html.kofx.FXContext",
    4.16 +                "org.netbeans.html.ko4j.FXContext",
    4.17                  FrameworkUtil.getBundle(KnockoutEquinoxTCKImpl.class).getBundleContext()
    4.18              );
    4.19 -            Object fx = fxCls.getConstructor(Fn.Presenter.class).newInstance(browserContext);
    4.20 +            final Constructor<?> cnstr = fxCls.getConstructor(Fn.Presenter.class);
    4.21 +            cnstr.setAccessible(true);
    4.22 +            Object fx = cnstr.newInstance(browserContext);
    4.23              Contexts.Builder cb = Contexts.newBuilder().
    4.24                  register(Technology.class, (Technology)fx, 10).
    4.25                  register(Transfer.class, (Transfer)fx, 10);
     5.1 --- a/ko-ws-tyrus/pom.xml	Thu Jan 09 15:07:00 2014 +0100
     5.2 +++ b/ko-ws-tyrus/pom.xml	Thu Jan 09 15:43:04 2014 +0100
     5.3 @@ -106,8 +106,8 @@
     5.4      </dependency>
     5.5      <dependency>
     5.6        <groupId>${project.groupId}</groupId>
     5.7 -      <artifactId>ko-fx</artifactId>
     5.8 -      <version>${project.version}</version>
     5.9 +      <artifactId>ko4j</artifactId>
    5.10 +      <version>0.7-SNAPSHOT</version>
    5.11        <scope>test</scope>
    5.12        <type>jar</type>
    5.13      </dependency>
     6.1 --- a/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusKnockoutTest.java	Thu Jan 09 15:07:00 2014 +0100
     6.2 +++ b/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusKnockoutTest.java	Thu Jan 09 15:43:04 2014 +0100
     6.3 @@ -58,7 +58,6 @@
     6.4  import net.java.html.BrwsrCtx;
     6.5  import net.java.html.boot.BrowserBuilder;
     6.6  import net.java.html.js.JavaScriptBody;
     6.7 -import org.netbeans.html.boot.impl.FnContext;
     6.8  import org.apidesign.html.boot.spi.Fn;
     6.9  import org.apidesign.html.context.spi.Contexts;
    6.10  import org.apidesign.html.json.spi.Technology;
    6.11 @@ -68,10 +67,11 @@
    6.12  import org.apidesign.html.json.tck.KnockoutTCK;
    6.13  import org.json.JSONException;
    6.14  import org.json.JSONObject;
    6.15 -import org.netbeans.html.kofx.FXContext;
    6.16 +import org.netbeans.html.boot.impl.FnContext;
    6.17 +import org.netbeans.html.ko4j.KO4J;
    6.18  import org.openide.util.lookup.ServiceProvider;
    6.19 +import static org.testng.Assert.*;
    6.20  import org.testng.annotations.Factory;
    6.21 -import static org.testng.Assert.*;
    6.22  
    6.23  /**
    6.24   *
    6.25 @@ -146,11 +146,11 @@
    6.26      
    6.27      @Override
    6.28      public BrwsrCtx createContext() {
    6.29 -        FXContext fx = new FXContext(browserContext);
    6.30 +        KO4J ko = new KO4J(browserContext);
    6.31          TyrusContext tc = new TyrusContext();
    6.32          Contexts.Builder cb = Contexts.newBuilder().
    6.33 -            register(Technology.class, fx, 10).
    6.34 -            register(Transfer.class, fx, 10).
    6.35 +            register(Technology.class, ko.knockout(), 10).
    6.36 +            register(Transfer.class, ko.transferViaOrgJSON(), 10).
    6.37              register(WSTransfer.class, tc, 10);
    6.38          return cb.build();
    6.39      }
     7.1 --- a/ko4j/src/main/java/org/netbeans/html/ko4j/KO4J.java	Thu Jan 09 15:07:00 2014 +0100
     7.2 +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/KO4J.java	Thu Jan 09 15:43:04 2014 +0100
     7.3 @@ -55,18 +55,74 @@
     7.4   * Registers {@link ContextProvider}, so {@link ServiceLoader} can find it.
     7.5   *
     7.6   * @author Jaroslav Tulach <jtulach@netbeans.org>
     7.7 + * @since 0.7
     7.8   */
     7.9  @ServiceProvider(service = Contexts.Provider.class)
    7.10  public final class KO4J implements Contexts.Provider {
    7.11 +    private final Fn.Presenter presenter;
    7.12 +    private FXContext c;
    7.13 +    
    7.14 +    public KO4J() {
    7.15 +        this(null);
    7.16 +    }
    7.17 +    
    7.18 +    public KO4J(Fn.Presenter presenter) {
    7.19 +        this.presenter = presenter;
    7.20 +    }
    7.21 +    
    7.22 +    private FXContext getKO() {
    7.23 +        if (c == null) {
    7.24 +            c = new FXContext(presenter == null ? Fn.activePresenter() : presenter);
    7.25 +        }
    7.26 +        return c;
    7.27 +    }
    7.28 +    
    7.29 +    /** Return instance of the knockout.js for Java technology.
    7.30 +     * @return non-null instance
    7.31 +     */
    7.32 +    public Technology knockout() {
    7.33 +        return getKO();
    7.34 +    }
    7.35 +    
    7.36 +    /** Java based implementation of transfer interface. Requires
    7.37 +     * org.json libraries on classpath. Use: <pre>
    7.38 +&lt;dependency&gt;
    7.39 +    &lt;groupId>de.twentyeleven.skysail&lt;/groupId&gt;
    7.40 +    &lt;artifactId>org.json-osgi&lt;/artifactId&gt;
    7.41 +&lt;/dependency&gt;
    7.42 +     * </pre>
    7.43 +     * @return instance of the technology or <code>null</code>, 
    7.44 +     *   if <code>org.json</code> interfaces are not around
    7.45 +     */
    7.46 +    public Transfer transferViaOrgJSON() {
    7.47 +        return getKO();
    7.48 +    }
    7.49 +    
    7.50 +    /** Returns browser based implementation of websocket transfer.
    7.51 +     * 
    7.52 +     * @return an instance or <code>null</code>, if there is no
    7.53 +     *   <code>WebSocket</code> object in the browser
    7.54 +     */
    7.55 +    public WSTransfer<?> websocketsViaBrowser() {
    7.56 +        return getKO().areWebSocketsSupported() ? getKO() : null;
    7.57 +    }
    7.58  
    7.59 +    /** Registers technologies at position 100:
    7.60 +     * <ul>
    7.61 +     *   <li>{@link #knockout()}</li>
    7.62 +     *   <li>{@link #transferViaOrgJSON()} - if <code>org.json</code> libraries are around</li>
    7.63 +     *   <li>{@link #websocketsViaBrowser()()} - if browser supports web sockets</li>
    7.64 +     * </ul>
    7.65 +     * @param context the context to register to
    7.66 +     * @param requestor the class requesting the registration
    7.67 +     */
    7.68      @Override
    7.69      public void fillContext(Contexts.Builder context, Class<?> requestor) {
    7.70          if (FXContext.isJavaScriptEnabled()) {
    7.71 -            FXContext c = new FXContext(Fn.activePresenter());
    7.72 -            context.register(Technology.class, c, 100);
    7.73 -            context.register(Transfer.class, c, 100);
    7.74 +            context.register(Technology.class, knockout(), 100);
    7.75 +            context.register(Transfer.class, transferViaOrgJSON(), 100);
    7.76              if (c.areWebSocketsSupported()) {
    7.77 -                context.register(WSTransfer.class, c, 100);
    7.78 +                context.register(WSTransfer.class, websocketsViaBrowser(), 100);
    7.79              }
    7.80          }
    7.81      }