Return-Path: Delivered-To: apmail-jakarta-hivemind-cvs-archive@www.apache.org Received: (qmail 79331 invoked from network); 11 Feb 2005 15:29:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 11 Feb 2005 15:29:57 -0000 Received: (qmail 6823 invoked by uid 500); 11 Feb 2005 15:29:56 -0000 Delivered-To: apmail-jakarta-hivemind-cvs-archive@jakarta.apache.org Received: (qmail 6807 invoked by uid 500); 11 Feb 2005 15:29:56 -0000 Mailing-List: contact hivemind-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: hivemind-dev@jakarta.apache.org Delivered-To: mailing list hivemind-cvs@jakarta.apache.org Received: (qmail 6792 invoked by uid 99); 11 Feb 2005 15:29:56 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 11 Feb 2005 07:29:54 -0800 Received: (qmail 79313 invoked by uid 1616); 11 Feb 2005 15:29:53 -0000 Date: 11 Feb 2005 15:29:53 -0000 Message-ID: <20050211152953.79312.qmail@minotaur.apache.org> From: hlship@apache.org To: jakarta-hivemind-cvs@apache.org Subject: cvs commit: jakarta-hivemind/examples/src/test/com/panorama/startup/impl TestTaskExecutor.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N hlship 2005/02/11 07:29:53 Modified: framework/src/documentation/content/xdocs/hivemind ThreadLocalStorage.xml src/documentation/content/xdocs index.xml site.xml links.ent localization.xml framework/src/descriptor/META-INF hivemodule.xml framework/src/java/org/apache/hivemind/impl ModuleImpl.java MessageFormatter.java . status.xml framework/src/java/org/apache/hivemind Messages.java HiveMind.java examples/src/test/com/panorama/startup/impl TestTaskExecutor.java Added: framework/src/documentation/content/xdocs/hivemind ThreadLocale.xml framework/src/java/org/apache/hivemind/service/impl ThreadLocaleFactory.java ThreadLocaleImpl.java framework/src/java/org/apache/hivemind/impl MessageFinderImpl.java ModuleMessages.java AbstractMessages.java framework/src/java/org/apache/hivemind/service ThreadLocale.java framework/src/test/org/apache/hivemind TestThreadLocale.java framework/src/java/org/apache/hivemind/internal MessageFinder.java framework/src/test/org/apache/hivemind/impl MessageFinder_fr.properties TestMessageFinder.java MessageFinder.properties Removed: framework/src/java/org/apache/hivemind/impl MessagesImpl.java framework/src/test/hivemind/test TestMessagesImpl.java Log: Allow locale to be changed for each thread. Revision Changes Path 1.7 +14 -21 jakarta-hivemind/framework/src/documentation/content/xdocs/hivemind/ThreadLocalStorage.xml Index: ThreadLocalStorage.xml =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/documentation/content/xdocs/hivemind/ThreadLocalStorage.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ThreadLocalStorage.xml 6 Jan 2005 01:45:14 -0000 1.6 +++ ThreadLocalStorage.xml 11 Feb 2005 15:29:51 -0000 1.7 @@ -14,25 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - - %common-links; - ]> + + + %common-links; + ]> -
- hivemind.ThreadLocalStorage Service -
- -

The - ThreadLocalStorage service implements the ThreadLocalStorage - interface. This service acts as a kind of Map for temporary data. The map - is local to the current thread, and is cleared at the end of the - transaction.

-

It is your responsibility to ensure that keys are unique, typically by - prefixing them with a module id or package name.

- -
+
+ hivemind.ThreadLocalStorage Service +
+ +

The ThreadLocalStorage service implements the ThreadLocalStorage interface. This service acts as a kind of Map for temporary data. The map is local to the current thread, and is cleared at the end of the transaction.

+

It is your responsibility to ensure that keys are unique, typically by prefixing them with a module id or package name.

+ ThreadLocalStorage is likely to be removed in a future release of HiveMind. It is advised that you use the threaded service model instead. + + \ No newline at end of file 1.1 jakarta-hivemind/framework/src/documentation/content/xdocs/hivemind/ThreadLocale.xml Index: ThreadLocale.xml =================================================================== %common-links; ]>
hivemind.ThreadLocale Service

The ThreadLocale service implements the ThreadLocale interface. This service stores the current thread's locale. You may use this service to read or update the thread's current locale.

1.27 +5 -0 jakarta-hivemind/src/documentation/content/xdocs/index.xml Index: index.xml =================================================================== RCS file: /home/cvs/jakarta-hivemind/src/documentation/content/xdocs/index.xml,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- index.xml 10 Feb 2005 01:04:34 -0000 1.26 +++ index.xml 11 Feb 2005 15:29:51 -0000 1.27 @@ -98,6 +98,11 @@

You can now omit the package name (generally) when specifying class name in a module descriptor. The &module; element's package attribute provides the package name to use.

+ +

+ The locale (used for localized messages) is no longer fixed, as it was in 1.0. You can change + the locale using the &hivemind.ThreadLocale; service. +

1.41 +1 -0 jakarta-hivemind/src/documentation/content/xdocs/site.xml Index: site.xml =================================================================== RCS file: /home/cvs/jakarta-hivemind/src/documentation/content/xdocs/site.xml,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- site.xml 16 Jan 2005 15:54:05 -0000 1.40 +++ site.xml 11 Feb 2005 15:29:51 -0000 1.41 @@ -78,6 +78,7 @@ href="LoggingInterceptor.html"/> + 1.23 +1 -0 jakarta-hivemind/src/documentation/content/xdocs/links.ent Index: links.ent =================================================================== RCS file: /home/cvs/jakarta-hivemind/src/documentation/content/xdocs/links.ent,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- links.ent 16 Jan 2005 15:54:05 -0000 1.22 +++ links.ent 11 Feb 2005 15:29:51 -0000 1.23 @@ -150,6 +150,7 @@ hivemind.SymbolSources'> +hivemind.ThreadLocale'> hivemind.ThreadLocalStorage'> hivemind.Translators'> 1.8 +28 -2 jakarta-hivemind/src/documentation/content/xdocs/localization.xml Index: localization.xml =================================================================== RCS file: /home/cvs/jakarta-hivemind/src/documentation/content/xdocs/localization.xml,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- localization.xml 5 Jan 2005 21:53:31 -0000 1.7 +++ localization.xml 11 Feb 2005 15:29:51 -0000 1.8 @@ -47,6 +47,13 @@ ]]>

