OSDN Git Service

* If automatic tagging is not used, value parameter of @ASN1Alternative for CHICE...
authorjwat <jwat@users.sourceforge.jp>
Wed, 22 Aug 2012 09:52:50 +0000 (18:52 +0900)
committerjwat <jwat@users.sourceforge.jp>
Wed, 22 Aug 2012 09:52:50 +0000 (18:52 +0900)
* Fix typo in EXTERNAL type definition ('arbitary' -> 'arbitrary').
* Modify comments in some file.

23 files changed:
jp/bitmeister/asn1/annotation/ASN1Alternative.java
jp/bitmeister/asn1/annotation/ASN1BuiltIn.java
jp/bitmeister/asn1/annotation/ASN1Element.java
jp/bitmeister/asn1/annotation/ASN1Identifier.java
jp/bitmeister/asn1/annotation/ASN1ModuleTags.java
jp/bitmeister/asn1/annotation/ASN1Tag.java
jp/bitmeister/asn1/codec/ber/BerDecoder.java
jp/bitmeister/asn1/codec/ber/BerEncoder.java
jp/bitmeister/asn1/codec/ber/DerEncoder.java
jp/bitmeister/asn1/codec/xer/XerDecoder.java
jp/bitmeister/asn1/codec/xer/XerEncoder.java
jp/bitmeister/asn1/sample/FrightStatus.java
jp/bitmeister/asn1/sample/FrightStatusMain.java
jp/bitmeister/asn1/sample/FrightStatusTypes.java
jp/bitmeister/asn1/type/ASN1TagValue.java
jp/bitmeister/asn1/type/ASN1Type.java
jp/bitmeister/asn1/type/BuiltInModule.java
jp/bitmeister/asn1/type/ConstructiveType.java
jp/bitmeister/asn1/type/NamedTypeSpecification.java
jp/bitmeister/asn1/type/PrimitiveType.java
jp/bitmeister/asn1/type/builtin/BIT_STRING.java
jp/bitmeister/asn1/type/useful/EXTERNAL.java
jp/bitmeister/asn1/value/BinString.java

index 0438960..6878bce 100644 (file)
@@ -28,12 +28,13 @@ import jp.bitmeister.asn1.type.builtin.CHOICE;
  * 
  * <p>
  * If an {@code @ASN1Alternative} annotation is present on a field, the field is
- * treated as an alternative of a sub-class of {@code SelectiveType}. A field
- * annotated as {@code @ASN1Alternative} must be declared as {@code public}
- * non-{@code final} non-{@code static}, and the type shall be a sub-class of
- * {@code ASN1Type}. The {@code value} parameter represents an order of
- * appearance of a field in an ASN.1 type definition and is used for automatic
- * tagging.
+ * treated as an alternative element of a sub-class of {@code SelectiveType}. A
+ * field annotated as {@code @ASN1Alternative} must be declared as
+ * {@code public} non- {@code final} non-{@code static}, and the type shall be a
+ * sub-class of {@code ASN1Type}. The {@code value} parameter represents an
+ * order of appearance of a field in an ASN.1 type definition and is used for
+ * automatic tagging. If automatic tagging is not used, {@code value} parameter
+ * can be omitted.
  * </p>
  * <p>
  * For example, following ASN.1 definition :
@@ -72,6 +73,6 @@ public @interface ASN1Alternative {
         * 
         * @return Order of this element.
         */
-       public int value() default 0;
+       public int value() default -1;
 
 }
index 825aa14..d66495c 100644 (file)
@@ -34,5 +34,4 @@ import java.lang.annotation.Target;
 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.RUNTIME)
 public @interface ASN1BuiltIn {
-
 }
index c7d6de4..1ed49c8 100644 (file)
@@ -31,9 +31,10 @@ import jp.bitmeister.asn1.type.ConstructiveType;
  * {@code @ASN1Element} must be declared as {@code public} non-{@code final}
  * non-{@code static}, and the type shall be a sub-class of {@code ASN1Type}.
  * The {@code value} parameter represents an order of appearance of a field in
