Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 93134 invoked from network); 20 Jul 2009 12:37:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 Jul 2009 12:37:40 -0000 Received: (qmail 96636 invoked by uid 500); 20 Jul 2009 12:38:44 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 96519 invoked by uid 500); 20 Jul 2009 12:38:44 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 96509 invoked by uid 99); 20 Jul 2009 12:38:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Jul 2009 12:38:43 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of rosenberg.leon@googlemail.com designates 72.14.220.157 as permitted sender) Received: from [72.14.220.157] (HELO fg-out-1718.google.com) (72.14.220.157) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Jul 2009 12:38:32 +0000 Received: by fg-out-1718.google.com with SMTP id l27so479967fgb.1 for ; Mon, 20 Jul 2009 05:38:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=HvlFhrph7rYeaEso9FdOzfmY4eAPcVfvv6vfPexlppE=; b=ax7dyZA67gYJG3T6IpZrRCKHoBSm7jC+LctIXrnCccW/GzA1GuKhDGOmube1iuUClH ejcVVKJMwKrW7T4hmqHq2yXf7H9iNcfGF0+5RgevItlT+V1Twmukh1sHVOI8rWgEcxZ/ 5Qenhd4+IbTfKXgjN8ipSJMvL8iQ1TvdQU6G0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=rBcV/FIycerjHV2+U80YbW0zqRIRkvw9w/xOjKZWC/XSYUTEJWK7U29qXDj2FvbOYl MULYOUXt/8k/hR6s0iYuZjvEHtIDVco8QqKfFTG5vhwJ4ioPEYlkiUPgR3FzXDV00rW8 50OfdYNT3+p1iZnRFzFfE9GEn/82c/h2MPUxg= MIME-Version: 1.0 Received: by 10.86.70.20 with SMTP id s20mr3426905fga.64.1248093491147; Mon, 20 Jul 2009 05:38:11 -0700 (PDT) In-Reply-To: References: <327858f40907190504t28eb5d13w8ec5a808bcdecbfc@mail.gmail.com> Date: Mon, 20 Jul 2009 14:38:11 +0200 Message-ID: <327858f40907200538x58e73727tf861a299adc73cf2@mail.gmail.com> Subject: Re: New Tag - Looking for Comments (Maintain user code during regeneration of files) From: Leon Rosenberg To: Commons Users List Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Hello Jason, thank you very much for the detailed answer. On Mon, Jul 20, 2009 at 12:42 AM, Jason Weinstein wrote: > > Hi Leon, > > Often generated files are only a starting point. An interesting point. Actually the mess that happens if you try to "regenerate" edited generated file is the main agrument against code generation (see also rod johnsons j2ee development without ejb). So why would someone use a system that actually relies on changing generated code? Giving 2 examples: How many real life projects REALLY use code generated by rational rose et al? But, millions of sites are using jsps on the daily basis, as an example of code generator jsp -> jsp.java and i think that noone actually edits and changes code generated by jasper or other jsp generator / compiler. So maybe instead of allowing user to alter generated code and even persist those changes over generation cycles, it makes more sense to parametrize either the generator or the generated code, so there is no need to edit it? Staying with your it would be : public class Factory { private String className =3D RuntimeConfiguration.get("className"); public Object create() throws Exception { return Class.forName(className).newInstance(); } This way you at least can rely that the result of a generation is predictable and repeatable for the defined version of the generator. regards Leon > > Example > > Template > > public class Factory { > > =A0 =A0private String className =3D "${className}"; > > > > =A0 =A0public Object create() throws Exception { > > =A0 =A0 =A0 =A0return Class.forName(className).newInstance(); > > =A0 =A0} > > } > > > First time template generates: > > public class Factory { > =A0 =A0private String className =3D "foo"; > > =A0 =A0public Object create() throws Exception { > =A0 =A0 =A0 =A0return Class.forName(className).newInstance(); > =A0 =A0} > } > > User may change this generated file to be: > > public class Factory { > > =A0 =A0private String className =3D "foo"; > > > > =A0 =A0public Object create() throws Exception { > =A0 =A0 =A0 =A0Object o =3D Class.forName(className).newInstance(); > > =A0 =A0 =A0 =A0System.out.println("creating object " =A0+ o); > =A0 =A0 =A0 =A0Statistic.createdObject(className, +1); > =A0 =A0 =A0 =A0return o; > > =A0 =A0} > > } > > Template may be updated to generate: > > public class Factory { > > =A0 =A0private String className =3D "foo"; > > > > =A0 =A0public Object create() throws Exception { > > > =A0 =A0 =A0 =A0return Class.forName(className).newInstance(); > > > =A0 =A0} > > > > =A0 =A0public Object create(ClassLoader cl) throws Exception { > > > =A0 =A0 =A0 =A0return Class.forName(className, cl, true).newInstance(); > > > =A0 =A0} > > > } > > When user code is maintained the generated file would be > > public class Factory { > > =A0 =A0private String className =3D "foo"; > > > > =A0 =A0public Object create() throws Exception { > =A0 =A0 =A0 =A0Object o =3D Class.forName(className).newInstance(); > > > =A0 =A0 =A0 =A0System.out.println("creating object " =A0+ o); > > =A0 =A0 =A0 =A0Statistic.createdObject(className, +1); > > =A0 =A0 =A0 =A0return o; > > > =A0 =A0} > > > > =A0 =A0public Object create(ClassLoader cl) throws Exception { > > > > =A0 =A0 =A0 =A0return Class.forName(className, cl, true).newInstance(); > > > > =A0 =A0} > > > > } > > And not (missing user code) > > public class Factory { > > > =A0 =A0private String className =3D "foo"; > > > > > > =A0 =A0public Object create() throws Exception { > > > > =A0 =A0 =A0 =A0return Class.forName(className).newInstance(); > > > > =A0 =A0} > > > > > > =A0 =A0public Object create(ClassLoader cl) throws Exception { > > > > =A0 =A0 =A0 =A0return Class.forName(className, cl, true).newInstance(); > > > > =A0 =A0} > > > > } > > > Many times generated files need updating. Sometimes generated files are j= ust starting points meant for the user to fill in and sometimes they are me= ant to be final results but developers/users may wish to make mods to them = anyways. > > The above is a simplistic example, but a user mod could be anything from = adding an annotation to a log statement to employing an optimization such a= s a cache to adding a new method, etc. > > What i presented, was a simple practical way to allow user mods to be mai= ntained during file regeneration. > > In conclusion, very often not everything is accounted for during generati= on. Sometimes the files need to be regenerated as templates change. What wa= s presented was a way to maintain user changes in the generated files as fi= les are regenerated. When combined with a compile step this also allows an = easy way to flag incompatible user changes, or simply flag that the file wa= s changed by the user. > > > These types of comments often need work arounds in real systems as genera= ted code does not always meet user requirements or may even have bugs or ot= her limitations. > > // user generated code - do not modify - overwrites > > > > > > > > A couple side thoughts > > - way to use different template during codegen, useful = as workaround for end user in prod system > - way to test for user mods, and flag errors, may skip whitesp= ace, etc > >> Date: Sun, 19 Jul 2009 14:04:53 +0200 >> Subject: Re: New Tag - Looking for Comments (Maintain user code during = =A0 =A0 =A0 =A0regeneration of files) >> From: rosenberg.leon@googlemail.com >> To: user@commons.apache.org >> >> On Fri, Jul 17, 2009 at 11:11 AM, Jason >> Weinstein wrote: >> > >> > A common problem with templating systems is that they overwrite change= s made >> > to the generated files, when things are regenerated. >> >> Hello, >> >> maybe I don't understand your point, but why should someone change >> generated files? >> >> Leon >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >> For additional commands, e-mail: user-help@commons.apache.org >> > > _________________________________________________________________ > Windows Live=99 Hotmail=AE: Celebrate the moment with your favorite sport= s pics. Check it out. > http://www.windowslive.com/Online/Hotmail/Campaign/QuickAdd?ocid=3DTXT_TA= GLM_WL_QA_HM_sports_photos_072009&cat=3Dsports --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org