hlship 2003/07/02 14:41:14
Modified: hivemind/src/java/org/apache/commons/hivemind/impl
BaseModule.java ServiceExtensionPointImpl.java
RegistryBuilder.java
ConfigurationContributionImpl.java
RegistryImpl.java
hivemind/src/java/org/apache/commons/hivemind Registry.java
ServiceExtensionPoint.java Module.java
HiveMindMessages.properties InterceptorStack.java
hivemind/xdocs descriptor.xml navigation.xml
hivemind/src/test/hivemind/test TestRegistryBuilder.java
HiveMindSuite.java HiveMindTestCase.java
hivemind/src/java/org/apache/commons/hivemind/parse
AbstractConfigurator.java DescriptorParser.java
HiveMind_1.0.xsd ServiceRefDescriptor.java
ExpressionDescriptor.java XMLDescriptor.java
ValueDescriptor.java
AbstractInstanceBuilderDescriptor.java
ResourceDescriptor.java
hivemind/src/java/org/apache/commons/hivemind/service
NameLookup.java
hivemind/src/test/hivemind/test/parse
TestDescriptorParser.java TestToString.java
hivemind/src/xsl hivemind.xsl
hivemind/src/test/hivemind/test/config MockRegistry.java
TestConfiguration.java
hivemind/common links.xml
hivemind/src/test/hivemind/test/services TestServices.java
hivemind/src/test/hivemind/test/external
TestExternalParser.java
Added: hivemind/src/java/org/apache/commons/hivemind/impl
MessagesImpl.java
hivemind/xdocs localization.xml
hivemind/src/test/hivemind/test TestMessagesImpl.java
hivemind/src/java/org/apache/commons/hivemind/parse
MessageDescriptor.java
hivemind/src/test/hivemind/test/parse Message.xml
SetMessage.xml
hivemind/src/test/hivemind/test/config
hivemodule_fr.properties hivemodule.properties
Messages.xml
Log:
Add support for localization via the <message> and <set-message> elements.
Revision Changes Path
1.6 +14 -2
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/BaseModule.java
Index: BaseModule.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/BaseModule.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BaseModule.java 30 Jun 2003 23:04:29 -0000 1.5
+++ BaseModule.java 2 Jul 2003 21:41:12 -0000 1.6
@@ -61,8 +61,8 @@
import java.util.List;
import java.util.Map;
-import org.apache.commons.hivemind.HiveMind;
import org.apache.commons.hivemind.ConfigurationExtensionPoint;
+import org.apache.commons.hivemind.HiveMind;
import org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.Registry;
import org.apache.commons.hivemind.ServiceExtensionPoint;
@@ -70,6 +70,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.ApplicationRuntimeException;
+import org.apache.tapestry.IMessages;
+import org.apache.tapestry.IResourceLocation;
import org.apache.tapestry.IResourceResolver;
import org.apache.tapestry.spec.BaseLocatable;
@@ -86,6 +88,7 @@
private String _moduleId;
private Registry _registry;
private IResourceResolver _resolver;
+ private IMessages _messages;
/**
* Map of [EMAIL PROTECTED] IServiceExtensionPoint} keyed on fully qualified id.
@@ -267,6 +270,15 @@
public IResourceResolver getResourceResolver()
{
return _resolver;
+ }
+
+ public synchronized IMessages getMessages()
+ {
+ if (_messages == null)
+ _messages =
+ new MessagesImpl(getLocation().getResourceLocation(),
_registry.getLocale());
+
+ return _messages;
}
public String toString()
1.3 +2 -2
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/ServiceExtensionPointImpl.java
Index: ServiceExtensionPointImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/ServiceExtensionPointImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ServiceExtensionPointImpl.java 2 Jul 2003 15:40:38 -0000 1.2
+++ ServiceExtensionPointImpl.java 2 Jul 2003 21:41:12 -0000 1.3
@@ -74,7 +74,7 @@
import org.apache.tapestry.IResourceResolver;
/**
- * Implementation of [EMAIL PROTECTED]
org.apache.commons.hivemind.IServiceExtensionPoint}.
+ * Implementation of [EMAIL PROTECTED]
org.apache.commons.hivemind.ServiceExtensionPoint}.
*
* @author Howard Lewis Ship
* @version $Id$
1.11 +7 -6
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/RegistryBuilder.java
Index: RegistryBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/RegistryBuilder.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- RegistryBuilder.java 2 Jul 2003 15:40:38 -0000 1.10
+++ RegistryBuilder.java 2 Jul 2003 21:41:12 -0000 1.11
@@ -64,6 +64,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import org.apache.commons.hivemind.HiveMind;
@@ -92,7 +93,7 @@
* Class used to build a [EMAIL PROTECTED] org.apache.commons.hivemind.Registry}
from individual
* [EMAIL PROTECTED] org.apache.commons.hivemind.parse.ModuleDescriptor}. The
descriptors
* are processed one at a time and the registry is constructed using a single call
- * to [EMAIL PROTECTED] #constructRegistry()} at the end.
+ * to [EMAIL PROTECTED] #constructRegistry(Locale)} at the end.
*
* <p>
* A note about threadsafety: The assumption is that a single thread will access
the RegistryBuilder
@@ -189,7 +190,7 @@
/**
* Processes a parsed HiveMind module descriptor. This may be called
- * repeatedly before invoking [EMAIL PROTECTED] #constructRegistry()}.
+ * repeatedly before invoking [EMAIL PROTECTED] #constructRegistry(Locale)}.
*
* @param resolver A resolver used to access resources and classes within the
module.
* @param md the parsed module descriptor
@@ -389,7 +390,7 @@
* This first resolves all the contributions, then constructs and returns
* the registry.
*/
- public Registry constructRegistry()
+ public Registry constructRegistry(Locale locale)
{
// TBD: check dependencies and versions!
@@ -410,7 +411,7 @@
checkConfigurationCounts();
- RegistryImpl result = new RegistryImpl();
+ RegistryImpl result = new RegistryImpl(locale);
// Add each module to the registry.
@@ -526,7 +527,7 @@
}
/**
- * Adds an [EMAIL PROTECTED] AbstractInstanceBuilderDescriptor}
+ * Adds an [EMAIL PROTECTED]
org.apache.commons.hivemind.parse.AbstractInstanceBuilderDescriptor}
* to a service extension point.
*
*
1.2 +3 -3
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/ConfigurationContributionImpl.java
Index: ConfigurationContributionImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/ConfigurationContributionImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConfigurationContributionImpl.java 30 Jun 2003 23:04:29 -0000 1.1
+++ ConfigurationContributionImpl.java 2 Jul 2003 21:41:12 -0000 1.2
@@ -102,8 +102,8 @@
}
/**
- * Invokes [EMAIL PROTECTED] ValueProvider#provideValue(Module)}, passing
- * the module which contributed the value provider.
+ * Invokes [EMAIL PROTECTED]
org.apache.commons.hivemind.parse.ValueProvider#provideValue(Module)},
+ * passing the module which contributed the value provider.
*/
public Object getContributedElement(ConfigurationExtensionPoint point)
{
1.2 +21 -3
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/RegistryImpl.java
Index: RegistryImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/RegistryImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RegistryImpl.java 30 Jun 2003 23:04:29 -0000 1.1
+++ RegistryImpl.java 2 Jul 2003 21:41:12 -0000 1.2
@@ -61,6 +61,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import org.apache.commons.hivemind.HiveMind;
@@ -86,13 +87,29 @@
private Map _modules = new HashMap();
private SymbolSource[] _variableSources;
+ private Locale _locale;
+
+ public RegistryImpl(Locale locale)
+ {
+ _locale = locale;
+ }
- public synchronized void addModule(Module module)
+ public Locale getLocale()
+ {
+ return _locale;
+ }
+
+ // Only invoked during the non-threaded initialization phase.
+
+ public void addModule(Module module)
{
_modules.put(module.getModuleId(), module);
}
- public synchronized Module getModule(String moduleId)
+ // Invoked post-initialization, but _modules
+ // is stable
+
+ public Module getModule(String moduleId)
{
Module result = (Module) _modules.get(moduleId);
@@ -136,6 +153,7 @@
{
ToStringBuilder builder = new ToStringBuilder(this);
+ builder.append("locale", _locale);
builder.append("modules", _modules.size());
return builder.toString();
1.1
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/MessagesImpl.java
Index: MessagesImpl.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.hivemind.impl;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import org.apache.commons.hivemind.HiveMind;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.IMessages;
import org.apache.tapestry.IResourceLocation;
import org.apache.tapestry.util.LocalizedNameGenerator;
/**
* Implementation of [EMAIL PROTECTED] org.apache.tapestry.IMessages} for
* a [EMAIL PROTECTED] org.apache.commons.hivemind.Module}.
*
* @author Howard Lewis Ship
* @version $Id: MessagesImpl.java,v 1.1 2003/07/02 21:41:12 hlship Exp $
*/
public class MessagesImpl implements IMessages
{
private static final Log LOG = LogFactory.getLog(MessagesImpl.class);
private Properties _properties;
private Locale _locale;
public MessagesImpl(IResourceLocation moduleLocation, Locale locale)
{
_locale = locale;
initialize(moduleLocation);
}
private void initialize(IResourceLocation moduleLocation)
{
if (LOG.isDebugEnabled())
LOG.debug("Reading message properties for module at " + moduleLocation);
LocalizedNameGenerator g = new LocalizedNameGenerator("hivemodule", _locale,
".properties");
List urls = new ArrayList();
while (g.more())
{
String name = g.next();
IResourceLocation l = moduleLocation.getRelativeLocation(name);
URL url = l.getResourceURL();
if (url != null)
urls.add(url);
}
// Now read an assemble them, least specific to most specific.
// More specific keys overwrite less specific keys.
int count = urls.size();
_properties = new Properties();
for (int i = count - 1; i >= 0; i--)
{
URL url = (URL) urls.get(i);
if (LOG.isDebugEnabled())
LOG.debug("Reading message properties from " + url);
try
{
InputStream stream = url.openStream();
_properties.load(stream);
stream.close();
}
catch (IOException ex)
{
throw new ApplicationRuntimeException(
HiveMind.format("MessagesImpl.unable-to-read", url),
ex);
}
}
}
public String getMessage(String key)
{
String result = _properties.getProperty(key);
if (result == null)
result = "[" + key.toUpperCase() + "]";
// Reasons not to write the result back in as a new property:
// 1) This is a developer error that should be resolved before an app goes
into production
// 2) Would have to synchronize getMessage() methods
// 3) Would screw up #getMessage(String, String)
return result;
}
public String getMessage(String key, String defaultValue)
{
return _properties.getProperty(key, defaultValue);
}
public String format(String key, Object[] args)
{
String pattern = getMessage(key);
// 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(_locale);
messageFormat.applyPattern(pattern);
return messageFormat.format(args);
}
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 });
}
}
1.2 +8 -1
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/Registry.java
Index: Registry.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/Registry.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Registry.java 30 Jun 2003 23:04:30 -0000 1.1
+++ Registry.java 2 Jul 2003 21:41:12 -0000 1.2
@@ -58,6 +58,7 @@
package org.apache.commons.hivemind;
import java.util.List;
+import java.util.Locale;
import org.apache.tapestry.ILocation;
@@ -122,4 +123,10 @@
*/
public String convertSymbols(String input, ILocation location);
+
+ /**
+ * Returns the locale for which the registry was created.
+ */
+
+ public Locale getLocale();
}
1.2 +3 -3
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/ServiceExtensionPoint.java
Index: ServiceExtensionPoint.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/ServiceExtensionPoint.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServiceExtensionPoint.java 30 Jun 2003 23:04:30 -0000 1.1
+++ ServiceExtensionPoint.java 2 Jul 2003 21:41:12 -0000 1.2
@@ -60,7 +60,7 @@
import java.util.List;
/**
- * Sub-interface of [EMAIL PROTECTED] IServiceExtensionPoint}
+ * Sub-interface of [EMAIL PROTECTED] org.apache.commons.hivemind.ExtensionPoint}
* that defines a service extension point. A service may have
* a single factory contribution, and any number of interceptor
* contributions.
@@ -106,7 +106,7 @@
* <p>Once the core implementation is created and the interceptor
* stack is assembled, the core implementation is checked
* to see if it implements [EMAIL PROTECTED] InitializeService}.
- * If so [EMAIL PROTECTED]
InitializeService#initializeService(IServiceExtensionPoint, Object)}
+ * If so [EMAIL PROTECTED]
InitializeService#initializeService(ServiceExtensionPoint, Object)}
* is invoked, to let the core service implementation
* initialize.
*
1.2 +11 -1
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/Module.java
Index: Module.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/Module.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Module.java 30 Jun 2003 23:04:30 -0000 1.1
+++ Module.java 2 Jul 2003 21:41:12 -0000 1.2
@@ -60,6 +60,7 @@
import java.util.List;
import org.apache.tapestry.ILocatable;
+import org.apache.tapestry.IMessages;
import org.apache.tapestry.IResourceResolver;
/**
@@ -132,4 +133,13 @@
*/
public IResourceResolver getResourceResolver();
+
+ /**
+ * Returns an object that can provide and format localized messages for this
+ * module. The messages come from a properties file,
+ * <code>hivemodule.properties</code> (localized)
+ * stored with the HiveMind deployment descriptor in the META-INF folder.
+ */
+
+ public IMessages getMessages();
}
1.9 +3 -1
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/HiveMindMessages.properties
Index: HiveMindMessages.properties
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/HiveMindMessages.properties,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- HiveMindMessages.properties 1 Jul 2003 20:13:02 -0000 1.8
+++ HiveMindMessages.properties 2 Jul 2003 21:41:12 -0000 1.9
@@ -58,6 +58,8 @@
InterceptorStack.null-interceptor=Service {0} generated a null interceptor (for
service extension point {1}).
InterceptorStack.null-factory=Interceptor factory {0} (requested for service
extension point {1}) is null and is being skipped.
+MessagesImpl.unable-to-read=Unable to read message properties from {0}.
+
# parse package
InstanceBuilderDescriptor.unable-to-set-property=Unable to set property {0} of {1}
to {2}: {3}
1.2 +2 -2
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/InterceptorStack.java
Index: InterceptorStack.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/InterceptorStack.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InterceptorStack.java 30 Jun 2003 23:04:30 -0000 1.1
+++ InterceptorStack.java 2 Jul 2003 21:41:12 -0000 1.2
@@ -78,7 +78,7 @@
/**
* Returns the interface for the service; the same
- * as [EMAIL PROTECTED] IServiceExtensionPoint#getServiceInterface()}.
+ * as [EMAIL PROTECTED] ServiceExtensionPoint#getServiceInterface()}.
*/
public Class getServiceInterface();
1.12 +71 -1 jakarta-commons-sandbox/hivemind/xdocs/descriptor.xml
Index: descriptor.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/descriptor.xml,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- descriptor.xml 2 Jul 2003 15:40:38 -0000 1.11
+++ descriptor.xml 2 Jul 2003 21:41:12 -0000 1.12
@@ -408,6 +408,11 @@
<td>Includes a literal value as a contribution
to the extension point.</td>
</tr>
<tr>
+ <td colspan="2"><a
href="#message">message</a></td>
+ <td>0..n</td>
+ <td>A localized message.</td>
+ </tr>
+ <tr>
<td colspan="2">
<a href="#service-ref">service-ref</a>
</td>
@@ -535,6 +540,13 @@
</tr>
<tr>
<td colspan="2">
+ <a href="#set-message">set-message</a>
+ </td>
+ <td>0..n</td>
+ <td>Sets a property of the object to a
localized message.</td>
+ </tr>
+ <tr>
+ <td colspan="2">
<a
href="#setservice-ref">set-service-ref</a>
</td>
<td>0..n</td>
@@ -963,6 +975,64 @@
resource file.</td>
</tr>
</table>
+ </section>
+
+ <section name="message">
+
+ <p> &_message; contributes a localized message provided by the
contributing
+ module. </p>
+
+ <table>
+ <tr>
+ <th>Attribute</th>
+ <th>Type</th>
+ <th>Required ?</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td>key</td>
+ <td>string</td>
+ <td>yes</td>
+ <td>The message key</td>
+ </tr>
+ </table>
+
+ <p>
+ &_message; contains the same elements as &configuration;, with
+ the exception of &_description; which is excluded.
+ </p>
+ </section>
+
+ <section name="set-message">
+
+ <p> &_set-message; contributes a localized message provided by the
contributing
+ module. </p>
+
+ <table>
+ <tr>
+ <th>Attribute</th>
+ <th>Type</th>
+ <th>Required ?</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td>property</td>
+ <td>string</td>
+ <td>yes</td>
+ <td>The name of the property to be
updated.</td>
+ </tr>
+ <tr>
+ <td>key</td>
+ <td>string</td>
+ <td>yes</td>
+ <td>The message key</td>
+ </tr>
+ </table>
+
+ <p>
+ &_message; contains the same elements as &configuration;, with
+ the exception of &_description; which is excluded.
+ </p>
</section>
<section name="new">
1.9 +1 -0 jakarta-commons-sandbox/hivemind/xdocs/navigation.xml
Index: navigation.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/navigation.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- navigation.xml 24 Jun 2003 19:04:32 -0000 1.8
+++ navigation.xml 2 Jul 2003 21:41:12 -0000 1.9
@@ -5,6 +5,7 @@
<menu name="Reference">
<item name="Services" href="/services.html"/>
<item name="Configurations" href="/configuration.html"/>
+ <item name="Localization" href="/localization.html"/>
<item name="Module Descriptor" href="/descriptor.html"/>
<item name="HiveMind Registry" href="/registry.html"/>
<item name="Ant Tasks" href="/ant/index.html" collapse="true">
1.1 jakarta-commons-sandbox/hivemind/xdocs/localization.xml
Index: localization.xml
===================================================================
<?xml version="1.0"?>
<!-- $Id: localization.xml,v 1.1 2003/07/02 21:41:12 hlship Exp $ -->
<!DOCTYPE document [
<!ENTITY % common-links SYSTEM "../common/links.xml">
%common-links;
]>
<document>
<properties>
<title>HiveMind Localization</title>
<author email="[EMAIL PROTECTED]">Howard M. Lewis Ship</author>
</properties>
<body>
<section name="Localization">
<p>
Every HiveMind module may have its own set of messages. Messages are stored alongside
the module deployment descriptor, as
<code>META-INF/hivemodule.properties</code> (within the module's JAR).
</p>
<p>
Within the HiveMind module descriptor, the
&message; and &set-message;
elements can access the strings in the properties file.
</p>
<p>
By adding additional files, message localization can be accomplished. For example,
adding a second file, <code>META-INF/hivemodule_fr.properties</code>
would provide French language localizations. Any common keys between the two files
defer to the more specific file.
</p>
</section>
<section name="Building complex messages">
<p>
The &message; and &set-message; elements may take a list of arguments. The arguments
are plugged into the message as arguments. Internally, HiveMind uses
the <code>MessageFormat</code> class, which allows a lot of flexibility. For example:
<source>
<![CDATA[<message key="greeting">
<expression>new java.util.Date()</expression>
</message>
]]></source>
Would build a message by obtaining the <code>greeting</code> string pattern from the
properties file
and substituting the current date for <code>{0}</code>.
</p>
</section>
<section name="Setting the locale">
<p>
When a
<a href="apidocs/org/apache/commons/hivemind/Registry.html">Registry</a>
is created by the
<a
href="apidocs/org/apache/commons/hivemind/impl/RegistryBuilder.html">RegistryBuilder</a>,
a locale may be specified. This is the locale for the Registry and, by extension
for all Modules.
The locale may not be changed. By default, the JVM default locale is used.
</p>
</section>
</body>
</document>
1.3 +4 -3
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/TestRegistryBuilder.java
Index: TestRegistryBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/TestRegistryBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestRegistryBuilder.java 30 Jun 2003 23:04:31 -0000 1.2
+++ TestRegistryBuilder.java 2 Jul 2003 21:41:12 -0000 1.3
@@ -61,6 +61,7 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;
+import java.util.Locale;
import org.apache.commons.hivemind.Registry;
import org.apache.commons.hivemind.impl.RegistryBuilder;
@@ -88,7 +89,7 @@
b.processModules(_resolver);
- Registry r = b.constructRegistry();
+ Registry r = b.constructRegistry(Locale.getDefault());
try
{
@@ -121,7 +122,7 @@
RegistryBuilder b = new RegistryBuilder();
b.processModules(resolver);
- Registry r = b.constructRegistry();
+ Registry r = b.constructRegistry(Locale.getDefault());
List l = r.getConfiguration("hivemind.test.config.Dogs");
assertEquals(1, l.size());
1.8 +2 -1
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/HiveMindSuite.java
Index: HiveMindSuite.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/HiveMindSuite.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- HiveMindSuite.java 12 Jun 2003 20:57:39 -0000 1.7
+++ HiveMindSuite.java 2 Jul 2003 21:41:12 -0000 1.8
@@ -80,6 +80,7 @@
{
TestSuite suite = new TestSuite("Master HiveMind Test Suite");
+ suite.addTestSuite(TestMessagesImpl.class);
suite.addTestSuite(TestDescriptorParser.class);
suite.addTestSuite(TestExternalParser.class);
suite.addTestSuite(TestServices.class);
1.11 +4 -3
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/HiveMindTestCase.java
Index: HiveMindTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/HiveMindTestCase.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- HiveMindTestCase.java 2 Jul 2003 15:40:39 -0000 1.10
+++ HiveMindTestCase.java 2 Jul 2003 21:41:12 -0000 1.11
@@ -61,6 +61,7 @@
import java.io.File;
import java.net.URL;
import java.util.List;
+import java.util.Locale;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
@@ -115,7 +116,7 @@
builder.processModule(_resolver, md);
}
- return builder.constructRegistry();
+ return builder.constructRegistry(Locale.getDefault());
}
protected Registry buildRegistry(IResourceLocation l) throws Exception
@@ -125,7 +126,7 @@
ModuleDescriptor md = _parser.parse(l);
builder.processModule(_resolver, md);
- return builder.constructRegistry();
+ return builder.constructRegistry(Locale.getDefault());
}
protected ModuleDescriptor parse(String file) throws Exception
1.1
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/TestMessagesImpl.java
Index: TestMessagesImpl.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package hivemind.test;
import java.util.Locale;
import org.apache.commons.hivemind.impl.MessagesImpl;
import org.apache.tapestry.IMessages;
import org.apache.tapestry.IResourceLocation;
/**
* Does some tests on [EMAIL PROTECTED]
org.apache.commons.hivemind.impl.MessagesImpl}.
*
* @author Howard Lewis Ship
* @version $Id: TestMessagesImpl.java,v 1.1 2003/07/02 21:41:12 hlship Exp $
*/
public class TestMessagesImpl extends HiveMindTestCase
{
public TestMessagesImpl(String name)
{
super(name);
}
protected IMessages read(String file, Locale locale) throws Exception
{
IResourceLocation l = getLocation(file);
return new MessagesImpl(l, locale);
}
public void testSimple() throws Exception
{
IMessages m = read("config/Messages.xml", Locale.ENGLISH);
assertEquals("Some Damn Thing", m.getMessage("inner-message"));
assertEquals("[MISSING-MESSAGE]", m.getMessage("missing-message"));
assertEquals(
"Default for missing.",
m.getMessage("missing-message", "Default for missing."));
}
public void testMissing() throws Exception
{
IMessages m = read("config/Messages.xml", Locale.ENGLISH);
assertEquals("[MISSING-MESSAGE]", m.getMessage("missing-message"));
}
public void testDefault() throws Exception
{
IMessages m = read("config/Messages.xml", Locale.ENGLISH);
assertEquals(
"Default for missing.",
m.getMessage("missing-message", "Default for missing."));
}
public void testLocalized() throws Exception
{
IMessages m = read("config/Messages.xml", Locale.FRANCE);
assertEquals("Une Certaine Fichue Chose", m.getMessage("inner-message"));
}
public void testOneArg() throws Exception
{
IMessages m = read("config/Messages.xml", Locale.ENGLISH);
assertEquals("[fred]", m.format("one-arg", "fred"));
}
public void testTwoArg() throws Exception
{
IMessages m = read("config/Messages.xml", Locale.ENGLISH);
assertEquals("[abbot, costello]", m.format("two-arg", "abbot", "costello"));
}
public void testThreeArg() throws Exception
{
IMessages m = read("config/Messages.xml", Locale.ENGLISH);
assertEquals("[moe, larry, curly]", m.format("three-arg", "moe", "larry",
"curly"));
}
public void testFourArg() throws Exception
{
IMessages m = read("config/Messages.xml", Locale.ENGLISH);
assertEquals(
"[alpha, bravo, delta, gamma]",
m.format("four-arg", new String[] { "alpha", "bravo", "delta", "gamma"
}));
}
}
1.7 +10 -1
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/AbstractConfigurator.java
Index: AbstractConfigurator.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/AbstractConfigurator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractConfigurator.java 30 Jun 2003 23:04:54 -0000 1.6
+++ AbstractConfigurator.java 2 Jul 2003 21:41:12 -0000 1.7
@@ -146,4 +146,13 @@
return provideValue(module);
}
+ /**
+ * Standard implementation; invokes [EMAIL PROTECTED]
ValueProvider#provideValue(Module)}.
+ */
+ public void configure(Object object, Module module)
+ {
+ Object value = provideValue(module);
+
+ configureProperty(object, value, module);
+ }
}
1.12 +18 -1
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/DescriptorParser.java
Index: DescriptorParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/DescriptorParser.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DescriptorParser.java 2 Jul 2003 15:40:37 -0000 1.11
+++ DescriptorParser.java 2 Jul 2003 21:41:12 -0000 1.12
@@ -327,6 +327,13 @@
result.addRule(pattern, setLocationRule);
result.addSetNext(pattern, "addProvider");
+ pattern = "*/message";
+
+ result.addObjectCreate(pattern, MessageDescriptor.class);
+ result.addRule(pattern, setLocationRule);
+ result.addSetLimitedProperties(pattern, "key", "key");
+ result.addSetNext(pattern, "addProvider");
+
pattern = "*/set-xml";
result.addObjectCreate(pattern, XMLDescriptor.class);
@@ -375,6 +382,16 @@
new String[] { "propertyName", "factoryServiceId" });
result.addSetNext(pattern, "addConfigurator");
+ pattern = "*/set-message";
+
+ result.addObjectCreate(pattern, MessageDescriptor.class);
+ result.addRule(pattern, setLocationRule);
+ result.addSetLimitedProperties(
+ pattern,
+ new String[] { "property", "key" },
+ new String[] { "propertyName", "key" });
+ result.addSetNext(pattern, "addConfigurator");
+
pattern = "*/interceptor";
result.addObjectCreate(pattern, InterceptorDescriptor.class);
1.12 +45 -13
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/HiveMind_1.0.xsd
Index: HiveMind_1.0.xsd
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/HiveMind_1.0.xsd,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- HiveMind_1.0.xsd 2 Jul 2003 15:40:38 -0000 1.11
+++ HiveMind_1.0.xsd 2 Jul 2003 21:41:12 -0000 1.12
@@ -53,16 +53,15 @@
</xs:sequence>
<xs:attribute name="id"
type="simple-id" use="required">
<xs:annotation>
- <xs:documentation>The
simple id for the service; the module's id will be prefixed
- to form the
complete service id.</xs:documentation>
- </xs:annotation>
+
<xs:documentation>The simple id for the service; the module's
+ id
will be prefixed to form the complete service id.</xs:documentation>
+ </xs:annotation>
</xs:attribute>
<xs:attribute name="interface"
type="xs:string" use="required">
<xs:annotation>
-
<xs:documentation>
- The fully
qualified name of a Java interface for the service.
-
</xs:documentation>
- </xs:annotation>
+
<xs:documentation>The fully qualified name of a Java interface
+ for
the service.</xs:documentation>
+ </xs:annotation>
</xs:attribute>
<xs:attribute name="required"
type="xs:boolean" use="optional"
default="true">
@@ -72,12 +71,12 @@
then
the service is optional.</xs:documentation>
</xs:annotation>
</xs:attribute>
- <xs:attribute
name="overridable" type="xs:boolean" use="optional" default="false">
+ <xs:attribute
name="overridable" type="xs:boolean" use="optional"
+ default="false">
<xs:annotation>
- <xs:documentation>
- If true, then the core
implementation provided as an internal contribution
- may be overriden by
another module.
- </xs:documentation>
+
<xs:documentation>If true, then the core implementation
+
provided as an internal contribution may be overriden by
+
another module.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
@@ -275,6 +274,23 @@
</xs:attribute>
</xs:complexType>
</xs:element>
+ <xs:element name="set-message">
+ <xs:annotation>
+ <xs:documentation>Sets a property of the
object to a localized message
+ from the containing module. Nested
elements are arguments used to
+ contruct the
message.</xs:documentation>
+ </xs:annotation>
+ <xs:complexType>
+ <xs:group ref="value-providers-group"
minOccurs="0"
+ maxOccurs="unbounded" />
+ <xs:attributeGroup ref="property-setter"/>
+ <xs:attribute name="key" type="xs:string"
use="required">
+ <xs:annotation>
+ <xs:documentation>The key used
to locate the message.</xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ </xs:complexType>
+ </xs:element>
</xs:choice>
</xs:group>
<xs:group name="value-providers-group">
@@ -289,6 +305,7 @@
<xs:element ref="create-instance"/>
<xs:element ref="factory"/>
<xs:element ref="resource"/>
+ <xs:element ref="message"/>
</xs:choice>
</xs:group>
<xs:group name="contribute-group">
@@ -525,6 +542,21 @@
<xs:annotation>
<xs:documentation>The path of the XML file,
relative to the
contributing module's module
descriptor.</xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="message">
+ <xs:annotation>
+ <xs:documentation>Contributes a localized message from the
containing
+ module. Nested elements are arguments used to contruct
the message.</xs:documentation>
+ </xs:annotation>
+ <xs:complexType>
+ <xs:group ref="value-providers-group" minOccurs="0"
maxOccurs="unbounded"
+ />
+ <xs:attribute name="key" type="xs:string" use="required">
+ <xs:annotation>
+ <xs:documentation>The key used to locate the
message.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
1.6 +1 -12
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ServiceRefDescriptor.java
Index: ServiceRefDescriptor.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ServiceRefDescriptor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ServiceRefDescriptor.java 30 Jun 2003 23:05:08 -0000 1.5
+++ ServiceRefDescriptor.java 2 Jul 2003 21:41:12 -0000 1.6
@@ -78,17 +78,6 @@
}
/**
- * Invokes [EMAIL PROTECTED] #provideValue(Module)} to get the service,
- * and assigns it to the property.
- */
- public void configure(Object object, Module module)
- {
- Object value = provideValue(module);
-
- configureProperty(object, value, module);
- }
-
- /**
* Invokes [EMAIL PROTECTED] Registry#getService(String, Class)} to retrieve
the
* service.
*/
1.7 +1 -8
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ExpressionDescriptor.java
Index: ExpressionDescriptor.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ExpressionDescriptor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ExpressionDescriptor.java 30 Jun 2003 23:04:53 -0000 1.6
+++ ExpressionDescriptor.java 2 Jul 2003 21:41:13 -0000 1.7
@@ -79,13 +79,6 @@
builder.append("expression", _expression);
}
- public void configure(Object object, Module module)
- {
- Object value = provideValue(module);
-
- configureProperty(object, value, module);
- }
-
/**
* Evaluates the expression, using the module as the current object.
*/
1.6 +1 -8
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/XMLDescriptor.java
Index: XMLDescriptor.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/XMLDescriptor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XMLDescriptor.java 30 Jun 2003 23:04:54 -0000 1.5
+++ XMLDescriptor.java 2 Jul 2003 21:41:13 -0000 1.6
@@ -100,13 +100,6 @@
}
}
- public void configure(Object object, Module module)
- {
- Object value = provideValue(module);
-
- configureProperty(object, value, module);
- }
-
public String getPath()
{
return _path;
1.6 +2 -7
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ValueDescriptor.java
Index: ValueDescriptor.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ValueDescriptor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ValueDescriptor.java 30 Jun 2003 23:05:13 -0000 1.5
+++ ValueDescriptor.java 2 Jul 2003 21:41:13 -0000 1.6
@@ -73,14 +73,9 @@
{
private String _value;
- public void configure(Object object, Module module)
- {
- configureProperty(object, _value, module);
- }
-
/**
* Returns the content, filtered through
- * [EMAIL PROTECTED] Registry#convertVariableReferences(String, ILocation)}.
+ * [EMAIL PROTECTED] Registry#convertSymbols(String, ILocation)}.
*/
public Object provideValue(Module module)
{
1.7 +1 -9
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/AbstractInstanceBuilderDescriptor.java
Index: AbstractInstanceBuilderDescriptor.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/AbstractInstanceBuilderDescriptor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractInstanceBuilderDescriptor.java 30 Jun 2003 23:04:54 -0000 1.6
+++ AbstractInstanceBuilderDescriptor.java 2 Jul 2003 21:41:13 -0000 1.7
@@ -140,12 +140,4 @@
{
builder.append("configurators", _configurators);
}
-
- public void configure(Object object, Module module)
- {
- Object value = provideValue(module);
-
- configureProperty(object, value, module);
- }
-
}
1.2 +1 -8
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ResourceDescriptor.java
Index: ResourceDescriptor.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ResourceDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ResourceDescriptor.java 1 Jul 2003 20:13:01 -0000 1.1
+++ ResourceDescriptor.java 2 Jul 2003 21:41:13 -0000 1.2
@@ -79,13 +79,6 @@
builder.append("path", _path);
}
- public void configure(Object object, Module module)
- {
- Object value = provideValue(module);
-
- configureProperty(object, value, module);
- }
-
/**
* Returns a location relative to the module's resource location.
*/
1.1
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/MessageDescriptor.java
Index: MessageDescriptor.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.hivemind.parse;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.hivemind.Module;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.IMessages;
/**
* Descriptor for the <message> and
* <set-message> elements.
*
* @author Howard Lewis Ship
* @version $Id: MessageDescriptor.java,v 1.1 2003/07/02 21:41:12 hlship Exp $
*/
public class MessageDescriptor extends AbstractConfigurator
{
private String _key;
private List _providers;
public void addProvider(ValueProvider provider)
{
if (_providers == null)
_providers = new ArrayList();
_providers.add(provider);
}
public List getProviders()
{
return _providers;
}
protected void extendDescription(ToStringBuilder builder)
{
builder.append("key", _key);
builder.append("providers", _providers);
}
public Object provideValue(Module module)
{
IMessages messages = module.getMessages();
Object[] arguments = null;
if (_providers != null)
{
int count = _providers.size();
arguments = new Object[count];
for (int i = 0; i < count; i++)
{
ValueProvider p = (ValueProvider) _providers.get(i);
arguments[i] = p.provideValue(module);
}
}
return messages.format(_key, arguments);
}
public String getKey()
{
return _key;
}
public void setKey(String string)
{
_key = string;
}
}
1.2 +2 -2
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/NameLookup.java
Index: NameLookup.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/NameLookup.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NameLookup.java 1 Jul 2003 11:28:52 -0000 1.1
+++ NameLookup.java 2 Jul 2003 21:41:13 -0000 1.2
@@ -61,7 +61,7 @@
* Service interface for performing name lookups. This is typically
* implemented as a wrapper around JNDI. This service is available
* as <code>org.apache.commons.hivemind.NameLookupImpl</code>.
- * or [EMAIL PROTECTED] HiveMind#NAME_LOOKUP_SERVICE_ID}.
+ * or [EMAIL PROTECTED]
org.apache.commons.hivemind.HiveMind#NAME_LOOKUP_SERVICE_ID}.
* The default configuration does not include a core implementation,
* but a standard implementation is available as
* [EMAIL PROTECTED] org.apache.commons.hivemind.service.impl.NameLookupImpl}.
1.12 +29 -1
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/TestDescriptorParser.java
Index: TestDescriptorParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/TestDescriptorParser.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- TestDescriptorParser.java 2 Jul 2003 15:40:43 -0000 1.11
+++ TestDescriptorParser.java 2 Jul 2003 21:41:13 -0000 1.12
@@ -71,6 +71,7 @@
import org.apache.commons.hivemind.parse.FactoryDescriptor;
import org.apache.commons.hivemind.parse.InstanceBuilder;
import org.apache.commons.hivemind.parse.InterceptorDescriptor;
+import org.apache.commons.hivemind.parse.MessageDescriptor;
import org.apache.commons.hivemind.parse.ModuleDescriptor;
import org.apache.commons.hivemind.parse.NewDescriptor;
import org.apache.commons.hivemind.parse.ParametersDescriptor;
@@ -617,5 +618,32 @@
ServiceDescriptor sd = d.getService("Foo");
assertEquals(true, sd.isOverridable());
+ }
+
+ public void testMessage() throws Exception
+ {
+ ModuleDescriptor d = parse("Message.xml");
+ ConfigurationDescriptor cd = d.getConfiguration("Message");
+ List l = cd.getProviders();
+ assertEquals(1, l.size());
+
+ MessageDescriptor md = (MessageDescriptor) l.get(0);
+ assertEquals("message-key", md.getKey());
+ }
+
+ public void testSetMessage() throws Exception
+ {
+ ModuleDescriptor d = parse("SetMessage.xml");
+ ConfigurationDescriptor cd = d.getConfiguration("SetMessage");
+ List l = cd.getProviders();
+ assertEquals(1, l.size());
+
+ NewDescriptor nd = (NewDescriptor) l.get(0);
+ l = nd.getConfigurators();
+ assertEquals(1, l.size());
+
+ MessageDescriptor md = (MessageDescriptor) l.get(0);
+ assertEquals("alakazam", md.getKey());
+ assertEquals("baz", md.getPropertyName());
}
}
1.7 +6 -2
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/TestToString.java
Index: TestToString.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/TestToString.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TestToString.java 1 Jul 2003 20:13:02 -0000 1.6
+++ TestToString.java 2 Jul 2003 21:41:13 -0000 1.7
@@ -57,6 +57,8 @@
package hivemind.test.parse;
+import java.util.Locale;
+
import hivemind.test.HiveMindTestCase;
import org.apache.commons.hivemind.impl.AttributeImpl;
@@ -75,6 +77,7 @@
import org.apache.commons.hivemind.parse.ExpressionDescriptor;
import org.apache.commons.hivemind.parse.FactoryDescriptor;
import org.apache.commons.hivemind.parse.InterceptorDescriptor;
+import org.apache.commons.hivemind.parse.MessageDescriptor;
import org.apache.commons.hivemind.parse.ModuleDescriptor;
import org.apache.commons.hivemind.parse.ParametersDescriptor;
import org.apache.commons.hivemind.parse.ResourceDescriptor;
@@ -114,10 +117,11 @@
new InterceptorDescriptor().toString();
new ParametersDescriptor().toString();
new ResourceDescriptor().toString();
+ new MessageDescriptor().toString();
new FactoryContributionImpl().toString();
new BaseModule().toString();
- new RegistryImpl().toString();
+ new RegistryImpl(Locale.ENGLISH).toString();
new ConfigurationContributionImpl().toString();
new ConfigurationExtensionPointImpl().toString();
new ElementImpl("foo").toString();
1.1
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/Message.xml
Index: Message.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: Message.xml,v 1.1 2003/07/02 21:41:13 hlship Exp $ -->
<module
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://jakarta.apache.org/commons/hivemind/schema/HiveMind_1.0.xsd"
id="hivemind.test.parse"
version="1.0.0">
<configuration id="Message" element-type="java.lang.String">
<message key="message-key"/>
</configuration>
</module>
1.1
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/SetMessage.xml
Index: SetMessage.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: SetMessage.xml,v 1.1 2003/07/02 21:41:13 hlship Exp $ -->
<module
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://jakarta.apache.org/commons/hivemind/schema/HiveMind_1.0.xsd"
id="hivemind.test.parse"
version="1.0.0">
<configuration id="SetMessage" element-type="foo.foe.Fum">
<new>
<set-message property="baz" key="alakazam"/>
</new>
</configuration>
</module>
1.9 +44 -4 jakarta-commons-sandbox/hivemind/src/xsl/hivemind.xsl
Index: hivemind.xsl
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/xsl/hivemind.xsl,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- hivemind.xsl 2 Jul 2003 15:40:39 -0000 1.8
+++ hivemind.xsl 2 Jul 2003 21:41:13 -0000 1.9
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!-- $Id$ -->
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:exsl="http://exslt.org/common"
-
- extension-element-prefixes="exsl">
-
+ xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
+
<xsl:param name="base.dir"/>
<xsl:template match="/registry">
@@ -585,6 +584,47 @@
<span class="attribute"> property</span>="<xsl:value-of
select="@property"/>"
<span class="attribute"> path</span>"<xsl:value-of
select="@path"/>
<span class="tag">/></span>
+ </li>
+ </xsl:template>
+
+ <xsl:template match="message">
+ <li>
+ <span class="tag"><message</span>
+ <span class="attribute"> key</span>="<xsl:value-of
select="@key"/>"
+
+ <xsl:choose>
+ <xsl:when test="*">
+ <span class="tag">></span>
+ <ul>
+ <xsl:apply-templates/>
+ </ul>
+ <span class="tag"></message></span>
+ </xsl:when>
+ <xsl:otherwise>
+ <span class="tag">/></span>
+ </xsl:otherwise>
+ </xsl:choose>
+ </li>
+ </xsl:template>
+
+ <xsl:template match="set-message">
+ <li>
+ <span class="tag"><set-message</span>
+ <span class="attribute"> property</span>="<xsl:value-of
select="@property"/>"
+ <span class="attribute"> key</span>="<xsl:value-of
select="@key"/>"
+
+ <xsl:choose>
+ <xsl:when test="*">
+ <span class="tag">></span>
+ <ul>
+ <xsl:apply-templates/>
+ </ul>
+ <span class="tag"></set-message></span>
+ </xsl:when>
+ <xsl:otherwise>
+ <span class="tag">/></span>
+ </xsl:otherwise>
+ </xsl:choose>
</li>
</xsl:template>
1.4 +7 -1
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/MockRegistry.java
Index: MockRegistry.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/MockRegistry.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MockRegistry.java 30 Jun 2003 23:04:42 -0000 1.3
+++ MockRegistry.java 2 Jul 2003 21:41:13 -0000 1.4
@@ -58,6 +58,7 @@
package hivemind.test.config;
import java.util.List;
+import java.util.Locale;
import org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.Registry;
@@ -91,6 +92,11 @@
public String convertSymbols(String input, ILocation location)
{
return input;
+ }
+
+ public Locale getLocale()
+ {
+ return null;
}
}
1.13 +25 -3
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/TestConfiguration.java
Index: TestConfiguration.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/TestConfiguration.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- TestConfiguration.java 2 Jul 2003 15:40:41 -0000 1.12
+++ TestConfiguration.java 2 Jul 2003 21:41:13 -0000 1.13
@@ -69,7 +69,7 @@
import org.apache.commons.hivemind.Registry;
import org.apache.commons.hivemind.impl.RegistryBuilder;
import org.apache.commons.hivemind.parse.DescriptorParser;
-import org.apache.log4j.spi.LoggingEvent;
+import org.apache.commons.hivemind.parse.ModuleDescriptor;
import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.ILocation;
import org.apache.tapestry.IResourceLocation;
@@ -331,7 +331,7 @@
b.processModule(_resolver, p.parse(getMasterModuleLocation()));
b.processModule(_resolver, p.parse(getLocation("Symbols.xml")));
- Registry r = b.constructRegistry();
+ Registry r = b.constructRegistry(Locale.getDefault());
List l = r.getConfiguration("hivemind.test.config.Dogs");
assertEquals(1, l.size());
@@ -349,7 +349,7 @@
b.processModule(_resolver, p.parse(getMasterModuleLocation()));
b.processModule(_resolver, p.parse(getLocation("ExpressionSymbols.xml")));
- Registry r = b.constructRegistry();
+ Registry r = b.constructRegistry(Locale.getDefault());
List l = r.getConfiguration("hivemind.test.config.Dogs");
assertEquals(1, l.size());
@@ -514,5 +514,27 @@
checkException(t, "Resource Xyzzyx relative to module
hivemind.test.config");
}
+ }
+
+ public void testMessages() throws Exception
+ {
+ Registry r = buildRegistry("Messages.xml");
+ List l = r.getConfiguration("hivemind.test.config.Messages");
+ assertEquals(1, l.size());
+
+ assertEquals("Test message #22 from fred about: Some Damn Thing.",
l.get(0));
+ }
+
+ public void testLocalizedMessages() throws Exception
+ {
+ RegistryBuilder builder = new RegistryBuilder();
+ ModuleDescriptor md = parse("Messages.xml");
+ builder.processModule(_resolver, md);
+ Registry r = builder.constructRegistry(Locale.FRANCE);
+
+ List l = r.getConfiguration("hivemind.test.config.Messages");
+ assertEquals(1, l.size());
+
+ assertEquals("Test message #22 from fred about: Une Certaine Fichue
Chose.", l.get(0));
}
}
1.1
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/hivemodule_fr.properties
Index: hivemodule_fr.properties
===================================================================
# $Id: hivemodule_fr.properties,v 1.1 2003/07/02 21:41:13 hlship Exp $
inner-message=Une Certaine Fichue Chose
1.1
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/hivemodule.properties
Index: hivemodule.properties
===================================================================
# $Id: hivemodule.properties,v 1.1 2003/07/02 21:41:13 hlship Exp $
test-message=Test message #{1} from {0} about: {2}.
inner-message=Some Damn Thing
one-arg=[{0}]
two-arg=[{0}, {1}]
three-arg=[{0}, {1}, {2}]
four-arg=[{0}, {1}, {2}, {3}]
1.1
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/Messages.xml
Index: Messages.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: Messages.xml,v 1.1 2003/07/02 21:41:13 hlship Exp $ -->
<module
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://jakarta.apache.org/commons/hivemind/schema/HiveMind_1.0.xsd"
id="hivemind.test.config"
version="1.0.0">
<configuration id="Messages" element-type="java.lang.String">
<message key="test-message">
<value>fred</value>
<expression>22</expression>
<message key="inner-message"/>
</message>
</configuration>
</module>
1.9 +8 -2 jakarta-commons-sandbox/hivemind/common/links.xml
Index: links.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/common/links.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- links.xml 1 Jul 2003 20:13:02 -0000 1.8
+++ links.xml 2 Jul 2003 21:41:13 -0000 1.9
@@ -80,4 +80,10 @@
<!ENTITY resource '<a href="descriptor.html#resource">&_resource;</a>'>
<!ENTITY _set-resource '<code><set-resource></code>'>
-<!ENTITY set-resource '<a href="descriptor.html#set-resource">&_set-resource;</a>'>
\ No newline at end of file
+<!ENTITY set-resource '<a href="descriptor.html#set-resource">&_set-resource;</a>'>
+
+<!ENTITY _message '<code><message></code>'>
+<!ENTITY message '<a href="descriptor.html#message">&_message;</a>'>
+
+<!ENTITY _set-message '<code><set-message></code>'>
+<!ENTITY set-message '<a href="descriptor.html#set-message">&_set-message;</a>'>
\ No newline at end of file
1.11 +18 -14
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/TestServices.java
Index: TestServices.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/TestServices.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- TestServices.java 2 Jul 2003 15:40:40 -0000 1.10
+++ TestServices.java 2 Jul 2003 21:41:14 -0000 1.11
@@ -66,6 +66,7 @@
import java.rmi.RemoteException;
import java.util.List;
+import java.util.Locale;
import org.apache.commons.hivemind.Registry;
import org.apache.commons.hivemind.impl.RegistryBuilder;
@@ -185,7 +186,7 @@
interceptLogging("hivemind.test.services.Demo");
- Registry r = b.constructRegistry();
+ Registry r = b.constructRegistry(Locale.getDefault());
DemoService s =
(DemoService) r.getService("hivemind.test.services.Demo",
DemoService.class);
@@ -254,7 +255,7 @@
DescriptorParser p = new DescriptorParser();
b.processModule(_resolver, p.parse(getMasterModuleLocation()));
b.processModule(_resolver, p.parse(getLocation("EJBProxy.xml")));
- Registry r = b.constructRegistry();
+ Registry r = b.constructRegistry(Locale.getDefault());
SimpleHomeImpl home = new SimpleHomeImpl();
FakeContext context = new FakeContext();
@@ -275,7 +276,7 @@
DescriptorParser p = new DescriptorParser();
b.processModule(_resolver, p.parse(getMasterModuleLocation()));
b.processModule(_resolver, p.parse(getLocation("EJBProxy.xml")));
- Registry r = b.constructRegistry();
+ Registry r = b.constructRegistry(Locale.getDefault());
FakeContext context = new FakeContext();
context.setForceError(true);
@@ -307,7 +308,7 @@
DescriptorParser p = new DescriptorParser();
b.processModule(_resolver, p.parse(getMasterModuleLocation()));
b.processModule(_resolver, p.parse(getLocation("EJBProxy.xml")));
- Registry r = b.constructRegistry();
+ Registry r = b.constructRegistry(Locale.getDefault());
SimpleHomeImpl home = new SimpleHomeImpl();
home.setForceError(true);
@@ -333,13 +334,16 @@
}
}
- public void testServiceOverride() throws Exception
- {
- Registry r = buildRegistry("ServiceOverride.xml");
-
- SimpleService s =
(SimpleService)r.getService("hivemind.test.services.ServiceOverride",
SimpleService.class);
-
- // The bad impl multiplies, not add.
- assertEquals(28, s.add(4, 7));
- }
+ public void testServiceOverride() throws Exception
+ {
+ Registry r = buildRegistry("ServiceOverride.xml");
+
+ SimpleService s =
+ (SimpleService) r.getService(
+ "hivemind.test.services.ServiceOverride",
+ SimpleService.class);
+
+ // The bad impl multiplies, not add.
+ assertEquals(28, s.add(4, 7));
+ }
}
1.9 +3 -3
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/external/TestExternalParser.java
Index: TestExternalParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/external/TestExternalParser.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TestExternalParser.java 2 Jul 2003 15:40:43 -0000 1.8
+++ TestExternalParser.java 2 Jul 2003 21:41:14 -0000 1.9
@@ -262,7 +262,7 @@
b.processModule(_resolver, dp.parse(getMasterModuleLocation()));
b.processModule(_resolver, dp.parse(getLocation("XMLSymbols.xml")));
- Registry r = b.constructRegistry();
+ Registry r = b.constructRegistry(Locale.getDefault());
List elements = r.getConfiguration("hivemind.test.external.Elements");
assertEquals(1, elements.size());
@@ -305,7 +305,7 @@
b.processModule(_resolver, dp.parse(getMasterModuleLocation()));
b.processModule(_resolver, dp.parse(getLocation("SymbolSourceOrder.xml")));
- Registry r = b.constructRegistry();
+ Registry r = b.constructRegistry(Locale.getDefault());
List elements = r.getConfiguration("hivemind.test.external.Elements");
assertEquals(1, elements.size());
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]