Browse Source

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
master
Stefan Bodewig 17 years ago
parent
commit
f179a42859
1 changed files with 16 additions and 0 deletions
  1. +16
    -0
      src/main/org/apache/tools/ant/types/Resource.java

+ 16
- 0
src/main/org/apache/tools/ant/types/Resource.java View File

@@ -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.
*
* <p>This allows extension interfaces to be added to resources
* without growing the number of permutations of interfaces
* decorators/adapters need to implement.</p>
*
* <p>This implementation of the method will return the current
* instance itself if it can be assigned to the given class.</p>
*
* @since ant 1.8.0
*/
public Object as(Class clazz) {
return clazz.isAssignableFrom(getClass()) ? this : null;
}
}

Loading…
Cancel
Save