This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 248918
Collapse All | Expand All

(-)a/boot-fx/src/main/java/net/java/html/boot/fx/FXBrowsers.java (-1 / +4 lines)
Lines 94-100 Link Here
94
        Class<?> onPageLoad, String methodName,
94
        Class<?> onPageLoad, String methodName,
95
        String... args
95
        String... args
96
    ) {
96
    ) {
97
        BrowserBuilder.newBrowser(new Load(webView)).
97
        Object[] context = new Object[args.length + 1];
98
        System.arraycopy(args, 0, context, 1, args.length);
99
        context[0] = new Load(webView);
100
        BrowserBuilder.newBrowser(context).
98
            loadPage(url.toExternalForm()).
101
            loadPage(url.toExternalForm()).
99
            loadClass(onPageLoad).
102
            loadClass(onPageLoad).
100
            invoke(methodName, args).
103
            invoke(methodName, args).
(-)a/boot/src/main/java/net/java/html/boot/BrowserBuilder.java (-1 / +1 lines)
Lines 298-304 Link Here
298
                    if (browserClass != null) {
298
                    if (browserClass != null) {
299
                        browserClass[0] = newClazz;
299
                        browserClass[0] = newClazz;
300
                    }
300
                    }
301
                    Contexts.Builder cb = Contexts.newBuilder();
301
                    Contexts.Builder cb = Contexts.newBuilder(context);
302
                    if (!Contexts.fillInByProviders(newClazz, cb)) {
302
                    if (!Contexts.fillInByProviders(newClazz, cb)) {
303
                        LOG.log(Level.WARNING, "Using empty technology for {0}", newClazz);
303
                        LOG.log(Level.WARNING, "Using empty technology for {0}", newClazz);
304
                    }
304
                    }
(-)a/context/src/main/java/org/netbeans/html/context/impl/CtxImpl.java (-14 / +41 lines)
Lines 44-51 Link Here
44
44
45
import java.util.ArrayList;
45
import java.util.ArrayList;
46
import java.util.Collections;
46
import java.util.Collections;
47
import java.util.Comparator;
47
import java.util.List;
48
import java.util.List;
48
import net.java.html.BrwsrCtx;
49
import net.java.html.BrwsrCtx;
50
import org.netbeans.html.context.spi.Contexts;
49
51
50
/** Implementation detail. Holds list of technologies for particular
52
/** Implementation detail. Holds list of technologies for particular
51
 * {@link BrwsrCtx}.
53
 * {@link BrwsrCtx}.
Lines 54-66 Link Here
54
 */
56
 */
55
public final class CtxImpl {
57
public final class CtxImpl {
56
    private final List<Bind<?>> techs;
58
    private final List<Bind<?>> techs;
59
    private final Object[] context;
57
    
60
    
58
    public CtxImpl() {
61
    public CtxImpl(Object[] context) {
59
        techs = new ArrayList<Bind<?>>();
62
        this(context, new ArrayList<Bind<?>>());
60
    }
63
    }
61
    
64
    
62
    private CtxImpl(List<Bind<?>> techs) {
65
    private CtxImpl(Object[] context, List<Bind<?>> techs) {
63
        this.techs = techs;
66
        this.techs = techs;
67
        this.context = context;
64
    }
68
    }
65
    
69
    
66
    public static <Tech> Tech find(BrwsrCtx context, Class<Tech> technology) {
70
    public static <Tech> Tech find(BrwsrCtx context, Class<Tech> technology) {
Lines 74-82 Link Here
74
    }
78
    }
75
79
76
    public BrwsrCtx build() {
80
    public BrwsrCtx build() {
77
        Collections.sort(techs);
81
        Collections.sort(techs, new BindCompare());
78
        final List<Bind<?>> arr = Collections.unmodifiableList(techs);
82
        final List<Bind<?>> arr = Collections.unmodifiableList(techs);
79
        CtxImpl impl = new CtxImpl(arr);
83
        CtxImpl impl = new CtxImpl(context, arr);
80
        BrwsrCtx ctx = CtxAccssr.getDefault().newContext(impl);
84
        BrwsrCtx ctx = CtxAccssr.getDefault().newContext(impl);
81
        return ctx;
85
        return ctx;
82
    }
86
    }
Lines 85-91 Link Here
85
        techs.add(new Bind<Tech>(type, impl, priority));
89
        techs.add(new Bind<Tech>(type, impl, priority));
86
    }
90
    }
87
    
91
    
88
    private static final class Bind<Tech> implements Comparable<Bind<?>> {
92
    private static final class Bind<Tech> {
89
        private final Class<Tech> clazz;
93
        private final Class<Tech> clazz;
90
        private final Tech impl;
94
        private final Tech impl;
91
        private final int priority;
95
        private final int priority;
Lines 97-112 Link Here
97
        }
101
        }
98
102
99
        @Override
103
        @Override
100
        public int compareTo(Bind<?> o) {
101
            if (priority != o.priority) {
102
                return priority - o.priority;
103
            }
104
            return clazz.getName().compareTo(o.clazz.getName());
105
        }
106
107
        @Override
108
        public String toString() {
104
        public String toString() {
109
            return "Bind{" + "clazz=" + clazz + "@" + clazz.getClassLoader() + ", impl=" + impl + ", priority=" + priority + '}';
105
            return "Bind{" + "clazz=" + clazz + "@" + clazz.getClassLoader() + ", impl=" + impl + ", priority=" + priority + '}';
110
        }
106
        }
111
    }
