From 87118181a63b355cfc23c9333b3b9281b40a2aa2 Mon Sep 17 00:00:00 2001 From: Costin Manolache Date: Fri, 27 Dec 2002 18:01:14 +0000 Subject: [PATCH] Add a new method to get an IntrospectionHelper. If one already exists, it'll be returned. The method will register itself for projectEnd notifications. ( this avoids multiple IH and listeners ) PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273702 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/IntrospectionHelper.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java index a4dec726f..8ef8da741 100644 --- a/src/main/org/apache/tools/ant/IntrospectionHelper.java +++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java @@ -385,6 +385,30 @@ public class IntrospectionHelper implements BuildListener { return ih; } + /** + * Returns a helper for the given class, either from the cache + * or by creating a new instance. + * + * The method will make sure the helper will be cleaned up at the end of + * the project, and only one instance will be created for each class. + * + * @param c The class for which a helper is required. + * Must not be null. + * + * @return a helper for the specified class + */ + public static synchronized IntrospectionHelper getHelper(Project p, Class c) + { + IntrospectionHelper ih = (IntrospectionHelper) helpers.get(c); + if (ih == null) { + ih = new IntrospectionHelper(c); + helpers.put(c, ih); + // Cleanup at end of project + p.addBuildListener(ih); + } + return ih; + } + /** * Sets the named attribute in the given element, which is part of the * given project.