|
From: <ope...@li...> - 2012-07-31 14:40:27
|
Revision: 297
http://openfast.svn.sourceforge.net/openfast/?rev=297&view=rev
Author: joshseidel
Date: 2012-07-31 14:40:16 +0000 (Tue, 31 Jul 2012)
Log Message:
-----------
Update branch to reflect ComposedDecimalParser changes in trunk.
Modified Paths:
--------------
branches/generics-cleanup/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java
branches/generics-cleanup/src/test/java/org/openfast/template/loader/ComposedDecimalParserTest.java
Property Changed:
----------------
branches/generics-cleanup/
Property changes on: branches/generics-cleanup
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk:267-291
+ /trunk:267-296
Modified: branches/generics-cleanup/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java
===================================================================
--- branches/generics-cleanup/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java 2012-05-14 12:29:26 UTC (rev 296)
+++ branches/generics-cleanup/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java 2012-07-31 14:40:16 UTC (rev 297)
@@ -95,27 +95,31 @@
String exponentNamespace = context.getNamespace();
if ((mantissaNode != null) && mantissaNode.hasChildNodes()) {
Element operatorElement = getElement((Element) mantissaNode, 1);
- mantissaOperator = operatorElement.getNodeName();
- if (operatorElement.hasAttribute("value"))
- mantissaDefaultValue = Type.I64.getValue(operatorElement.getAttribute("value"));
- if (operatorElement.hasAttribute("ns"))
- mantissaNamespace = operatorElement.getAttribute("ns");
- if (operatorElement.hasAttribute("key"))
- mantissaKey = new QName(operatorElement.getAttribute("key"), mantissaNamespace);
- if (operatorElement.hasAttribute("dictionary"))
- mantissaDictionary = operatorElement.getAttribute("dictionary");
+ if (operatorElement != null) {
+ mantissaOperator = operatorElement.getNodeName();
+ if (operatorElement.hasAttribute("value"))
+ mantissaDefaultValue = Type.I64.getValue(operatorElement.getAttribute("value"));
+ if (operatorElement.hasAttribute("ns"))
+ mantissaNamespace = operatorElement.getAttribute("ns");
+ if (operatorElement.hasAttribute("key"))
+ mantissaKey = new QName(operatorElement.getAttribute("key"), mantissaNamespace);
+ if (operatorElement.hasAttribute("dictionary"))
+ mantissaDictionary = operatorElement.getAttribute("dictionary");
+ }
}
if ((exponentNode != null) && exponentNode.hasChildNodes()) {
Element operatorElement = getElement((Element) exponentNode, 1);
- exponentOperator = operatorElement.getNodeName();
- if (operatorElement.hasAttribute("value"))
- exponentDefaultValue = Type.I32.getValue(operatorElement.getAttribute("value"));
- if (operatorElement.hasAttribute("ns"))
- exponentNamespace = operatorElement.getAttribute("ns");
- if (operatorElement.hasAttribute("key"))
- exponentKey = new QName(operatorElement.getAttribute("key"), exponentNamespace);
- if (operatorElement.hasAttribute("dictionary"))
- exponentDictionary = operatorElement.getAttribute("dictionary");
+ if (operatorElement != null) {
+ exponentOperator = operatorElement.getNodeName();
+ if (operatorElement.hasAttribute("value"))
+ exponentDefaultValue = Type.I32.getValue(operatorElement.getAttribute("value"));
+ if (operatorElement.hasAttribute("ns"))
+ exponentNamespace = operatorElement.getAttribute("ns");
+ if (operatorElement.hasAttribute("key"))
+ exponentKey = new QName(operatorElement.getAttribute("key"), exponentNamespace);
+ if (operatorElement.hasAttribute("dictionary"))
+ exponentDictionary = operatorElement.getAttribute("dictionary");
+ }
}
ComposedScalar scalar = Util.composedDecimal(name, Operator.getOperator(exponentOperator), exponentDefaultValue, Operator
.getOperator(mantissaOperator), mantissaDefaultValue, optional);
Modified: branches/generics-cleanup/src/test/java/org/openfast/template/loader/ComposedDecimalParserTest.java
===================================================================
--- branches/generics-cleanup/src/test/java/org/openfast/template/loader/ComposedDecimalParserTest.java 2012-05-14 12:29:26 UTC (rev 296)
+++ branches/generics-cleanup/src/test/java/org/openfast/template/loader/ComposedDecimalParserTest.java 2012-07-31 14:40:16 UTC (rev 297)
@@ -12,45 +12,67 @@
public class ComposedDecimalParserTest extends OpenFastTestCase {
- private FieldParser parser;
- private ParsingContext context;
+ private FieldParser parser;
+ private ParsingContext context;
- protected void setUp() throws Exception {
- parser = new ComposedDecimalParser();
- context = XMLMessageTemplateLoader.createInitialContext();
- }
-
- public void testParse() throws Exception {
- Element decimalDef = document("<decimal name=\"composed\"><mantissa><delta/></mantissa><exponent><constant value=\"-2\"/></exponent></decimal>").getDocumentElement();
- assertTrue(parser.canParse(decimalDef, context));
- ComposedScalar decimal = (ComposedScalar) parser.parse(decimalDef, context);
- assertComposedScalarField(decimal, Type.DECIMAL, "composed", Operator.CONSTANT, new IntegerValue(-2), Operator.DELTA, ScalarValue.UNDEFINED);
- }
+ protected void setUp() throws Exception {
+ parser = new ComposedDecimalParser();
+ context = XMLMessageTemplateLoader.createInitialContext();
+ }
- public void testInheritDictionary() throws Exception {
- Element decimalDef = document("<decimal name=\"composed\"><mantissa><delta/></mantissa><exponent><constant value=\"-2\"/></exponent></decimal>").getDocumentElement();
- context.setDictionary("template");
- assertTrue(parser.canParse(decimalDef, context));
- ComposedScalar decimal = (ComposedScalar) parser.parse(decimalDef, context);
- assertComposedScalarField(decimal, Type.DECIMAL, "composed", Operator.CONSTANT, new IntegerValue(-2), Operator.DELTA, ScalarValue.UNDEFINED);
- assertEquals("template", decimal.getFields()[0].getDictionary());
- assertEquals("template", decimal.getFields()[1].getDictionary());
- }
-
- public void testFullyDefinedOperators() throws Exception {
- Element decimalDef = document("<decimal name=\"composed\"><mantissa><delta dictionary=\"template\" key=\"variable\" value=\"100\"/></mantissa><exponent><copy dictionary=\"template\" key=\"static\" value=\"-2\"/></exponent></decimal>").getDocumentElement();
- assertTrue(parser.canParse(decimalDef, context));
- ComposedScalar decimal = (ComposedScalar) parser.parse(decimalDef, context);
+ public void testParse() throws Exception {
+ Element decimalDef = document(
+ "<decimal name=\"composed\"><mantissa><delta/></mantissa><exponent><constant value=\"-2\"/></exponent></decimal>")
+ .getDocumentElement();
+ assertTrue(parser.canParse(decimalDef, context));
+ ComposedScalar decimal = (ComposedScalar) parser.parse(decimalDef, context);
+ assertComposedScalarField(decimal, Type.DECIMAL, "composed", Operator.CONSTANT, new IntegerValue(-2), Operator.DELTA,
+ ScalarValue.UNDEFINED);
+ }
+
+ public void testParseEmptyMantissaAndExponent() throws Exception {
- assertComposedScalarField(decimal, Type.DECIMAL, "composed", Operator.COPY, new IntegerValue(-2), Operator.DELTA, new IntegerValue(100));
-
- Scalar exponent = decimal.getFields()[0];
- Scalar mantissa = decimal.getFields()[1];
-
- assertEquals("template", exponent.getDictionary());
- assertEquals(new QName("static"), exponent.getKey());
-
- assertEquals("template", exponent.getDictionary());
- assertEquals(new QName("variable"), mantissa.getKey());
- }
+ Element decimalDef = document(
+ "<decimal name=\"composed\"><mantissa> </mantissa><exponent> </exponent></decimal>")
+ .getDocumentElement();
+ assertTrue(parser.canParse(decimalDef, context));
+ ComposedScalar decimal = (ComposedScalar) parser.parse(decimalDef, context);
+ assertComposedScalarField(decimal, Type.DECIMAL, "composed", Operator.NONE, ScalarValue.UNDEFINED, Operator.NONE,
+ ScalarValue.UNDEFINED);
+ }
+
+ public void testInheritDictionary() throws Exception {
+ Element decimalDef = document(
+ "<decimal name=\"composed\"><mantissa><delta/></mantissa><exponent><constant value=\"-2\"/></exponent></decimal>")
+ .getDocumentElement();
+ context.setDictionary("template");
+ assertTrue(parser.canParse(decimalDef, context));
+ ComposedScalar decimal = (ComposedScalar) parser.parse(decimalDef, context);
+ assertComposedScalarField(decimal, Type.DECIMAL, "composed", Operator.CONSTANT, new IntegerValue(-2), Operator.DELTA,
+ ScalarValue.UNDEFINED);
+ assertEquals("template", decimal.getFields()[0].getDictionary());
+ assertEquals("template", decimal.getFields()[1].getDictionary());
+ }
+
+ public void testFullyDefinedOperators() throws Exception {
+ Element decimalDef = document(
+ "<decimal name=\"composed\"><mantissa><delta dictionary=\"template\" key=\"variable\" value=\"100\"/></mantissa><exponent><copy dictionary=\"template\" key=\"static\" value=\"-2\"/></exponent></decimal>")
+ .getDocumentElement();
+ assertTrue(parser.canParse(decimalDef, context));
+ ComposedScalar decimal = (ComposedScalar) parser.parse(decimalDef, context);
+
+ assertComposedScalarField(decimal, Type.DECIMAL, "composed", Operator.COPY, new IntegerValue(-2), Operator.DELTA,
+ new IntegerValue(100));
+
+ Scalar[] decimalFields = decimal.getFields();
+ Scalar exponent = decimalFields[0];
+ Scalar mantissa = decimalFields[1];
+
+ String exponentDictionary = exponent.getDictionary();
+ assertEquals("template", exponentDictionary);
+ assertEquals(new QName("static"), exponent.getKey());
+
+ assertEquals("template", exponentDictionary);
+ assertEquals(new QName("variable"), mantissa.getKey());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|