This project has retired. For details please refer to its Attic page.
Source code
001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.tang;
020
021
022import org.apache.reef.tang.annotations.Name;
023import org.apache.reef.tang.exceptions.BindException;
024import org.apache.reef.tang.exceptions.NameResolutionException;
025
026import java.util.List;
027import java.util.Set;
028
029/**
030 * Convenience methods that extend the ConfigurationBuilder but assume that
031 * the underlying ClassHierarchy delegates to the default Java classloader.
032 * <p/>
033 * In addition to being less verbose, this interface expresses many of Tang's
034 * type checks in Java's generic type system.  This improves IDE
035 * auto-completion.  It also allows the errors to be caught at compile time
036 * instead of later on in the build process, or at runtime.
037 *
038 * @see ConfigurationModule which pushes additional type checks to class load
039 * time.  This allows Tint, Tang's static analysis tool, to detect a wide
040 * range of runtime configuration errors at build time.
041 */
042public interface JavaConfigurationBuilder extends ConfigurationBuilder {
043
044  /**
045   * Bind named parameters, implementations or external constructors, depending
046   * on the types of the classes passed in.
047   *
048   * @param iface
049   * @param impl
050   */
051  public <T> JavaConfigurationBuilder bind(Class<T> iface, Class<?> impl) throws BindException;
052
053  /**
054   * Binds the Class impl as the implementation of the interface iface
055   *
056   * @param <T>
057   * @param iface
058   * @param impl
059   */
060  public <T> JavaConfigurationBuilder bindImplementation(Class<T> iface, Class<? extends T> impl)
061      throws BindException;
062
063
064  /**
065   * Set the value of a named parameter.
066   *
067   * @param name  The dummy class that serves as the name of this parameter.
068   * @param value A string representing the value of the parameter. Reef must know
069   *              how to parse the parameter's type.
070   * @throws NameResolutionException
071   */
072  public JavaConfigurationBuilder bindNamedParameter(Class<? extends Name<?>> name, String value)
073      throws BindException;
074
075  public <T> JavaConfigurationBuilder bindNamedParameter(Class<? extends Name<T>> iface,
076                                                         Class<? extends T> impl) throws BindException;
077
078  public <T> JavaConfigurationBuilder bindConstructor(Class<T> c,
079                                                      Class<? extends ExternalConstructor<? extends T>> v) throws BindException;
080
081  public <T> JavaConfigurationBuilder bindSetEntry(Class<? extends Name<Set<T>>> iface, String value) throws BindException;
082
083  public <T> JavaConfigurationBuilder bindSetEntry(Class<? extends Name<Set<T>>> iface, Class<? extends T> impl) throws BindException;
084
085  /**
086   * Binds a specfic list to a named parameter. List's elements can be string values or class implementations.
087   * Their type would be checked in this method. If their types are not applicable to the named parameter,
088   * it will make an exception.
089   *
090   * @param iface The target named parameter to be injected into
091   * @param impl  A concrete list
092   * @param <T>
093   * @return
094   * @throws BindException
095   */
096  public <T> JavaConfigurationBuilder bindList(Class<? extends Name<List<T>>> iface, List impl)
097      throws BindException;
098}