InfoObjectAsn1Example.java
( ASN.1 Examples | Home )// ---------------------------------------------------------------- // -- Copyright (c) 2003-2012, Monfox, LLC. All Rights Reserved -- // ---------------------------------------------------------------- import monfox.log.*; import monfox.stack.osi.asn1.*; import monfox.stack.osi.asn1.metadata.*; import monfox.stack.osi.api.ValueException; /** * <p><br> * See the usage below: * <pre> * USAGE * * java InfoObjectAsn1Example * * </pre> * */ public class InfoObjectAsn1Example { public static void main(String args[]) { try { // -- // -- initialize the logger // -- Logger.setProvider(new SimpleLogger.Provider("InfoObjectAsn1Example.log")); // -- // -- initialize the ASN.1 API and metadata // -- Asn1Api api = new Asn1Api(); api.getConfig().isLaxMode(true); // -- // -- load the metadata // -- try { System.out.println("-- [ loading metadata ] --"); api.loadMetadata("InfoObjectAsn1Example.ser"); } catch(Exception e) { System.err.println("\n\n initialization failed: \n" + e +"\n\n"); System.exit(1); } // -- // -- Access a definedValue message from Metadata // -- AbstractData set_message = api.getValue("setRequestMessage").getAbstractData(); System.out.println("\n\nSET-REQUEST-MESSAGE: " + set_message); System.out.println("\n\n"); // -- // -- Create a new OPERATION called newOp // -- InfoObject new_operation = api.getMetadata().newInfoObject("InfoObject-ASN1Module","newOp", "OPERATION"); new_operation.setField("ArgumentType", "AttributeList"); new_operation.setField("ResultType", "INTEGER"); new_operation.setField("operationCode", "100"); // -- // -- Add the new operation to the Metadata's OperationSet InfoObjectSet // -- InfoObjectSet operation_set = api.getMetadata().getInfoObjectSet("InfoObject-ASN1Module.OperationSet"); operation_set.addInfoObject(new_operation); // -- // -- Create a new ATTRIBUTE called newAttribute // -- InfoObject new_attribute = api.getMetadata().newInfoObject("InfoObject-ASN1Module","newAttribute", "ATTRIBUTE"); new_attribute.setField("id", "4"); new_attribute.setField("Type", "OBJECT IDENTIFIER"); // -- // -- Add the new operation to the Metadata's AttributeSet InfoObjectSet // -- InfoObjectSet attribute_set = api.getMetadata().getInfoObjectSet("InfoObject-ASN1Module.AttributeSet"); attribute_set.addInfoObject(new_attribute); // -- // -- Create a new Message for the newly created operation using API methods // -- AbstractData request = api.newData("Message"); request.rset("request.opCode","newOp.&operationCode"); // -- setOp operation // -- populate the attribute list AbstractData attribute_list = request.rref("request.argument"); attribute_list.refAppend().set("id","nameAttribute.&id").set("value","Steve Rogers"); attribute_list.refAppend().set("id","2").set("value",25); attribute_list.refAppend().set("id",3).set("value","11111"); attribute_list.refAppend().set("id","newAttribute.&id").set("value","{ 1 2 3 4 5 6 }"); System.out.println("NEW REQUEST: " + request); ByteBuffer new_encoded = api.getAsn1Coder().encode(request); System.out.println("NEW ENCODED BUFFER: \n" + new_encoded); AbstractData new_decoded_message = api.getAsn1Coder().decode("Message", new_encoded); System.out.println("\n\nNEW DECODED MESSAGE: " + new_decoded_message); System.out.println("\n\n"); } catch(Exception e) { e.printStackTrace(); } } }