Commit MetaInfo

Revision26b2482eefe5c44c4dad9d10317deebf2d007bd0 (tree)
Time2011-12-08 13:26:59
Authorjwat <jwat@user...>
Commiterjwat

Log Message

Bug fix on XerDecoder and some modifications.
* XerDecoder accepts xml elements include whitespaces.
* Accept SET and SEQUENCE type that has no element.
* HexString accepts String contains space and newline.

Change Summary

Incremental Difference

--- a/jp/bitmeister/asn1/codec/xer/XerDecoder.java
+++ b/jp/bitmeister/asn1/codec/xer/XerDecoder.java
@@ -152,7 +152,9 @@ public class XerDecoder implements ASN1Decoder,
152152 */
153153 @Override
154154 void characters(String characters) {
155- decoder.characters(characters);
155+ if (decoder != null) {
156+ decoder.characters(characters);
157+ }
156158 }
157159
158160 }
@@ -454,8 +456,11 @@ public class XerDecoder implements ASN1Decoder,
454456 * jp.bitmeister.asn1.codec.xer.XerDecoder.XerHandler#initializeData
455457 * (java.lang.String)
456458 */
457- void initializeData(String qName) {
459+ void initializeData(String qName) throws SAXException {
458460 data = ASN1ModuleManager.instantiate(module, qName);
461+ if (data == null) {
462+ throw new SAXException("Unknown data type '" + qName + "'.");
463+ }
459464 }
460465
461466 };
--- a/jp/bitmeister/asn1/type/ConstructiveType.java
+++ b/jp/bitmeister/asn1/type/ConstructiveType.java
@@ -72,13 +72,6 @@ public abstract class ConstructiveType extends StructuredType {
7272 .getSuperclass();
7373 ElementSpecification[] array;
7474 if (parent == SET.class || parent == SEQUENCE.class) {
75- if (elements.isEmpty()) {
76- ASN1IllegalDefinition ex = new ASN1IllegalDefinition();
77- ex.setMessage(
78- "SET and SEQUENCE type shall have at least one element.",
79- null, type, null, null);
80- throw ex;
81- }
8275 Collections.sort(elements);
8376 array = elements.toArray(new ElementSpecification[0]);
8477 if (TypeSpecification.getSpecification(type).tagDefault() == ASN1TagDefault.AUTOMATIC_TAGS) {
--- a/jp/bitmeister/asn1/type/ModuleSpecification.java
+++ b/jp/bitmeister/asn1/type/ModuleSpecification.java
@@ -22,7 +22,6 @@ import static java.lang.reflect.Modifier.STATIC;
2222
2323 import java.util.HashMap;
2424 import java.util.Map;
25-import java.util.Map.Entry;
2625
2726 import jp.bitmeister.asn1.exception.ASN1IllegalDefinition;
2827
@@ -160,10 +159,9 @@ class ModuleSpecification {
160159 if (type != null) {
161160 return ASN1Type.instantiate(type);
162161 }
163- for (Entry<String, Class<? extends ASN1Module>> e : importedModules
164- .entrySet()) {
165- ModuleSpecification spec = ASN1ModuleManager.specification(e
166- .getValue());
162+ for (Class<? extends ASN1Module> clazz : importedModules
163+ .values()) {
164+ ModuleSpecification spec = ASN1ModuleManager.specification(clazz);
167165 ASN1Type data = spec.instantiate(tagClass, tagNumber);
168166 if (data != null) {
169167 return data;
--- a/jp/bitmeister/asn1/value/HexString.java
+++ b/jp/bitmeister/asn1/value/HexString.java
@@ -41,14 +41,20 @@ public class HexString implements StringItem {
4141 * hexadecimal characters.
4242 */
4343 public HexString(String string) {
44- if (!string.matches("[0-9A-Fa-f]*")) {
44+ if (!string.matches("[0-9A-Fa-f \n]*")) {
4545 ASN1IllegalArgument ex = new ASN1IllegalArgument();
4646 ex.setMessage("Invalid string '" + string
4747 + "'. hString must consist of hexadecimal string.", null,
4848 null, null, null);
4949 throw ex;
5050 }
51- this.string = string.trim().toUpperCase();
51+ StringBuilder builder = new StringBuilder();
52+ for (char c: string.toCharArray()) {
53+ if (Character.digit(c, 16) >= 0) {
54+ builder.append(c);
55+ }
56+ }
57+ this.string = builder.toString().trim().toUpperCase();
5258 }
5359
5460 /**
Show on old repository browser