- * an ASN.1 type definition. The {@code value} parameter must be set even if a
- * container type is a {@code SET} type. It will be used by the automatic
- * tagging process.
+ * an ASN.1 type definition. If automatic tagging is used, the {@code value}
+ * parameter must be set even if a container type is a {@code SET} type.
+ * Otherwise, the {@code value} parameter for element of {@code SET} type can be
+ * omitted.
  * </p>
  * <p>
  * For example, following ASN.1 definition :
@@ -73,17 +74,19 @@ public @interface ASN1Element {
         * 
         * @return Order of this element.
         */
-       public int value();
+       public int value() default -1;
 
        /**
-        * Indicates that the element is optional or not.
+        * Indicates that the element is optional or not. The default value of
+        * {@code optional} is {@code false}.
         * 
         * @return {@code true} if the element is optional.
         */
        public boolean optional() default false;
 
        /**
-        * Indicates that the element has default value or not.
+        * Indicates that the element has default value or not. The default value of
+        * {@code hasDefault} is {@code false}.
         * 
         * @return {@code true} if the element has default value.
         */
index a2f9ce4..4f91ccd 100644 (file)
@@ -34,7 +34,7 @@ import java.lang.annotation.Target;
  * For example, following ASN.1 definition :
  * 
  * <pre>
- * Signed-Number ::= SEQUENCE {        -- '-' can't be used for identifier.
+ * Signed-Number ::= SEQUENCE {        -- '-' can't be used for Java identifier.
  *     int INTEGER             -- 'int' is a reserved word.
  * }
  * </pre>
index fb07d52..a32f926 100644 (file)
@@ -33,13 +33,15 @@ import jp.bitmeister.asn1.type.ASN1TagDefault;
  * @author WATANABE, Jun. <jwat at bitmeister.jp>
  * 
  * @see ASN1Module
+ * @see ASN1TagDefault
  */
 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.RUNTIME)
 public @interface ASN1ModuleTags {
 
        /**
-        * Indicates 'TagDefault' specification.
+        * Indicates 'TagDefault' specification. The default value of {@code value}
+        * is {@code ASN1TagDefault.EXPLICIT_TAGS}.
         * 
         * @return The default tagging mode.
         */
index 20ee32a..f36fed9 100644 (file)
@@ -73,14 +73,16 @@ public @interface ASN1Tag {
        public int value();
 
        /**
-        * Indicates tag class of this tag.
+        * Indicates tag class of this tag. The default value of {@code tagClass} is
+        * {@code ASN1TagClass.CONTEXT_SPECIFIC}.
         * 
         * @return Tag class.
         */
        public ASN1TagClass tagClass() default ASN1TagClass.CONTEXT_SPECIFIC;
 
        /**
-        * Indicates the tagging mode of this tag.
+        * Indicates the tagging mode of this tag. The default value of
+        * {@code tagMode} is {@code ASN1TagMode.DEFAULT}.
         * 
         * @return The tagging mode.
         */
index 25c5ae8..567e8a9 100644 (file)
@@ -61,7 +61,7 @@ import jp.bitmeister.asn1.type.builtin.SET_OF;
  * <p>
  * {@code BerDecoder} is an implementation of {@code ASN1Decoder}. It reads a
  * number of bytes from an {@code InputStream} that is specified when a decoder
- * is instantiated, and decodes them to an ASN.1 data with Basic Encoding Rules
+ * is instantiated, and decodes them to an ASN.1 data using Basic Encoding Rules
  * (BER).
  * </p>
  * 
@@ -591,7 +591,7 @@ public class BerDecoder implements ASN1Decoder,
 
                        public void process() throws ASN1DecodingException {
                                @SuppressWarnings("unchecked")
-                               T component = (T) ASN1Type.instantiate(data.getClass());
+                               T component =  (T) ASN1Type.instantiate(data.getClass());
                                data.concatenate(decodeImpl(component));
                        }
 
index 9bb84c4..e3e3186 100644 (file)
@@ -56,7 +56,7 @@ import jp.bitmeister.asn1.type.builtin.SET_OF;
  * 
  * <p>
  * {@code BerEncoder} is an implementation of {@code ASN1Encoder}. It encodes an
- * ASN.1 data to an array of {@code byte} with Basic Encoding Rules(BER) and
+ * ASN.1 data to an array of {@code byte} using Basic Encoding Rules(BER) and
  * writes the result to {@code OutputStream} that is specified when the encoder
  * was instantiated. BER encoding process is light-weight compared with
  * Distinguished Encoding Rules (DER) encoding because some restrictions on DER
index 2f2b5e1..49818aa 100644 (file)
@@ -44,15 +44,16 @@ import jp.bitmeister.asn1.type.useful.UTCTime;
  * 
  * <p>
  * {@code DerEncoder} is an implementation of {@code ASN1Encoder}. It encodes an
- * ASN.1 data to an array of {@code byte} with Distinguished Encoding Rules(DER) and
- * writes the result to {@code OutputStream} that is specified when the encoder
- * was instantiated.
+ * ASN.1 data to an array of {@code byte} using Distinguished Encoding
+ * Rules(DER) and writes the result to {@code OutputStream} that is specified
+ * when the encoder was instantiated.
  * </p>
  * <p>
  * DER applies some restrictions on Basic Encoding Rules(BER). The result octets
  * can be decoded by any BER decoder because DER is a sub-set of BER and
  * compatible with it.
  * </p>
+ * 
  * @author WATANABE, Jun. <jwat at bitmeister.jp>
  * 
  * @see ASN1Encoder
index cc0c88e..4991e50 100644 (file)
@@ -69,7 +69,7 @@ import org.xml.sax.helpers.XMLReaderFactory;
  * <p>
  * {@code XerDecoder} is an implementation of {@code ASN1Decoder}. It reads a
  * number of bytes from an {@code InputStream} that is specified when a decoder
- * is instantiated, and decodes them to an ASN.1 data with XML Encoding Rules
+ * is instantiated, and decodes them to an ASN.1 data using XML Encoding Rules
  * (XER).
  * </p>
  * 
index 0a4a41f..19ca50e 100644 (file)
@@ -65,7 +65,7 @@ import jp.bitmeister.asn1.value.HexString;
  * 
  * <p>
  * {@code XerEncoder} is an implementation of {@code ASN1Encoder}. It encodes an
- * ASN.1 data to an XML document with XML Encoding Rules(XER) and writes the
+ * ASN.1 data to an XML document using XML Encoding Rules(XER) and writes the
  * result to {@code OutputStream} that is specified when the encoder was
  * instantiated. XER encoding process is light-weight compared with Canonical
  * XML Encoding Rules (CXER) encoding because some restrictions on CXER are not
index 0ccd75e..27ddae7 100644 (file)
@@ -41,9 +41,8 @@ public class FrightStatus extends SEQUENCE {
        @ASN1Tag(value = 1, tagMode = ASN1TagMode.IMPLICIT)
        public Information arrival;
        
-       @ASN1Element(value = 3, hasDefault = true)
-       @ASN1Tag(2)
-       public Status status = new Status(ASN1TagClass.CONTEXT_SPECIFIC, 0, new NULL());
+       @ASN1Element(value = 3,hasDefault = true)
+       public Status status = new Status(new NULL());
        
        public FrightStatus() {}
 
index 1ce192c..9c3d557 100644 (file)
@@ -30,7 +30,6 @@ import jp.bitmeister.asn1.sample.FrightStatusTypes.AllFrights;
 import jp.bitmeister.asn1.sample.FrightStatusTypes.FrightNumber;
 import jp.bitmeister.asn1.sample.FrightStatusTypes.Information;
 import jp.bitmeister.asn1.sample.FrightStatusTypes.Status;
-import jp.bitmeister.asn1.type.ASN1TagClass;
 import jp.bitmeister.asn1.type.ASN1Type;
 import jp.bitmeister.asn1.type.builtin.INTEGER;
 import jp.bitmeister.asn1.type.useful.UTCTime;
@@ -66,7 +65,7 @@ public class FrightStatusMain {
                                                                new UTCTime("110627093000"),
                                                                null
                                                ),
-                                               new Status(ASN1TagClass.CONTEXT_SPECIFIC, 1, new INTEGER(10))
+                                               new Status(new INTEGER(10))
                                                )
                                );
 
index 5237550..4faf044 100644 (file)
@@ -89,7 +89,7 @@ public class FrightStatusTypes extends ASN1Module {
 
        public static class Information extends AbstractSequence {
 
-               @ASN1Element(value = 0)
+               @ASN1Element(0)
                public Airport airport;
 
                @ASN1Element(1)
index 65c66d9..c97deec 100644 (file)
@@ -72,7 +72,7 @@ public class ASN1TagValue {
                                && tag.tagClass() != ASN1TagClass.PRIVATE) {
                        ASN1IllegalDefinition ex = new ASN1IllegalDefinition();
                        ex.setMessage(
-                                       "Only context-specific or private tagging is allowed to an elements of structured type.",
+                                       "Only context-specific or private tagging is allowed to elements of structured type.",
                                        null, namedType.enclosingType(), namedType.identifier(),
                                        null);
                        throw ex;
index ffb3dbe..3d45ecc 100644 (file)
@@ -72,7 +72,7 @@ public abstract class ASN1Type implements Cloneable {
                        throw ex;
                } catch (IllegalAccessException e) {
                        ASN1RuntimeException ex = new ASN1IllegalDefinition();
-                       ex.setMessage("Default constructor might be not accessable.", e,
+                       ex.setMessage("Default constructor might be not accessible.", e,
                                        type, null, null);
                        throw ex;
                }
@@ -143,7 +143,7 @@ public abstract class ASN1Type implements Cloneable {
         *            The visitor.
         * @return Result.
         * @throws E 
-        *             When an error occured in the {@code visit} method of the
+        *             When an error occurred in the {@code visit} method of the
         *             visitor.
         */
        public abstract <R, E extends Throwable> R accept(ASN1Visitor<R, E> visitor)
index 74e6418..dfdebfd 100644 (file)
@@ -87,7 +87,7 @@ import jp.bitmeister.asn1.type.useful.VisibleString;
                GeneralizedTime.class,   // UNIVERSAL 24
                GraphicString.class,     // UNIVERSAL 25
                VisibleString.class,     // UNIVERSAL 26
-               GeneralString.class,     // UNIVERSAL27
+               GeneralString.class,     // UNIVERSAL 27
                UniversalString.class,   // UNIVERSAL 28
                CHARACTER_STRING.class,  // UNIVERSAL 29
                BMPString.class          // UNIVERSAL 30
index 3320ae4..0194751 100644 (file)
@@ -61,14 +61,21 @@ public abstract class ConstructiveType extends StructuredType {
                if (ELEMENTS_MAP.containsKey(type)) {
                        return ELEMENTS_MAP.get(type);
                }
+               Class<? extends ConstructiveType> parent = type.getSuperclass().asSubclass(ConstructiveType.class);
                List<ElementSpecification> elements = new ArrayList<ElementSpecification>();
                for (Field f : type.getDeclaredFields()) {
                        if (f.isAnnotationPresent(ASN1Element.class)) {
-                               elements.add(new ElementSpecification(f
-                                               .getAnnotation(ASN1Element.class), f));
+                               ASN1Element element = f.getAnnotation(ASN1Element.class);
+                               if (element.value() < 0 && SEQUENCE.class.isAssignableFrom(type)) {
+                                       ASN1IllegalDefinition ex = new ASN1IllegalDefinition();
+                                       ex.setMessage(
+                                                       "Order of appearance of fields of a SEQUENCE type must be defined by @ASN1Element annotation.",
+                                                       null, type, f.getName(), null);
+                                       throw ex;
+                               }
+                               elements.add(new ElementSpecification(element, f));
                        }
                }
-               Class<? extends ConstructiveType> parent = type.getSuperclass().asSubclass(ConstructiveType.class);
                ElementSpecification[] array;
                if (parent == SET.class || parent == SEQUENCE.class
                                || parent.isAnnotationPresent(ASN1Extendable.class)) {
@@ -77,7 +84,7 @@ public abstract class ConstructiveType extends StructuredType {
                        if (TypeSpecification.getSpecification(type).tagDefault() == ASN1TagDefault.AUTOMATIC_TAGS) {
                                generateAutomaticTags(array);
                        }
-                       if (parent == SET.class) {
+                       if (SET.class.isAssignableFrom(type)) {
                                new UnorderedElementsChecker(type).check(array);
                        } else {
                                new OrderedElementsChecker(type).check(array);
index 77b3754..0f81215 100644 (file)
@@ -198,6 +198,14 @@ public class NamedTypeSpecification implements
         *            The appearing order of this element in the type definition.
         */
        void generateAutomaticTag(int order) {
+               if (this.order < 0) {
+                       ASN1IllegalDefinition ex = new ASN1IllegalDefinition();
+                       ex.setMessage(
+                                       "Order of appearance of the field must be specified by @ASN1Element"
+                                 + " or @ASN1Alternative annotation for automatic tagging process.",
+                                       null, enclosingType(), identifier, null);
+                       throw ex;                       
+               }
                tag = new ASN1TagValue(order, type());
        }
 
index 87274fd..fde1637 100644 (file)
@@ -20,7 +20,7 @@ package jp.bitmeister.asn1.type;
  * 
  * <p>
  * This class provides common methods and a value field for classes which
- * represents simple, unconstructive ASN.1 types.
+ * represent simple, unconstructive ASN.1 types.
  * </p>
  * 
  * @author WATANABE, Jun. <jwat at bitmeister.jp>
index 348f026..b6fde13 100644 (file)
@@ -208,8 +208,11 @@ public class BIT_STRING extends PrimitiveType<boolean[]> implements
         *            Indexes of bits to be set true.
         */
        public void set(int ...indexes) {
-               Arrays.sort(indexes);
-               expand(indexes[indexes.length - 1]);
+               int max = -1;
+               for (int e: indexes) {
+                       max = Math.max(max, e);
+               }
+               expand(max);
                for (int e: indexes) {
                        value()[e] = true;
                }
@@ -243,8 +246,11 @@ public class BIT_STRING extends PrimitiveType<boolean[]> implements
         *            Indexes of bits to be set false.
         */
        public void unset(int ...indexes) {
-               Arrays.sort(indexes);
-               expand(indexes[indexes.length - 1]);
+               int max = -1;
+               for (int e: indexes) {
+                       max = Math.max(max, e);
+               }
+               expand(max);
                for (int e: indexes) {
                        value()[e] = false;
                }
@@ -296,7 +302,7 @@ public class BIT_STRING extends PrimitiveType<boolean[]> implements
        }
 
        /**
-        * Returns the indentifier of the bit specified by the index number.
+        * Returns the identifier of the bit specified by the index number.
         * 
         * @param index
         *            The index number of a bit.
index 4ac80e1..9bc9b66 100644 (file)
@@ -48,7 +48,7 @@ import jp.bitmeister.asn1.type.builtin.SEQUENCE;
  *   encoding CHOICE {
  *     single-ASN1-type [0] ANY,
  *     octet-aligned    [1] IMPLICIT OCTET STRING,
- *     arbitary         [2] IMPLICIT BIT STRING } }
+ *     arbitrary        [2] IMPLICIT BIT STRING } }
  * </pre>
  * 
  * </p>
@@ -111,11 +111,11 @@ public class EXTERNAL extends SEQUENCE {
                public OCTET_STRING octet_aligned;
 
                /**
-                * 'arbitary' field.
+                * 'arbitrary' field.
                 */
                @ASN1Alternative
                @ASN1Tag(2)
-               public BIT_STRING arbitary;
+               public BIT_STRING arbitrary;
 
                public Encoding() {
                        super();
@@ -128,7 +128,7 @@ public class EXTERNAL extends SEQUENCE {
        }
 
        /**
-        * Instanciate an empty {@code ExternalType}.
+        * Instantiate an empty {@code ExternalType}.
         */
        public EXTERNAL() {
        }
index 7ff0ddf..1dc7264 100644 (file)
@@ -65,7 +65,7 @@ public class BinString implements StringItem {
        /**
         * Returns the string value of this bString.
         * 
-        * @return The hexadecimal string.
+        * @return The binary string that consists of '0's and '1's.
         */
        public String string() {
                return string;