diff --git a/src/main/org/apache/tools/ant/types/Resource.java b/src/main/org/apache/tools/ant/types/Resource.java index 1107f06c8..40ccbcdff 100644 --- a/src/main/org/apache/tools/ant/types/Resource.java +++ b/src/main/org/apache/tools/ant/types/Resource.java @@ -423,4 +423,20 @@ public class Resource extends DataType implements Cloneable, Comparable, Resourc super.setRefid(r); } + /** + * Returns a view of this resource that implements the interface + * given as the argument or null if there is no such view. + * + *
This allows extension interfaces to be added to resources + * without growing the number of permutations of interfaces + * decorators/adapters need to implement.
+ * + *This implementation of the method will return the current + * instance itself if it can be assigned to the given class.
+ * + * @since ant 1.8.0 + */ + public Object as(Class clazz) { + return clazz.isAssignableFrom(getClass()) ? this : null; + } }