The two keys (message.key and other.message.key ) are searched for in the contributing module's messages.

+ + + Support for this '%' syntax will likely be removed soon. This is because + the locale is now changeable; what locale to use when converting configuration + data becomes dangerously ambiguous. + +

HiveMind gracefully recovers from undefined messages. If a message is not in the properties file, then HiveMind provides a substitute value by converting the key to upper-case and adding brackets, i.e. @@ -56,11 +63,30 @@ example, adding a second file, META-INF/hivemodule_fr.properties would provide French language localizations. Any common keys between the two files defer to the more specific file.

+ +

+ The &hivemind.BuilderFactory; can inject an &api.Messages; object that allows access + to the module's messages. +

Setting the locale

When a &api.Registry; is created by the &api.RegistryBuilder;, a locale - is specified. This is the locale for the Registry and, by extension, for - all Modules in the registry. The locale may not be changed.

+ is specified. This is the default locale for the Registry and, by extension, for + all Modules in the registry.

+ +

+ Threads will always use this locale by default, but the locale for + an individual thread may be changed using the &hivemind.ThreadLocale; service. + The &api.Messages; injected into your services automatically adjusts for the + thread's current locale. +

+ +

+ You should not store, in your services, any localized values, since different threads + may want different localizations. Instead, you should always obtain values + from the &api.Messages;. +

+
1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/ThreadLocaleFactory.java Index: ThreadLocaleFactory.java =================================================================== // Copyright 2005 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.hivemind.service.impl; import java.util.Locale; import org.apache.hivemind.ServiceImplementationFactory; import org.apache.hivemind.ServiceImplementationFactoryParameters; /** * Specialized factory used to create instances of * {@link org.apache.hivemind.service.impl.ThreadLocaleImpl}(i.e., service hivemind.ThreadLocale). * This is necessary because there isn't a way to inject the Registry's locale into a property. It's * also more efficient, and this is a service that will be constructed frequently. * * @author Howard M. Lewis Ship * @since 1.1 */ public class ThreadLocaleFactory implements ServiceImplementationFactory { public Object createCoreServiceImplementation( ServiceImplementationFactoryParameters factoryParameters) { Locale defaultLocale = factoryParameters.getInvokingModule().getLocale(); return new ThreadLocaleImpl(defaultLocale); } } 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/ThreadLocaleImpl.java Index: ThreadLocaleImpl.java =================================================================== // Copyright 2005 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.hivemind.service.impl; import java.util.Locale; import org.apache.hivemind.service.ThreadLocale; import org.apache.hivemind.util.Defense; /** * @author Howard M. Lewis Ship * @since 1.1 */ public class ThreadLocaleImpl implements ThreadLocale { private Locale _locale; public ThreadLocaleImpl(Locale locale) { setLocale(locale); } public void setLocale(Locale locale) { Defense.notNull(locale, "locale"); _locale = locale; } public Locale getLocale() { return _locale; } } 1.23 +17 -0 jakarta-hivemind/framework/src/descriptor/META-INF/hivemodule.xml Index: hivemodule.xml =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/descriptor/META-INF/hivemodule.xml,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- hivemodule.xml 10 Feb 2005 01:04:33 -0000 1.22 +++ hivemodule.xml 11 Feb 2005 15:29:52 -0000 1.23 @@ -701,4 +701,21 @@ + + + Stores the locale for the current thread. The default is determined when the Registry is first + constructed. This locale is used for any messages. + + + + + + + + Special service implementation factory for the ThreadLocale service. + + + + + 1.17 +13 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ModuleImpl.java Index: ModuleImpl.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ModuleImpl.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- ModuleImpl.java 10 Feb 2005 01:04:33 -0000 1.16 +++ ModuleImpl.java 11 Feb 2005 15:29:52 -0000 1.17 @@ -21,13 +21,16 @@ import org.apache.hivemind.ApplicationRuntimeException; import org.apache.hivemind.ClassResolver; import org.apache.hivemind.ErrorHandler; +import org.apache.hivemind.HiveMind; import org.apache.hivemind.Location; import org.apache.hivemind.Messages; +import org.apache.hivemind.internal.MessageFinder; import org.apache.hivemind.internal.Module; import org.apache.hivemind.internal.RegistryInfrastructure; import org.apache.hivemind.internal.ServiceModelFactory; import org.apache.hivemind.internal.ServicePoint; import org.apache.hivemind.schema.Translator; +import org.apache.hivemind.service.ThreadLocale; import org.apache.hivemind.util.IdUtils; import org.apache.hivemind.util.ToStringBuilder; @@ -122,7 +125,16 @@ public synchronized Messages getMessages() { if (_messages == null) - _messages = new MessagesImpl(getLocation().getResource(), _registry.getLocale()); + { + ThreadLocale threadLocale = (ThreadLocale) _registry.getService( + HiveMind.THREAD_LOCALE_SERVICE, + ThreadLocale.class, + this); + + MessageFinder finder = new MessageFinderImpl(getLocation().getResource()); + + _messages = new ModuleMessages(finder, threadLocale); + } return _messages; } 1.8 +10 -76 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/MessageFormatter.java Index: MessageFormatter.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/MessageFormatter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- MessageFormatter.java 5 Jan 2005 18:04:09 -0000 1.7 +++ MessageFormatter.java 11 Feb 2005 15:29:52 -0000 1.8 @@ -14,23 +14,23 @@ package org.apache.hivemind.impl; -import java.text.MessageFormat; +import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hivemind.HiveMind; /** - * A wrapper around {@link java.util.ResourceBundle} that makes - * it easier to access and format messages. - * + * A wrapper around {@link java.util.ResourceBundle}that makes it easier to access and format + * messages. + * * @author Howard Lewis Ship */ -public class MessageFormatter +public class MessageFormatter extends AbstractMessages { private Log _log; + private ResourceBundle _bundle; public MessageFormatter(Log log, ResourceBundle bundle) @@ -54,7 +54,7 @@ this(log, ResourceBundle.getBundle(bundleName)); } - public String getMessage(String key) + protected String findMessage(String key) { try { @@ -63,78 +63,12 @@ catch (MissingResourceException ex) { _log.error("Missing resource key: " + key + "."); - return "[" + key.toUpperCase() + "]"; - } - } - - public String format(String key, Object arg) - { - return format(key, new Object[] { arg }); - } - - public String format(String key, Object arg1, Object arg2) - { - return format(key, new Object[] { arg1, arg2 }); - } - - public String format(String key, Object arg1, Object arg2, Object arg3) - { - return format(key, new Object[] { arg1, arg2, arg3 }); - } - - /** - * Formats a message using the key to obtain a pattern, and passing the arguments. - * - *

