Moving Context into its own separate module, renaming to BrwsrCtx and making it flexible
2 * HTML via Java(tm) Language Bindings
3 * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. apidesign.org
13 * designates this particular file as subject to the
14 * "Classpath" exception as provided by apidesign.org
15 * in the License file that accompanied this code.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. Look for COPYING file in the top folder.
19 * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
21 package org.apidesign.html.context.spi;
23 import net.java.html.BrwsrCtx;
24 import org.apidesign.html.context.impl.CtxImpl;
28 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
30 public final class Contexts {
34 /** Creates new, empty builder for creation of {@link BrwsrCtx}. At the
35 * end call the {@link #build()} method to generate the context.
37 * @return new instance of the builder
39 public static Builder newBuilder() {
43 /** Seeks for the specified technology in the provided context.
45 * @param <Tech> type of the technology
46 * @param context the context to seek in
47 * (previously filled with ({@link Builder#register(java.lang.Class, java.lang.Object, int)})
48 * @param technology class that identifies the technology
51 public static <Tech> Tech find(BrwsrCtx context, Class<Tech> technology) {
52 return CtxImpl.find(context, technology);
55 /** Implementors of various HTML technologies should
56 * register their implementation via {@link ServiceProvider} so
57 * {@link ServiceProvider} can find them, when their JARs are included
58 * on the classpath of the running application.
60 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
62 public static interface Provider {
64 /** Register into the context if suitable technology is
65 * available for the requesting class.
66 * The provider should check if its own technology is available in current
67 * scope (e.g. proper JDK, proper browser, etc.). The provider
68 * can also find the right context depending on requestor's classloader, etc.
70 * Providers should use {@link Builder} to enrich appropriately
73 * @param context the context builder to fill with technologies
74 * @param requestor the application class requesting access the the HTML page
75 * @see BrwsrCtx#findDefault(java.lang.Class)
77 void fillContext(Builder context, Class<?> requestor);
80 /** Support for providers of new {@link BrwsrCtx}. Providers of different
81 * technologies should be of particular interest in this class. End users
82 * designing their application with existing technologies should rather
83 * point their attention to {@link BrwsrCtx} and co.
85 * @author Jaroslav Tulach <jtulach@netbeans.org>
87 public static final class Builder {
88 private CtxImpl impl = new CtxImpl();
93 /** Registers new technology into the context. Each technology is
94 * exactly identified by its implementation class and can be associated
95 * with (positive) priority. In case of presence of multiple technologies
96 * with the same class, the one with higher lower priority takes precedence.
98 public <Tech> Builder register(Class<Tech> type, Tech impl, int priority) {
100 throw new IllegalStateException();
102 this.impl.register(type, impl, priority);
106 /** Generates context based on values previously inserted into
109 * @return new, immutable instance of {@link BrwsrCtx}
111 public BrwsrCtx build() {