1 /* 2 ***************************************************************************** 3 * Copyright (C) 2000-2007, International Business Machines Corporation and * 4 * others. All Rights Reserved. * 5 ***************************************************************************** 6 */ 7 package com.ibm.rbm; 8 9 10 import java.io.*; 11 12 import com.ibm.rbm.gui.RBManagerGUI; 13 14 import java.util.*; 15 import java.net.*; 16 17 /** 18 * This is the super class for all importer plug-in classes. As of yet, there 19 * is little contained in this class. 20 * 21 * @author Jared Jackson 22 * @see com.ibm.rbm.RBManager 23 */ 24 public class RBJavaImporter extends RBImporter { 25 RBJavaImporter(String title, RBManager rbm, RBManagerGUI gui)26 public RBJavaImporter(String title, RBManager rbm, RBManagerGUI gui) { 27 super(title, rbm, gui); 28 } 29 setupFileChooser()30 protected void setupFileChooser() { 31 chooser.setFileFilter(new javax.swing.filechooser.FileFilter(){ 32 public boolean accept(File f) { 33 if (f.isDirectory()) return true; 34 if (f.getName().endsWith(".class") && f.getName().indexOf("_") < 0) return true; 35 return false; 36 } 37 38 public String getDescription() { 39 return Resources.getTranslation("import_java_file_description"); 40 } 41 }); 42 } 43 beginImport()44 protected void beginImport() throws IOException { 45 super.beginImport(); 46 ListResourceBundle base_lrb = null; 47 URLClassLoader urlLoader = null; 48 try { 49 File baseFile = getChosenFile(); 50 URL baseURL = baseFile.toURL(); 51 URL urls[] = new URL[1]; 52 urls[0] = baseURL; 53 urlLoader = new URLClassLoader(urls); 54 String baseName = baseFile.getName(); 55 baseName = baseName.substring(0, baseName.indexOf(".class")); 56 57 Class baseClass = urlLoader.loadClass(baseName); 58 base_lrb = (ListResourceBundle)baseClass.newInstance(); 59 } catch (Exception e) { 60 RBManagerGUI.debugMsg(e.toString()); 61 RBManagerGUI.debugMsg(e.getMessage()); 62 e.printStackTrace(System.err); 63 } 64 if (base_lrb != null) { 65 Enumeration keys = base_lrb.getKeys(); 66 while (keys.hasMoreElements()) { 67 String key = keys.nextElement().toString(); 68 RBManagerGUI.debugMsg("Resource -> " + key + " = " + base_lrb.getString(key)); 69 } 70 } 71 } 72 } 73 74 /* 75 class myClassLoader extends ClassLoader { 76 public myClassLoader() { 77 super(); 78 } 79 80 public Class myDefineClass(String name, byte array[], int off, int len) { 81 return super.defineClass(name, array, off, len); 82 } 83 } 84 */ 85