OSDN Git Service

Bug fix on XerDecoder and some modifications.
authorjwat <jwat@users.sourceforge.jp>
Thu, 8 Dec 2011 04:26:59 +0000 (13:26 +0900)
committerjwat <jwat@users.sourceforge.jp>
Thu, 8 Dec 2011 04:26:59 +0000 (13:26 +0900)
* XerDecoder accepts xml elements include whitespaces.
* Accept SET and SEQUENCE type that has no element.
* HexString accepts String contains space and newline.

jp/bitmeister/asn1/codec/xer/XerDecoder.java
jp/bitmeister/asn1/type/ConstructiveType.java
jp/bitmeister/asn1/type/ModuleSpecification.java
jp/bitmeister/asn1/value/HexString.java

index 14260bc..bc287ed 100644 (file)
@@ -152,7 +152,9 @@ public class XerDecoder implements ASN1Decoder,
                 */
                @Override
                void characters(String characters) {
-                       decoder.characters(characters);
+                       if (decoder != null) {
+                               decoder.characters(characters);
+                       }
                }
 
        }
@@ -454,8 +456,11 @@ public class XerDecoder implements ASN1Decoder,
                         * jp.bitmeister.asn1.codec.xer.XerDecoder.XerHandler#initializeData
                         * (java.lang.String)
                         */
-                       void initializeData(String qName) {
+                       void initializeData(String qName) throws SAXException {
                                data = ASN1ModuleManager.instantiate(module, qName);
+                               if (data == null) {
+                                       throw new SAXException("Unknown data type '" + qName + "'.");
+                               }
                        }
 
                };
index cac6eb8..03d8916 100644 (file)
@@ -72,13 +72,6 @@ public abstract class ConstructiveType extends StructuredType {
                                .getSuperclass();
                ElementSpecification[] array;
                if (parent == SET.class || parent == SEQUENCE.class) {
-                       if (elements.isEmpty()) {
-                               ASN1IllegalDefinition ex = new ASN1IllegalDefinition();
-                               ex.setMessage(
-                                               "SET and SEQUENCE type shall have at least one element.",
-                                               null, type, null, null);
-                               throw ex;
-                       }
                        Collections.sort(elements);
                        array = elements.toArray(new ElementSpecification[0]);
                        if (TypeSpecification.getSpecification(type).tagDefault() == ASN1TagDefault.AUTOMATIC_TAGS) {
index 8c6a1e3..a2df100 100644 (file)
@@ -22,7 +22,6 @@ import static java.lang.reflect.Modifier.STATIC;
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Map.Entry;
 
 import jp.bitmeister.asn1.exception.ASN1IllegalDefinition;
 
@@ -160,10 +159,9 @@ class ModuleSpecification {
                if (type != null) {
                        return ASN1Type.instantiate(type);
                }
-               for (Entry<String, Class<? extends ASN1Module>> e : importedModules
-                               .entrySet()) {
-                       ModuleSpecification spec = ASN1ModuleManager.specification(e
-                                       .getValue());
+               for (Class<? extends ASN1Module> clazz : importedModules
+                               .values()) {
+                       ModuleSpecification spec = ASN1ModuleManager.specification(clazz);
                        ASN1Type data = spec.instantiate(tagClass, tagNumber);
                        if (data != null) {
                                return data;
index 17e3351..f93b50f 100644 (file)
@@ -41,14 +41,20 @@ public class HexString implements StringItem {
         *            hexadecimal characters.
         */
        public HexString(String string) {
-               if (!string.matches("[0-9A-Fa-f]*")) {
+               if (!string.matches("[0-9A-Fa-f \n]*")) {
                        ASN1IllegalArgument ex = new ASN1IllegalArgument();
                        ex.setMessage("Invalid string '" + string
                                        + "'. hString must consist of hexadecimal string.", null,
                                        null, null, null);
                        throw ex;
                }
-               this.string = string.trim().toUpperCase();
+               StringBuilder builder = new StringBuilder();
+               for (char c: string.toCharArray()) {
+                       if (Character.digit(c, 16) >= 0) {
+                               builder.append(c);
+                       }
+               }
+               this.string = builder.toString().trim().toUpperCase();
        }
 
        /**