1 /*
2 * Grapht, an open source dependency injector.
3 * Copyright 2014-2015 various contributors (see CONTRIBUTORS.txt)
4 * Copyright 2010-2014 Regents of the University of Minnesota
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 51
18 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 package org.grouplens.grapht.reflect;
21
22 import java.io.Serializable;
23
24 /**
25 * A possibly-not-concrete type. This represents the type of a dependency; it
26 * may or may not be concrete. It can effectively be any type. Desires are
27 * iteratively resolved and narrowed until they finally correspond to
28 * {@link Satisfaction}s.
29 *
30 * @author <a href="http://grouplens.org">GroupLens Research</a>
31 *
32 */
33 public interface Desire extends Serializable {
34 /**
35 * Query whether this desire is instantiable, that is, resolved to a
36 * concrete type. If it is instantiable, then it can be converted to a Satisfaction
37 * with {@link #getSatisfaction()}.
38 *
39 * @return <tt>true</tt> if the desire is for a concrete class. The only
40 * further desires or satisfactions that can satisfy it are for subclasses
41 * of the desire type.
42 */
43 boolean isInstantiable();
44
45 /**
46 * Get the satisfaction (concrete type) if this desire is fully resolved.
47 *
48 * @return The satisfaction for this desire, or <tt>null</tt> if the desire is not a
49 * concrete type.
50 */
51 Satisfaction getSatisfaction();
52
53 /**
54 * @return The injection point of this desire
55 */
56 InjectionPoint getInjectionPoint();
57
58 /**
59 * @return The desired type, potentially more constrained than the injection
60 * point's type
61 */
62 Class<?> getDesiredType();
63
64 /**
65 * Return a new Desire that restricts the type of this desire to the given
66 * class. The type must be a subclass of the desired type.
67 *
68 * @param type The restricted type
69 * @return A restricted Desire
70 */
71 Desire restrict(Class<?> type);
72
73 /**
74 * Return a new Desire that restricts the type of this desire to the erased
75 * type of the satisfaction. The returned Desire will also be instantiable
76 * and return the provided satisfaction from {@link #getSatisfaction()}.
77 *
78 * @param satisfaction The satisfaction to restrict this desire to
79 * @return A restricted and satisfied desire
80 */
81 Desire restrict(Satisfaction satisfaction);
82 }