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