Example #1
0
 private static void netxsurgery() throws Exception {
   /* Force off NetX codebase classloading. */
   Class<?> nxc;
   try {
     nxc = Class.forName("net.sourceforge.jnlp.runtime.JNLPClassLoader");
   } catch (ClassNotFoundException e1) {
     try {
       nxc = Class.forName("netx.jnlp.runtime.JNLPClassLoader");
     } catch (ClassNotFoundException e2) {
       throw (new Exception("No known NetX on classpath"));
     }
   }
   ClassLoader cl = MainFrame.class.getClassLoader();
   if (!nxc.isInstance(cl)) {
     throw (new Exception("Not running from a NetX classloader"));
   }
   Field cblf, lf;
   try {
     cblf = nxc.getDeclaredField("codeBaseLoader");
     lf = nxc.getDeclaredField("loaders");
   } catch (NoSuchFieldException e) {
     throw (new Exception("JNLPClassLoader does not conform to its known structure"));
   }
   cblf.setAccessible(true);
   lf.setAccessible(true);
   Set<Object> loaders = new HashSet<Object>();
   Stack<Object> open = new Stack<Object>();
   open.push(cl);
   while (!open.empty()) {
     Object cur = open.pop();
     if (loaders.contains(cur)) continue;
     loaders.add(cur);
     Object curl;
     try {
       curl = lf.get(cur);
     } catch (IllegalAccessException e) {
       throw (new Exception("Reflection accessibility not available even though set"));
     }
     for (int i = 0; i < Array.getLength(curl); i++) {
       Object other = Array.get(curl, i);
       if (nxc.isInstance(other)) open.push(other);
     }
   }
   for (Object cur : loaders) {
     try {
       cblf.set(cur, null);
     } catch (IllegalAccessException e) {
       throw (new Exception("Reflection accessibility not available even though set"));
     }
   }
 }
Example #2
0
 // todo eliminate code duplication in BaseLogicalViewProjectPane
 private <T extends TreeNode> T getSelectedTreeNode(Class<T> nodeClass) {
   TreePath selectionPath = getTree().getSelectionPath();
   if (selectionPath == null) return null;
   Object selectedNode = selectionPath.getLastPathComponent();
   if (!(nodeClass.isInstance(selectedNode))) return null;
   return (T) selectedNode;
 }
 /*
  * Recursive method which returns a count of the number of listeners in
  * EventListener, handling the (common) case of l actually being an
  * AWTEventMulticaster.  Additionally, only listeners of type listenerType
  * are counted.  Method modified to fix bug 4513402.  -bchristi
  */
 private static int getListenerCount(EventListener l, Class listenerType) {
   if (l instanceof AWTEventMulticaster) {
     AWTEventMulticaster mc = (AWTEventMulticaster) l;
     return getListenerCount(mc.a, listenerType) + getListenerCount(mc.b, listenerType);
   } else {
     // Only count listeners of correct type
     return listenerType.isInstance(l) ? 1 : 0;
   }
 }
 public <T> T getUserData(final Class<T> userDataClass) {
   if (myUserData != null) {
     for (Object o : myUserData) {
       if (userDataClass.isInstance(o)) {
         //noinspection unchecked
         return (T) o;
       }
     }
   }
   return null;
 }
Example #5
0
 /** Return the control based on a control type for the PlugIn. */
 public Object getControl(String controlType) {
   try {
     Class cls = Class.forName(controlType);
     Object cs[] = getControls();
     for (int i = 0; i < cs.length; i++) {
       if (cls.isInstance(cs[i])) return cs[i];
     }
     return null;
   } catch (Exception e) { // no such controlType or such control
     return null;
   }
 }