The ASN.1/Java Tools can parse ASN.1 value notation data into Java objects that represent values defined by value notation.
To parse values specified in ASN.1 value notation format:
ValueNotationReader parser = ProjectName.getValueNotationReader();
The Bcas.asn schema file is used in this example.
BCASModule DEFINITIONS ::= BEGIN BBCard ::= SEQUENCE { name IA5String (SIZE (1..60)), team IA5String (SIZE (1..60)), age INTEGER (1..100), position IA5String (SIZE (1..60)), handedness ENUMERATED {left-handed(0), right-handed(1), ambidextrous(2)}, batting-average REAL } END
The following source code shows the sample Java application that parses the BBCard ASN.1 type values:
package bcas; import com.oss.asn1.AVNParseException; import com.oss.asn1.AbstractData; import com.oss.asn1.AVNInput; import com.oss.asn1.ValueNotationReader; import java.io.StringReader; public class Test { public static void main(String[] args) throws AVNParseException { // The value notation for the value of the BBCard type String myCard = "{\n" + " name \"Casey\",\n" + " team \"Mudville Nine\"," + " age 32,\n" + " position \"left field\",\n" + " handedness ambidextrous,\n" + " batting-average {mantissa 250, base 10, exponent -3}\n" + "}\n"; // Instantiate the ValueNotationReader ValueNotationReader parser = Bcas.getValueNotationReader(); // Parse the value notation contained in the myCard string AbstractData myCardPdu1 = parser.readValue(myCard, new bcas.bcasmodule.BBCard()); // Print the object parsed from the value notation in the // myCard string System.out.println("myCardPdu1 " + myCardPdu1); // Create the string that contains the ASN.1 value assignment for the // value of BBCard String myCardAssignment = "myCard BBCard ::= " + myCard; // Parse the value assignment contained in the myCardAssignment // string. The parser will detect the type of the value from the // ASN.1 type name specified in the value assignment (BBCard). AbstractData myCardPdu2 = parser.readValueAssignment(myCardAssignment); // Print the C# object parsed from the value assignment in the // myCardAssignment string System.out.println("myCardPdu2 " + myCardPdu2); // Parse the input that contains multiple values of the BBCard type String myCards = "-- first value\n" + "{\n" + " name \"Casey\",\n" + " team \"Mudville Nine\"," + " age 32,\n" + " position \"left field\",\n" + "handedness ambidextrous,\n" + "batting-average {mantissa 250, base 10, exponent -3}\n" + "}\n" + "-- second value\n" + "{\n" + " name \"Doug\",\n" + "team \"Octopus Eight\"," + "age 27,\n" + "position \"right field\",\n" + "handedness right-handed,\n" + "batting-average {mantissa 250, base 10, exponent -3}\n" + "}\n"; { AbstractData myCardPdu; AVNInput reader = new AVNInput(new StringReader(myCards)); // Parse all the values contained in the myCards while ((myCardPdu = parser.readValue(reader, new bcas.bcasmodule.BBCard())) != null) System.out.println("myCardPdu " + myCardPdu); } } }
The following methods automatically determine the value type from the ASN.1 type name specified in the ASN.1 value assignment:
The following generic methods allow you to specify the value type explicitly. The value type is identified by the "T extends AbstractData" parameter, which is an empty instance of the Java class that represents the value type:
Type ":" Valueonly the "typereference" alternative of the "Type" production is supported. Also, the type specified by "typereference" must be a PDU.
NOTE: The ASN.1 value notation parser is a chargeable feature in non-evaluation licenses. Contact Sales to obtain pricing information.
This documentation applies to the OSS® ASN.1 Tools for Java release 8.7 and later.
Copyright © 2024 OSS Nokalva, Inc. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means electronic, mechanical, photocopying, recording or otherwise, without the prior permission of OSS Nokalva, Inc.
Every distributed copy of the OSS® ASN.1 Tools for Java is associated with a specific license and related unique license number. That license determines, among other things, what functions of the OSS ASN.1 Tools for Java are available to you.