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
021import org.apache.reef.tang.exceptions.ClassHierarchyException;
022import org.apache.reef.tang.exceptions.ParseException;
023import org.apache.reef.tang.types.NamedParameterNode;
024import org.apache.reef.tang.types.Node;
025
026public interface JavaClassHierarchy extends ClassHierarchy {
027  /**
028   * Look up a class object in this ClassHierarchy. Unlike the version that
029   * takes a string in ClassHierarchy, this version does not throw
030   * NameResolutionException.
031   * <p>
032   * The behavior of this method is undefined if the provided Class object is
033   * not from the ClassLoader (or an ancestor of the ClassLoader) associated
034   * with this JavaClassHierarchy. By default, Tang uses the default runtime
035   * ClassLoader as its root ClassLoader, so static references (expressions like
036   * getNode(Foo.class)) are safe.
037   *
038   * @param c The class to be looked up in the class hierarchy.
039   * @return The associated NamedParameterNode or ClassNode.
040   */
041  Node getNode(Class<?> c);
042
043  Class<?> classForName(String name) throws ClassNotFoundException;
044
045  /**
046   * Parse a string value that has been passed into a named parameter.
047   *
048   * @param <T> A type
049   * @param name  The named parameter that will receive the value.
050   * @param value A string value to be validated and parsed.
051   * @return An instance of T, or a {@code ClassNode<? extends T>}.
052   * @throws ParseException if the value failed to parse, or parsed to the
053   *                        wrong type (such as when it specifies a class that does not implement
054   *                        or extend T).
055   */
056  <T> T parse(NamedParameterNode<T> name, String value) throws ParseException;
057
058  /**
059   * Obtain a parsed instance of the default value of a named parameter.
060   *
061   * @param <T> A type
062   * @param name The named parameter that should be checked for a default instance.
063   * @return The default instance or null, unless T is a set type.  If T is a set,
064   * then this method returns a (potentially empty) set of default instances.
065   * @throws ClassHierarchyException if an instance failed to parse.
066   */
067  <T> T parseDefaultValue(NamedParameterNode<T> name) throws ClassHierarchyException;
068
069}