tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Howard M. Lewis Ship" <hls...@comcast.net>
Subject RE: [PATCH] Javadoc, Logging strings and some
Date Sun, 02 May 2004 22:55:22 GMT
Yep, that's pretty much what I was visualizing. It gets more interesting in the code that is
formatting exception messages, since those do more complex things when calling Tapestry.format().

--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Tapestry: Java Web Components 
Creator, HiveMind
http://howardlewisship.com


> -----Original Message-----
> From: HansD [mailto:cobra@pobox.com] 
> Sent: Sunday, May 02, 2004 4:42 PM
> To: tapestry-dev@jakarta.apache.org
> Subject: RE: [PATCH] Javadoc, Logging strings and some
> 
> 
> 
> Something like:
> 
> //  Copyright 2004 The Apache Software Foundation
> //
> // Licensed under the Apache License, Version 2.0 (the "License");
> // you may not use this file except in compliance with the License.
> // You may obtain a copy of the License at
> //
> //     http://www.apache.org/licenses/LICENSE-2.0
> //
> // Unless required by applicable law or agreed to in writing, software
> // distributed under the License is distributed on an "AS IS" BASIS,
> // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
> express or implied.
> // See the License for the specific language governing permissions and
> // limitations under the License.
> 
> package org.apache.tapestry;
> 
> import java.util.Locale;
> 
> import javax.servlet.http.HttpSession;
> 
> /**
>  * Convenience class for providing formatted messages for the 
>  * {@link org.apache.tapestry} package.
>  * 
>  * <p>
>  * Instead of using hardcoded key-id's in statements like:
>  * <code>throw new 
> ApplicationRuntimeException(Tapestry.format("Parser.unexpected
> DTD", publicId),getLocation());</code>
>  * (or using a constant for the key, like 
> <code>MSG_UNEXPECTED_DTD</code>, 
>  * this can be more clearly expressed as
>  * <code>throw new 
> ApplicationRuntimeException(TapestryMessages.unexpectedDTD(pub
> licId), getLocation());</code>.
>  * 
>  * <p>
>  * Per package their should be a Message class. 
>  *
>  *  @since 3.1 
>  *
>  */
> 
> public final class TapestryMessages {
> 	
> 	/**
> 	 * @return "Returning {engine} to pool."
> 	 */
> 	public final static String engineToPool(IEngine engine) {
> 		return 
> Tapestry.format("ApplicationServlet.engine-to-pool", engine);
> 	}
> 
> 	/**
> 	 * @return "Engine {engine} is stateful even though 
> there is no HttpSession. Discarding the engine."
> 	 */
> 	public final static String 
> engineStatefulWithoutSession(IEngine engine) {
> 		return 
> Tapestry.format("ApplicationServlet.engine-stateful-without-se
> ssion", engine);
> 	}
> 
> 	/**
> 	 * @return "Session invalidated."
> 	 */
> 	public final static String sessionInvalidated() {
> 		return 
> Tapestry.getMessage("ApplicationServlet.session-invalidated");
> 	}
> 
> 	/**
> 	 * @return "Storing {engine} into session as {attribute}."
> 	 */
> 	public final static String 
> storingEngineInSession(IEngine engine, String attribute) {
> 		return 
> Tapestry.format("ApplicationServlet.storing-engine-in-session"
> , engine, attribute);
> 	}
> 
> 	/**
> 	 * @return "Could not locate an engine to service this request."
> 	 */
> 	public final static String engineNotLocated() {
> 		return 
> Tapestry.getMessage("ApplicationServlet.could-not-locate-engine");
> 	}
> 
> 	/**
> 	 * @return "Using pooled engine {engine} (from locale 
> {locale})."
> 	 */
> 	public final static String engineFromPool(IEngine 
> engine, Locale locale) {
> 		return 
> Tapestry.format("ApplicationServlet.using-pooled-engine", 
> engine, locale);
> 	}
> 
> 	/**
> 	 * @return "Session exists, but doesn't contain an engine."
> 	 */
> 	public final static String engineNotInSession() {
> 		return 
> Tapestry.getMessage("ApplicationServlet.session-no-engine");
> 	}
> 
> 	/**
> 	 * @return "Retrieved {engine} from session {session}."
> 	 */
> 	public final static String engineFoundInSession(IEngine 
> engine, HttpSession session) {
> 		return 
> Tapestry.format("ApplicationServlet.engine-fom-session", 
> engine, session.getId());
> 	}
> 
> 	/**
> 	 * @return "Created engine {engine}."
> 	 */
> 	public final static String engineCreated(IEngine engine) {
> 		return 
> Tapestry.format("ApplicationServlet.created-engine", engine);
> 	}
> 
> 	/**
> 	 * @return "Creating engine from class {className}."
> 	 */
> 	public final static String engineToBeCreated(String className) {
> 		return 
> Tapestry.format("ApplicationServlet.creating-engine", className);
> 	}
> 	
> 	
> }
> 
> 
> ?
> 
> 
> 
> >
> >Subject: RE: [PATCH] Javadoc, Logging strings and some
> >   From: "Howard M. Lewis Ship" <hlship@comcast.net>
> >   Date: Sun, 2 May 2004 14:08:11 -0400
> >     To: "'Tapestry development'" <tapestry-dev@jakarta.apache.org>
> >
> >If we were talking instances, I'd say sure ... but with 
> statics, we either eat lots of duplicated
> >code or have unwanted wierdness keeping the resource bundles 
> straight.  I say keep it one big
> >..properties file right now, and leave the format() messages 
> in Tapestry as-is.
> >
> >--
> >Howard M. Lewis Ship
> >Independent J2EE / Open-Source Java Consultant
> >Creator, Tapestry: Java Web Components 
> >Creator, HiveMind
> >http://howardlewisship.com
> >
> >
> >> -----Original Message-----
> >> From: HansD [mailto:cobra@pobox.com] 
> >> Sent: Sunday, May 02, 2004 2:11 PM
> >> To: tapestry-dev@jakarta.apache.org
> >> Subject: RE: [PATCH] Javadoc, Logging strings and some
> >> 
> >> 
> >> 
> >> The static strings were to make the log statements bit more 
> >> readable in the various methods (and with the refactor 
> >> functionality of eclipse the work was not that hard).
> >> But the presence of those statics in the java class was also 
> >> not one of my favorites.
> >> Refactoring to the sugested msg classes is perhaps a better idea.
> >> 
> >> I'm willing to help out with this..
> >> 
> >> So, per package a msg class (derived from a master class 
> >> providing the basic functionality).
> >> Should the properties file also be per package (with some of 
> >> the more general strings moved to a central location)?
> >> 
> >> Hans
> >> 
> >> 
> >> >Subject: RE: [PATCH] Javadoc, Logging strings and some
> >> >   From: "Howard M. Lewis Ship" <hlship@comcast.net>
> >> >   Date: Sun, 2 May 2004 09:26:37 -0400
> >> >     To: "'Tapestry development'" 
> <tapestry-dev@jakarta.apache.org>
> >> >
> >> >I appreciate the effort you area putting into this, but I'm 
> >> not really seeing the added utility of
> >> >all those static strings. For the most part, each of those 
> >> strings is used just once (there's only a
> >> >handful of truly general messages). This ends up making 
> >> Tapestry.java a chokepoint if there are
> >> >multiple developers.
> >> >
> >> >However, I did come up with an alternate idea.
> >> >
> >> >The problem with Tapestry.format() and friends is:
> >> >- You have to know the message key
> >> >- You have to know how all the arguments are used
> >> >- You may have to convert or format some of the objects aguments
> >> >- You may have to create an Object[] array if you have more 
> >> than three arguments
> >> >
> >> >Now, what if there was a TapestryMessages class, and it had 
> >> a static method for each message.  It
> >> >could take typed parameters and, in turn, invoke 
> Tapestry.format().
> >> >
> >> >Better yet, what if each package inside Tapestry had its own 
> >> Mesasges classes, such that there isn't
> >> >a chokepoint.
> >> >
> >> >This would make the Tapestry code that much more readable, i.e.
> >> >
> >> >throw new ApplicationRuntimeException(
> >> >	ParserMessage.unexpectedDTD(publicId), getLocation());
> >> >
> >> >instead of:
> >> >
> >> >throw new ApplicationRuntimeException(
> >> >	Tapestry.format("Parser.unexpectedDTD", publicId),
> >> >      getLocation());
> >> >
> >> >--
> >> >Howard M. Lewis Ship
> >> >Independent J2EE / Open-Source Java Consultant
> >> >Creator, Tapestry: Java Web Components 
> >> >Creator, HiveMind
> >> >http://howardlewisship.com
> >> >
> >> >
> >> >> -----Original Message-----
> >> >> From: HansD [mailto:cobra@pobox.com] 
> >> >> Sent: Sunday, May 02, 2004 4:45 AM
> >> >> To: tapestry-dev@jakarta.apache.org
> >> >> Subject: [PATCH] Javadoc, Logging strings and some
> >> >> 
> >> >> 
> >> >> Howard,
> >> >> 
> >> >> Since you've been updating the 3.1 code to the main trunk,
> >> >> here's a new patch
> >> >> 
> >> >> Please let me know what I can do to improve the quality of 
> >> >> the submitted patches.
> >> >> 
> >> >> Hans
> >> >> 
> >> >> 
> >> <snip>
> >> 
> >> 
> >> 
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: 
> tapestry-dev-help@jakarta.apache.org
> >> 
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org


Mime
View raw message