codecbuilderinfo.java
来自「ASN.1工具源代码,包括编译源码生成工具和各种基本类型构造类型的编解码实现代码」· Java 代码 · 共 582 行 · 第 1/2 页
JAVA
582 行
/** * * CodecBuilderInfo * * @author Ian Ibbotson ( ibbo@k-int.com ) * @version $Id: CodecBuilderInfo.java,v 1.3 2001/01/05 13:50:26 ianibbo Exp $ * * Copyright: Copyright (C) 2000, Knowledge Integration Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the license, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite * 330, Boston, MA 02111-1307, USA. * * */package com.k_int.codec.comp;import com.k_int.codec.runtime.*;import java.io.File;import java.io.FileInputStream;import java.io.FileWriter;import java.io.Writer;import java.util.Vector;import java.util.Enumeration;import java.util.Hashtable;public class CodecBuilderInfo{ // Table used to figure out which internal types to use (where we can) // for some of the BuiltinASN types. Where null is specified, there is // no atomic mapping and the work will have to be done by generated code public static String builtinTypeInfo[][] = { { "java.math.BigInteger", null }, // Integer { "com.k_int.codec.runtime.AsnBitString", null }, // Bitstring { null, null }, // SetOrSeq { "java.util.Vector",null }, // SetOrSeq Of { null, null }, // Choice { null, null }, // Selection { null, null }, // Tagged { null, null }, // Any { "java.math.BigInteger",null }, // Enumeration (Just big integer for now) { "java.lang.String", null }, // OctetString { "int[]", null }, // OID { "java.math.BigDecimal", null }, // Real { "java.lang.Boolean", null }, // Bool { "com.k_int.codec.runtime.AsnNull", null } }; // Null private static int inline_codec_counter= 0; private static CodecBuilderInfo self = null; String pkg_name = null; String pkg_dir = null; private Vector import_list = new Vector(); private Hashtable modules = new Hashtable(); boolean default_tagging_is_explicit = true; String current_module_name = null; public static synchronized CodecBuilderInfo getInfo() { if ( null == self ) { self = new CodecBuilderInfo(); // registerType("","Integer",true,AsnParser.UNIVERSAL,AsnParser.INTEGER,true,null,nu // Populate type register with base types } return self; } public CodecBuilderInfo() { // Stuff to do only once // Register base types (Add any new built in types we need to handle here) registerModule("Builtin",true,false); ModuleInfo bim = lookupModule("Builtin"); bim.registerType( "Integer", new BuiltinTypeInfo("Integer", true, SerializationManager.UNIVERSAL, SerializationManager.INTEGER, false, null, "BigInteger", bim)); bim.registerType( "BitString", new BuiltinTypeInfo("BitString", true, SerializationManager.UNIVERSAL, SerializationManager.BITSTRING, false, null, "AsnBitString", bim)); bim.registerType( "OID", new BuiltinTypeInfo("OID", true, SerializationManager.UNIVERSAL, SerializationManager.OID, false, null, "int[]", bim)); bim.registerType( "OctetString", new BuiltinTypeInfo("OctetString", true, SerializationManager.UNIVERSAL, SerializationManager.OCTETSTRING, false, null, "String", bim)); bim.registerType( "BOOL", new BuiltinTypeInfo("BOOL", true, SerializationManager.UNIVERSAL, SerializationManager.BOOLEAN, false, null, "Boolean", bim)); // bim.registerType( "SequenceOf", new BuiltinTypeInfo("SequenceOf", true, SerializationManager.UNIVERSAL, SerializationManager.SEQUENCEOF, false, null, "java.util.Vector", bim)); bim.registerType( "SetOrSequenceOf", new BuiltinTypeInfo("SetOrSequenceOf", true, SerializationManager.UNIVERSAL, SerializationManager.SEQUENCEOF, false, null, "java.util.Vector", bim)); bim.registerType( "Any", new BuiltinTypeInfo("Any", true, SerializationManager.UNIVERSAL, SerializationManager.ANY, false, null, "byte[]", bim)); bim.registerType( "Enumerated", new BuiltinTypeInfo("Enumerated", true, SerializationManager.UNIVERSAL, SerializationManager.ENUMERATED, false, null, "BigInteger", bim)); bim.registerType( "NULL", new BuiltinTypeInfo("NULL", true, SerializationManager.UNIVERSAL, SerializationManager.NULL, false, null, "com.k_int.codec.runtime.AsnNull", bim)); // See if we can load the AsnUseful file // File useful_types_file = new File("./useful.asn1"); // if ( useful_types_file.exists() ) // { // try // { // System.err.println("Located AsnUseful types... Loading...."); // FileInputStream fis = new FileInputStream(useful_types_file); // AsnParser parser = new AsnParser(fis); // parser.Input(); // parser.jjtree.rootNode().pass1(); // System.err.println("All done"); // } // catch ( Exception e ) // { // e.printStackTrace(); // } // } } public static int getNextInlineCounter() { return inline_codec_counter++; } public ModuleInfo lookupModule(String module_name) { return (ModuleInfo)(modules.get(module_name)); } public String getInternalClass(int index) { return builtinTypeInfo[index][0]; } public String getCurrentModuleName() { return current_module_name; } public ModuleInfo getCurrentModule() { return lookupModule(current_module_name); } public void setCurrentModuleName(String s) { current_module_name = s; } public void registerModule(String module_reference, boolean default_explicit_tagging, boolean create_java) { System.err.println(" registerModule("+module_reference+","+default_explicit_tagging+")"); // The module may have allready been registered as the result of processing an imports ... from // clause, if so, just add the xtra tagging and create info ModuleInfo mi = (ModuleInfo)modules.get(module_reference); if ( null == mi ) { modules.put(module_reference, new ModuleInfo(module_reference,default_explicit_tagging,create_java)); } else { mi.setDefaultExplicitTagging(default_explicit_tagging); mi.setCreateJava(create_java); } } public void registerType(String module, String type, TypeInfo ti) { // System.err.println("registerType("+module+","+type+",...)"); // Find the module that this type belogs in ModuleInfo mi = (ModuleInfo)modules.get(module); if ( null != mi ) { mi.registerType(type, ti); } else { System.err.println("Unknown module reference"); System.exit(1); } } public void setCurrentPackageName(String pkg_name) { this.pkg_name = pkg_name; } public void setCurrentPackageDir(String pkg_dir) { this.pkg_dir = pkg_dir; } public void defaultTaggingIsImplicit() { this.default_tagging_is_explicit = false; } public void defaultTaggingIsExplicit() { this.default_tagging_is_explicit = true; } public String getCurrentPackageName() { return pkg_name; } public String getCurrentPackageDir() { return pkg_dir; } public boolean defaultTagModeIsExplicit() { return default_tagging_is_explicit; } public void resetImportList() { import_list.clear(); } public void addImport(String imp) { System.err.println("Adding import..."+imp); import_list.add(imp); } String getFullyQualifiedClassName(String classname) { // See if any of the imports end in .classname for (Enumeration e = import_list.elements() ; e.hasMoreElements() ;) { String current = (String)e.nextElement(); if ( current.endsWith("."+classname) ) return current; } // else return null return null; } public void writeModuleImports(FileWriter codec_writer) { try { for (Enumeration e = import_list.elements() ; e.hasMoreElements() ;) codec_writer.write("import "+e.nextElement()+";\n"); } catch ( java.io.IOException ioe ) { System.err.println(ioe); } } // Run through all modules and types creating appropriate codecs & types where needed public void create() { System.err.println("Processing Modules............."); for (Enumeration e = modules.elements() ; e.hasMoreElements() ;) { // Reset the counter for inline type definitions inline_codec_counter = 0; ModuleInfo mi = (ModuleInfo)e.nextElement(); System.out.println("Processing "+mi.getModulePackageName()+" "+mi.createJava()); if ( mi.createJava() ) mi.createCode(); else System.err.println("Skipping module......"+mi.getModulePackageName()); } } public void registerImport(String module_reference, String type_reference)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?