1.1 --- a/context/src/main/java/org/netbeans/html/context/spi/Contexts.java Tue Aug 26 18:13:30 2014 +0200
1.2 +++ b/context/src/main/java/org/netbeans/html/context/spi/Contexts.java Thu Dec 04 09:21:55 2014 +0100
1.3 @@ -42,6 +42,10 @@
1.4 */
1.5 package org.netbeans.html.context.spi;
1.6
1.7 +import java.lang.annotation.ElementType;
1.8 +import java.lang.annotation.Retention;
1.9 +import java.lang.annotation.RetentionPolicy;
1.10 +import java.lang.annotation.Target;
1.11 import java.util.ServiceLoader;
1.12 import net.java.html.BrwsrCtx;
1.13 import org.netbeans.html.context.impl.CtxImpl;
1.14 @@ -59,11 +63,23 @@
1.15
1.16 /** Creates new, empty builder for creation of {@link BrwsrCtx}. At the
1.17 * end call the {@link Builder#build()} method to generate the context.
1.18 - *
1.19 + *
1.20 + * @param context instances of various classes or names of {@link Id technologies}
1.21 + * to be preferred and used in the built {@link BrwsrCtx context}.
1.22 + * @return new instance of the builder
1.23 + * @since 1.1
1.24 + */
1.25 + public static Builder newBuilder(Object... context) {
1.26 + return new Builder(context);
1.27 + }
1.28 + /** Creates new, empty builder for creation of {@link BrwsrCtx}. At the
1.29 + * end call the {@link Builder#build()} method to generate the context.
1.30 + * Simply calls {@link #newBuilder(java.lang.Object...) newBuilder(new Object[0])}.
1.31 + *
1.32 * @return new instance of the builder
1.33 */
1.34 public static Builder newBuilder() {
1.35 - return new Builder();
1.36 + return newBuilder(new Object[0]);
1.37 }
1.38
1.39 /** Seeks for the specified technology in the provided context.
1.40 @@ -118,6 +134,23 @@
1.41 }
1.42 return found;
1.43 }
1.44 +
1.45 + /** Identifies the technologies passed to {@link Builder context builder}
1.46 + * by a name. Each implementation of a technology
1.47 + * {@link Builder#register(java.lang.Class, java.lang.Object, int) registered into a context}
1.48 + * can be annotated with a name (or multiple names). Such implementation
1.49 + * will later be
1.50 + * {@link Contexts#fillInByProviders(java.lang.Class, org.netbeans.html.context.spi.Contexts.Builder) preferred during lookup}
1.51 + * if their name(s) has been requested in when
1.52 + * {@link Contexts#newBuilder(java.lang.Object...) creating a context}.
1.53 + * @since 1.1
1.54 + */
1.55 + @Retention(RetentionPolicy.RUNTIME)
1.56 + @Target(ElementType.TYPE)
1.57 + public @interface Id {
1.58 + /** Identifier(s) for the implementation. */
1.59 + public String[] value();
1.60 + }
1.61
1.62 /** Implementors of various HTML technologies should
1.63 * register their implementation via <code>org.openide.util.lookup.ServiceProvider</code>, so
1.64 @@ -152,9 +185,10 @@
1.65 * @author Jaroslav Tulach
1.66 */
1.67 public static final class Builder {
1.68 - private final CtxImpl impl = new CtxImpl();
1.69 + private final CtxImpl impl;
1.70
1.71 - Builder() {
1.72 + public Builder(Object[] context) {
1.73 + this.impl = new CtxImpl(context);
1.74 }
1.75
1.76 /** Registers new technology into the context. Each technology is