Commit MetaInfo

Revisiona3926ba723236feb6c5af2f31f1785e8b0a94b0d (tree)
Time2012-08-22 18:52:50
Authorjwat <jwat@user...>
Commiterjwat

Log Message

* If automatic tagging is not used, value parameter of @ASN1Alternative for CHICE type and @ASN1Element for SET type can be omitted.
* Fix typo in EXTERNAL type definition ('arbitary' -> 'arbitrary').
* Modify comments in some file.

Change Summary

Incremental Difference

--- a/jp/bitmeister/asn1/annotation/ASN1Alternative.java
+++ b/jp/bitmeister/asn1/annotation/ASN1Alternative.java
@@ -28,12 +28,13 @@ import jp.bitmeister.asn1.type.builtin.CHOICE;
2828 *
2929 * <p>
3030 * If an {@code @ASN1Alternative} annotation is present on a field, the field is
31- * treated as an alternative of a sub-class of {@code SelectiveType}. A field
32- * annotated as {@code @ASN1Alternative} must be declared as {@code public}
33- * non-{@code final} non-{@code static}, and the type shall be a sub-class of
34- * {@code ASN1Type}. The {@code value} parameter represents an order of
35- * appearance of a field in an ASN.1 type definition and is used for automatic
36- * tagging.
31+ * treated as an alternative element of a sub-class of {@code SelectiveType}. A
32+ * field annotated as {@code @ASN1Alternative} must be declared as
33+ * {@code public} non- {@code final} non-{@code static}, and the type shall be a
34+ * sub-class of {@code ASN1Type}. The {@code value} parameter represents an
35+ * order of appearance of a field in an ASN.1 type definition and is used for
36+ * automatic tagging. If automatic tagging is not used, {@code value} parameter
37+ * can be omitted.
3738 * </p>
3839 * <p>
3940 * For example, following ASN.1 definition :
@@ -72,6 +73,6 @@ public @interface ASN1Alternative {
7273 *
7374 * @return Order of this element.
7475 */
75- public int value() default 0;
76+ public int value() default -1;
7677
7778 }
--- a/jp/bitmeister/asn1/annotation/ASN1BuiltIn.java
+++ b/jp/bitmeister/asn1/annotation/ASN1BuiltIn.java
@@ -34,5 +34,4 @@ import java.lang.annotation.Target;
3434 @Target(ElementType.TYPE)
3535 @Retention(RetentionPolicy.RUNTIME)
3636 public @interface ASN1BuiltIn {
37-
3837 }
--- a/jp/bitmeister/asn1/annotation/ASN1Element.java
+++ b/jp/bitmeister/asn1/annotation/ASN1Element.java
@@ -31,9 +31,10 @@ import jp.bitmeister.asn1.type.ConstructiveType;
3131 * {@code @ASN1Element} must be declared as {@code public} non-{@code final}
3232 * non-{@code static}, and the type shall be a sub-class of {@code ASN1Type}.
3333 * The {@code value} parameter represents an order of appearance of a field in
34- * an ASN.1 type definition. The {@code value} parameter must be set even if a
35- * container type is a {@code SET} type. It will be used by the automatic
36- * tagging process.
34+ * an ASN.1 type definition. If automatic tagging is used, the {@code value}
35+ * parameter must be set even if a container type is a {@code SET} type.
36+ * Otherwise, the {@code value} parameter for element of {@code SET} type can be
37+ * omitted.
3738 * </p>
3839 * <p>
3940 * For example, following ASN.1 definition :
@@ -73,17 +74,19 @@ public @interface ASN1Element {
7374 *
7475 * @return Order of this element.
7576 */
76- public int value();
77+ public int value() default -1;
7778
7879 /**
79- * Indicates that the element is optional or not.
80+ * Indicates that the element is optional or not. The default value of
81+ * {@code optional} is {@code false}.
8082 *
8183 * @return {@code true} if the element is optional.
8284 */
8385 public boolean optional() default false;
8486
8587 /**
86- * Indicates that the element has default value or not.
88+ * Indicates that the element has default value or not. The default value of
89+ * {@code hasDefault} is {@code false}.
8790 *
8891 * @return {@code true} if the element has default value.
8992 */
--- a/jp/bitmeister/asn1/annotation/ASN1Identifier.java
+++ b/jp/bitmeister/asn1/annotation/ASN1Identifier.java
@@ -34,7 +34,7 @@ import java.lang.annotation.Target;
3434 * For example, following ASN.1 definition :
3535 *
3636 * <pre>
37- * Signed-Number ::= SEQUENCE { -- '-' can't be used for identifier.
37+ * Signed-Number ::= SEQUENCE { -- '-' can't be used for Java identifier.
3838 * int INTEGER -- 'int' is a reserved word.
3939 * }
4040 * </pre>
--- a/jp/bitmeister/asn1/annotation/ASN1ModuleTags.java
+++ b/jp/bitmeister/asn1/annotation/ASN1ModuleTags.java
@@ -33,13 +33,15 @@ import jp.bitmeister.asn1.type.ASN1TagDefault;
3333 * @author WATANABE, Jun. <jwat at bitmeister.jp>
3434 *
3535 * @see ASN1Module
36+ * @see ASN1TagDefault
3637 */
3738 @Target(ElementType.TYPE)
3839 @Retention(RetentionPolicy.RUNTIME)
3940 public @interface ASN1ModuleTags {
4041
4142 /**
42- * Indicates 'TagDefault' specification.
43+ * Indicates 'TagDefault' specification. The default value of {@code value}
44+ * is {@code ASN1TagDefault.EXPLICIT_TAGS}.
4345 *
4446 * @return The default tagging mode.
4547 */
--- a/jp/bitmeister/asn1/annotation/ASN1Tag.java
+++ b/jp/bitmeister/asn1/annotation/ASN1Tag.java
@@ -73,14 +73,16 @@ public @interface ASN1Tag {
7373 public int value();
7474
7575 /**
76- * Indicates tag class of this tag.
76+ * Indicates tag class of this tag. The default value of {@code tagClass} is
77+ * {@code ASN1TagClass.CONTEXT_SPECIFIC}.
7778 *
7879 * @return Tag class.
7980 */
8081 public ASN1TagClass tagClass() default ASN1TagClass.CONTEXT_SPECIFIC;
8182
8283 /**
83- * Indicates the tagging mode of this tag.
84+ * Indicates the tagging mode of this tag. The default value of
85+ * {@code tagMode} is {@code ASN1TagMode.DEFAULT}.
8486 *
8587 * @return The tagging mode.
8688 */
--- a/jp/bitmeister/asn1/codec/ber/BerDecoder.java
+++ b/jp/bitmeister/asn1/codec/ber/BerDecoder.java
@@ -61,7 +61,7 @@ import jp.bitmeister.asn1.type.builtin.SET_OF;
6161 * <p>
6262 * {@code BerDecoder} is an implementation of {@code ASN1Decoder}. It reads a
6363 * number of bytes from an {@code InputStream} that is specified when a decoder
64- * is instantiated, and decodes them to an ASN.1 data with Basic Encoding Rules
64+ * is instantiated, and decodes them to an ASN.1 data using Basic Encoding Rules
6565 * (BER).
6666 * </p>
6767 *
@@ -591,7 +591,7 @@ public class BerDecoder implements ASN1Decoder,
591591
592592 public void process() throws ASN1DecodingException {
593593 @SuppressWarnings("unchecked")
594- T component = (T) ASN1Type.instantiate(data.getClass());
594+ T component = (T) ASN1Type.instantiate(data.getClass());
595595 data.concatenate(decodeImpl(component));
596596 }
597597
--- a/jp/bitmeister/asn1/codec/ber/BerEncoder.java
+++ b/jp/bitmeister/asn1/codec/ber/BerEncoder.java
@@ -56,7 +56,7 @@ import jp.bitmeister.asn1.type.builtin.SET_OF;
5656 *
5757 * <p>
5858 * {@code BerEncoder} is an implementation of {@code ASN1Encoder}. It encodes an
59- * ASN.1 data to an array of {@code byte} with Basic Encoding Rules(BER) and
59+ * ASN.1 data to an array of {@code byte} using Basic Encoding Rules(BER) and
6060 * writes the result to {@code OutputStream} that is specified when the encoder
6161 * was instantiated. BER encoding process is light-weight compared with
6262 * Distinguished Encoding Rules (DER) encoding because some restrictions on DER
--- a/jp/bitmeister/asn1/codec/ber/DerEncoder.java
+++ b/jp/bitmeister/asn1/codec/ber/DerEncoder.java
@@ -44,15 +44,16 @@ import jp.bitmeister.asn1.type.useful.UTCTime;
4444 *
4545 * <p>
4646 * {@code DerEncoder} is an implementation of {@code ASN1Encoder}. It encodes an
47- * ASN.1 data to an array of {@code byte} with Distinguished Encoding Rules(DER) and
48- * writes the result to {@code OutputStream} that is specified when the encoder
49- * was instantiated.
47+ * ASN.1 data to an array of {@code byte} using Distinguished Encoding
48+ * Rules(DER) and writes the result to {@code OutputStream} that is specified
49+ * when the encoder was instantiated.
5050 * </p>
5151 * <p>
5252 * DER applies some restrictions on Basic Encoding Rules(BER). The result octets
5353 * can be decoded by any BER decoder because DER is a sub-set of BER and
5454 * compatible with it.
5555 * </p>
56+ *
5657 * @author WATANABE, Jun. <jwat at bitmeister.jp>
5758 *
5859 * @see ASN1Encoder
--- a/jp/bitmeister/asn1/codec/xer/XerDecoder.java
+++ b/jp/bitmeister/asn1/codec/xer/XerDecoder.java
@@ -69,7 +69,7 @@ import org.xml.sax.helpers.XMLReaderFactory;
6969 * <p>
7070 * {@code XerDecoder} is an implementation of {@code ASN1Decoder}. It reads a
7171 * number of bytes from an {@code InputStream} that is specified when a decoder
72- * is instantiated, and decodes them to an ASN.1 data with XML Encoding Rules
72+ * is instantiated, and decodes them to an ASN.1 data using XML Encoding Rules
7373 * (XER).
7474 * </p>
7575 *
--- a/jp/bitmeister/asn1/codec/xer/XerEncoder.java
+++ b/jp/bitmeister/asn1/codec/xer/XerEncoder.java
@@ -65,7 +65,7 @@ import jp.bitmeister.asn1.value.HexString;
6565 *
6666 * <p>
6767 * {@code XerEncoder} is an implementation of {@code ASN1Encoder}. It encodes an
68- * ASN.1 data to an XML document with XML Encoding Rules(XER) and writes the
68+ * ASN.1 data to an XML document using XML Encoding Rules(XER) and writes the
6969 * result to {@code OutputStream} that is specified when the encoder was
7070 * instantiated. XER encoding process is light-weight compared with Canonical
7171 * XML Encoding Rules (CXER) encoding because some restrictions on CXER are not
--- a/jp/bitmeister/asn1/sample/FrightStatus.java
+++ b/jp/bitmeister/asn1/sample/FrightStatus.java
@@ -41,9 +41,8 @@ public class FrightStatus extends SEQUENCE {
4141 @ASN1Tag(value = 1, tagMode = ASN1TagMode.IMPLICIT)
4242 public Information arrival;
4343
44- @ASN1Element(value = 3, hasDefault = true)
45- @ASN1Tag(2)
46- public Status status = new Status(ASN1TagClass.CONTEXT_SPECIFIC, 0, new NULL());
44+ @ASN1Element(value = 3,hasDefault = true)
45+ public Status status = new Status(new NULL());
4746
4847 public FrightStatus() {}
4948
--- a/jp/bitmeister/asn1/sample/FrightStatusMain.java
+++ b/jp/bitmeister/asn1/sample/FrightStatusMain.java
@@ -30,7 +30,6 @@ import jp.bitmeister.asn1.sample.FrightStatusTypes.AllFrights;
3030 import jp.bitmeister.asn1.sample.FrightStatusTypes.FrightNumber;
3131 import jp.bitmeister.asn1.sample.FrightStatusTypes.Information;
3232 import jp.bitmeister.asn1.sample.FrightStatusTypes.Status;
33-import jp.bitmeister.asn1.type.ASN1TagClass;
3433 import jp.bitmeister.asn1.type.ASN1Type;
3534 import jp.bitmeister.asn1.type.builtin.INTEGER;
3635 import jp.bitmeister.asn1.type.useful.UTCTime;
@@ -66,7 +65,7 @@ public class FrightStatusMain {
6665 new UTCTime("110627093000"),
6766 null
6867 ),
69- new Status(ASN1TagClass.CONTEXT_SPECIFIC, 1, new INTEGER(10))
68+ new Status(new INTEGER(10))
7069 )
7170 );
7271
--- a/jp/bitmeister/asn1/sample/FrightStatusTypes.java
+++ b/jp/bitmeister/asn1/sample/FrightStatusTypes.java
@@ -89,7 +89,7 @@ public class FrightStatusTypes extends ASN1Module {
8989
9090 public static class Information extends AbstractSequence {
9191
92- @ASN1Element(value = 0)
92+ @ASN1Element(0)
9393 public Airport airport;
9494
9595 @ASN1Element(1)
--- a/jp/bitmeister/asn1/type/ASN1TagValue.java
+++ b/jp/bitmeister/asn1/type/ASN1TagValue.java
@@ -72,7 +72,7 @@ public class ASN1TagValue {
7272 && tag.tagClass() != ASN1TagClass.PRIVATE) {
7373 ASN1IllegalDefinition ex = new ASN1IllegalDefinition();
7474 ex.setMessage(
75- "Only context-specific or private tagging is allowed to an elements of structured type.",
75+ "Only context-specific or private tagging is allowed to elements of structured type.",
7676 null, namedType.enclosingType(), namedType.identifier(),
7777 null);
7878 throw ex;
--- a/jp/bitmeister/asn1/type/ASN1Type.java
+++ b/jp/bitmeister/asn1/type/ASN1Type.java
@@ -72,7 +72,7 @@ public abstract class ASN1Type implements Cloneable {
7272 throw ex;
7373 } catch (IllegalAccessException e) {
7474 ASN1RuntimeException ex = new ASN1IllegalDefinition();
75- ex.setMessage("Default constructor might be not accessable.", e,
75+ ex.setMessage("Default constructor might be not accessible.", e,
7676 type, null, null);
7777 throw ex;
7878 }
@@ -143,7 +143,7 @@ public abstract class ASN1Type implements Cloneable {
143143 * The visitor.
144144 * @return Result.
145145 * @throws E
146- * When an error occured in the {@code visit} method of the
146+ * When an error occurred in the {@code visit} method of the
147147 * visitor.
148148 */
149149 public abstract <R, E extends Throwable> R accept(ASN1Visitor<R, E> visitor)
--- a/jp/bitmeister/asn1/type/BuiltInModule.java
+++ b/jp/bitmeister/asn1/type/BuiltInModule.java
@@ -87,7 +87,7 @@ import jp.bitmeister.asn1.type.useful.VisibleString;
8787 GeneralizedTime.class, // UNIVERSAL 24
8888 GraphicString.class, // UNIVERSAL 25
8989 VisibleString.class, // UNIVERSAL 26
90- GeneralString.class, // UNIVERSAL27
90+ GeneralString.class, // UNIVERSAL 27
9191 UniversalString.class, // UNIVERSAL 28
9292 CHARACTER_STRING.class, // UNIVERSAL 29
9393 BMPString.class // UNIVERSAL 30
--- a/jp/bitmeister/asn1/type/ConstructiveType.java
+++ b/jp/bitmeister/asn1/type/ConstructiveType.java
@@ -61,14 +61,21 @@ public abstract class ConstructiveType extends StructuredType {
6161 if (ELEMENTS_MAP.containsKey(type)) {
6262 return ELEMENTS_MAP.get(type);
6363 }
64+ Class<? extends ConstructiveType> parent = type.getSuperclass().asSubclass(ConstructiveType.class);
6465 List<ElementSpecification> elements = new ArrayList<ElementSpecification>();
6566 for (Field f : type.getDeclaredFields()) {
6667 if (f.isAnnotationPresent(ASN1Element.class)) {
67- elements.add(new ElementSpecification(f
68- .getAnnotation(ASN1Element.class), f));
68+ ASN1Element element = f.getAnnotation(ASN1Element.class);
69+ if (element.value() < 0 && SEQUENCE.class.isAssignableFrom(type)) {
70+ ASN1IllegalDefinition ex = new ASN1IllegalDefinition();
71+ ex.setMessage(
72+ "Order of appearance of fields of a SEQUENCE type must be defined by @ASN1Element annotation.",
73+ null, type, f.getName(), null);
74+ throw ex;
75+ }
76+ elements.add(new ElementSpecification(element, f));
6977 }
7078 }
71- Class<? extends ConstructiveType> parent = type.getSuperclass().asSubclass(ConstructiveType.class);
7279 ElementSpecification[] array;
7380 if (parent == SET.class || parent == SEQUENCE.class
7481 || parent.isAnnotationPresent(ASN1Extendable.class)) {
@@ -77,7 +84,7 @@ public abstract class ConstructiveType extends StructuredType {
7784 if (TypeSpecification.getSpecification(type).tagDefault() == ASN1TagDefault.AUTOMATIC_TAGS) {
7885 generateAutomaticTags(array);
7986 }
80- if (parent == SET.class) {
87+ if (SET.class.isAssignableFrom(type)) {
8188 new UnorderedElementsChecker(type).check(array);
8289 } else {
8390 new OrderedElementsChecker(type).check(array);
--- a/jp/bitmeister/asn1/type/NamedTypeSpecification.java
+++ b/jp/bitmeister/asn1/type/NamedTypeSpecification.java
@@ -198,6 +198,14 @@ public class NamedTypeSpecification implements
198198 * The appearing order of this element in the type definition.
199199 */
200200 void generateAutomaticTag(int order) {
201+ if (this.order < 0) {
202+ ASN1IllegalDefinition ex = new ASN1IllegalDefinition();
203+ ex.setMessage(
204+ "Order of appearance of the field must be specified by @ASN1Element"
205+ + " or @ASN1Alternative annotation for automatic tagging process.",
206+ null, enclosingType(), identifier, null);
207+ throw ex;
208+ }
201209 tag = new ASN1TagValue(order, type());
202210 }
203211
--- a/jp/bitmeister/asn1/type/PrimitiveType.java
+++ b/jp/bitmeister/asn1/type/PrimitiveType.java
@@ -20,7 +20,7 @@ package jp.bitmeister.asn1.type;
2020 *
2121 * <p>
2222 * This class provides common methods and a value field for classes which
23- * represents simple, unconstructive ASN.1 types.
23+ * represent simple, unconstructive ASN.1 types.
2424 * </p>
2525 *
2626 * @author WATANABE, Jun. <jwat at bitmeister.jp>
--- a/jp/bitmeister/asn1/type/builtin/BIT_STRING.java
+++ b/jp/bitmeister/asn1/type/builtin/BIT_STRING.java
@@ -208,8 +208,11 @@ public class BIT_STRING extends PrimitiveType<boolean[]> implements
208208 * Indexes of bits to be set true.
209209 */
210210 public void set(int ...indexes) {
211- Arrays.sort(indexes);
212- expand(indexes[indexes.length - 1]);
211+ int max = -1;
212+ for (int e: indexes) {
213+ max = Math.max(max, e);
214+ }
215+ expand(max);
213216 for (int e: indexes) {
214217 value()[e] = true;
215218 }
@@ -243,8 +246,11 @@ public class BIT_STRING extends PrimitiveType<boolean[]> implements
243246 * Indexes of bits to be set false.
244247 */
245248 public void unset(int ...indexes) {
246- Arrays.sort(indexes);
247- expand(indexes[indexes.length - 1]);
249+ int max = -1;
250+ for (int e: indexes) {
251+ max = Math.max(max, e);
252+ }
253+ expand(max);
248254 for (int e: indexes) {
249255 value()[e] = false;
250256 }
@@ -296,7 +302,7 @@ public class BIT_STRING extends PrimitiveType<boolean[]> implements
296302 }
297303
298304 /**
299- * Returns the indentifier of the bit specified by the index number.
305+ * Returns the identifier of the bit specified by the index number.
300306 *
301307 * @param index
302308 * The index number of a bit.
--- a/jp/bitmeister/asn1/type/useful/EXTERNAL.java
+++ b/jp/bitmeister/asn1/type/useful/EXTERNAL.java
@@ -48,7 +48,7 @@ import jp.bitmeister.asn1.type.builtin.SEQUENCE;
4848 * encoding CHOICE {
4949 * single-ASN1-type [0] ANY,
5050 * octet-aligned [1] IMPLICIT OCTET STRING,
51- * arbitary [2] IMPLICIT BIT STRING } }
51+ * arbitrary [2] IMPLICIT BIT STRING } }
5252 * </pre>
5353 *
5454 * </p>
@@ -111,11 +111,11 @@ public class EXTERNAL extends SEQUENCE {
111111 public OCTET_STRING octet_aligned;
112112
113113 /**
114- * 'arbitary' field.
114+ * 'arbitrary' field.
115115 */
116116 @ASN1Alternative
117117 @ASN1Tag(2)
118- public BIT_STRING arbitary;
118+ public BIT_STRING arbitrary;
119119
120120 public Encoding() {
121121 super();
@@ -128,7 +128,7 @@ public class EXTERNAL extends SEQUENCE {
128128 }
129129
130130 /**
131- * Instanciate an empty {@code ExternalType}.
131+ * Instantiate an empty {@code ExternalType}.
132132 */
133133 public EXTERNAL() {
134134 }
--- a/jp/bitmeister/asn1/value/BinString.java
+++ b/jp/bitmeister/asn1/value/BinString.java
@@ -65,7 +65,7 @@ public class BinString implements StringItem {
6565 /**
6666 * Returns the string value of this bString.
6767 *
68- * @return The hexadecimal string.
68+ * @return The binary string that consists of '0's and '1's.
6969 */
7070 public String string() {
7171 return string;
Show on old repository browser