107
    }
108
    
109
    private final class BindCompare implements Comparator<Bind<?>> {
110
        boolean isPrefered(Bind<?> b) {
111
            final Class<?> implClazz = b.impl.getClass();
112
            Contexts.TechnologyId id = implClazz.getAnnotation(Contexts.TechnologyId.class);
113
            if (id == null) {
114
                return false;
115
            }
116
            for (String v : id.value()) {
117
                for (Object c : context) {
118
                    if (v.equals(c)) {
119
                        return true;
120
                    }
121
                }
122
            }
123
            return false;
124
        }
125
        
126
        @Override
127
        public int compare(Bind<?> o1, Bind<?> o2) {
128
            boolean p1 = isPrefered(o1);
129
            boolean p2 = isPrefered(o2);
130
            if (p1 != p2) {
131
                return p1 ? -1 : 1;
132
            }
133
            if (o1.priority != o2.priority) {
134
                return o1.priority - o2.priority;
135
            }
136
            return o1.clazz.getName().compareTo(o2.clazz.getName());
137
        }
138
    } // end of BindCompare
112
}
139
}
(-)a/context/src/main/java/org/netbeans/html/context/spi/Contexts.java (-3 / +17 lines)
Lines 42-47 Link Here
42
 */
42
 */
43
package org.netbeans.html.context.spi;
43
package org.netbeans.html.context.spi;
44
44
45
import java.lang.annotation.ElementType;
46
import java.lang.annotation.Retention;
47
import java.lang.annotation.RetentionPolicy;
48
import java.lang.annotation.Target;
45
import java.util.ServiceLoader;
49
import java.util.ServiceLoader;
46
import net.java.html.BrwsrCtx;
50
import net.java.html.BrwsrCtx;
47
import org.netbeans.html.context.impl.CtxImpl;
51
import org.netbeans.html.context.impl.CtxImpl;
Lines 62-69 Link Here
62
     *
66
     *
63
     * @return new instance of the builder
67
     * @return new instance of the builder
64
     */
68
     */
69
    public static Builder newBuilder(Object... context) {
70
        return new Builder(context);
71
    }
65
    public static Builder newBuilder() {
72
    public static Builder newBuilder() {
66
        return new Builder();
73
        return newBuilder(new Object[0]);
67
    }
74
    }
68
75
69
    /** Seeks for the specified technology in the provided context.
76
    /** Seeks for the specified technology in the provided context.
Lines 118-123 Link Here
118
        }
125
        }
119
        return found;
126
        return found;
120
    }
127
    }
128
    
129
    @Retention(RetentionPolicy.RUNTIME)
130
    @Target(ElementType.TYPE)
131
    public @interface TechnologyId {
132
        public String[] value();
133
    }
121
134
122
    /** Implementors of various HTML technologies should
135
    /** Implementors of various HTML technologies should
123
     * register their implementation via <code>org.openide.util.lookup.ServiceProvider</code>, so
136
     * register their implementation via <code>org.openide.util.lookup.ServiceProvider</code>, so
Lines 152-160 Link Here
152
     * @author Jaroslav Tulach
165
     * @author Jaroslav Tulach
153
     */
166
     */
