hlship 2003/09/23 15:23:52
Modified: hivemind/xdocs index.xml ioc.xml override.xml case1.xml
configurations.xml bootstrap.xml services.xml
rules.xml interceptors.xml
hivemind/framework/src/test/hivemind/test/rules
MockSchemaProcessor.java
hivemind/framework/src/java/org/apache/commons/hivemind
HiveMindMessages.properties
hivemind/common links.xml
hivemind/framework/src/java/org/apache/commons/hivemind/parse
DescriptorParser.java
hivemind/framework/src/xsl hivemind.xsl
Added: hivemind/framework/src/test/hivemind/test/rules
TestSetModule.java TestNumericTranslators.java
hivemind/framework/src/java/org/apache/commons/hivemind/schema/rules
SetModuleRule.java LongTranslator.java
Log:
Add LongTranslator and SetModuleRule.
Revision Changes Path
1.14 +4 -4 jakarta-commons-sandbox/hivemind/xdocs/index.xml
Index: index.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/index.xml,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- index.xml 18 Sep 2003 19:00:57 -0000 1.13
+++ index.xml 23 Sep 2003 22:23:51 -0000 1.14
@@ -124,9 +124,9 @@
and configurations. Each module consists of:
<ul>
<li>Configuration points</li>
- <li>Configurations (contributed to configuration points)</li>
+ <li>Contributions (to configuration points)</li>
<li>Service points</li>
- <li>Services (implementation contributions to service points)</li>
+ <li>Implementation contributions (to service points)</li>
</ul>
</p>
@@ -285,7 +285,7 @@
</td>
<td>
Let HiveMind add a
-<a href="&baseregistry;#service:hivemind.LoggingInterceptor">logging
interceptor</a>
+<a href="&hivemind-registry;#service:hivemind.LoggingInterceptor">logging
interceptor</a>
to your service.
</td>
</tr>
1.11 +2 -2 jakarta-commons-sandbox/hivemind/xdocs/ioc.xml
Index: ioc.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/ioc.xml,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ioc.xml 18 Sep 2003 19:00:57 -0000 1.10
+++ ioc.xml 23 Sep 2003 22:23:51 -0000 1.11
@@ -35,7 +35,7 @@
all the modules it can find at runtime. HiveMind is responsible for creating
services (including core implementations
and interceptors). It is quite possible to create service factories that do very
container-like things,
including connecting services together.
-<a
href="&baseregistry;#service:hivemind.BuilderFactory">hivemind.BuilderFactory</a>
+<a
href="&hivemind-registry;#service:hivemind.BuilderFactory">hivemind.BuilderFactory</a>
does just that, instantiating an object to act as the core service implementation,
then setting
properties of the object, some of which are references to services and
configuration point element data.
</p>
1.4 +2 -2 jakarta-commons-sandbox/hivemind/xdocs/override.xml
Index: override.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/override.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- override.xml 18 Sep 2003 19:00:57 -0000 1.3
+++ override.xml 23 Sep 2003 22:23:51 -0000 1.4
@@ -183,7 +183,7 @@
<p>
To be honest, if this kind of indirection becomes extremely frequent, then HiveMind
should change
-to accomadate the pattern, perhaps adding an <code><override></code> element,
similar to a &_interceptor; element.
+to accomidate the pattern, perhaps adding an <code><override></code> element,
similar to a &_interceptor; element.
</p>
</section>
1.8 +6 -2 jakarta-commons-sandbox/hivemind/xdocs/case1.xml
Index: case1.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/case1.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- case1.xml 19 Sep 2003 18:25:20 -0000 1.7
+++ case1.xml 23 Sep 2003 22:23:51 -0000 1.8
@@ -207,6 +207,7 @@
</p>
+
<subsection name="Startup configuration point">
<p>
@@ -253,6 +254,8 @@
</p>
<p>
+Adding <code>throws Exception</code> to the method signature allows the caller to
be responsible
+for exception reporting, which simplifies the task implementations.
Shortly, we'll see how the application's master servlet invokes the Startup
service.
</p>
@@ -798,7 +801,8 @@
</p>
<p>
-The end result: an agile, easily extended system. Courtesy of HiveMind.
+The end result: an agile, easily extended system. HiveMind has provided the tools
and environment
+to support an elegant, data-driven solution ... replacing the old, code-heavy EJB
implementation.
</p>
</section>
1.2 +8 -8 jakarta-commons-sandbox/hivemind/xdocs/configurations.xml
Index: configurations.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/configurations.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- configurations.xml 18 Sep 2003 19:00:57 -0000 1.1
+++ configurations.xml 23 Sep 2003 22:23:51 -0000 1.2
@@ -20,16 +20,16 @@
</p>
<p>
-There is not a direct connection between a service and a configuration point,
though it is often the case
+There is no explicit connection between a service and a configuration point, though
it is often the case
that a service and a configuration point will be similarily named (or even
identically named; services
and configuration points are in seperate namespaces). Any relationship
between a service and an configuration point
-is explicit only in code ... the service may be configured with the elements of an
configuration point and operate
+is explicit only in code ... the service may be configured with the elements of a
configuration point and operate
on those elements in some way.
</p>
</section>
-<section name="Defining a Extension Point">
+<section name="Defining a Configuration Point">
<p>
A module may include &configuration-point; elements to define new configuration
points.
@@ -136,7 +136,7 @@
</section>
-<section name="Accessing Extension Points">
+<section name="Accessing Configuration Points">
<p>Like services, configuration points are meant to be easy to access (the only
trick is getting a
reference to the registry to start from).</p>
@@ -244,7 +244,7 @@
<p>
This begs the question: where do symbol values come from? The answser is
application dependent.
HiveMind itself defines a configuration configuration point for this purpose:
-<a
href="&baseregistry;#configuration-point:hivemind.SymbolSource">hivemind.SymbolSource</a>.
Contributions to this configuration point define
+<a
href="&hivemind-registry;#configuration:hivemind.SymbolSource">hivemind.SymbolSource</a>.
Contributions to this configuration point define
new objects that can provide values for symbols, and identify the order in which
these objects should be consulted.
</p>
@@ -263,9 +263,9 @@
<p>
There is now an configuration point for setting factory defaults:
- <a
href="base-registry/hivemind.html#configuration-point:hivemind.FactoryDefaults">hivemind.FactoryDefaults</a>.
+ <a
href="base-registry/hivemind.html#configuration:hivemind.FactoryDefaults">hivemind.FactoryDefaults</a>.
A second configuration point, for application defaults, overrides the factory
defaults:
- <a
href="base-registry/hivemind.html#configuration-point:hivemind.ApplicationDefaults">hivemind.ApplicationDefaults</a>.
+ <a
href="base-registry/hivemind.html#configuration:hivemind.ApplicationDefaults">hivemind.ApplicationDefaults</a>.
</p>
<p>
1.6 +3 -2 jakarta-commons-sandbox/hivemind/xdocs/bootstrap.xml
Index: bootstrap.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/bootstrap.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- bootstrap.xml 18 Sep 2003 20:08:59 -0000 1.5
+++ bootstrap.xml 23 Sep 2003 22:23:51 -0000 1.6
@@ -237,7 +237,8 @@
<p>
The only other oddity was to add <code>src/conf</code> to the runtime
classpath; this is to include
-a <code>log4j.properties</code>; otherwise Log4J will write console errors about
missing configuration.
+the <code>log4j.properties</code> configuration file;
+otherwise Log4J will write console errors about missing configuration.
</p>
</section>
1.24 +19 -13 jakarta-commons-sandbox/hivemind/xdocs/services.xml
Index: services.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/services.xml,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- services.xml 18 Sep 2003 19:00:57 -0000 1.23
+++ services.xml 23 Sep 2003 22:23:51 -0000 1.24
@@ -78,7 +78,7 @@
</p>
<subsection name="Service Constructors">
- <p>An service constructor is used to instantiate a
Java class as the
+ <p>A service constructor is used to instantiate a Java
class as the
core implementation instance for the service.
</p>
<p>There are two forms of service constructors:
instance creators and
@@ -91,7 +91,13 @@
<a
href="&apiroot;/ServiceImplementationFactory.html">ServiceImplementationFactory</a>
- interface).</p>
+ interface).
+
+ The most common example is the
+ <a
href="&hivemind-registry;#service:hivemind.BuilderFactory">hivemind.BuilderFactory</a>
+ service.
+
+ </p>
</subsection>
@@ -99,14 +105,13 @@
<p>
An implementation factory is used to create a core
implementation for a
- service at runtime. This may be accomplished using JDK
Proxies or
- bytecode enhancement.
+ service at runtime.
</p>
<p>
Often, the factory will need some additional configuration
information.
For example, the
- <a
href="&baseregistry;#service:hivemind.EJBProxyFactory">hivemind.EJBProxyFactory</a>
+ <a
href="&hivemind-lib-registry;#service:hivemind.lib.EJBProxyFactory">hivemind.lib.EJBProxyFactory</a>
service uses its parameters to identify the JNDI name of the
EJB's home interface,
as well as the home interface class itself.
</p>
@@ -119,8 +124,8 @@
<p>
- Another common service factory is
- <a
href="&baseregistry;#service:hivemind.BuilderFactory">hivemind.BuilderFactory</a>.
+ The most common service factory is
+ <a
href="&hivemind-registry;#service:hivemind.BuilderFactory">hivemind.BuilderFactory</a>.
It is used to construct a service and then set properties of
the service implementation object.
</p>
@@ -140,7 +145,7 @@
service extension point), adding the
functionality of that interface.
For example, the
-<a
href="&baseregistry;#service:hivemind.LoggingInterceptor">hivemind.LoggingInterceptor</a>
+<a
href="&hivemind-registry;#service:hivemind.LoggingInterceptor">hivemind.LoggingInterceptor</a>
factory creates an
instance that logs entry and exit to each
method.
</p>
@@ -210,7 +215,7 @@
care.</p>
<p>We need to create a module to contain this service. We'll
create a
simple HiveMind deployment descriptor. This is an XML
file, named
- hivemind.xml, that must be included in the module's
META-INF directory.</p>
+ hivemodule.xml, that must be included in the module's
META-INF directory.</p>
<source><![CDATA[
<?xml version="1.0"?>
<module id="com.myco.mypackage" version="1.0.0">
@@ -280,7 +285,7 @@
the service is constructed on first reference. This is appropriate for
services such as service factories and interceptor factories, and for
several of the basic services provided in the
- <a href="&baseregistry;">hivemind module</a>.
+ <a href="&hivemind-registry;">hivemind module</a>.
</p>
@@ -343,7 +348,7 @@
<p>
The service implementation is discarded when notified to cleanup; this is
controlled by the
-<a
href="&baseregistry;#service:hivemind.ThreadEventNotifier">hivemind.ThreadEventNotifier</a>
service.
+<a
href="&hivemind-registry;#service:hivemind.ThreadEventNotifier">hivemind.ThreadEventNotifier</a>
service.
If your application has any threaded services, you are responsible for invoking the
<code>fireThreadCleanup()</code>
method of the service.
</p>
@@ -411,12 +416,13 @@
interface (in addition to the service interface).
This interface defines a callback that occurs only
after
the core service has been constructed and configured,
and the interceptor stack
+ (if any)
has been assembled.
</p>
</li>
<li>
- <strong>What if I don't invoke
<code>ThreadEventNotifier.fireThreadCleanup()</code>?</strong>
+ <strong>What if I don't invoke
ThreadEventNotifier.fireThreadCleanup()?</strong>
<p>
Then service implementations bound to the current
thread stay bound. When the thread
1.8 +38 -2 jakarta-commons-sandbox/hivemind/xdocs/rules.xml
Index: rules.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/rules.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- rules.xml 18 Sep 2003 19:00:57 -0000 1.7
+++ rules.xml 23 Sep 2003 22:23:51 -0000 1.8
@@ -64,6 +64,7 @@
<li>&invoke-parent;</li>
<li>&read-attribute;</li>
<li>&read-content;</li>
+ <li>&set-module;</li>
<li>&set-parent;</li>
</ul>
</p>
@@ -227,6 +228,32 @@
</table>
</subsection>
+<subsection name="set-module">
+
+ <p>
+&_set-module; is used to set a property of the top object on the stack to the
module which
+made the contribution. This is often used when some other attribute of the
contribution
+is the name of a service or configuration extension point (but it is advantageous
+to defer access to the service or configuration). The module can be used to resolve
+names of services or configurations that are local to 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 of the top object
to update with the contributing module.</td>
+ </tr>
+ </table>
+
+</subsection>
+
<subsection name="set-parent">
<p>
@@ -349,7 +376,7 @@
<p>
The int translator converts the input into an integer value. It recognizes three
initializer values:
<ul>
-<li>default: the default value (normally 0) to use when the input is null or
invavlid</li>
+<li>default: the default value (normally 0) to use when the input is null or
invalid</li>
<li>min: a minimum acceptible value</li>
<li>max: a maximum acceptible value</li>
</ul>
@@ -359,6 +386,15 @@
If the value is outside of the range defined by the min and max initializer keys,
it is constrained into the range.
</p>
+</subsection>
+
+<subsection name="long">
+
+<p>
+The long translator is identitical to the int translator, except that the input is
converted to a long (64 bit) integer.
+</p>
+
+
</subsection>
<subsection name="resource">
1.6 +22 -10 jakarta-commons-sandbox/hivemind/xdocs/interceptors.xml
Index: interceptors.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/interceptors.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- interceptors.xml 18 Sep 2003 19:00:57 -0000 1.5
+++ interceptors.xml 23 Sep 2003 22:23:51 -0000 1.6
@@ -26,12 +26,13 @@
<p>
In fact, if you've heard about "Aspect Oriented Programming", interceptors are
simply one kind of aspect, a
-method introduction, based on service interface.
+method introduction, based on the service interface.
</p>
<p>
Be warned; interceptors are an example of programs writing other programs; it's a
whole new level of abstraction and
-requires a bit of getting used to.
+requires a bit of getting used to. Also, note that the term "interceptor" can
mean two different, related things:
+a service interceptor factory or a fabricated class created by the factory; this
should be obvious by the context.
</p>
</section>
@@ -39,10 +40,16 @@
<section name="Interceptor Factories">
<p>
-Interceptors are created, at runtime, by interceptor factories. An interceptor
factory builds a custom class at runtime
+Interceptors are created, at runtime, by service interceptor factories. A service
+interceptor factory builds a custom class at runtime
using the Javassist library. The class is then instantiated.
</p>
+<blockquote>
+The use of Javassist is not mandated but is generally easy and is more efficient at
runtime.
+It is possible to accomplish the same thing using JDK proxies.
+</blockquote>
+
<p>
Interceptor factories are HiveMind services which implement the
<a href="&apiroot;/ServiceInterceptorFactory.html">ServiceInterceptorFactory</a>
@@ -133,19 +140,24 @@
<p>
ClassFab and friends are just a wrapper around the Javassist framework, a library
used for runtime bytecode enhancement and
other aspect oriented programming tasks. HiveMind uses only a small fraction of
the capabilities of Javassist.
-Javassist's greatest feature is how new code is specified ... as enhanced Java code!
+Javassist's greatest feature is how new code is specified ... it looks like
ordinary Java source code, with a few
+additions.
</p>
<p>
The
<a href="&apiroot;/service/BodyBuilder.html">BodyBuilder</a> class helps
-with assembling method bodies in bits and pieces. The <code>_inner</code> variable
is a private instance variable,
+with assembling method bodies from bits and pieces. The <code>_inner</code>
variable is a private instance variable,
the inner for this interceptor. The <code>($r)</code> reference means "cast to the
return type for this method", and properly handles
void methods. The <code>$$</code> is a placeholder for a comma-seperated list of
all the parameters to the method.
</p>
+<p>
+Put together, this simply says "reinvoke the method on the same implementation of
the next inner class."
+</p>
+
<p>AbstractServiceInterceptorFactory is responsible for creating the
<code>_inner</code> variable and
- building the constructor which sets it, as well as invoking the constructor on
the
+ building the constructor which sets it up, as well as invoking the constructor
on the
completed interceptor class.
</p>
@@ -155,7 +167,7 @@
<p>
To use a service, it is necessary to declare the service in a module deployment
descriptor. The
-AbstractServiceInterceptorFactory expects two properties to be set when the service
is constructed,
+AbstractServiceInterceptorFactory base class expects two properties to be set when
the service is constructed,
<code>extensionId</code> and <code>factory</code>:
<source><![CDATA[
@@ -278,7 +290,7 @@
</subsection>
-<subsection name="Adding a Service Methods">
+<subsection name="Adding the Service Methods">
<p>
The last, and most complex, part of this is the method which actually creates
each
@@ -403,7 +415,7 @@
<section name="Conclusion">
<p>
-Interceptors, and interceptor factories, are a powerful concept that allow you to
add consistent, efficient,
+Interceptors are a powerful concept that allow you to add consistent, efficient,
robust behavior to your services. It takes a little while to wrap your brain around
the idea of
classes writing the code for other classes ... but once you do, a whole world of
advanced techniques
opens up to you!
1.2 +12 -5
jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/rules/MockSchemaProcessor.java
Index: MockSchemaProcessor.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/rules/MockSchemaProcessor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MockSchemaProcessor.java 16 Sep 2003 18:51:16 -0000 1.1
+++ MockSchemaProcessor.java 23 Sep 2003 22:23:52 -0000 1.2
@@ -60,11 +60,18 @@
import org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.schema.SchemaProcessor;
-
+/**
+ * Used for testing of various rules and translators.
+ *
+ * @author Howard Lewis Ship
+ * @version $Id$
+ */
public class MockSchemaProcessor implements SchemaProcessor
{
- private Module _contributingModule = new MockModule();
-
+ private Module _contributingModule = new MockModule();
+
+ private Object _peek;
+
public void addElement(Object element)
{
@@ -72,7 +79,7 @@
public void push(Object object)
{
-
+ _peek = object;
}
public Object pop()
@@ -82,7 +89,7 @@
public Object peek()
{
- return null;
+ return _peek;
}
public Object peek(int depth)
1.1
jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/rules/TestSetModule.java
Index: TestSetModule.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 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.rules;
import hivemind.test.FrameworkTestCase;
import org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.schema.rules.SetModuleRule;
/**
* Tests the [EMAIL PROTECTED]
org.apache.commons.hivemind.schema.rules.SetModuleRule} rule class.
*
* @author Howard Lewis Ship
* @version $Id: TestSetModule.java,v 1.1 2003/09/23 22:23:52 hlship Exp $
*/
public class TestSetModule extends FrameworkTestCase
{
public static class Target
{
private Module _module;
public Module getModule()
{
return _module;
}
public void setModule(Module module)
{
_module = module;
}
}
public TestSetModule(String name)
{
super(name);
}
public void testSetModuleRule()
{
MockSchemaProcessor processor = new MockSchemaProcessor();
Target t = new Target();
SetModuleRule rule = new SetModuleRule();
rule.setPropertyName("module");
processor.push(t);
rule.begin(processor, null);
assertSame(processor.getContributingModule(), t.getModule());
}
}
1.1
jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/rules/TestNumericTranslators.java
Index: TestNumericTranslators.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 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.rules;
import hivemind.test.FrameworkTestCase;
import org.apache.commons.hivemind.Element;
import org.apache.commons.hivemind.impl.ElementImpl;
import org.apache.commons.hivemind.schema.SchemaProcessor;
import org.apache.commons.hivemind.schema.rules.IntTranslator;
import org.apache.commons.hivemind.schema.rules.LongTranslator;
/**
* Tests the numeric translators.
*
* @author Howard Lewis Ship
* @version $Id: TestNumericTranslators.java,v 1.1 2003/09/23 22:23:52 hlship Exp $
*/
public class TestNumericTranslators extends FrameworkTestCase
{
public TestNumericTranslators(String name)
{
super(name);
}
/**
* Tests [EMAIL PROTECTED]
org.apache.commons.hivemind.schema.rules.IntTranslator} with
* the default constructor.
*/
public void testIntTranslator()
{
IntTranslator t = new IntTranslator();
assertEquals(new Integer(10), t.translate(null, null, "10"));
}
public void testIntDefault()
{
IntTranslator t = new IntTranslator();
assertEquals(new Integer(0), t.translate(null, null, null));
}
public void testIntRange()
{
IntTranslator t = new IntTranslator("min=5,max=200");
SchemaProcessor p = new MockSchemaProcessor();
Element e = new ElementImpl();
interceptLogging();
assertEquals(new Integer(5), t.translate(p, e, "3"));
assertLoggedMessage("Value 3 (at null) is less than minimum value 5.");
assertEquals(new Integer(200), t.translate(p, e, "50900"));
assertLoggedMessage("Value 50900 (at null) is greater than maximum value
200.");
}
public void testIntDefaultValue()
{
IntTranslator t = new IntTranslator("default=7");
assertEquals(new Integer(7), t.translate(null, null, null));
}
public void testIntInvalid()
{
IntTranslator t = new IntTranslator("default=13");
interceptLogging();
assertEquals(
new Integer(13),
t.translate(new MockSchemaProcessor(), new ElementImpl(), "qbert"));
assertLoggedMessage("'qbert' (in element foo/bar/baz at null) is not an
integer value.");
}
public void testLongTranslator()
{
LongTranslator t = new LongTranslator();
assertEquals(new Long(10), t.translate(null, null, "10"));
}
public void testLongDefault()
{
LongTranslator t = new LongTranslator();
assertEquals(new Long(0), t.translate(null, null, null));
}
public void testLongRange()
{
LongTranslator t = new LongTranslator("min=5,max=200");
SchemaProcessor p = new MockSchemaProcessor();
Element e = new ElementImpl();
interceptLogging();
assertEquals(new Long(5), t.translate(p, e, "3"));
assertLoggedMessage("Value 3 (at null) is less than minimum value 5.");
assertEquals(new Long(200), t.translate(p, e, "50900"));
assertLoggedMessage("Value 50900 (at null) is greater than maximum value
200.");
}
public void testLongDefaultValue()
{
LongTranslator t = new LongTranslator("default=7");
assertEquals(new Long(7), t.translate(null, null, null));
}
public void testLongInvalid()
{
LongTranslator t = new LongTranslator("default=13");
interceptLogging();
assertEquals(
new Long(13),
t.translate(new MockSchemaProcessor(), new ElementImpl(), "qbert"));
assertLoggedMessage("'qbert' (in element foo/bar/baz at null) is not a long
value.");
}
}
1.3 +5 -1
jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/commons/hivemind/HiveMindMessages.properties
Index: HiveMindMessages.properties
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/commons/hivemind/HiveMindMessages.properties,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HiveMindMessages.properties 18 Sep 2003 19:00:59 -0000 1.2
+++ HiveMindMessages.properties 23 Sep 2003 22:23:52 -0000 1.3
@@ -107,6 +107,10 @@
IntTranslator.min-value=Value {0} (at {1}) is less than minimum value {2}.
IntTranslator.max-value=Value {0} (at {1}) is greater than maximum value {2}.
+LongTranslator.invalid-value=''{0}'' (in element {1} at {2}) is not a long value.
+LongTranslator.min-value=Value {0} (at {1}) is less than minimum value {2}.
+LongTranslator.max-value=Value {0} (at {1}) is greater than maximum value {2}.
+
ServiceTranslator.invalid-value=Error resolving service {0} (in element {1} at
{2}): {3}
EnumerationTranslator.not-recognized=''{0}'' (at {1}) is not a recognized
enumerated value.
1.15 +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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- links.xml 18 Sep 2003 19:00:58 -0000 1.14
+++ links.xml 23 Sep 2003 22:23:52 -0000 1.15
@@ -1,7 +1,9 @@
<!-- $Id$ -->
<!ENTITY apiroot 'commons-hivemind/apidocs/org/apache/commons/hivemind'>
-<!ENTITY baseregistry 'commons-hivemind/base-registry/hivemind.html'>
+<!ENTITY base-registry 'commons-hivemind/base-registry'>
+<!ENTITY hivemind-registry '&base-registry;/hivemind.html'>
+<!ENTITY hivemind-lib-registry '&base-registry;/hivemind.lib.html'>
<!ENTITY _module '<code><module></code>'>
<!ENTITY module '<a href="descriptor.html#module">&_module;</a>'>
@@ -59,6 +61,10 @@
<!ENTITY _read-content '<code><read-content></code>'>
<!ENTITY read-content '<a href="rules.html#read-content">&_read-content;</a>'>
+
+
+<!ENTITY _set-module '<code><set-module></code>'>
+<!ENTITY set-module '<a href="rules.html#set-module">&_set-module;</a>'>
<!ENTITY _set-parent '<code><set-parent></code>'>
<!ENTITY set-parent '<a href="rules.html#set-parent">&_set-parent;</a>'>
1.3 +63 -39
jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/commons/hivemind/parse/DescriptorParser.java
Index: DescriptorParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/commons/hivemind/parse/DescriptorParser.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DescriptorParser.java 18 Sep 2003 19:01:00 -0000 1.2
+++ DescriptorParser.java 23 Sep 2003 22:23:52 -0000 1.3
@@ -91,15 +91,17 @@
import org.apache.commons.hivemind.schema.impl.SchemaImpl;
import org.apache.commons.hivemind.schema.rules.BooleanTranslator;
import org.apache.commons.hivemind.schema.rules.ClassTranslator;
+import org.apache.commons.hivemind.schema.rules.ConfigurationTranslator;
import org.apache.commons.hivemind.schema.rules.CreateObjectRule;
import org.apache.commons.hivemind.schema.rules.EnumerationTranslator;
-import org.apache.commons.hivemind.schema.rules.ConfigurationTranslator;
import org.apache.commons.hivemind.schema.rules.IntTranslator;
import org.apache.commons.hivemind.schema.rules.InvokeParentRule;
+import org.apache.commons.hivemind.schema.rules.LongTranslator;
import org.apache.commons.hivemind.schema.rules.ReadAttributeRule;
import org.apache.commons.hivemind.schema.rules.ReadContentRule;
import org.apache.commons.hivemind.schema.rules.ResourceTranslator;
import org.apache.commons.hivemind.schema.rules.ServiceTranslator;
+import org.apache.commons.hivemind.schema.rules.SetModuleRule;
import org.apache.commons.hivemind.schema.rules.SetParentRule;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -192,130 +194,136 @@
private static final int STATE_NO_CONTENT = 300;
- private static final Map MODULE_ATTRIBUTES = new HashMap();
+ private final Map MODULE_ATTRIBUTES = new HashMap();
- static {
+ {
MODULE_ATTRIBUTES.put("id", Boolean.TRUE);
MODULE_ATTRIBUTES.put("version", Boolean.TRUE);
}
- private static final Map CONTRIBUTION_ATTRIBUTES = new HashMap();
+ private final Map CONTRIBUTION_ATTRIBUTES = new HashMap();
- static {
+ {
CONTRIBUTION_ATTRIBUTES.put("configuration-id", Boolean.TRUE);
}
- private static final Map CONFIGURATION_POINT_ATTRIBUTES = new HashMap();
+ private final Map CONFIGURATION_POINT_ATTRIBUTES = new HashMap();
- static {
+ {
CONFIGURATION_POINT_ATTRIBUTES.put("id", Boolean.TRUE);
CONFIGURATION_POINT_ATTRIBUTES.put("occurs", Boolean.FALSE);
}
- private static final Map SERVICE_POINT_ATTRIBUTES = new HashMap();
+ private final Map SERVICE_POINT_ATTRIBUTES = new HashMap();
- static {
+ {
SERVICE_POINT_ATTRIBUTES.put("id", Boolean.TRUE);
SERVICE_POINT_ATTRIBUTES.put("interface", Boolean.TRUE);
SERVICE_POINT_ATTRIBUTES.put("model", Boolean.FALSE);
}
- private static final Map IMPLEMENTATION_ATTRIBUTES = new HashMap();
+ private final Map IMPLEMENTATION_ATTRIBUTES = new HashMap();
- static {
+ {
IMPLEMENTATION_ATTRIBUTES.put("service-id", Boolean.TRUE);
}
- private static final Map CREATE_INSTANCE_ATTRIBUTES = new HashMap();
+ private final Map CREATE_INSTANCE_ATTRIBUTES = new HashMap();
- static {
+ {
CREATE_INSTANCE_ATTRIBUTES.put("class", Boolean.TRUE);
}
- private static final Map INTERCEPTOR_ATTRIBUTES = new HashMap();
+ private final Map INTERCEPTOR_ATTRIBUTES = new HashMap();
- static {
+ {
INTERCEPTOR_ATTRIBUTES.put("order", Boolean.FALSE);
INTERCEPTOR_ATTRIBUTES.put("service-id", Boolean.TRUE);
}
- private static final Map ELEMENT_ATTRIBUTES = new HashMap();
+ private final Map ELEMENT_ATTRIBUTES = new HashMap();
- static {
+ {
ELEMENT_ATTRIBUTES.put("name", Boolean.TRUE);
}
- private static final Map ATTRIBUTE_ATTRIBUTES = new HashMap();
+ private final Map ATTRIBUTE_ATTRIBUTES = new HashMap();
- static {
+ {
ATTRIBUTE_ATTRIBUTES.put("name", Boolean.TRUE);
ATTRIBUTE_ATTRIBUTES.put("required", Boolean.FALSE);
}
- private static final Map CREATE_OBJECT_ATTRIBUTES = CREATE_INSTANCE_ATTRIBUTES;
+ private final Map CREATE_OBJECT_ATTRIBUTES = CREATE_INSTANCE_ATTRIBUTES;
- private static final Map INVOKE_PARENT_ATTRIBUTES = new HashMap();
+ private final Map INVOKE_PARENT_ATTRIBUTES = new HashMap();
- static {
+ {
INVOKE_PARENT_ATTRIBUTES.put("method", Boolean.TRUE);
}
- private static final Map SET_PARENT_ATTRIBUTES = new HashMap();
+ private final Map SET_PARENT_ATTRIBUTES = new HashMap();
- static {
+ {
SET_PARENT_ATTRIBUTES.put("property", Boolean.TRUE);
}
- private static final Map READ_ATTRIBUTE_ATTRIBUTES = new HashMap();
+ private final Map READ_ATTRIBUTE_ATTRIBUTES = new HashMap();
- static {
+ {
READ_ATTRIBUTE_ATTRIBUTES.put("property", Boolean.TRUE);
READ_ATTRIBUTE_ATTRIBUTES.put("attribute", Boolean.TRUE);
READ_ATTRIBUTE_ATTRIBUTES.put("skip-if-null", Boolean.FALSE);
READ_ATTRIBUTE_ATTRIBUTES.put("translator", Boolean.FALSE);
}
- private static final Map READ_CONTENT_ATTRIBUTES = new HashMap();
+ private final Map READ_CONTENT_ATTRIBUTES = new HashMap();
- static {
+ {
READ_CONTENT_ATTRIBUTES.put("property", Boolean.TRUE);
READ_CONTENT_ATTRIBUTES.put("translator", Boolean.FALSE);
}
- private static final Map INVOKE_FACTORY_ATTRIBUTES = new HashMap();
+ private final Map INVOKE_FACTORY_ATTRIBUTES = new HashMap();
- static {
+ {
INVOKE_FACTORY_ATTRIBUTES.put("service-id", Boolean.TRUE);
}
/**
* Applies to schema and parameter-schema elements.
*/
- private static final Map SCHEMA_ATTRIBUTES = new HashMap();
+ private final Map SCHEMA_ATTRIBUTES = new HashMap();
- static {
+ {
SCHEMA_ATTRIBUTES.put("id", Boolean.FALSE);
SCHEMA_ATTRIBUTES.put("ref-id", Boolean.FALSE);
}
- private static final Map CUSTOM_ATTRIBUTES = new HashMap();
+ private final Map SET_MODULE_ATTRIBUTES = new HashMap();
+
+ {
+ SET_MODULE_ATTRIBUTES.put("property", Boolean.TRUE);
+ }
+
+ private final Map CUSTOM_ATTRIBUTES = new HashMap();
- static {
+ {
CUSTOM_ATTRIBUTES.put("class", Boolean.TRUE);
}
- private static final Map OCCURS_MAP = new HashMap();
+ private final Map OCCURS_MAP = new HashMap();
- static {
+ {
OCCURS_MAP.put("0..1", Occurances.OPTIONAL);
OCCURS_MAP.put("1", Occurances.REQUIRED);
OCCURS_MAP.put("1..n", Occurances.ONE_PLUS);
OCCURS_MAP.put("0..n", Occurances.UNBOUNDED);
}
- private static final Map MODEL_MAP = new HashMap();
+ private final Map MODEL_MAP = new HashMap();
- static {
+ {
MODEL_MAP.put("singleton", ServiceModel.SINGLETON);
MODEL_MAP.put("deferred", ServiceModel.DEFERRED);
MODEL_MAP.put("threaded", ServiceModel.THREADED);
@@ -348,6 +356,7 @@
_translatorClasses.put("enumeration", EnumerationTranslator.class);
_translatorClasses.put("configuration", ConfigurationTranslator.class);
_translatorClasses.put("resource", ResourceTranslator.class);
+ _translatorClasses.put("long", LongTranslator.class);
}
/**
@@ -1275,6 +1284,21 @@
rule.setTranslator(getTranslator());
elementModel.addRule(rule);
+ return;
+ }
+
+ if (elementName.equals("set-module"))
+ {
+ SetModuleRule rule = new SetModuleRule();
+
+ push(elementName, rule, STATE_NO_CONTENT);
+
+ checkAttributes(SET_MODULE_ATTRIBUTES);
+
+ rule.setPropertyName(getAttribute("property"));
+
+ elementModel.addRule(rule);
+
return;
}
1.3 +4 -4 jakarta-commons-sandbox/hivemind/framework/src/xsl/hivemind.xsl
Index: hivemind.xsl
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/framework/src/xsl/hivemind.xsl,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- hivemind.xsl 18 Sep 2003 19:00:59 -0000 1.2
+++ hivemind.xsl 23 Sep 2003 22:23:52 -0000 1.3
@@ -144,7 +144,7 @@
</xsl:template>
<xsl:template match="configuration-point">
- <a name="configuration-point:[EMAIL PROTECTED]"/>
+ <a name="[EMAIL PROTECTED]"/>
<h2 id="[EMAIL PROTECTED]">
Configuration Point <xsl:value-of select="@id"/> </h2>
<table class="summary">
@@ -319,7 +319,7 @@
<xsl:template match="contribution">
<h2> <xsl:attribute name="id"><xsl:value-of
select="@uid"/></xsl:attribute>
- Contribution
+ Contribution to
<xsl:apply-templates select="/registry/module/[EMAIL
PROTECTED] = current()/@point-id]" mode="link"/>
@@ -380,7 +380,7 @@
<xsl:for-each select="/registry/module/[EMAIL PROTECTED] =
current()/@id]">
<xsl:sort select="../@id"/>
- <h3>Implementations from module
+ <h3>Contributions from module
<a href="{../@[EMAIL PROTECTED]">
<xsl:value-of select="../@id"/>
</a>
1.1
jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/commons/hivemind/schema/rules/SetModuleRule.java
Index: SetModuleRule.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 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.schema.rules;
import org.apache.commons.hivemind.Element;
import org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.schema.SchemaProcessor;
/**
* Rule used to set a property of the top stack object
* to the [EMAIL PROTECTED] org.apache.commons.hivemind.Module} the
* element was contributed from.
*
* @author Howard Lewis Ship
* @version $Id: SetModuleRule.java,v 1.1 2003/09/23 22:23:52 hlship Exp $
*/
public class SetModuleRule extends BaseRule
{
private String _propertyName;
public void begin(SchemaProcessor processor, Element element)
{
Object top = processor.peek();
Module contributingModule = processor.getContributingModule();
RuleUtils.setProperty(processor, element, _propertyName, top,
contributingModule);
}
public void setPropertyName(String string)
{
_propertyName = string;
}
}
1.1
jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/commons/hivemind/schema/rules/LongTranslator.java
Index: LongTranslator.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 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.schema.rules;
import java.util.Map;
import org.apache.commons.hivemind.Element;
import org.apache.commons.hivemind.HiveMind;
import org.apache.commons.hivemind.schema.SchemaProcessor;
import org.apache.commons.hivemind.schema.Translator;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Translates strings to long values.
*
* @author Howard Lewis Ship
* @version $Id: LongTranslator.java,v 1.1 2003/09/23 22:23:52 hlship Exp $
*/
public class LongTranslator implements Translator
{
private static final Log LOG = LogFactory.getLog(LongTranslator.class);
private long _minValue;
private boolean _isMinValue;
private long _maxValue;
private boolean _isMaxValue;
private long _defaultValue = 0;
public LongTranslator()
{
}
/**
* Initializers:
* <ul>
* <li>default: default value for empty or invalid input
* <li>min: minimum acceptible value
* <li>max: maximum acceptible value
*/
public LongTranslator(String initializer)
{
Map m = RuleUtils.convertInitializer(initializer);
String defaultInit = (String) m.get("default");
if (defaultInit != null)
_defaultValue = Long.parseLong(defaultInit);
String minInit = (String) m.get("min");
if (minInit != null)
{
_isMinValue = true;
_minValue = Long.parseLong(minInit);
}
String maxInit = (String) m.get("max");
if (maxInit != null)
{
_isMaxValue = true;
_maxValue = Long.parseLong(maxInit);
}
}
/**
* Converts the string to an Long. The empty string is returned as zero.
* On failure, an error is logged and the method returns zero.
*/
public Object translate(SchemaProcessor processor, Element element, String
inputValue)
{
if (StringUtils.isBlank(inputValue))
return new Long(_defaultValue);
long value;
try
{
value = Long.parseLong(inputValue);
if (_isMinValue && value < _minValue)
{
LOG.error(
HiveMind.format(
"LongTranslator.min-value",
inputValue,
element.getLocation(),
Long.toString(_minValue)));
value = _minValue;
}
if (_isMaxValue && value > _maxValue)
{
LOG.error(
HiveMind.format(
"LongTranslator.max-value",
inputValue,
element.getLocation(),
Long.toString(_maxValue)));
value = _maxValue;
}
}
catch (Exception ex)
{
LOG.error(
HiveMind.format(
"LongTranslator.invalid-value",
inputValue,
processor.getElementPath(),
element.getLocation()));
value = _defaultValue;
}
return new Long(value);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]