jaroslav@110: */
jaroslav@110: public static interface Provider {
jaroslav@110:
jaroslav@110: /** Register into the context if suitable technology is
jaroslav@110: * available for the requesting class.
jaroslav@110: * The provider should check if its own technology is available in current
jaroslav@110: * scope (e.g. proper JDK, proper browser, etc.). The provider
jaroslav@110: * can also find the right context depending on requestor's classloader, etc.
jaroslav@110: *
jaroslav@110: * Providers should use {@link Builder} to enrich appropriately
jaroslav@110: * the context.
jaroslav@110: *
jaroslav@110: * @param context the context builder to fill with technologies
jaroslav@110: * @param requestor the application class requesting access the the HTML page
jaroslav@110: * @see BrwsrCtx#findDefault(java.lang.Class)
jaroslav@110: */
jaroslav@110: void fillContext(Builder context, Class> requestor);
jaroslav@110: }
jaroslav@110:
jaroslav@110: /** Support for providers of new {@link BrwsrCtx}. Providers of different
jaroslav@110: * technologies should be of particular interest in this class. End users
jaroslav@110: * designing their application with existing technologies should rather
jaroslav@110: * point their attention to {@link BrwsrCtx} and co.
jaroslav@110: *
jaroslav@110: * @author Jaroslav Tulach
jaroslav@110: */
jaroslav@110: public static final class Builder {
jaroslav@256: private final CtxImpl impl = new CtxImpl();
jaroslav@110:
jaroslav@110: Builder() {
jaroslav@110: }
jaroslav@110:
jaroslav@110: /** Registers new technology into the context. Each technology is
jaroslav@110: * exactly identified by its implementation class and can be associated
jaroslav@110: * with (positive) priority. In case of presence of multiple technologies
jaroslav@110: * with the same class, the one with higher lower priority takes precedence.
jaroslav@256: * @param type of technology to register
jaroslav@256: * @param type the real class of the technology type
jaroslav@256: * @param impl an instance of the technology class
jaroslav@256: * @param position the lower position, the more important implementation
jaroslav@256: * which will be consulted sooner when seeking for a {@link Contexts#find(net.java.html.BrwsrCtx, java.lang.Class)}
jaroslav@256: * an implementation
jaroslav@256: * @return this builder
jaroslav@110: */
jaroslav@256: public Builder register(Class type, Tech impl, int position) {
jaroslav@256: if (position <= 0) {
jaroslav@110: throw new IllegalStateException();
jaroslav@110: }
jaroslav@256: this.impl.register(type, impl, position);
jaroslav@110: return this;
jaroslav@110: }
jaroslav@110:
jaroslav@110: /** Generates context based on values previously inserted into
jaroslav@110: * this builder.
jaroslav@110: *
jaroslav@110: * @return new, immutable instance of {@link BrwsrCtx}
jaroslav@110: */
jaroslav@110: public BrwsrCtx build() {
jaroslav@110: return impl.build();
jaroslav@110: }
jaroslav@110: }
jaroslav@110: }