- * It is common to pass an exception instance as an arg. Those are treated specially: - * The exception instance is replaced with its message {@link Throwable#getMessage()}. If the - * message is blank (null or empty), then the exception's class name is used. - */ - public String format(String key, Object[] args) - { - String pattern = getMessage(key); - - if (args == null) - return pattern; - - for (int i = 0; i < args.length; i++) - { - if (args[i] instanceof Throwable) - { - Throwable t = (Throwable) args[i]; - - args[i] = extractMessage(t); - } - } - - try - { - return MessageFormat.format(pattern, args); - } - catch (Exception ex) - { - _log.error("Unable to format message: \"" + pattern + "\" from key " + key + ".", ex); - return null; } } - /** - * Extracts the message from an exception. If the message is null, the the class name - * of the exception is returned. - * - */ - private String extractMessage(Throwable t) + protected Locale getLocale() { - if (t == null) - return null; - - String message = t.getMessage(); - - if (HiveMind.isBlank(message)) - return t.getClass().getName(); - - return message; + return Locale.getDefault(); } - -} +} \ No newline at end of file 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/MessageFinderImpl.java Index: MessageFinderImpl.java =================================================================== // Copyright 2005 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.hivemind.impl; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Properties; import org.apache.hivemind.ApplicationRuntimeException; import org.apache.hivemind.Resource; import org.apache.hivemind.internal.MessageFinder; import org.apache.hivemind.util.Defense; import org.apache.hivemind.util.LocalizedNameGenerator; /** * @author Howard M. Lewis Ship * @since 1.1 */ public class MessageFinderImpl implements MessageFinder { private static final String EXTENSION = ".properties"; private static class Localization { private Locale _locale; private Resource _resource; Localization(Locale locale, Resource resource) { _locale = locale; _resource = resource; } public Locale getLocale() { return _locale; } public Resource getResource() { return _resource; } } private Resource _baseResource; private String _baseName; private Map _propertiesMap = new HashMap(); private Properties _emptyProperties = new Properties(); public MessageFinderImpl(Resource baseResource) { Defense.notNull(baseResource, "baseResource"); _baseResource = baseResource; // Strip off the extension to form the base name // when building new (localized) resources. String name = _baseResource.getName(); int dotx = name.lastIndexOf('.'); _baseName = name.substring(0, dotx); } public String getMessage(String key, Locale locale) { return findProperties(locale).getProperty(key); } private synchronized Properties findProperties(Locale locale) { Properties result = (Properties) _propertiesMap.get(locale); // If doesn't exist, build it (which will update the // propertiesMap as a side effect. if (result == null) result = buildProperties(locale); return result; } private Properties buildProperties(Locale locale) { Properties result = _emptyProperties; List localizations = findLocalizations(locale); Iterator i = localizations.iterator(); while (i.hasNext()) { Localization l = (Localization) i.next(); result = readProperties(l.getLocale(), l.getResource(), result); } return result; } /** * Returns the properties, reading them if necessary. Properties may have been previously read * for this locale, in which case the cached value is returned. Also, if the resource doesn't * exist, then the parent is returned as is. Updates the propertiesMap cache. */ private Properties readProperties(Locale locale, Resource propertiesResource, Properties parent) { Properties result = (Properties) _propertiesMap.get(locale); if (result != null) return result; URL url = propertiesResource.getResourceURL(); if (url == null) result = parent; else result = readPropertiesFile(url, parent); _propertiesMap.put(locale, result); return result; } private Properties readPropertiesFile(URL url, Properties parent) { InputStream stream = null; Properties result = new Properties(parent); try { stream = new BufferedInputStream(url.openStream()); result.load(stream); stream.close(); stream = null; } catch (IOException ex) { throw new ApplicationRuntimeException(ImplMessages.unableToReadMessages(url), ex); } finally { close(stream); } return result; } private void close(InputStream stream) { if (stream != null) try { stream.close(); } catch (IOException ex) { // Ignore. } } /** * Returns a List of Localizations, in order from most generic (i.e., hivemodule.properties) to * most specific (i.e., hivemodule_en_US_yokel.properties). */ private List findLocalizations(Locale locale) { List result = new ArrayList(); LocalizedNameGenerator g = new LocalizedNameGenerator(_baseName, locale, EXTENSION); while (g.more()) { String name = g.next(); Localization l = new Localization(g.getCurrentLocale(), _baseResource .getRelativeResource(name)); result.add(l); } Collections.reverse(result); return result; } } 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ModuleMessages.java Index: ModuleMessages.java =================================================================== // Copyright 2005 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.hivemind.impl; import java.util.Locale; import org.apache.hivemind.internal.MessageFinder; import org.apache.hivemind.service.ThreadLocale; import org.apache.hivemind.util.Defense; /** * An implementation of {@link org.apache.hivemind.Messages}that obtains messages from a * {@link org.apache.hivemind.internal.MessageFinder}, in a locale provided by the * {@link org.apache.hivemind.service.ThreadLocale}service. * * @author Howard M. Lewis Ship * @since 1.1 */ public class ModuleMessages extends AbstractMessages { private MessageFinder _messageFinder; private ThreadLocale _threadLocale; public ModuleMessages(MessageFinder messageFinder, ThreadLocale threadLocale) { Defense.notNull(messageFinder, "messageFinder"); Defense.notNull(threadLocale, "threadLocale"); _messageFinder = messageFinder; _threadLocale = threadLocale; } protected Locale getLocale() { return _threadLocale.getLocale(); } protected String findMessage(String key) { return _messageFinder.getMessage(key, getLocale()); } } 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/AbstractMessages.java Index: AbstractMessages.java =================================================================== // Copyright 2005 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.hivemind.impl; import java.text.MessageFormat; import java.util.Locale; import org.apache.hivemind.HiveMind; import org.apache.hivemind.Messages; import org.apache.hivemind.util.Defense; /** * Abstract base class for implementations of {@link org.apache.hivemind.Messages}. Subclasses must * provide {@link #getLocale()}and {@link #findMessage(String)}implementations. * * @author Howard M. Lewis Ship * @since 1.1 */ public abstract class AbstractMessages implements Messages { public String format(String key, Object[] args) { String pattern = getMessage(key); for (int i = 0; i < args.length; i++) { Object arg = args[i]; if (arg != null && arg instanceof Throwable) args[i] = extractMessage((Throwable) arg); } // This ugliness is mandated for JDK 1.3 compatibility, which has a bug // in MessageFormat ... the // pattern is applied in the constructor, using the system default Locale, // regardless of what locale is later specified! // It appears that the problem does not exist in JDK 1.4. MessageFormat messageFormat = new MessageFormat(""); messageFormat.setLocale(getLocale()); messageFormat.applyPattern(pattern); return messageFormat.format(args); } private String extractMessage(Throwable t) { String message = t.getMessage(); return HiveMind.isNonBlank(message) ? message : t.getClass().getName(); } public String format(String key, Object arg0) { return format(key, new Object[] { arg0 }); } public String format(String key, Object arg0, Object arg1) { return format(key, new Object[] { arg0, arg1 }); } public String format(String key, Object arg0, Object arg1, Object arg2) { return format(key, new Object[] { arg0, arg1, arg2 }); } public String getMessage(String key) { Defense.notNull(key, "key"); String result = findMessage(key); if (result == null) result = "[" + key.toUpperCase() + "]"; return result; } /** * Concrete implementations must provide a non-null Locale. */ protected abstract Locale getLocale(); /** * Concrete implementations must implement this method. * * @param key * @returns the localized message for the key, or null if no such message exists. */ protected abstract String findMessage(String key); } 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/service/ThreadLocale.java Index: ThreadLocale.java =================================================================== // Copyright 2005 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.hivemind.service; import java.util.Locale; /** * The hivemind.ThreadLocale service is intrinsic to HiveMind; its a threaded service for storing * the locale for the current thread (it uses the threaded service). * * @author Howard M. Lewis Ship * @since 1.1 */ public interface ThreadLocale { /** * Changes the locale from the default. */ public void setLocale(Locale locale); /** * Returns the current locale. Initially, this is the * {@link org.apache.hivemind.Registry#getLocale()}default locale. This may be changed for a * thread. */ public Locale getLocale(); } 1.97 +113 -373 jakarta-hivemind/status.xml Index: status.xml =================================================================== RCS file: /home/cvs/jakarta-hivemind/status.xml,v retrieving revision 1.96 retrieving revision 1.97 diff -u -r1.96 -r1.97 --- status.xml 10 Feb 2005 01:04:32 -0000 1.96 +++ status.xml 11 Feb 2005 15:29:52 -0000 1.97 @@ -20,7 +20,6 @@ - JMX Integration @@ -29,390 +28,131 @@ visibility (configuration points, service points), interceptor sets - - - - - Better, prettier HiveDoc. - - - Error running examples using Ant targets. - - - Add package attribute to <module> and automatically qualify Java class and interface names - into that package. - + Better, prettier HiveDoc. + Error running examples using Ant targets. + Add package attribute to <module> and automatically qualify Java class and interface names into that package. + Allow the locale to be changed. - - - Added <dependency> construct providing support for dependencies between modules. - Refactoring of RegistryBuilder: Now constructs Registry using a ModuleProvider. - - - Add visibility (public or private) to configuration points, service points and schemas. - - - Add <null> constructor parameter element to BuilderFactory service. - - - Report error if module descriptors define conflicting service or configuration points. - - - HiveDoc is now being generated from the parsed module descriptors instead of directly from - the XML files. This will allow HiveDoc generation for module descriptors in other formats. - - - Upgrade to Forrest 0.6 (still in progress). - - - Re-work the HiveDoc report to work naturally at the module (not project) level. - - - CVS connection string on website is incorrect - - - Synchronize all access to java.beans.Introspector through a common mutex. - - - Clear the PropertyUtils and Introspector caches when the Registry is shutdown. - - - Properly report the actual method name when invoking a service initializer method. - - - Move some logic related to primitive Java types and arrays from Tapestry directly into DefaultClassResolver. - - - ApplicationRuntimeException will now display the location (if known) as part of its toString() method, making it - much easier to track down problems in stack traces (especially deeply nested ones). - - - Add support for the ErrorLog (a simple wrapper around an ErrorHandler and a Log). Add support - for setting the service's ErrorLog to BuilderFactory. - - - Switch Javassist to version 3.0-rc-1. - - - Add toString() support to ClassFab and MethodFab. - - - Add the hivemind.lib.AdapterRegistryFactory service implementation factory. - - Removed the module parameter from ClassFactory.newClass() and from - DefaultImplementationBuilder.buildDefaultImplementation(). - - BuilderFactory now supports autowiring through constructor based dependency injection. - - - Add ability to set default value for non-matches in MethodMatcher. - - - Improve MethodSignature and MethodIterator to filter out duplicate methods that differ - only in terms of thrown exceptions. - - - Change BuilderFactoryLogic to report the actual exception, not the InvocationTargetException, - when an exception is thrown by a constructor or by a initializer method invocation. - - - Added Groovy support. Module descriptors can now be defined using Groovy scripts. Although - it requires some additional work in building the Registry. - - - Support the EasyMock Class Extension, if present on the classpath, to allow classes (not just - interfaces) to be mocked. - - - Refactored SpringLookupFactory to identify a Spring BeanFactory directly, rather than - via a SpringBeanFactorySource. - - - Added support for mapped configurations. A configuration schema can now specify an attribute - which should be used as the key in a Map of all contributions. The BuilderFactory can inject - such configurations as List or Maps. - - - Move ContextResource from Tapestry to HiveMind. - - - Change HiveMindFilter load WEB-INF/hivemodule.xml if present. - - - Add support for conditional contributions. - - - Allow services to be serialized (that is, service proxies can be serialized and - deserialized). - - - Smart translator properly returns attribute values as Strings when used with - a <push-attribute> rule. - - - Attribute values are symbol-expanded by a <push-attribute> rule before being - translated and pushed on the stack. - - - Add hivemind.lib.ChainBuilder service, an implementation of Gang Of Four Chain of Command. - - - Add hivemind.lib.ChainFactory service. - + Added <dependency> construct providing support for dependencies between modules. Refactoring of RegistryBuilder: Now constructs Registry using a ModuleProvider. + Add visibility (public or private) to configuration points, service points and schemas. + Add <null> constructor parameter element to BuilderFactory service. + Report error if module descriptors define conflicting service or configuration points. + HiveDoc is now being generated from the parsed module descriptors instead of directly from the XML files. This will allow HiveDoc generation for module descriptors in other formats. + Upgrade to Forrest 0.6 (still in progress). + Re-work the HiveDoc report to work naturally at the module (not project) level. + CVS connection string on website is incorrect + Synchronize all access to java.beans.Introspector through a common mutex. + Clear the PropertyUtils and Introspector caches when the Registry is shutdown. + Properly report the actual method name when invoking a service initializer method. + Move some logic related to primitive Java types and arrays from Tapestry directly into DefaultClassResolver. + ApplicationRuntimeException will now display the location (if known) as part of its toString() method, making it much easier to track down problems in stack traces (especially deeply nested ones). + Add support for the ErrorLog (a simple wrapper around an ErrorHandler and a Log). Add support for setting the service's ErrorLog to BuilderFactory. + Switch Javassist to version 3.0-rc-1. + Add toString() support to ClassFab and MethodFab. + Add the hivemind.lib.AdapterRegistryFactory service implementation factory. + Removed the module parameter from ClassFactory.newClass() and from DefaultImplementationBuilder.buildDefaultImplementation(). + BuilderFactory now supports autowiring through constructor based dependency injection. + Add ability to set default value for non-matches in MethodMatcher. + Improve MethodSignature and MethodIterator to filter out duplicate methods that differ only in terms of thrown exceptions. + Change BuilderFactoryLogic to report the actual exception, not the InvocationTargetException, when an exception is thrown by a constructor or by a initializer method invocation. + Added Groovy support. Module descriptors can now be defined using Groovy scripts. Although it requires some additional work in building the Registry. + Support the EasyMock Class Extension, if present on the classpath, to allow classes (not just interfaces) to be mocked. + Refactored SpringLookupFactory to identify a Spring BeanFactory directly, rather than via a SpringBeanFactorySource. + Added support for mapped configurations. A configuration schema can now specify an attribute which should be used as the key in a Map of all contributions. The BuilderFactory can inject such configurations as List or Maps. + Move ContextResource from Tapestry to HiveMind. + Change HiveMindFilter load WEB-INF/hivemodule.xml if present. + Add support for conditional contributions. + Allow services to be serialized (that is, service proxies can be serialized and deserialized). + Smart translator properly returns attribute values as Strings when used with a <push-attribute> rule. + Attribute values are symbol-expanded by a <push-attribute> rule before being translated and pushed on the stack. + Add hivemind.lib.ChainBuilder service, an implementation of Gang Of Four Chain of Command. + Add hivemind.lib.ChainFactory service. + + + Ensure that the logging interceptor will work properly when wrapping around JDK dynamic proxies. + + + Add method getSymbolValue() to RegistryInfrastructure and Module + Fix class loader issues concerning fabricated classes in different modules. + Allow symbols to be escaped rather than expanded. + The previous fix was incomplete; this should close the remaining sychronization gaps. + Class loading issue inside Tomcat. + Tweak HiveMind to work properly in a JavaWebStart application. + Add clearCache() method to PropertyUtils. + Change the API for ClassFactory to take a ClassLoader, not a Module. + Handle duplicated methods in service interfaces, avoiding "attempt to redefine method" errors. + Class loading issue inside Tomcat. + Tweak HiveMind to work properly in a JavaWebStart application. + Add clearCache() method to PropertyUtils. + Change the API for ClassFactory to take a ClassLoader, not a Module. + Handle duplicated methods in service interfaces, avoiding "attempt to redefine method" errors. - - - - Ensure that the logging interceptor will work properly when wrapping around JDK dynamic proxies. - - - - - - Add method getSymbolValue() to RegistryInfrastructure and Module - - - Fix class loader issues concerning fabricated classes in different modules. - - - Allow symbols to be escaped rather than expanded. - - - The previous fix was incomplete; this should close the remaining sychronization gaps. - - - Class loading issue inside Tomcat. - - - Tweak HiveMind to work properly in a JavaWebStart application. - - - Add clearCache() method to PropertyUtils. - - - Change the API for ClassFactory to take a ClassLoader, not a Module. - - - Handle duplicated methods in service interfaces, avoiding "attempt to redefine method" errors. - - - Class loading issue inside Tomcat. - - - Tweak HiveMind to work properly in a JavaWebStart application. - - - Add clearCache() method to PropertyUtils. - - - Change the API for ClassFactory to take a ClassLoader, not a Module. - - - Handle duplicated methods in service interfaces, avoiding "attempt to redefine method" errors. - - - - - Remove support for Simple Data Language ... it's all XML again. - - - Re-work part of PipelineFactory to take advantage of object references. - - - Make the service-id of <invoke-factory> optional and default - to hivemind.BuilderFactory. - - - Change the hivemind.Startup configuration to take an object reference, not - a service id. - - - SmartTranslator should differentiate between blank strings and null input - - - Improvements to HiveBuild to properly handle changing versions or useages of artifacts. - - - Add ability to mark attributes of an element as unique, such that - duplicate values in contributions result in errors. - - - Add checks to SchemaProcessorImpl for empty stack conditions - - - Add parameters-occurs attribute to <service-point> element. - - - Specify location in all module deployment descriptor parse exceptions. - - - Add Quick Reference Sheet. - - - Add getCause() method to ApplicationRuntimeException - - - Add polling methods to Registry. - - - Add polling methods to BeanFactory. - - - Fix broken synchronization in ThreadedServiceModel and PooledServiceModel that could make them - randomly fail when creating a service by invoking a factory. - - - Check for <sub-module> references that do not exist. - + Remove support for Simple Data Language ... it's all XML again. + Re-work part of PipelineFactory to take advantage of object references. + Make the service-id of <invoke-factory> optional and default to hivemind.BuilderFactory. + Change the hivemind.Startup configuration to take an object reference, not a service id. + SmartTranslator should differentiate between blank strings and null input + Improvements to HiveBuild to properly handle changing versions or useages of artifacts. + Add ability to mark attributes of an element as unique, such that duplicate values in contributions result in errors. + Add checks to SchemaProcessorImpl for empty stack conditions + Add parameters-occurs attribute to <service-point> element. + Specify location in all module deployment descriptor parse exceptions. + Add Quick Reference Sheet. + Add getCause() method to ApplicationRuntimeException + Add polling methods to Registry. + Add polling methods to BeanFactory. + Fix broken synchronization in ThreadedServiceModel and PooledServiceModel that could make them randomly fail when creating a service by invoking a factory. + Check for <sub-module> references that do not exist. - - - Removed dependency on Werkz. - - - Added link to the Jakarta mailing lists page. - - - Modifed the build scripts to properly include variable info when compiling. - - - Moved the Ant build scripts to a new directory, hivebuild, in preparation - for making hivebuild reusable on new projects. - - - Added protected method constructRegistry() to HiveMindFilter. - - - Renamed existing 'object' translator to 'instance', and created - a new 'object' translator with great flexibility. Extend BuilderFactory - to add a set-object element that leverages the object translator. - - - Created service-property object translator. - - - Added a version of Registry.getService() that omits the service id - (but requires that exactly one service point implements the service interface). - - - Extended the BuilderFactory to autowire services. - - - Added a new module that contains HiveMind example code. - - - Fixed some latent bugs related to submodules inside the constructRegistry task. - Made some more improvements to the hivebuild scripts. - - - Updated the download location for the Forrest distribution. - - - Added more examples and examples documentation. - - - Added StrictErrorHandler, an implementation of ErrorHandler that always throws an ApplicationRuntimeException. - - - Moved the code for the Grabber Ant task into the tree and improve the build scripts to dynamically - compile and use it. - - - Typo in jar-module.xml causes broken build if junit library is missing - - - Made a number of changes to ensure HiveMind compatibility with JDK 1.3. - - - Changed some unit tests to adapt to platform line endings. - - - Fix the HiveDoc XSL to use XML (not SDL) output. - + Removed dependency on Werkz. + Added link to the Jakarta mailing lists page. + Modifed the build scripts to properly include variable info when compiling. + Moved the Ant build scripts to a new directory, hivebuild, in preparation for making hivebuild reusable on new projects. + Added protected method constructRegistry() to HiveMindFilter. + Renamed existing 'object' translator to 'instance', and created a new 'object' translator with great flexibility. Extend BuilderFactory to add a set-object element that leverages the object translator. + Created service-property object translator. + Added a version of Registry.getService() that omits the service id (but requires that exactly one service point implements the service interface). + Extended the BuilderFactory to autowire services. + Added a new module that contains HiveMind example code. + Fixed some latent bugs related to submodules inside the constructRegistry task. Made some more improvements to the hivebuild scripts. + Updated the download location for the Forrest distribution. + Added more examples and examples documentation. + Added StrictErrorHandler, an implementation of ErrorHandler that always throws an ApplicationRuntimeException. + Moved the code for the Grabber Ant task into the tree and improve the build scripts to dynamically compile and use it. + Typo in jar-module.xml causes broken build if junit library is missing + Made a number of changes to ensure HiveMind compatibility with JDK 1.3. + Changed some unit tests to adapt to platform line endings. + Fix the HiveDoc XSL to use XML (not SDL) output. - Added change log. - Refactored ClassFab and related classes - for easier reuse outside of HiveMind. Added a new suite of tests - related to ClassFab. - Created two new services in hivemind-lib for - creating default implementations of arbitrary interfaces (DefaultImplementationBuilder) - and for using that to create placeholder services (PlaceholderFactory). - Created MessageFormatter class as a wrapper - around ResourceBundle and an easy way for individual packages to gain - access to runtime messages. - Modified the read-attribute rule to allow - a translator to be specified (overriding the translator for the - attribute). - Added the qualified-id and - id-list translators. - Added the hivemind.lib.PipelineFactory - and related code, schemas, tests and documentation. - Enhance logging of - exceptions when setting a service property to a contribution - Added service hivemind.lib.BeanFactoryBuilder. - - Removed the <description> element - from the module descriptor format; descriptions are now provided as - enclosed text for element that support descriptions. - Changed the MethodMatcher classes to use - a MethodSignature rather than a Method. - Changed MessageFormatter to - automatically convert Throwables into their message or class name. - + Refactored ClassFab and related classes for easier reuse outside of HiveMind. Added a new suite of tests related to ClassFab. + Created two new services in hivemind-lib for creating default implementations of arbitrary interfaces (DefaultImplementationBuilder) and for using that to create placeholder services (PlaceholderFactory). + Created MessageFormatter class as a wrapper around ResourceBundle and an easy way for individual packages to gain access to runtime messages. + Modified the read-attribute rule to allow a translator to be specified (overriding the translator for the attribute). + Added the qualified-id and id-list translators. + Added the hivemind.lib.PipelineFactory and related code, schemas, tests and documentation. + Enhance logging of exceptions when setting a service property to a contribution + Added service hivemind.lib.BeanFactoryBuilder. + Removed the <description> element from the module descriptor format; descriptions are now provided as enclosed text for element that support descriptions. + Changed the MethodMatcher classes to use a MethodSignature rather than a Method. + Changed MessageFormatter to automatically convert Throwables into their message or class name. Added FileResource. - Extended hivemind.BuilderFactory to - be able to set the ClassResolver; for a service - implementation, and to autowire common properties (log, messages, - serviceId, errorHandler, classResolver) if the properties are writeable - and of the correct type. - - Added methods newControl(), newMock(), - addControl(), replayControls() - and verifyControls() to HiveMindTestCase - to simplify test cases that use multiple - EasyMock mock objects. - - - Changed HiveMindFilter to log a message after it stores - the registry into the servlet context. - - - Restore the getConfiguration() and expandSymbols() - methods to the Registry interface. - - SimpleDataLanguageParser calls the - ContentHandler with a null namespace argument instead of "". That leads - to some problems if you want to use transformers. - - Fix how certain translator messages are generated to avoid unit test failures. - - - Modify the build files to enable debugging by default. - - - Added validation of id attributes in module deployment descriptors (using ORO regular expressions). - - - Fix some typos in definition of the - hivemind.lib.NameLookup - service. - - - Fix a mistake in the BuilderFactory's set-object element, and add integration tests. - + Extended hivemind.BuilderFactory to be able to set the ClassResolver; for a service implementation, and to autowire common properties (log, messages, serviceId, errorHandler, classResolver) if the properties are writeable and of the correct type. + Added methods newControl(), newMock(), addControl(), replayControls() and verifyControls() to HiveMindTestCase to simplify test cases that use multiple EasyMock mock objects. + Changed HiveMindFilter to log a message after it stores the registry into the servlet context. + Restore the getConfiguration() and expandSymbols() methods to the Registry interface. + SimpleDataLanguageParser calls the ContentHandler with a null namespace argument instead of "". That leads to some problems if you want to use transformers. + Fix how certain translator messages are generated to avoid unit test failures. + Modify the build files to enable debugging by default. + Added validation of id attributes in module deployment descriptors (using ORO regular expressions). + Fix some typos in definition of the hivemind.lib.NameLookup service. + Fix a mistake in the BuilderFactory's set-object element, and add integration tests. \ No newline at end of file 1.1 jakarta-hivemind/framework/src/test/org/apache/hivemind/TestThreadLocale.java Index: TestThreadLocale.java =================================================================== // Copyright 2005 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.hivemind; import java.util.Locale; import org.apache.hivemind.impl.RegistryBuilder; import org.apache.hivemind.service.ThreadLocale; import org.apache.hivemind.test.HiveMindTestCase; /** * Tests for {@link org.apache.hivemind.service.ThreadLocale}service. We revert to using * integration tests because unit tests would not be very meaningful. * * @author Howard M. Lewis Ship * @since 1.1 */ public class TestThreadLocale extends HiveMindTestCase { public void testThreadSpecific() throws Exception { final Registry r = RegistryBuilder.constructDefaultRegistry(); final ThreadLocale tl = (ThreadLocale) r.getService(ThreadLocale.class); assertSame(r.getLocale(), tl.getLocale()); tl.setLocale(Locale.KOREAN); assertSame(Locale.KOREAN, tl.getLocale()); Thread t = new Thread() { public void run() { assertSame(r.getLocale(), tl.getLocale()); } }; t.start(); t.join(); } public void testResetOnThreadCleanup() throws Exception { Registry r = RegistryBuilder.constructDefaultRegistry(); ThreadLocale tl = (ThreadLocale) r.getService(ThreadLocale.class); Locale start = r.getLocale(); assertSame(start, tl.getLocale()); tl.setLocale(Locale.CANADA_FRENCH); r.cleanupThread(); assertSame(start, tl.getLocale()); } } 1.4 +12 -27 jakarta-hivemind/framework/src/java/org/apache/hivemind/Messages.java Index: Messages.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/Messages.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Messages.java 5 Jan 2005 18:05:21 -0000 1.3 +++ Messages.java 11 Feb 2005 15:29:52 -0000 1.4 @@ -15,43 +15,28 @@ package org.apache.hivemind; /** - * A set of localized message strings. This is somewhat like - * a {@link java.util.ResourceBundle}, but with more - * flexibility about where the messages come from. In addition, - * it includes methods similar to {@link java.text.MessageFormat} - * for treating the messages as patterns. + * A set of localized message strings. This is somewhat like a {@link java.util.ResourceBundle}, + * but with more flexibility about where the messages come from. In addition, it includes methods + * similar to {@link java.text.MessageFormat}for treating the messages as patterns. * * @author Howard Lewis Ship - * */ public interface Messages { /** - * Searches for a localized string with the given key. - * If not found, a modified version of the key - * is returned (all upper-case and surrounded by square - * brackets). + * Searches for a localized string with the given key. If not found, a modified version of the + * key is returned (all upper-case and surrounded by square brackets). */ public String getMessage(String key); /** - * Searches for a localized string with the given key. - * If not found, then the default value (which should already - * be localized) is returned. Passing a default of null - * is useful when trying to determine if the strings contains - * a given key. - */ - - public String getMessage(String key, String defaultValue); - - /** - * Formats a string, using - * {@link MessageFormat#format(java.lang.String, java.lang.Object[])}. - * - * @param key the key used to obtain a localized pattern using - * {@link #getMessage(String)} - * @param arguments passed to the formatter + * Formats a string, using {@link MessageFormat#format(java.lang.String, java.lang.Object[])}. + * + * @param key + * the key used to obtain a localized pattern using {@link #getMessage(String)} + * @param arguments + * passed to the formatter */ public String format(String key, Object[] arguments); @@ -71,4 +56,4 @@ * Convienience method for invoking {@link #format(String, Object[])}. */ public String format(String key, Object argument1, Object argument2, Object argument3); -} +} \ No newline at end of file 1.16 +7 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/HiveMind.java Index: HiveMind.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/HiveMind.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- HiveMind.java 5 Jan 2005 18:05:21 -0000 1.15 +++ HiveMind.java 11 Feb 2005 15:29:52 -0000 1.16 @@ -29,10 +29,16 @@ public static final String THREAD_EVENT_NOTIFIER_SERVICE = "hivemind.ThreadEventNotifier"; /** + * The full id of the {@link org.apache.hivemind.service.ThreadLocale}service. + */ + + public static final String THREAD_LOCALE_SERVICE = "hivemind.ThreadLocale"; + + /** * An object used to synchronize access to {@link java.beans.Introspector}(which is not fully * threadsafe). * - * @since 3.1 + * @since 1.1 */ public static final Object INTROSPECTOR_MUTEX = new Object(); 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/MessageFinder.java Index: MessageFinder.java =================================================================== // Copyright 2005 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.hivemind.internal; import java.util.Locale; /** * An abstraction around the ResourceBundler-style property names and localized messages. The goal * is to implement a {@link org.apache.hivemind.Messages}that obtains the actual localizations from * an external source. * * @author Howard M. Lewis Ship */ public interface MessageFinder { /** * Returns a message matching the key, in the indicated locale. */ public String getMessage(String key, Locale locale); } 1.1 jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/MessageFinder_fr.properties Index: MessageFinder_fr.properties =================================================================== # Copyright 2005 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. overridden-in-base=MessageFinder_fr.overriden-in-base 1.1 jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestMessageFinder.java Index: TestMessageFinder.java =================================================================== // Copyright 2005 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.hivemind.impl; import java.util.Locale; import org.apache.hivemind.internal.MessageFinder; import org.apache.hivemind.test.HiveMindTestCase; import org.apache.hivemind.util.ClasspathResource; /** * @author Howard M. Lewis Ship */ public class TestMessageFinder extends HiveMindTestCase { private MessageFinder newFinder() { ClasspathResource r = new ClasspathResource(new DefaultClassResolver(), "org/apache/hivemind/impl/MessageFinder.xml"); return new MessageFinderImpl(r); } public void testLocaleOverridesBase() { MessageFinder mf = newFinder(); assertEquals("MessageFinder_fr.overriden-in-base", mf.getMessage( "overridden-in-base", Locale.FRENCH)); // FRANCE is more detailed than FRENCH // Also, there is no MessageFinder_fr_FR.properties file, // and that's ok. assertEquals("MessageFinder_fr.overriden-in-base", mf.getMessage( "overridden-in-base", Locale.FRANCE)); } public void testLocaleDoeNotObscureBase() { MessageFinder mf = newFinder(); assertEquals("MessageFinder.only-in-properties", mf.getMessage( "only-in-base", Locale.FRENCH)); } } 1.1 jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/MessageFinder.properties Index: MessageFinder.properties =================================================================== # Copyright 2005 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. only-in-base=MessageFinder.only-in-properties overridden-in-base=MessageFinder.overriden-in-base 1.10 +8 -2 jakarta-hivemind/examples/src/test/com/panorama/startup/impl/TestTaskExecutor.java Index: TestTaskExecutor.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/examples/src/test/com/panorama/startup/impl/TestTaskExecutor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- TestTaskExecutor.java 5 Jan 2005 18:06:00 -0000 1.9 +++ TestTaskExecutor.java 11 Feb 2005 15:29:53 -0000 1.10 @@ -24,7 +24,11 @@ import org.apache.hivemind.ErrorLog; import org.apache.hivemind.Messages; import org.apache.hivemind.Resource; -import org.apache.hivemind.impl.MessagesImpl; +import org.apache.hivemind.impl.MessageFinderImpl; +import org.apache.hivemind.impl.ModuleMessages; +import org.apache.hivemind.internal.MessageFinder; +import org.apache.hivemind.service.ThreadLocale; +import org.apache.hivemind.service.impl.ThreadLocaleImpl; import org.apache.hivemind.test.AggregateArgumentsMatcher; import org.apache.hivemind.test.ArgumentMatcher; import org.apache.hivemind.test.HiveMindTestCase; @@ -69,8 +73,10 @@ String path = projectRoot + "/examples/src/descriptor/META-INF/panorama.startup.xml"; Resource r = new FileResource(path); + MessageFinder mf = new MessageFinderImpl(r); + ThreadLocale tl = new ThreadLocaleImpl(Locale.getDefault()); - return new MessagesImpl(r, Locale.getDefault()); + return new ModuleMessages(mf, tl); } public void testSuccess() --------------------------------------------------------------------- To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org