You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by kn...@apache.org on 2005/01/10 14:14:59 UTC
cvs commit: jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules PushAttributeRule.java SmartTranslator.java
knut 2005/01/10 05:14:59
Modified: framework/src/test/hivemind/test/rules
TestSmartTranslator.java TestPushAttributeRule.java
framework/src/descriptor/META-INF hivemodule.xml
framework/src/java/org/apache/hivemind/service/impl
BuilderPropertyFacet.java
framework/src/test/hivemind/test/services/impl
ConstructorAccessImpl.java
framework/src/test/hivemind/test/services TestServices.java
ConstructorFactory.xml
. status.xml
framework/src/java/org/apache/hivemind/schema/rules
PushAttributeRule.java SmartTranslator.java
Log:
Fixed issues HIVEMIND-15, HIVEMIND-57, and HIVEMIND-80. All relating to <push-attribute> and / or the smart translator.
Revision Changes Path
1.8 +22 -10 jakarta-hivemind/framework/src/test/hivemind/test/rules/TestSmartTranslator.java
Index: TestSmartTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/rules/TestSmartTranslator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TestSmartTranslator.java 6 Jan 2005 01:45:14 -0000 1.7
+++ TestSmartTranslator.java 10 Jan 2005 13:14:59 -0000 1.8
@@ -25,7 +25,7 @@
/**
* Tests for {@link org.apache.hivemind.schema.rules.SmartTranslator}.
- *
+ *
* @author Howard Lewis Ship
*/
public class TestSmartTranslator extends HiveMindTestCase
@@ -78,10 +78,8 @@
}
/**
- * Test with a String value (apparently, this doesn't always work,
- * see bug HIVEMIND-15).
+ * Test with a String value (apparently, this doesn't always work, see bug HIVEMIND-15).
*/
-
public void testString()
{
Translator t = new SmartTranslator();
@@ -91,14 +89,30 @@
assertEquals("Fluffy Puppies", result);
}
+ /**
+ * The input value should be returned as is (i.e. as a String) when the property type is Object
+ * (see HIVEMIND-15).
+ */
+ public void testObjectAsString()
+ {
+ Translator t = new SmartTranslator();
+
+ Object result = t.translate(null, Object.class, "Fluffy Puppies", null);
+
+ assertEquals("Fluffy Puppies", result);
+ }
+
public void testStringWithNoEditor()
{
- PropertyEditorManager.setEditorSearchPath( new String[] { "bogus.package" } );
+ PropertyEditorManager.setEditorSearchPath(new String[]
+ { "bogus.package" });
Translator t = new SmartTranslator();
+
Object result = t.translate(null, String.class, "Fluffy Puppies", null);
+
assertEquals("Fluffy Puppies", result);
}
-
+
public void testNoEditor()
{
Translator t = new SmartTranslator();
@@ -112,10 +126,8 @@
}
catch (ApplicationRuntimeException ex)
{
- assertEquals(
- "Unable to translate 'fred' to type org.apache.hivemind.Registry: "
- + "No property editor for org.apache.hivemind.Registry.",
- ex.getMessage());
+ assertEquals("Unable to translate 'fred' to type org.apache.hivemind.Registry: "
+ + "No property editor for org.apache.hivemind.Registry.", ex.getMessage());
assertSame(l, ex.getLocation());
}
1.6 +10 -4 jakarta-hivemind/framework/src/test/hivemind/test/rules/TestPushAttributeRule.java
Index: TestPushAttributeRule.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/rules/TestPushAttributeRule.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestPushAttributeRule.java 5 Jan 2005 18:04:06 -0000 1.5
+++ TestPushAttributeRule.java 10 Jan 2005 13:14:59 -0000 1.6
@@ -33,7 +33,7 @@
ElementImpl element = new ElementImpl();
element.setElementName("myelement");
- Attribute attribute = new AttributeImpl("fred", "flintstone");
+ Attribute attribute = new AttributeImpl("fred", "${flintstone}");
element.addAttribute(attribute);
@@ -48,12 +48,18 @@
mockProcessor.getContributingModule();
- control.setReturnValue(newMock(Module.class));
+ MockControl moduleControl = newControl(Module.class);
+ Module mockModule = (Module) moduleControl.getMock();
- mockProcessor.push("flintstone");
+ control.setReturnValue(mockModule, 2);
+
+ mockModule.expandSymbols("${flintstone}", element.getLocation());
+ moduleControl.setReturnValue("FLINTSTONE");
+
+ mockProcessor.push("FLINTSTONE");
mockProcessor.pop();
- control.setReturnValue("flintstone");
+ control.setReturnValue("FLINTSTONE");
replayControls();
1.21 +1 -1 jakarta-hivemind/framework/src/descriptor/META-INF/hivemodule.xml
Index: hivemodule.xml
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/descriptor/META-INF/hivemodule.xml,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- hivemodule.xml 6 Jan 2005 01:45:15 -0000 1.20
+++ hivemodule.xml 10 Jan 2005 13:14:59 -0000 1.21
@@ -221,7 +221,7 @@
<rules>
<create-object class="org.apache.hivemind.service.impl.BuilderPropertyFacet"/>
- <set-property property="translator" value="string"/>
+ <set-property property="translator" value="smart"/>
<read-content property="value"/>
<invoke-parent depth="7" method="addParameter"/>
</rules>
1.10 +15 -6 jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java
Index: BuilderPropertyFacet.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- BuilderPropertyFacet.java 5 Jan 2005 18:05:01 -0000 1.9
+++ BuilderPropertyFacet.java 10 Jan 2005 13:14:59 -0000 1.10
@@ -14,6 +14,7 @@
package org.apache.hivemind.service.impl;
+import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ServiceImplementationFactoryParameters;
import org.apache.hivemind.schema.Translator;
import org.apache.hivemind.util.ConstructorUtils;
@@ -47,12 +48,20 @@
public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters,
Class targetType)
{
- Object facetValue = getFacetValue(factoryParameters, targetType);
-
- if (facetValue == null)
- return !targetType.isPrimitive();
-
- return ConstructorUtils.isCompatible(targetType, facetValue.getClass());
+ try
+ {
+ // TODO should Translator declare an analoguous isAssignableToType method?
+ Object facetValue = getFacetValue(factoryParameters, targetType);
+
+ if (facetValue == null)
+ return !targetType.isPrimitive();
+
+ return ConstructorUtils.isCompatible(targetType, facetValue.getClass());
+ }
+ catch (ApplicationRuntimeException e)
+ {
+ return false;
+ }
}
/** @since 1.1 */
1.7 +5 -0 jakarta-hivemind/framework/src/test/hivemind/test/services/impl/ConstructorAccessImpl.java
Index: ConstructorAccessImpl.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/services/impl/ConstructorAccessImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ConstructorAccessImpl.java 6 Jan 2005 01:45:11 -0000 1.6
+++ ConstructorAccessImpl.java 10 Jan 2005 13:14:59 -0000 1.7
@@ -46,6 +46,11 @@
actualMessage = "(long)";
}
+ public ConstructorAccessImpl(String string)
+ {
+ actualMessage = "(String)";
+ }
+
public ConstructorAccessImpl(ConstructorAccess service)
{
actualMessage = "(ConstructorAccess)";
1.25 +1 -0 jakarta-hivemind/framework/src/test/hivemind/test/services/TestServices.java
Index: TestServices.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/services/TestServices.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- TestServices.java 6 Jan 2005 01:45:05 -0000 1.24
+++ TestServices.java 10 Jan 2005 13:14:59 -0000 1.25
@@ -311,6 +311,7 @@
{
"DefaultConstructor",
"LongConstructor",
+ "StringConstructor",
"ServiceConstructor",
"MultiConstructor",
"ConfigurationConstructor",
1.7 +9 -0 jakarta-hivemind/framework/src/test/hivemind/test/services/ConstructorFactory.xml
Index: ConstructorFactory.xml
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/services/ConstructorFactory.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ConstructorFactory.xml 6 Jan 2005 01:45:05 -0000 1.6
+++ ConstructorFactory.xml 10 Jan 2005 13:14:59 -0000 1.7
@@ -34,6 +34,15 @@
</invoke-factory>
</service-point>
+ <service-point id="StringConstructor" interface="hivemind.test.services.ConstructorAccess">
+ <invoke-factory>
+ <construct class="hivemind.test.services.impl.ConstructorAccessImpl">
+ <string>Foo</string>
+ <set property="expectedConstructorMessage" value="(String)"/>
+ </construct>
+ </invoke-factory>
+ </service-point>
+
<service-point id="ServiceConstructor" interface="hivemind.test.services.ConstructorAccess">
<invoke-factory>
<construct class="hivemind.test.services.impl.ConstructorAccessImpl">
1.91 +8 -0 jakarta-hivemind/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/jakarta-hivemind/status.xml,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -r1.90 -r1.91
--- status.xml 5 Jan 2005 22:23:14 -0000 1.90
+++ status.xml 10 Jan 2005 13:14:59 -0000 1.91
@@ -135,6 +135,14 @@
Allow services to be serialized (that is, service proxies can be serialized and
deserialized).
</action>
+ <action type="fix" dev="KW" fixes-bug="HIVEMIND-15" due-to="James Carman">
+ Smart translator properly returns attribute values as Strings when used with
+ a <push-attribute> rule.
+ </action>
+ <action type="fix" dev="KW" fixes-bug="HIVEMIND-57">
+ Attribute values are symbol-expanded by a <push-attribute> rule before being
+ translated and pushed on the stack.
+ </action>
</release>
<release version="1.0" date="Sep 22 2004">
1.8 +8 -8 jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/PushAttributeRule.java
Index: PushAttributeRule.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/PushAttributeRule.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- PushAttributeRule.java 5 Jan 2005 18:03:41 -0000 1.7
+++ PushAttributeRule.java 10 Jan 2005 13:14:59 -0000 1.8
@@ -19,9 +19,9 @@
import org.apache.hivemind.schema.Translator;
/**
- * A rule that reads an attribute, passes it through a translator, then pushes the result
- * onto the processor stack.
- *
+ * A rule that reads an attribute, passes it through a translator, then pushes the result onto the
+ * processor stack.
+ *
* @author Howard Lewis Ship
*/
public class PushAttributeRule extends BaseRule
@@ -29,20 +29,20 @@
private String _attributeName;
/**
- * Uses the translator to convert the specified attribute into an object and pushes
- * that object onto the processor stack.
+ * Uses the translator to convert the specified attribute into an object and pushes that object
+ * onto the processor stack.
*/
public void begin(SchemaProcessor processor, Element element)
{
Translator t = processor.getAttributeTranslator(_attributeName);
String attributeValue = element.getAttributeValue(_attributeName);
+ String value = RuleUtils.processText(processor, element, attributeValue);
- Object finalValue =
- t.translate(
+ Object finalValue = t.translate(
processor.getContributingModule(),
Object.class,
- attributeValue,
+ value,
element.getLocation());
processor.push(finalValue);
1.8 +16 -21 jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/SmartTranslator.java
Index: SmartTranslator.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/SmartTranslator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SmartTranslator.java 6 Jan 2005 01:45:08 -0000 1.7
+++ SmartTranslator.java 10 Jan 2005 13:14:59 -0000 1.8
@@ -24,9 +24,9 @@
import org.apache.hivemind.schema.Translator;
/**
- * A "smart" translator that attempts to automatically convert from string types
- * to object or wrapper types, using {@link java.beans.PropertyEditor}s.
- *
+ * A "smart" translator that attempts to automatically convert from string types to object or
+ * wrapper types, using {@link java.beans.PropertyEditor}s.
+ *
* @author Howard Lewis Ship
*/
public class SmartTranslator implements Translator
@@ -50,17 +50,11 @@
_default = (String) m.get("default");
}
- public Object translate(
- Module contributingModule,
- Class propertyType,
- String inputValue,
- Location location)
+ public Object translate(Module contributingModule, Class propertyType, String inputValue,
+ Location location)
{
- // HIVEMIND-10: Inside JavaWebStart you (strangely) can't rely on
- // a PropertyEditor for String (even though it is trivial).
-
- if (propertyType.equals(String.class))
- return inputValue;
+ // HIVEMIND-10: Inside JavaWebStart you (strangely) can't rely on
+ // a PropertyEditor for String (even though it is trivial).
if (inputValue == null)
{
@@ -70,15 +64,16 @@
inputValue = _default;
}
+ if (propertyType.equals(String.class) || propertyType.equals(Object.class))
+ return inputValue;
+
try
{
PropertyEditor e = PropertyEditorManager.findEditor(propertyType);
if (e == null)
- throw new ApplicationRuntimeException(
- RulesMessages.noPropertyEditor(propertyType),
- location,
- null);
+ throw new ApplicationRuntimeException(RulesMessages.noPropertyEditor(propertyType),
+ location, null);
e.setAsText(inputValue);
@@ -86,10 +81,10 @@
}
catch (Exception ex)
{
- throw new ApplicationRuntimeException(
- RulesMessages.smartTranslatorError(inputValue, propertyType, ex),
- location,
- ex);
+ throw new ApplicationRuntimeException(RulesMessages.smartTranslatorError(
+ inputValue,
+ propertyType,
+ ex), location, ex);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org