154
    public static final class Builder {
167
    public static final class Builder {
155
        private final CtxImpl impl = new CtxImpl();
168
        private final CtxImpl impl;
156
169
157
        Builder() {
170
        public Builder(Object[] context) {
171
            this.impl = new CtxImpl(context);
158
        }
172
        }
159
        
173
        
160
        /** Registers new technology into the context. Each technology is
174
        /** Registers new technology into the context. Each technology is
(-)a/context/src/test/java/net/java/html/BrwsrCtxTest.java (+43 lines)
Lines 44-49 Link Here
44
44
45
import org.netbeans.html.context.spi.Contexts;
45
import org.netbeans.html.context.spi.Contexts;
46
import static org.testng.Assert.*;
46
import static org.testng.Assert.*;
47
import org.testng.annotations.Test;
47
48
48
/**
49
/**
49
 *
50
 *
Lines 72-75 Link Here
72
        assertTrue(arr[0], "Runnable was executed");
73
        assertTrue(arr[0], "Runnable was executed");
73
    }
74
    }
74
    
75
    
76
    @Test public void defaultOrderOfRegistrations() {
77
        BrwsrCtx ctx = registerRs(Contexts.newBuilder());
78
        Class<? extends Runnable> clazz = Contexts.find(ctx, Runnable.class).getClass();
79
        assertEquals(clazz, R1.class, "R1 is registered at value 10");
80
    }
81
    
82
    @Test public void preferOne() {
83
        BrwsrCtx ctx = registerRs(Contexts.newBuilder("one"));
84
        Class<? extends Runnable> clazz = Contexts.find(ctx, Runnable.class).getClass();
85
        assertEquals(clazz, R1.class, "R1 is registered at value 10");
86
    }
87
88
    @Test public void preferTwo() {
89
        BrwsrCtx ctx = registerRs(Contexts.newBuilder("two"));
90
        Class<? extends Runnable> clazz = Contexts.find(ctx, Runnable.class).getClass();
91
        assertEquals(clazz, R2.class, "R2 is preferred");
92
    }
93
94
    @Test public void preferBoth() {
95
        BrwsrCtx ctx = registerRs(Contexts.newBuilder("one", "two"));
96
        Class<? extends Runnable> clazz = Contexts.find(ctx, Runnable.class).getClass();
97
        assertEquals(clazz, R1.class, "R1 is registered at value 10");
98
    }
99
    
100
    private static BrwsrCtx registerRs(Contexts.Builder b) {
101
        b.register(Runnable.class, new R1(), 10);
102
        b.register(Runnable.class, new R2(), 20);
103
        return b.build();
104
    }
105
106
    @Contexts.TechnologyId("one")
107
    static final class R1 implements Runnable {
108
        @Override
109
        public void run() {
110
        }
111
    }
112
    @Contexts.TechnologyId("two")
113
    static final class R2 implements Runnable {
114
        @Override
115
        public void run() {
116
        }
117
    }
75
}
118
}
(-)a/ko4j/src/main/java/org/netbeans/html/ko4j/FXContext.java (+2 lines)
Lines 51-56 Link Here
51
import java.net.URL;
51
import java.net.URL;
52
import java.util.logging.Logger;
52
import java.util.logging.Logger;
53
import org.netbeans.html.boot.spi.Fn;
53
import org.netbeans.html.boot.spi.Fn;
54
import org.netbeans.html.context.spi.Contexts;
54
import org.netbeans.html.json.spi.FunctionBinding;
55
import org.netbeans.html.json.spi.FunctionBinding;
55
import org.netbeans.html.json.spi.JSONCall;
56
import org.netbeans.html.json.spi.JSONCall;
56
import org.netbeans.html.json.spi.PropertyBinding;
57
import org.netbeans.html.json.spi.PropertyBinding;
Lines 65-70 Link Here
65
 *
66
 *
66
 * @author Jaroslav Tulach
67
 * @author Jaroslav Tulach
67
 */
68
 */
69
@Contexts.TechnologyId("ko4j")
68
final class FXContext
70
final class FXContext
69
implements Technology.BatchInit<Object>, Technology.ValueMutated<Object>,
71
implements Technology.BatchInit<Object>, Technology.ValueMutated<Object>,
70
Transfer, WSTransfer<LoadWS> {
72
Transfer, WSTransfer<LoadWS> {
(-)a/ko4j/src/main/java/org/netbeans/html/ko4j/KO4J.java (+3 lines)
Lines 54-59 Link Here
54
/** Support for <a href="http://knockoutjs.com">knockout.js</a>
54
/** Support for <a href="http://knockoutjs.com">knockout.js</a>
55
 * and its Java binding via {@link Model model classes}.
55
 * and its Java binding via {@link Model model classes}.
56
 * Registers {@link Provider}, so {@link java.util.ServiceLoader} can find it.
56
 * Registers {@link Provider}, so {@link java.util.ServiceLoader} can find it.
57
 * The provider registers following technologies:
58
 * <ul>
59
 * </ul>
57
 *
60
 *
58
 * @author Jaroslav Tulach
61
 * @author Jaroslav Tulach
59
 * @since 0.7
62
 * @since 0.7

Return to bug 248918