Pricing      Download   
MENU 
 Home Products About Support Contact



ParameterAsn1Example.java

( ASN.1 Examples | Home )

// ----------------------------------------------------------------
// -- Copyright (c) 2003-2011, Monfox, LLC. All Rights Reserved  -- 
// ----------------------------------------------------------------

import monfox.log.*;
import monfox.stack.osi.asn1.*;
import monfox.stack.osi.api.ValueException;

/**
 * <p><br>
 * See the usage below:
 * <pre>
 *     USAGE
 *  
 *       java ParameterAsn1Example
 *  
 * </pre>
 *  
 */
public class ParameterAsn1Example
{
   public static void main(String args[])
   {
      try
      {
	 // -- 
	 // --  initialize the logger
	 // -- 
	 Logger.setProvider(new SimpleLogger.Provider("ParameterAsn1Example.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("ParameterAsn1Example.ser");
	 }
	 catch(Exception e)
	 {
	    System.err.println("\n\n  initialization failed: \n" + e +"\n\n");
	    System.exit(1);
	 }

	 // -- create a new value from a defined value
	 AbstractData append_counter_list = api.newData("counterList1");

	 append_counter_list.refAppend().set("name","ctr1").set("value","100");;
	 append_counter_list.refAppend().set("name","ctr2").set("value","200");;
	 append_counter_list.refAppend().set("name","ctr3").set("value","300");;

	 System.out.println("\n\nAPPENDED COUNTER LIST: " + append_counter_list);


	 // -- simply access a defined value from metadata  (don't copy) 
	 AbstractData counter_list_1 = api.getValue("counterList1").getAbstractData();
	 System.out.println("\n\ncounterList1: " + counter_list_1);


	 // -- build a new value with the API -- 
	 AbstractData new_counter_list = api.newData("CounterList");

	 new_counter_list.refAppend().set("name","ctr1").set("value","100");;
	 new_counter_list.refAppend().set("name","ctr2").set("value","200");;
	 new_counter_list.refAppend().set("name","ctr3").set("value","300");;

	 System.out.println("\n\nNEW COUNTER LIST: " + new_counter_list);

	 ByteBuffer buf = api.getAsn1Coder().encode(new_counter_list);

	 System.out.println("\n\nBER ENCODED COUNTER LIST: " + buf);

	 AbstractData decoded_value = api.getAsn1Coder().decode("CounterList", buf);

	 System.out.println("\n\nDECODED COUNTER LIST: " + decoded_value);

	 System.out.println("\n\n");
      }
      catch(Exception e)
      {
         e.printStackTrace();
      }
   }
}