You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by hl...@apache.org on 2003/08/05 02:50:36 UTC
cvs commit: jakarta-commons-sandbox/hivemind/src/META-INF hivemodule.xml
hlship 2003/08/04 17:50:36
Modified: hivemind/src/test/hivemind/test/services
RecursiveService.xml TestServices.java Tracker.xml
hivemind/src/java/org/apache/commons/hivemind/schema/rules
ServiceTranslator.java
hivemind/src/java/org/apache/commons/hivemind/parse
DescriptorParser.java
hivemind/src/test/hivemind/test HiveMindSuite.java
hivemind/src/java/org/apache/commons/hivemind/service/impl
SetPropertyValue.java
hivemind/src/java/org/apache/commons/hivemind HiveMind.java
HiveMindMessages.properties
hivemind/xdocs rules.xml
hivemind/src/META-INF hivemodule.xml
Added: hivemind/src/test/hivemind/test/services Constructed.java
ServiceTranslator.xml
hivemind/src/java/org/apache/commons/hivemind/schema/rules
EnumerationTranslator.java
ExtensionPointTranslator.java
hivemind/src/test/hivemind/test/rules
ExtensionPointTranslator.xml
TestExtensionPointTranslator.java
TestBooleanTranslator.java DatumHolder.java
MockModule.java MockSchemaProcessor.java
TestClassTranslator.java
TestEnumerationTranslator.java
hivemind/src/test/hivemind/test/services/impl
ConstructedImpl.java
hivemind/src/test/hivemind/test/rules/impl
DatumHolderImpl.java
Log:
Add new translators for enumerations and for extension points.
Allow BuilderFactory to set properties of the service implementation to services and extension points.
Revision Changes Path
1.6 +4 -4 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/RecursiveService.xml
Index: RecursiveService.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/RecursiveService.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- RecursiveService.xml 31 Jul 2003 21:06:24 -0000 1.5
+++ RecursiveService.xml 5 Aug 2003 00:50:36 -0000 1.6
@@ -6,7 +6,7 @@
<service id="Fred" interface="org.apache.commons.hivemind.ServiceInterceptorFactory">
<invoke-factory service-id="hivemind.BuilderFactory">
<construct class="hivemind.test.services.impl.TrackerFactory">
- <property name="name" value="Fred"/>
+ <set property="name" value="Fred"/>
</construct>
</invoke-factory>
<interceptor service-id="Barney"/>
@@ -15,7 +15,7 @@
<service id="Barney" interface="org.apache.commons.hivemind.ServiceInterceptorFactory">
<invoke-factory service-id="hivemind.BuilderFactory">
<construct class="hivemind.test.services.impl.TrackerFactory">
- <property name="name" value="Barney"/>
+ <set property="name" value="Barney"/>
</construct>
</invoke-factory>
<interceptor service-id="Wilma"/>
@@ -24,7 +24,7 @@
<service id="Wilma" interface="org.apache.commons.hivemind.ServiceInterceptorFactory">
<invoke-factory service-id="hivemind.BuilderFactory">
<construct class="hivemind.test.services.impl.TrackerFactory">
- <property name="name" value="Wilma"/>
+ <set property="name" value="Wilma"/>
</construct>
</invoke-factory>
<!-- Here's the cycle! -->
1.15 +24 -1 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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- TestServices.java 30 Jul 2003 22:34:53 -0000 1.14
+++ TestServices.java 5 Aug 2003 00:50:36 -0000 1.15
@@ -68,6 +68,7 @@
import java.util.List;
import org.apache.commons.hivemind.Registry;
+import org.apache.commons.hivemind.service.NameLookup;
import org.apache.tapestry.ApplicationRuntimeException;
/**
@@ -326,5 +327,27 @@
// The bad impl multiplies, not add.
assertEquals(28, s.add(4, 7));
+ }
+
+ public void testServiceTranslator() throws Exception
+ {
+ Registry r = buildRegistry("ServiceTranslator.xml");
+
+ SimpleService ss =
+ (SimpleService) r.getService("hivemind.test.services.Simple", SimpleService.class);
+
+ assertNotNull(ss);
+
+ NameLookup nl = (NameLookup) r.getService("hivemind.NameLookup", NameLookup.class);
+
+ assertNotNull(nl);
+
+ Constructed c =
+ (Constructed) r.getService("hivemind.test.services.Constructed", Constructed.class);
+
+ assertNotNull(c);
+
+ assertSame(ss, c.getSimpleService());
+ assertSame(nl, c.getNameLookup());
}
}
1.5 +4 -4 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/Tracker.xml
Index: Tracker.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/Tracker.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Tracker.xml 31 Jul 2003 21:06:24 -0000 1.4
+++ Tracker.xml 5 Aug 2003 00:50:36 -0000 1.5
@@ -5,7 +5,7 @@
interface="org.apache.commons.hivemind.ServiceInterceptorFactory">
<invoke-factory service-id="hivemind.BuilderFactory">
<construct class="hivemind.test.services.impl.TrackerFactory">
- <property name="name" value="Fred"/>
+ <set property="name" value="Fred"/>
</construct>
</invoke-factory>
</service>
@@ -13,7 +13,7 @@
interface="org.apache.commons.hivemind.ServiceInterceptorFactory">
<invoke-factory service-id="hivemind.BuilderFactory">
<construct class="hivemind.test.services.impl.TrackerFactory">
- <property name="name" value="Barney"/>
+ <set property="name" value="Barney"/>
</construct>
</invoke-factory>
</service>
@@ -21,7 +21,7 @@
interface="org.apache.commons.hivemind.ServiceInterceptorFactory">
<invoke-factory service-id="hivemind.BuilderFactory">
<construct class="hivemind.test.services.impl.TrackerFactory">
- <property name="name" value="Wilma"/>
+ <set property="name" value="Wilma"/>
</construct>
</invoke-factory>
</service>
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/Constructed.java
Index: Constructed.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 apache@apache.org.
*
* 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.services;
import org.apache.commons.hivemind.service.NameLookup;
/**
* Interface used as part of tests of {@link org.apache.commons.hivemind.schema.rules.ServiceTranslator}.
*
* @author Howard Lewis Ship
* @version $Id: Constructed.java,v 1.1 2003/08/05 00:50:36 hlship Exp $
*/
public interface Constructed
{
public NameLookup getNameLookup();
public SimpleService getSimpleService();
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/ServiceTranslator.xml
Index: ServiceTranslator.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: ServiceTranslator.xml,v 1.1 2003/08/05 00:50:36 hlship Exp $ -->
<module
id="hivemind.test.services"
version="1.0.0">
<service id="Simple" interface="hivemind.test.services.SimpleService">
<create-instance class="hivemind.test.services.impl.SimpleServiceImpl"/>
</service>
<service id="Constructed" interface="hivemind.test.services.Constructed">
<invoke-factory service-id="hivemind.BuilderFactory">
<construct class="hivemind.test.services.impl.ConstructedImpl">
<set-service property="nameLookup" service-id="hivemind.NameLookup"/>
<set-service property="simpleService" service-id="Simple"/>
</construct>
</invoke-factory>
</service>
</module>
1.2 +5 -7 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/schema/rules/ServiceTranslator.java
Index: ServiceTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/schema/rules/ServiceTranslator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServiceTranslator.java 29 Jul 2003 22:20:48 -0000 1.1
+++ ServiceTranslator.java 5 Aug 2003 00:50:36 -0000 1.2
@@ -59,6 +59,7 @@
import org.apache.commons.hivemind.Element;
import org.apache.commons.hivemind.HiveMind;
+import org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.schema.SchemaProcessor;
import org.apache.commons.hivemind.schema.Translator;
import org.apache.commons.lang.StringUtils;
@@ -85,16 +86,13 @@
if (StringUtils.isEmpty(inputValue))
return null;
- String serviceId = inputValue;
+ Module module = processor.getContributingModule();
- if (serviceId.indexOf('.') <= 0)
- serviceId = processor.getContributingModule().getModuleId() + "." + inputValue;
+ String serviceId = HiveMind.qualify(module, inputValue);
try
{
- return processor.getContributingModule().getRegistry().getService(
- serviceId,
- Object.class);
+ return module.getRegistry().getService(serviceId, Object.class);
}
catch (Exception ex)
{
1.1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/schema/rules/EnumerationTranslator.java
Index: EnumerationTranslator.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 apache@apache.org.
*
* 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.lang.reflect.Field;
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;
/**
* Used to translate a set of strings to one of a number of constant values.
* Each input string is matched against the name of a public static field
* of a class. The name of the class, and the mappings, are provided
* in the initializer.
*
* @author Howard Lewis Ship
* @version $Id: EnumerationTranslator.java,v 1.1 2003/08/05 00:50:36 hlship Exp $
*/
public class EnumerationTranslator implements Translator
{
private static final Log LOG = LogFactory.getLog(EnumerationTranslator.class);
private Map _mappings;
private String _className;
private Class _class;
/**
* Initialized the translator; the intitializer is the name of the class, a comma,
* and a series of key=value mappings from the input values to the names
* of the public static fields of the class.
*/
public EnumerationTranslator(String initializer)
{
int commax = initializer.indexOf(',');
_className = initializer.substring(0, commax);
_mappings = RuleUtils.convertInitializer(initializer.substring(commax + 1));
}
private synchronized Class getClass(SchemaProcessor processor)
{
if (_class == null)
_class = processor.getContributingModule().getResourceResolver().findClass(_className);
return _class;
}
public Object translate(SchemaProcessor processor, Element element, String inputValue)
{
if (StringUtils.isEmpty(inputValue))
return null;
Class c = getClass(processor);
String fieldName = (String) _mappings.get(inputValue);
if (fieldName == null)
{
LOG.error(
HiveMind.format(
"EnumerationTranslator.not-recognized",
inputValue,
element.getLocation()));
return null;
}
try
{
Field f = c.getField(fieldName);
return f.get(null);
}
catch (Exception ex)
{
LOG.error(
HiveMind.format(
"EnumerationTranslator.error",
_className,
fieldName,
ex.getMessage()),
ex);
}
return null;
}
}
1.1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/schema/rules/ExtensionPointTranslator.java
Index: ExtensionPointTranslator.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 apache@apache.org.
*
* 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.HiveMind;
import org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.Registry;
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;
/**
* Interprets a string as an extension point id, and provides
* the elements for that extension point.
*
* @author Howard Lewis Ship
* @version $Id: ExtensionPointTranslator.java,v 1.1 2003/08/05 00:50:36 hlship Exp $
*/
public class ExtensionPointTranslator implements Translator
{
private static final Log LOG = LogFactory.getLog(ExtensionPointTranslator.class);
public Object translate(SchemaProcessor processor, Element element, String inputValue)
{
if (StringUtils.isEmpty(inputValue))
return null;
Module module = processor.getContributingModule();
String pointId = HiveMind.qualify(module, inputValue);
Registry registry = module.getRegistry();
try
{
return registry.getExtensionPointElements(pointId);
}
catch (Exception ex)
{
LOG.error(
HiveMind.format(
"ExtensionPointTranslator.error",
pointId,
element.getLocation(),
ex.getMessage()),
ex);
}
return null;
}
}
1.19 +6 -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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- DescriptorParser.java 4 Aug 2003 14:21:56 -0000 1.18
+++ DescriptorParser.java 5 Aug 2003 00:50:36 -0000 1.19
@@ -81,6 +81,8 @@
import org.apache.commons.hivemind.schema.impl.AttributeModelImpl;
import org.apache.commons.hivemind.schema.impl.ElementModelImpl;
import org.apache.commons.hivemind.schema.impl.SchemaImpl;
+import org.apache.commons.hivemind.schema.rules.EnumerationTranslator;
+import org.apache.commons.hivemind.schema.rules.ExtensionPointTranslator;
import org.apache.commons.hivemind.schema.rules.InvokeParentRule;
import org.apache.commons.hivemind.schema.rules.BooleanTranslator;
import org.apache.commons.hivemind.schema.rules.ClassTranslator;
@@ -99,6 +101,7 @@
import org.apache.tapestry.IResourceResolver;
import org.apache.tapestry.Location;
import org.apache.tapestry.util.xml.DocumentParseException;
+import org.apache.tools.ant.types.EnumeratedAttribute;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
@@ -310,6 +313,8 @@
_builtinTranslators.put("class", ClassTranslator.class);
_builtinTranslators.put("int", IntTranslator.class);
_builtinTranslators.put("service", ServiceTranslator.class);
+ _builtinTranslators.put("enumeration", EnumerationTranslator.class);
+ _builtinTranslators.put("extension-point", ExtensionPointTranslator.class);
}
/**
1.11 +9 -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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- HiveMindSuite.java 4 Aug 2003 14:21:56 -0000 1.10
+++ HiveMindSuite.java 5 Aug 2003 00:50:36 -0000 1.11
@@ -82,6 +82,12 @@
suite.addTestSuite(TestConvertInitializer.class);
+ suite.addTestSuite(TestBooleanTranslator.class);
+
+ suite.addTestSuite(TestClassTranslator.class);
+
+ suite.addTestSuite(TestEnumerationTranslator.class);
+
suite.addTestSuite(TestMessagesImpl.class);
suite.addTestSuite(TestDescriptorParser.class);
@@ -97,6 +103,8 @@
suite.addTestSuite(TestManifestClassPath.class);
suite.addTestSuite(TestConstructRegistry.class);
+
+ suite.addTestSuite(TestExtensionPointTranslator.class);
return suite;
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/ExtensionPointTranslator.xml
Index: ExtensionPointTranslator.xml
===================================================================
<?xml version="1.0"?>
<!-- $Id: ExtensionPointTranslator.xml,v 1.1 2003/08/05 00:50:36 hlship Exp $ -->
<module id="hivemind.test.rules" version="1.0.0">
<extension-point id="EP">
<schema>
<element name="datum">
<attribute name="key" required="true"/>
<attribute name="value" required="true"/>
<rules>
<create-object class="hivemind.test.config.impl.Datum"/>
<read-attribute property="key" attribute="key"/>
<read-attribute property="value" attribute="value"/>
<invoke-parent method="addElement"/>
</rules>
</element>
</schema>
</extension-point>
<extension point-id="EP">
<datum key="key1" value="value1"/>
<datum key="key2" value="value2"/>
</extension>
<service id="ExtensionPointTranslator" interface="hivemind.test.rules.DatumHolder">
<invoke-factory service-id="hivemind.BuilderFactory">
<construct class="hivemind.test.rules.impl.DatumHolderImpl">
<set-extension-point property="elements" point-id="EP"/>
</construct>
</invoke-factory>
</service>
<service id="Failure" interface="hivemind.test.rules.DatumHolder">
<invoke-factory service-id="hivemind.BuilderFactory">
<construct class="hivemind.test.rules.impl.DatumHolderImpl">
<set-extension-point property="elements" point-id="missing"/>
</construct>
</invoke-factory>
</service>
</module>
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/TestExtensionPointTranslator.java
Index: TestExtensionPointTranslator.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 apache@apache.org.
*
* 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 java.util.List;
import hivemind.test.HiveMindTestCase;
import org.apache.commons.hivemind.Registry;
import org.apache.commons.hivemind.schema.rules.ExtensionPointTranslator;
/**
* Tests for {@link org.apache.commons.hivemind.schema.rules.ExtensionPointTranslator}.
*
* @author Howard Lewis Ship
* @version $Id: TestExtensionPointTranslator.java,v 1.1 2003/08/05 00:50:36 hlship Exp $
*/
public class TestExtensionPointTranslator extends HiveMindTestCase
{
public TestExtensionPointTranslator(String name)
{
super(name);
}
public void testNull()
{
ExtensionPointTranslator t = new ExtensionPointTranslator();
assertNull(t.translate(null, null, null));
}
public void testExtensionPointTranslator() throws Exception
{
Registry r = buildRegistry("ExtensionPointTranslator.xml");
DatumHolder h =
(DatumHolder) r.getService(
"hivemind.test.rules.ExtensionPointTranslator",
DatumHolder.class);
List l1 = h.getDatums();
List l2 = r.getExtensionPointElements("hivemind.test.rules.EP");
assertSame(l2, l1);
}
public void testFailure() throws Exception
{
Registry r = buildRegistry("ExtensionPointTranslator.xml");
interceptLogging();
DatumHolder h =
(DatumHolder) r.getService("hivemind.test.rules.Failure", DatumHolder.class);
checkLoggingEvent(
ExtensionPointTranslator.class.getName(),
"Error accessing extension point hivemind\\.test\\.rules\\.missing \\(at .*\\): "
+ "Extension point hivemind\\.test\\.rules\\.missing does not exist\\.");
assertNull(h.getDatums());
}
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/TestBooleanTranslator.java
Index: TestBooleanTranslator.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 apache@apache.org.
*
* 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 org.apache.commons.hivemind.schema.rules.BooleanTranslator;
import hivemind.test.HiveMindTestCase;
/**
* Fill in some gaps
* for {@link org.apache.commons.hivemind.schema.rules.BooleanTranslator}.
*
* @author Howard Lewis Ship
* @version $Id: TestBooleanTranslator.java,v 1.1 2003/08/05 00:50:36 hlship Exp $
*/
public class TestBooleanTranslator extends HiveMindTestCase
{
public TestBooleanTranslator(String name)
{
super(name);
}
public void testNull()
{
BooleanTranslator t = new BooleanTranslator();
assertEquals(Boolean.FALSE, t.translate(null, null, null));
}
public void testInitializer()
{
BooleanTranslator t = new BooleanTranslator("default=true");
assertEquals(Boolean.TRUE, t.translate(null, null, null));
}
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/DatumHolder.java
Index: DatumHolder.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 apache@apache.org.
*
* 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 java.util.List;
/**
* Part of tests for {@link org.apache.commons.hivemind.schema.rules.ExtensionPointTranslator}.
*
* @author Howard Lewis Ship
* @version $Id: DatumHolder.java,v 1.1 2003/08/05 00:50:36 hlship Exp $
*/
public interface DatumHolder
{
public List getDatums();
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/MockModule.java
Index: MockModule.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 apache@apache.org.
*
* 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 java.util.List;
import org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.Registry;
import org.apache.commons.hivemind.ServiceExtensionPoint;
import org.apache.tapestry.ILocation;
import org.apache.tapestry.IMessages;
import org.apache.tapestry.IResourceResolver;
import org.apache.tapestry.util.DefaultResourceResolver;
/**
* Mock implementation of {@link org.apache.commons.hivemind.Module} used
* for testing puposes.
*
* @author Howard Lewis Ship
* @version $Id: MockModule.java,v 1.1 2003/08/05 00:50:36 hlship Exp $
*/
public class MockModule implements Module
{
private IResourceResolver _resolver = new DefaultResourceResolver();
public String getModuleId()
{
return null;
}
public Object getService(String serviceId, Class serviceInterface)
{
return null;
}
public ServiceExtensionPoint getServiceExtensionPoint(String serviceId)
{
return null;
}
public List getExtensionPointElements(String extensionPointId)
{
return null;
}
public Registry getRegistry()
{
return null;
}
public IResourceResolver getResourceResolver()
{
return _resolver;
}
public IMessages getMessages()
{
return null;
}
public ILocation getLocation()
{
return null;
}
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/MockSchemaProcessor.java
Index: MockSchemaProcessor.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 apache@apache.org.
*
* 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 org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.schema.SchemaProcessor;
public class MockSchemaProcessor implements SchemaProcessor
{
private Module _contributingModule = new MockModule();
public void addElement(Object element)
{
}
public void push(Object object)
{
}
public Object pop()
{
return null;
}
public Object peek()
{
return null;
}
public Object peek(int depth)
{
return null;
}
public Module getContributingModule()
{
return _contributingModule;
}
public String getElementPath()
{
return "foo/bar/baz";
}
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/TestClassTranslator.java
Index: TestClassTranslator.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 apache@apache.org.
*
* 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.HiveMindTestCase;
import org.apache.commons.hivemind.impl.ElementImpl;
import org.apache.commons.hivemind.schema.SchemaProcessor;
import org.apache.commons.hivemind.schema.rules.ClassTranslator;
import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.ILocation;
import org.apache.tapestry.Location;
import org.apache.tapestry.spec.BaseLocatable;
/**
* Fill in some gaps in
* {@link org.apache.commons.hivemind.schema.rules.ClassTranslator}.
*
* @author Howard Lewis Ship
* @version $Id: TestClassTranslator.java,v 1.1 2003/08/05 00:50:36 hlship Exp $
*/
public class TestClassTranslator extends HiveMindTestCase
{
public TestClassTranslator(String name)
{
super(name);
}
public void testNull()
{
ClassTranslator t = new ClassTranslator();
assertNull(t.translate(null, null, null));
}
public void testBadClass() throws Exception
{
ClassTranslator t = new ClassTranslator();
ElementImpl e = new ElementImpl();
ILocation l = new Location(getLocation("TestClassTranslator.class"), 50);
e.setLocation(l);
SchemaProcessor p = new MockSchemaProcessor();
interceptLogging();
Object r = t.translate(p, e, "bad.class.Name");
assertNull(r);
checkLoggingEvent(
null,
"'bad.class.Name' is not a valid class name \\(at .*\\): Could not load class bad.class.Name");
}
public void testLocatable() throws Exception
{
ClassTranslator t = new ClassTranslator();
ElementImpl e = new ElementImpl();
ILocation l = new Location(getLocation("TestClassTranslator.class"), 50);
e.setLocation(l);
SchemaProcessor p = new MockSchemaProcessor();
BaseLocatable r = (BaseLocatable) t.translate(p, e, BaseLocatable.class.getName());
assertNotNull(r);
assertSame(l, r.getLocation());
}
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/TestEnumerationTranslator.java
Index: TestEnumerationTranslator.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 apache@apache.org.
*
* 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.HiveMindTestCase;
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.EnumerationTranslator;
import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.ILocation;
import org.apache.tapestry.Location;
/**
* Tests for {@link org.apache.commons.hivemind.schema.rules.EnumerationTranslator}.
*
* @author Howard Lewis Ship
* @version $Id: TestEnumerationTranslator.java,v 1.1 2003/08/05 00:50:36 hlship Exp $
*/
public class TestEnumerationTranslator extends HiveMindTestCase
{
public TestEnumerationTranslator(String name)
{
super(name);
}
private Element forgeElement()
{
ElementImpl e = new ElementImpl();
ILocation l = new Location(getLocation("TestEnumerationTranslator.class"), 50);
e.setLocation(l);
return e;
}
public void testNull()
{
SchemaProcessor p = new MockSchemaProcessor();
Element e = forgeElement();
EnumerationTranslator t =
new EnumerationTranslator("java.lang.Boolean,true=TRUE,false=FALSE");
assertEquals(null, t.translate(p, e, null));
}
public void testMatch()
{
SchemaProcessor p = new MockSchemaProcessor();
Element e = forgeElement();
EnumerationTranslator t =
new EnumerationTranslator("java.lang.Boolean,true=TRUE,false=FALSE");
assertEquals(Boolean.TRUE, t.translate(p, e, "true"));
assertEquals(Boolean.FALSE, t.translate(p, e, "false"));
}
public void testBadClass()
{
SchemaProcessor p = new MockSchemaProcessor();
Element e = forgeElement();
EnumerationTranslator t =
new EnumerationTranslator("lava.jang.Boolean,true=TRUE,false=FALSE");
try
{
t.translate(p, e, "true");
unreachable();
}
catch (ApplicationRuntimeException ex)
{
checkException(ex, "Could not load class lava.jang.Boolean");
}
}
public void testUnrecognizedValue() throws Exception
{
SchemaProcessor p = new MockSchemaProcessor();
Element e = forgeElement();
EnumerationTranslator t =
new EnumerationTranslator("java.lang.Boolean,true=TRUE,false=FALSE");
interceptLogging();
assertEquals(null, t.translate(p, e, "fred"));
checkLoggingEvent(
EnumerationTranslator.class.getName(),
"'fred' \\(at .*\\) is not a recognized enumerated value\\.");
}
public void testBadField() throws Exception
{
SchemaProcessor p = new MockSchemaProcessor();
Element e = forgeElement();
EnumerationTranslator t =
new EnumerationTranslator("java.lang.Boolean,true=HONEST_TO_GOD_TRUE,false=FALSE");
interceptLogging();
assertEquals(null, t.translate(p, e, "true"));
checkLoggingEvent(
EnumerationTranslator.class.getName(),
"Unable to obtain value for static field java\\.lang\\.Boolean\\.HONEST_TO_GOD_TRUE:");
}
}
1.2 +4 -4 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl/SetPropertyValue.java
Index: SetPropertyValue.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl/SetPropertyValue.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SetPropertyValue.java 30 Jul 2003 22:34:53 -0000 1.1
+++ SetPropertyValue.java 5 Aug 2003 00:50:36 -0000 1.2
@@ -68,14 +68,14 @@
public class SetPropertyValue
{
private String _propertyName;
- private String _value;
+ private Object _value;
public String getPropertyName()
{
return _propertyName;
}
- public String getValue()
+ public Object getValue()
{
return _value;
}
@@ -85,7 +85,7 @@
_propertyName = string;
}
- public void setValue(String string)
+ public void setValue(Object string)
{
_value = string;
}
1.13 +14 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/HiveMind.java
Index: HiveMind.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/HiveMind.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- HiveMind.java 4 Aug 2003 14:21:56 -0000 1.12
+++ HiveMind.java 5 Aug 2003 00:50:36 -0000 1.13
@@ -272,4 +272,17 @@
return Collections.unmodifiableList(sorted);
}
+ /**
+ * Returns a fully qualfied id. If the id contains a '.', then it
+ * is returned unchanged. Otherwise, the module's id is prefixed (with a
+ * seperator '.') and returned;
+ */
+ public static String qualify(Module module, String id)
+ {
+ if (id.indexOf('.') > 0)
+ return id;
+
+ return module.getModuleId() + "." + id;
+ }
+
}
1.18 +8 -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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- HiveMindMessages.properties 4 Aug 2003 14:21:56 -0000 1.17
+++ HiveMindMessages.properties 5 Aug 2003 00:50:36 -0000 1.18
@@ -106,6 +106,8 @@
CreateObjectRule.error-creating-object=Error creating instance of class {0} (at {1}): {2}
+ClassTranslator.bad-class-name=''{0}'' is not a valid class name (at {1}): {2}
+
BooleanTranslator.invalid-value=''{0}'' (in element {1} at {2}) is not a boolean value (which should be either ''true'' or ''false'').
IntTranslator.invalid-value=''{0}'' (in element {1} at {2}) is not an integer value.
@@ -114,7 +116,12 @@
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.
+EnumerationTranslator.error=Unable to obtain value for static field {0}.{1}: {2}
+
RuleUtils.invalid-initializer=Initializer string (''{0}'') is not in proper format (key=value[,key=value]*).
+
+ExtensionPointTranslator.error=Error accessing extension point {0} (at {1}): {2}
# service.impl package
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/impl/ConstructedImpl.java
Index: ConstructedImpl.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 apache@apache.org.
*
* 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.services.impl;
import org.apache.commons.hivemind.service.NameLookup;
import org.apache.tapestry.spec.BaseLocatable;
import hivemind.test.services.Constructed;
import hivemind.test.services.SimpleService;
/**
* Used for testing {@link org.apache.commons.hivemind.schema.rules.ServiceTranslator}.
*
* @author Howard Lewis Ship
* @version $Id: ConstructedImpl.java,v 1.1 2003/08/05 00:50:36 hlship Exp $
*/
public class ConstructedImpl extends BaseLocatable implements Constructed
{
private NameLookup _nameLookup;
private SimpleService _simpleService;
public NameLookup getNameLookup()
{
return _nameLookup;
}
public SimpleService getSimpleService()
{
return _simpleService;
}
public void setNameLookup(NameLookup lookup)
{
_nameLookup = lookup;
}
public void setSimpleService(SimpleService service)
{
_simpleService = service;
}
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/impl/DatumHolderImpl.java
Index: DatumHolderImpl.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 apache@apache.org.
*
* 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.impl;
import java.util.List;
import hivemind.test.rules.DatumHolder;
/**
* Part of test suite for {@link org.apache.commons.hivemind.schema.rules.ExtensionPointTranslator}.
*
* @author Howard Lewis Ship
* @version $Id: DatumHolderImpl.java,v 1.1 2003/08/05 00:50:36 hlship Exp $
*/
public class DatumHolderImpl implements DatumHolder
{
public List _elements;
public List getDatums()
{
return getElements();
}
public List getElements()
{
return _elements;
}
public void setElements(List list)
{
_elements = list;
}
}
1.3 +51 -7 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- rules.xml 4 Aug 2003 14:21:56 -0000 1.2
+++ rules.xml 5 Aug 2003 00:50:36 -0000 1.3
@@ -44,13 +44,13 @@
</p>
<p>
-XML Processing is based on an <i>object stack</i>. Several rules will manipulate the top object on the stack, setting properties
+XML Processing is based on an object stack. Several rules will manipulate the top object on the stack, setting properties
based on attributes or content. The &create-object; rule will instantiate a new object
at <code>begin()</code> and pop it off the stack at <code>end()</code>.
</p>
<p>
-In several cases, rule descriptions reference the <i>parent</i> and <i>child</i> objects. The top object on
+In several cases, rule descriptions reference the parent and child objects. The top object on
the stack is the child, the object beneath that is the parent. The &set-parent; and &invoke-parent; rules
are useful for creating hierarchies of objects.
</p>
@@ -229,7 +229,7 @@
<p>
Commonly, it is necessary to perform some translation or transformation of string attribute value to convert the
-value into some other type, such as boolean, integer or date. This can be accomplished by specifying a <i>translator</i>
+value into some other type, such as boolean, integer or date. This can be accomplished by specifying a translator
in the &read-attribute; rule (it also applies to element content, and the &read-content; rule).
</p>
@@ -241,10 +241,10 @@
</p>
<p>
-Translators can be configured using <i>initializer strings</i>. The initializer string is separated from the
+Translators can be configured using initializer strings. The initializer string is separated from the
translator id (or translator class name) by a comma, ex: <code>int,min=0</code>. Initializer
-strings are <i>generally</i> in the format of
-<code><i>key</i>=<i>value</i>[,<i>key</i>=<i>value</i>]*</code> ... but each Translator
+strings are generally in the format of
+<code>key=value[,key=value]*</code> ... but each Translator
is free to interpret the initializer string its own way.
</p>
@@ -266,6 +266,50 @@
<p>
The class translator converts a fully qualified class name into an object instance. The class must implement
a public no-arguments constructor.
+</p>
+
+</subsection>
+
+<subsection name="enumeration">
+
+<p>
+The enumeration translator converts input strings into enumerated values. Enumeration <em>requires</em>
+an initializer string, with a special format:
+<br/>
+<code>
+enumeration,class-name,input=field-name[,input=field-name]*
+</code>
+</p>
+
+<p>
+That is, the initializer begins with the name of the class containing some number of public static fields.
+Input values are mapped against field names. Example:
+
+<br/>
+
+<code>
+ enumeration,java.lang.Boolean,yes=TRUE,no=FALSE
+</code>
+</p>
+
+<p>
+If the input is null or empty, then the translator returns null. If there is an error (such as an invalid class
+name or unrecognized input value) then an error is logged and null is returned.
+</p>
+
+</subsection>
+
+<subsection name="extension-point">
+
+<p>
+The extension-point translator converts an input value into an extension point id, then obtains
+the elements for that extension point as the value. The id may be fully qualified, or a local id within
+the contributing module.
+</p>
+
+<p>
+A null input value returns null. Invalid input, such as an unknown extension point id, will be logged as an error and
+null will be returned.
</p>
</subsection>
1.10 +53 -6 jakarta-commons-sandbox/hivemind/src/META-INF/hivemodule.xml
Index: hivemodule.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/META-INF/hivemodule.xml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- hivemodule.xml 31 Jul 2003 21:06:25 -0000 1.9
+++ hivemodule.xml 5 Aug 2003 00:50:36 -0000 1.10
@@ -87,21 +87,68 @@
<invoke-parent method="addElement"/>
</rules>
- <element name="property">
+ <element name="set">
<description>
- Each property element identifies a property of the service instance to update and a value to update to.
+ Configures a property of the service instance to a string value.
</description>
- <attribute name="name" required="true"/>
- <attribute name="value" required="true"/>
+ <attribute name="property" required="true">
+ <description>The name of a property of the service instance to configure.</description>
+ </attribute>
+ <attribute name="value" required="true">
+ <description>A literal string value to set the property to.</description>
+ </attribute>
<rules>
<create-object class="org.apache.commons.hivemind.service.impl.SetPropertyValue"/>
- <read-attribute property="propertyName" attribute="name"/>
+ <read-attribute property="propertyName" attribute="property"/>
<read-attribute property="value" attribute="value"/>
<invoke-parent method="addProperty"/>
</rules>
</element>
+ <element name="set-service">
+ <description>
+ Configures a property of the service instance to another service.
+ </description>
+
+ <attribute name="property" required="true">
+ <description>The name of the property of the service instance to configure.</description>
+ </attribute>
+
+ <attribute name="service-id" required="true">
+ <description>The id of the service.</description>
+ </attribute>
+
+ <rules>
+ <create-object class="org.apache.commons.hivemind.service.impl.SetPropertyValue"/>
+ <read-attribute property="propertyName" attribute="property"/>
+ <read-attribute property="value" attribute="service-id" translator="service"/>
+ <invoke-parent method="addProperty"/>
+ </rules>
+
+ </element>
+
+ <element name="set-extension-point">
+ <description>Configures a property of the service instance to the elements
+ contributed to an extension point.</description>
+
+
+ <attribute name="property" required="true">
+ <description>The name of the property of the service instance to configure.</description>
+ </attribute>
+
+ <attribute name="point-id" required="true">
+ <description>The id of the extension point to access.</description>
+ </attribute>
+
+ <rules>
+ <create-object class="org.apache.commons.hivemind.service.impl.SetPropertyValue"/>
+ <read-attribute property="propertyName" attribute="property"/>
+ <read-attribute property="value" attribute="point-id" translator="extension-point"/>
+ <invoke-parent method="addProperty"/>
+ </rules>
+
+ </element>
</element>
</parameters-schema>