|
From: <jo...@us...> - 2011-04-11 12:40:59
|
Revision: 2458
http://qtitools.svn.sourceforge.net/qtitools/?rev=2458&view=rev
Author: jonhare
Date: 2011-04-11 12:40:53 +0000 (Mon, 11 Apr 2011)
Log Message:
-----------
added custominteractions, fix for and and match
Modified Paths:
--------------
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/AbstractNode.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/And.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/Match.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/item/interaction/CustomInteraction.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/item/interaction/Interaction.java
branches/lifeguide/JQTI/src/test/java/org/qtitools/qti/node/expression/operator/AndAcceptTest.java
Added Paths:
-----------
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/BranchRuleProxy.java
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/AbstractNode.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/AbstractNode.java 2010-10-04 13:22:19 UTC (rev 2457)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/AbstractNode.java 2011-04-11 12:40:53 UTC (rev 2458)
@@ -47,6 +47,7 @@
import org.qtitools.qti.group.NodeGroupList;
import org.qtitools.qti.node.expression.AbstractExpression;
import org.qtitools.qti.node.expression.operator.CustomOperator;
+import org.qtitools.qti.node.item.interaction.CustomInteraction;
import org.qtitools.qti.validation.ValidationResult;
import org.w3c.dom.Node;
@@ -448,6 +449,8 @@
//String c = this.getClass().getName();
if (this.getClassTag().equals(CustomOperator.CLASS_TAG))
JQTISerializer.writeString(dos, "org.qtitools.qti.node.expression.operator.CustomOperator");
+ else if (this.getClassTag().equals(CustomInteraction.CLASS_TAG))
+ JQTISerializer.writeString(dos, "org.qtitools.qti.node.item.interaction.CustomInteraction");
else
JQTISerializer.writeString(dos, this.getClass().getName());
}
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/And.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/And.java 2010-10-04 13:22:19 UTC (rev 2457)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/And.java 2011-04-11 12:40:53 UTC (rev 2458)
@@ -107,8 +107,6 @@
@Override
protected Value evaluateSelf(int depth)
{
- boolean containsNulls = false;
-
for (Expression subExpression : getChildren())
{
if (subExpression instanceof AbstractExpression)
@@ -118,15 +116,10 @@
Value value = subExpression.getValue();
- if (value.isNull())
- containsNulls = true;
- else if (!((BooleanValue) value).booleanValue())
+ if (value.isNull() || !((BooleanValue) value).booleanValue())
return new BooleanValue(false);
}
- if (containsNulls)
- return new NullValue();
-
return new BooleanValue(true);
}
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/Match.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/Match.java 2010-10-04 13:22:19 UTC (rev 2457)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/Match.java 2011-04-11 12:40:53 UTC (rev 2458)
@@ -46,6 +46,7 @@
import org.qtitools.qti.value.BooleanValue;
import org.qtitools.qti.value.Cardinality;
import org.qtitools.qti.value.NullValue;
+import org.qtitools.qti.value.NumberValue;
import org.qtitools.qti.value.Value;
/**
@@ -127,8 +128,15 @@
Value firstValue = getFirstChild().getValue();
Value secondValue = getSecondChild().getValue();
-
- return new BooleanValue(firstValue.equals(secondValue));
+
+ if (firstValue instanceof NumberValue && secondValue instanceof NumberValue)
+ {
+ return new BooleanValue(((NumberValue) getFirstChild().getValue()).doubleValue() == ((NumberValue) getSecondChild().getValue()).doubleValue());
+ }
+ else
+ {
+ return new BooleanValue(firstValue.equals(secondValue));
+ }
}
@Override
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/item/interaction/CustomInteraction.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/item/interaction/CustomInteraction.java 2010-10-04 13:22:19 UTC (rev 2457)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/item/interaction/CustomInteraction.java 2011-04-11 12:40:53 UTC (rev 2458)
@@ -93,7 +93,6 @@
interaction = (Interaction) constructor.newInstance(this.getParent()); //point the interactions' parent at our parent
//TODO: custom interactions that have children are not yet supported!
-
for (Attribute attribute : getAttributes()) {
Attribute interAttribute = null;
try {
@@ -112,28 +111,65 @@
}
}
- getAttributes().clear();
+ /*getAttributes().clear();
for (Attribute attribute : interaction.getAttributes())
+ {
+ //if (attribute.valueToString().equals("")) continue;
getAttributes().add(attribute);
+ }
+ System.out.println("Loaded " + getClassAttr() + " :: " + getAttributes().size() + " attribtues");
+ System.out.println( " " + getAttributes());*/
}
@Override
public void beforeProcessResponse() {
+ if (interaction == null)
+ {
+ try {
+ loadInteraction();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
interaction.beforeProcessResponse();
}
@Override
public ResponseDeclaration getResponseDeclaration() {
+ if (interaction == null)
+ {
+ try {
+ loadInteraction();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
return interaction.getResponseDeclaration();
}
@Override
public String getResponseIdentifier() {
+ if (interaction == null)
+ {
+ try {
+ loadInteraction();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
return interaction.getResponseIdentifier();
}
@Override
public List<String> getShuffledOrder() {
+ if (interaction == null)
+ {
+ try {
+ loadInteraction();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
return interaction.getShuffledOrder();
}
@@ -149,16 +185,40 @@
@Override
public void processResponse(List<String> responseList) {
+ if (interaction == null)
+ {
+ try {
+ loadInteraction();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
interaction.processResponse(responseList);
}
@Override
public void processResponse(String responseString) {
+ if (interaction == null)
+ {
+ try {
+ loadInteraction();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
interaction.processResponse(responseString);
}
@Override
public void setResponseIdentifier(String responseIdentifier) {
+ if (interaction == null)
+ {
+ try {
+ loadInteraction();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
interaction.setResponseIdentifier(responseIdentifier);
}
@@ -184,19 +244,42 @@
return result;
}
+
+ @Override
+ public String toXmlString(int depth, boolean printDefaultAttributes) {
+ // TODO Auto-generated method stub
+ if (interaction == null)
+ {
+ try {
+ loadInteraction();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "";
+ }
+ }
+ return interaction.toXmlString(depth, printDefaultAttributes);
+ }
@Override
public boolean validateResponse() {
+ if (interaction == null)
+ {
+ try {
+ loadInteraction();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
return interaction.validateResponse();
}
@Override
protected void writeInstanceVars(DataOutputStream dos) {
- this.interaction.writeBinary(dos);
+ //this.interaction.writeBinary(dos);
}
@Override
protected void readInstanceVars(DataInputStream dis) {
- this.interaction = (Interaction) AbstractNode.readBinary(dis, this);
+ //this.interaction = (Interaction) AbstractNode.readBinary(dis, this);
}
}
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/item/interaction/Interaction.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/item/interaction/Interaction.java 2010-10-04 13:22:19 UTC (rev 2457)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/item/interaction/Interaction.java 2011-04-11 12:40:53 UTC (rev 2458)
@@ -48,6 +48,7 @@
import org.qtitools.qti.value.FloatValue;
import org.qtitools.qti.value.IntegerValue;
import org.qtitools.qti.value.MultipleValue;
+import org.qtitools.qti.value.NullValue;
import org.qtitools.qti.value.OrderedValue;
import org.qtitools.qti.value.SingleValue;
import org.qtitools.qti.value.Value;
@@ -190,13 +191,13 @@
protected Value processResponse(List<String> responseList, ResponseDeclaration responseDeclaration) {
Value value = null;
-
if (responseDeclaration.getCardinality() == Cardinality.SINGLE) {
if (responseList == null || responseList.size() == 0 || responseList.get(0).length() == 0) {
+ //In LifeGuide, we'll let numeric interactions return null, so that responses can be forced
if (responseDeclaration.getBaseType().isFloat()) {
- value = new FloatValue(0);
+ value = new NullValue();//FloatValue(0);
} else if (responseDeclaration.getBaseType().isInteger()) {
- value = new IntegerValue(0);
+ value = new NullValue();//IntegerValue(0);
}
} else {
value = responseDeclaration.getBaseType().parseSingleValue(responseList.get(0));
Added: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/BranchRuleProxy.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/BranchRuleProxy.java (rev 0)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/BranchRuleProxy.java 2011-04-11 12:40:53 UTC (rev 2458)
@@ -0,0 +1,41 @@
+package org.qtitools.qti.node.test;
+
+import org.qtitools.qti.attribute.AttributeList;
+import org.qtitools.qti.group.NodeGroupList;
+import org.qtitools.qti.node.AbstractNode;
+
+public class BranchRuleProxy extends BranchRule {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private int index;
+ private boolean loaded = false;
+ private AssessmentItemRef realParent = null;
+
+ public BranchRuleProxy(int index, AssessmentItemRef parent) {
+ super(parent);
+ this.index = index;
+ this.loaded=true;
+ this.realParent = parent;
+ }
+ private BranchRule loadBranchRule()
+ {
+ //System.out.println(this.getParent().getBranchRules());
+ return realParent.getBranchRules().get(index);
+ }
+
+ public AttributeList getAttributes()
+ {
+ if (!loaded) return super.getAttributes();
+ return this.loadBranchRule().getAttributes();
+ }
+
+ public NodeGroupList getNodeGroups()
+ {
+ if (!loaded) return super.getNodeGroups();
+ return this.loadBranchRule().getNodeGroups();
+ }
+
+}
Modified: branches/lifeguide/JQTI/src/test/java/org/qtitools/qti/node/expression/operator/AndAcceptTest.java
===================================================================
--- branches/lifeguide/JQTI/src/test/java/org/qtitools/qti/node/expression/operator/AndAcceptTest.java 2010-10-04 13:22:19 UTC (rev 2457)
+++ branches/lifeguide/JQTI/src/test/java/org/qtitools/qti/node/expression/operator/AndAcceptTest.java 2011-04-11 12:40:53 UTC (rev 2458)
@@ -62,15 +62,16 @@
{
return Arrays.asList(new Object[][]
{
- // null
+ // null
+ // For LifeGuide, changed it so ands should return false.
{"<and>" +
"<null/>" +
- "</and>", null},
+ "</and>", false},
{"<and>" +
"<baseValue baseType='boolean'>true</baseValue>" +
"<null/>" +
"<baseValue baseType='boolean'>true</baseValue>" +
- "</and>", null},
+ "</and>", false},
// false
{"<and>" +
"<baseValue baseType='boolean'>false</baseValue>" +
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|