From f179a428596b5cdcd1185a3fcf92ec7475cd3cc3 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 17 Nov 2008 09:12:53 +0000 Subject: [PATCH] add an "as" method to Resource that allows extensions without actually implementing additional interfaces git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@718204 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/types/Resource.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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; + } }