Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4AEA1200B3C for ; Wed, 13 Jul 2016 17:54:30 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 496FD160A6A; Wed, 13 Jul 2016 15:54:30 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 912F2160A62 for ; Wed, 13 Jul 2016 17:54:29 +0200 (CEST) Received: (qmail 38125 invoked by uid 500); 13 Jul 2016 15:54:28 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 38110 invoked by uid 99); 13 Jul 2016 15:54:28 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Jul 2016 15:54:28 +0000 Received: from v45346.1blu.de (v45346.1blu.de [178.254.23.72]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id 1EA651A0042 for ; Wed, 13 Jul 2016 15:54:27 +0000 (UTC) Received: by v45346.1blu.de (Postfix, from userid 1000) id 846DF400004; Wed, 13 Jul 2016 17:54:24 +0200 (CEST) From: Stefan Bodewig To: user@ant.apache.org Subject: Re: Advice on how to achieve setting properties on an arbitrary class References: Date: Wed, 13 Jul 2016 17:54:24 +0200 In-Reply-To: (Austin Brooks's message of "Tue, 12 Jul 2016 14:39:54 -0700") Message-ID: <87lh15v8i7.fsf@v45346.1blu.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain archived-at: Wed, 13 Jul 2016 15:54:30 -0000 On 2016-07-12, Austin Brooks wrote: > What is the best way to achieve something that can resemble the following? > > > Basically, I am trying to make an extendable health check task that takes a > class and is then configured using additional attributes or elements. I am > not overly restricted to a certain syntax. The only real requirements I > have are: > 1. Is extendable by passing any class to the class attribute > 2. Custom class is not tied to ant, will pass configuration via hash map or > reflection property setting > So is there a way to configure this by sub-elements or defining a method > that is a collect all bucket for unknown attributes? There are two approaches, which one is better in your case is not completely clear to me. The first approach is to take advantage of as much of Ant as possible. If the classes you want to use provide setters you can use Ant's attribute setting logic[1]. (1) You typedef the classes (2) create an instance of it and let Ant set the properties (3) Use references to use them inside your task or alternatively if there is a commin interface of your check classes you could use an "void add(TheCommonInterface)" method in healthCheck and nest them directly like in The alternative approach is to implement org.apache.tools.ant.DynamicAttribute or its extension DynamicConfigurator (or the NS aware variants) in your task, collect the attributes and configure your checks programmatically. Stefan [1] https://ant.apache.org/manual/develop.html#writingowntask --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org