diff options
author | Mili Verma <mili.verma@isode.com> | 2012-01-10 15:55:29 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-01-11 13:44:37 (GMT) |
commit | be94e872d9423501c688c84c6cb945a420a5cb18 (patch) | |
tree | 77986e9e30282b526c0246bb6344c175b54ffb5f /src/com/isode/stroke/parser | |
parent | c9ff80a46b13b7d1987bf54cae87738a9baf552b (diff) | |
download | stroke-be94e872d9423501c688c84c6cb945a420a5cb18.zip stroke-be94e872d9423501c688c84c6cb945a420a5cb18.tar.bz2 |
Update review comment related stuff
This patch addresses some review comments:
1. Updates the Javadoc.
2. Disallows arguments from being null - throws NullPointerException.
3. Updates each test to use its own DummyEventLoop.
Test-information:
Unit tests pass.
Diffstat (limited to 'src/com/isode/stroke/parser')
3 files changed, 71 insertions, 10 deletions
diff --git a/src/com/isode/stroke/parser/payloadparsers/CommandParser.java b/src/com/isode/stroke/parser/payloadparsers/CommandParser.java index b94acfb..bb7fe27 100644 --- a/src/com/isode/stroke/parser/payloadparsers/CommandParser.java +++ b/src/com/isode/stroke/parser/payloadparsers/CommandParser.java @@ -33,7 +33,7 @@ public class CommandParser extends GenericPayloadParser<Command> { private Type noteType_; private FormParserFactory formParserFactory_; private FormParser formParser_; - private String currentText_; + private String currentText_ = ""; /** * Constructor @@ -51,7 +51,17 @@ public class CommandParser extends GenericPayloadParser<Command> { } public void handleStartElement(String element, String ns, - AttributeMap attributes) { + final AttributeMap attributes) { + if (element == null) { + throw new NullPointerException("'element' must not be null"); + } + if (ns == null) { + throw new NullPointerException("'ns' must not be null"); + } + if (attributes == null) { + throw new NullPointerException("'attributes' must not be null"); + } + ++level_; Command command = getPayloadInternal(); @@ -95,6 +105,13 @@ public class CommandParser extends GenericPayloadParser<Command> { } public void handleEndElement(String element, String ns) { + if (element == null) { + throw new NullPointerException("'element' must not be null"); + } + if (ns == null) { + throw new NullPointerException("'ns' must not be null"); + } + if (formParser_ != null) { formParser_.handleEndElement(element, ns); } @@ -122,6 +139,10 @@ public class CommandParser extends GenericPayloadParser<Command> { } public void handleCharacterData(String data) { + if (data == null) { + throw new NullPointerException("'data' must not be null"); + } + if (formParser_ != null) { formParser_.handleCharacterData(data); } else { @@ -130,6 +151,10 @@ public class CommandParser extends GenericPayloadParser<Command> { } private static Action parseAction(String action) { + if (action == null) { + throw new NullPointerException("'action' must not be null"); + } + return Action.getAction(action); } diff --git a/src/com/isode/stroke/parser/payloadparsers/FormParser.java b/src/com/isode/stroke/parser/payloadparsers/FormParser.java index 2ca50c1..0b72e6b 100644 --- a/src/com/isode/stroke/parser/payloadparsers/FormParser.java +++ b/src/com/isode/stroke/parser/payloadparsers/FormParser.java @@ -38,6 +38,10 @@ public class FormParser extends GenericPayloadParser<Form> { protected GenericFormField<T> field; public void addValue(String s) { + if (s == null) { + throw new NullPointerException("'s' must not be null"); + } + field.addRawValue(s); } @@ -48,47 +52,47 @@ public class FormParser extends GenericPayloadParser<Form> { private static class BoolFieldParseHelper extends FieldParseHelper<Boolean> { public void addValue(String s) { - field.setValue(((s.equals("1")) || (s.equals("true")))); super.addValue(s); + field.setValue(((s.equals("1")) || (s.equals("true")))); } } private static class StringFieldParseHelper extends FieldParseHelper<String> { public void addValue(String s) { + super.addValue(s); if (field.getValue().isEmpty()) { field.setValue(s); } else { field.setValue(field.getValue() + "\n" + s); } - super.addValue(s); } }; private static class JIDFieldParseHelper extends FieldParseHelper<JID> { public void addValue(String s) { - field.setValue(new JID(s)); super.addValue(s); + field.setValue(new JID(s)); } }; private static class StringListFieldParseHelper extends FieldParseHelper<List<String>> { public void addValue(String s) { + super.addValue(s); List<String> l = field.getValue(); l.add(s); field.setValue(l); - super.addValue(s); } }; private static class JIDListFieldParseHelper extends FieldParseHelper<List<JID>> { public void addValue(String s) { + super.addValue(s); List<JID> l = field.getValue(); l.add(new JID(s)); field.setValue(l); - super.addValue(s); } }; @@ -208,7 +212,7 @@ public class FormParser extends GenericPayloadParser<Form> { private int level_; private String currentText_ = ""; - private String currentOptionLabel_; + private String currentOptionLabel_ = ""; private FieldParseHelper<?> currentFieldParseHelper_ = null; /** @@ -221,7 +225,17 @@ public class FormParser extends GenericPayloadParser<Form> { } public void handleStartElement(String element, String ns, - AttributeMap attributes) { + final AttributeMap attributes) { + if (element == null) { + throw new NullPointerException("'element' must not be null"); + } + if (ns == null) { + throw new NullPointerException("'ns' must not be null"); + } + if (attributes == null) { + throw new NullPointerException("'attributes' must not be null"); + } + Form form = getPayloadInternal(); if (level_ == TopLevel) { @@ -296,6 +310,13 @@ public class FormParser extends GenericPayloadParser<Form> { } public void handleEndElement(String element, String ns) { + if (element == null) { + throw new NullPointerException("'element' must not be null"); + } + if (ns == null) { + throw new NullPointerException("'ns' must not be null"); + } + --level_; Form form = getPayloadInternal(); @@ -337,6 +358,10 @@ public class FormParser extends GenericPayloadParser<Form> { } public void handleCharacterData(String text) { + if (text == null) { + throw new NullPointerException("'text' must not be null"); + } + currentText_ += text; } diff --git a/src/com/isode/stroke/parser/payloadparsers/FormParserFactory.java b/src/com/isode/stroke/parser/payloadparsers/FormParserFactory.java index 228c093..0287cca 100644 --- a/src/com/isode/stroke/parser/payloadparsers/FormParserFactory.java +++ b/src/com/isode/stroke/parser/payloadparsers/FormParserFactory.java @@ -24,7 +24,18 @@ public class FormParserFactory implements PayloadParserFactory { public FormParserFactory() { } - public boolean canParse(String element, String ns, AttributeMap attributes) { + public boolean canParse(String element, String ns, + final AttributeMap attributes) { + if (element == null) { + throw new NullPointerException("'element' must not be null"); + } + if (ns == null) { + throw new NullPointerException("'ns' must not be null"); + } + if (attributes == null) { + throw new NullPointerException("'attributes' must not be null"); + } + return ns.equals("jabber:x:data"); } |