private ClassLoader getRootLoader() {
   ClassLoader ret;
   for (ret = this.getClass().getClassLoader();
       ret != null && ret.getParent() != null;
       ret = ret.getParent()) {}
   return ret;
 }
示例#2
0
 Class<?> getPluginClass(String packageName, String className)
     throws NameNotFoundException, ClassNotFoundException {
   Context pluginContext =
       this.mAppContext.createPackageContext(
           packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
   ClassLoader pluginCL = pluginContext.getClassLoader();
   return pluginCL.loadClass(className);
 }
示例#3
0
  /**
   * The value of <code>get(uidClassID)</code> must be the <code>String</code> name of a class that
   * implements the corresponding <code>ComponentUI</code> class. If the class hasn't been loaded
   * before, this method looks up the class with <code>uiClassLoader.loadClass()</code> if a non
   * <code>null</code> class loader is provided, <code>classForName()</code> otherwise.
   *
   * <p>If a mapping for <code>uiClassID</code> exists or if the specified class can't be found,
   * return <code>null</code>.
   *
   * <p>This method is used by <code>getUI</code>, it's usually not necessary to call it directly.
   *
   * @param uiClassID a string containing the class ID
   * @param uiClassLoader the object which will load the class
   * @return the value of <code>Class.forName(get(uidClassID))</code>
   * @see #getUI
   */
  public Class<? extends ComponentUI> getUIClass(String uiClassID, ClassLoader uiClassLoader) {
    try {
      String className = (String) get(uiClassID);
      if (className != null) {
        ReflectUtil.checkPackageAccess(className);

        Class cls = (Class) get(className);
        if (cls == null) {
          if (uiClassLoader == null) {
            cls = SwingUtilities.loadSystemClass(className);
          } else {
            cls = uiClassLoader.loadClass(className);
          }
          if (cls != null) {
            // Save lookup for future use, as forName is slow.
            put(className, cls);
          }
        }
        return cls;
      }
    } catch (ClassNotFoundException e) {
      return null;
    } catch (ClassCastException e) {
      return null;
    }
    return null;
  }
示例#4
0
 /**
  * Get the current thread's context class loader which is set to the CommonClassLoader by
  * ApplicationServer
  *
  * @return the thread's context classloader if it exists; else the system class loader.
  */
 public static ClassLoader getClassLoader() {
   if (Thread.currentThread().getContextClassLoader() != null) {
     return Thread.currentThread().getContextClassLoader();
   } else {
     return ClassLoader.getSystemClassLoader();
   }
 }
    public boolean hasNext() {
      if (nextProc != null) return true;
      else {
        if (!names.hasNext()) return false;
        else {
          String processorName = names.next();

          Processor processor;
          try {
            try {
              processor = (Processor) (processorCL.loadClass(processorName).newInstance());
            } catch (ClassNotFoundException cnfe) {
              log.error("proc.processor.not.found", processorName);
              return false;
            } catch (ClassCastException cce) {
              log.error("proc.processor.wrong.type", processorName);
              return false;
            } catch (Exception e) {
              log.error("proc.processor.cant.instantiate", processorName);
              return false;
            }
          } catch (ClientCodeException e) {
            throw e;
          } catch (Throwable t) {
            throw new AnnotationProcessingError(t);
          }
          nextProc = processor;
          return true;
        }
      }
    }
 /**
  * This function loads a class from file into the JVM given its fully-qualified name.
  *
  * @param classInfo the fully-qualified class name
  * @return a Class object representing the class name if such a class is defined, otherwise null
  */
 private static Class<?> getClass(String classInfo) {
   try {
     return ClassLoader.getSystemClassLoader().loadClass(classInfo);
   } catch (ClassNotFoundException e) {
     throw new RuntimeException(e.toString());
   }
 }
示例#7
0
 /* STATIC ACCESSORY METHODS */
 public static Class getClassOfBean(ClassLoader classLoader, String clazz) {
   Class cls = null;
   try {
     cls = classLoader.loadClass(clazz);
   } catch (ClassNotFoundException cnfe) {
   }
   return cls;
 }
 @SuppressWarnings("unchecked")
 public void addDefaultValue(String className, JSONObject oper) throws Exception {
   ObjectMapper defaultValueMapper = ObjectMapperFactory.getOperatorValueSerializer();
   Class<? extends Operator> clazz = (Class<? extends Operator>) classLoader.loadClass(className);
   if (clazz != null) {
     Operator operIns = clazz.newInstance();
     String s = defaultValueMapper.writeValueAsString(operIns);
     oper.put("defaultValue", new JSONObject(s).get(className));
   }
 }
示例#9
0
 public static void main(String[] args) throws Exception {
   ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); // Enable asserts
   new ProcessFiles(new AtUnit(), "class").start(args);
   if (failures == 0) Print.print("OK (" + testsRun + " tests)");
   else {
     Print.print("(" + testsRun + " tests)");
     Print.print("\n>>> " + failures + " FAILURE" + (failures > 1 ? "S" : "") + " <<<");
     for (String failed : failedTests) Print.print("  " + failed);
   }
 }
 public OperatorDiscoverer(String[] jars) {
   URL[] urls = new URL[jars.length];
   for (int i = 0; i < jars.length; i++) {
     pathsToScan.add(jars[i]);
     try {
       urls[i] = new URL("file://" + jars[i]);
     } catch (MalformedURLException ex) {
       throw new RuntimeException(ex);
     }
   }
   classLoader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader());
 }
示例#11
0
 public static Properties getPropertiesFromFile(String file) throws IOException {
   InputStream is = ClassLoader.getSystemResourceAsStream(file);
   if (is != null) {
     Properties config = new Properties();
     config.load(is);
     return config;
   } else {
     String remoteclient = "/" + file;
     InputStream is2 = Utility.class.getResourceAsStream(remoteclient);
     Properties config = new Properties();
     config.load(is2);
     return config;
   }
 }
  @SuppressWarnings("unchecked")
  public Class<? extends Operator> getOperatorClass(String className)
      throws ClassNotFoundException {
    if (CollectionUtils.isEmpty(operatorClassNames)) {
      loadOperatorClass();
    }

    Class<?> clazz = classLoader.loadClass(className);

    if (!Operator.class.isAssignableFrom(clazz)) {
      throw new IllegalArgumentException("Argument must be a subclass of Operator class");
    }
    return (Class<? extends Operator>) clazz;
  }
  /** Look on disk for an editor with the class name 'ocName'. */
  PluggableEditor loadEditorFromDisk(String ocName) {
    // if here, we need to look on disk for a pluggable editor class...
    log.finer("looking for ocName: " + ocName);
    try {
      Class c = myLoader.loadClass(ocName);
      Constructor constructor = c.getConstructor(new Class[0]);

      // XXX If the pluggable editor has an error in the constructor, under some
      // XXX circumstances it can fail so badly that this call never returns, and
      // XXX the thread hangs!  It doesn't even get to the exception handler below...
      // XXX but sometimes if the constructor fails everything works as expected.  Wierd.
      PluggableEditor editor = (PluggableEditor) constructor.newInstance(new Object[0]);

      editors.put(ocName, editor); // add the new editor to our list
      return editor;
    } catch (Exception e) // expected condition - just means no pluggable editor available
    {
      if (e
          instanceof
          InvocationTargetException) // rare exception - an error was encountered in the plugin's
                                     // constructor.
      {
        log.warning("unable to load special editor for: '" + ocName + "' " + e);
        if (JXConfig.debugLevel >= 1) {
          log.warning("Error loading plugin class: ");
          ((InvocationTargetException) e).getTargetException().printStackTrace();
        }
      }

      log.log(Level.FINEST, "'Expected' Error loading " + ocName, e);
      editors.put(ocName, NONE); // add a blank place holder - we can't load
      // an editor for this, and there's no point looking again. (change if want dynamic loading,
      // i.e. look *every* time)
    }
    return null; // only here if an error has occured.
  }
示例#14
0
  /**
   * Creates a new <code>java.awt.Frame</code>. This frame is the root for the AWT components that
   * will be embedded within the composite. In order for the embedding to succeed, the composite
   * must have been created with the SWT.EMBEDDED style.
   *
   * <p>IMPORTANT: As of JDK1.5, the embedded frame does not receive mouse events. When a
   * lightweight component is added as a child of the embedded frame, the cursor does not change. In
   * order to work around both these problems, it is strongly recommended that a heavyweight
   * component such as <code>java.awt.Panel</code> be added to the frame as the root of all
   * components.
   *
   * @param parent the parent <code>Composite</code> of the new <code>java.awt.Frame</code>
   * @return a <code>java.awt.Frame</code> to be the parent of the embedded AWT components
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the parent is null
   *       <li>ERROR_INVALID_ARGUMENT - if the parent Composite does not have the SWT.EMBEDDED style
   *     </ul>
   *
   * @since 3.0
   */
  public static Frame new_Frame(final Composite parent) {
    if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    if ((parent.getStyle() & SWT.EMBEDDED) == 0) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }

    final int /*long*/ handle = parent.view.id;

    Class clazz = null;
    try {
      String className =
          embeddedFrameClass != null ? embeddedFrameClass : "apple.awt.CEmbeddedFrame";
      if (embeddedFrameClass == null) {
        clazz = Class.forName(className, true, ClassLoader.getSystemClassLoader());
      } else {
        clazz = Class.forName(className);
      }
    } catch (ClassNotFoundException cne) {
      SWT.error(SWT.ERROR_NOT_IMPLEMENTED, cne);
    } catch (Throwable e) {
      SWT.error(SWT.ERROR_UNSPECIFIED, e, " [Error while starting AWT]");
    }

    initializeSwing();
    Object value = null;
    Constructor constructor = null;
    try {
      constructor = clazz.getConstructor(new Class[] {long.class});
      value = constructor.newInstance(new Object[] {new Long(handle)});
    } catch (Throwable e) {
      SWT.error(SWT.ERROR_NOT_IMPLEMENTED, e);
    }
    final Frame frame = (Frame) value;
    frame.addNotify();

    parent.setData(EMBEDDED_FRAME_KEY, frame);

    /* Forward the iconify and deiconify events */
    final Listener shellListener =
        new Listener() {
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.Deiconify:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_DEICONIFIED));
                      }
                    });
                break;
              case SWT.Iconify:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_ICONIFIED));
                      }
                    });
                break;
            }
          }
        };
    Shell shell = parent.getShell();
    shell.addListener(SWT.Deiconify, shellListener);
    shell.addListener(SWT.Iconify, shellListener);

    /*
     * Generate the appropriate events to activate and deactivate
     * the embedded frame. This is needed in order to make keyboard
     * focus work properly for lightweights.
     */
    Listener listener =
        new Listener() {
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.Dispose:
                Shell shell = parent.getShell();
                shell.removeListener(SWT.Deiconify, shellListener);
                shell.removeListener(SWT.Iconify, shellListener);
                parent.setVisible(false);
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        try {
                          frame.dispose();
                        } catch (Throwable e) {
                        }
                      }
                    });
                break;
              case SWT.FocusIn:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        if (frame.isActive()) return;
                        try {
                          Class clazz = frame.getClass();
                          Method method =
                              clazz.getMethod(
                                  "synthesizeWindowActivation", new Class[] {boolean.class});
                          if (method != null)
                            method.invoke(frame, new Object[] {new Boolean(true)});
                        } catch (Throwable e) {
                          e.printStackTrace();
                        }
                      }
                    });
                break;
              case SWT.Deactivate:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        if (!frame.isActive()) return;
                        try {
                          Class clazz = frame.getClass();
                          Method method =
                              clazz.getMethod(
                                  "synthesizeWindowActivation", new Class[] {boolean.class});
                          if (method != null)
                            method.invoke(frame, new Object[] {new Boolean(false)});
                        } catch (Throwable e) {
                          e.printStackTrace();
                        }
                      }
                    });
                break;
            }
          }
        };

    parent.addListener(SWT.FocusIn, listener);
    parent.addListener(SWT.Deactivate, listener);
    parent.addListener(SWT.Dispose, listener);

    parent
        .getDisplay()
        .asyncExec(
            new Runnable() {
              public void run() {
                if (parent.isDisposed()) return;
                final Rectangle clientArea = parent.getClientArea();
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.setSize(clientArea.width, clientArea.height);
                        frame.validate();

                        // Bug in Cocoa AWT? For some reason the frame isn't showing up on first
                        // draw.
                        // Toggling visibility seems to be the only thing that works.
                        frame.setVisible(false);
                        frame.setVisible(true);
                      }
                    });
              }
            });

    return frame;
  }
  public static void main(String[] args) throws Exception {
    System.out.println(
        "Checking that all known MBeans that are "
            + "NotificationBroadcasters have sane "
            + "MBeanInfo.getNotifications()");

    System.out.println("Checking platform MBeans...");
    checkPlatformMBeans();

    URL codeBase = ClassLoader.getSystemResource("javax/management/MBeanServer.class");
    if (codeBase == null) {
      throw new Exception("Could not determine codeBase for " + MBeanServer.class);
    }

    System.out.println();
    System.out.println("Looking for standard MBeans...");
    String[] classes = findStandardMBeans(codeBase);

    System.out.println("Testing standard MBeans...");
    for (int i = 0; i < classes.length; i++) {
      String name = classes[i];
      Class<?> c;
      try {
        c = Class.forName(name);
      } catch (Throwable e) {
        System.out.println(name + ": cannot load (not public?): " + e);
        continue;
      }
      if (!NotificationBroadcaster.class.isAssignableFrom(c)) {
        System.out.println(name + ": not a NotificationBroadcaster");
        continue;
      }
      if (Modifier.isAbstract(c.getModifiers())) {
        System.out.println(name + ": abstract class");
        continue;
      }

      NotificationBroadcaster mbean;
      Constructor<?> constr;
      try {
        constr = c.getConstructor();
      } catch (Exception e) {
        System.out.println(name + ": no public no-arg constructor: " + e);
        continue;
      }
      try {
        mbean = (NotificationBroadcaster) constr.newInstance();
      } catch (Exception e) {
        System.out.println(name + ": no-arg constructor failed: " + e);
        continue;
      }

      check(mbean);
    }

    System.out.println();
    System.out.println("Testing some explicit cases...");

    check(new RelationService(false));
    /*
      We can't do this:
        check(new RequiredModelMBean());
      because the Model MBean spec more or less forces us to use the
      names GENERIC and ATTRIBUTE_CHANGE for its standard notifs.
    */
    checkRMIConnectorServer();

    System.out.println();
    if (!suspicious.isEmpty()) System.out.println("SUSPICIOUS CLASSES: " + suspicious);

    if (failed.isEmpty()) System.out.println("TEST PASSED");
    else {
      System.out.println("TEST FAILED: " + failed);
      System.exit(1);
    }
  }
示例#16
0
    public void loadContents()
    {
        // read from the  class (operations and atributes)
        Debug.assert( getReference() != null, "my own ref null");

        org.omg.CORBA.StructDef myReference = 
            org.omg.CORBA.StructDefHelper.narrow( getReference());

        Debug.assert( myReference != null, "narrow failed for " + getReference() );

        /* load nested definitions from interfacePackage directory */
        
        String[] classes = null;
        if( my_dir != null )
        {
            classes = my_dir.list( new IRFilenameFilter(".class") );

            // load class files in this interface's Package directory
            if( classes != null) 
            {
                for( int j = 0; j < classes.length; j++ )
                {
                    try 
                    { 
                        org.jacorb.util.Debug.output(2, "Struct " +name+ " tries " + 
                                                 full_name.replace('.', fileSeparator) + 
                                                 "Package" + fileSeparator + 
                                                 classes[j].substring( 0, classes[j].indexOf(".class")) );

                        ClassLoader loader = getClass().getClassLoader();
                        if( loader == null )
                        {
                            loader = RepositoryImpl.loader;
                        }

                        Class cl = 
                            loader.loadClass( 
                                             ( full_name.replace('.', fileSeparator) + "Package" + fileSeparator + 
                                               classes[j].substring( 0, classes[j].indexOf(".class"))
                                               ).replace( fileSeparator, '/') );
                        

                        Contained containedObject = Contained.createContained( cl, 
                                                                               path,
                                                                               myReference, 
                                                                               containing_repository );
                        if( containedObject == null )
                            continue;
                        
                        org.omg.CORBA.Contained containedRef = 
                            Contained.createContainedReference(containedObject);
                        
                        if( containedObject instanceof ContainerType )
                            ((ContainerType)containedObject).loadContents();
                        
                        containedRef.move( myReference, containedRef.name(), containedRef.version() );
                        
                        org.jacorb.util.Debug.output(2, "Struct " + full_name + 
                                                 " loads "+ containedRef.name() );
                        contained.put( containedRef.name() , containedRef );
                        containedLocals.put( containedRef.name(), containedObject );                        
                    } 
                    catch ( Exception e ) 
                    {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
 public OperatorDiscoverer() {
   classLoader = ClassLoader.getSystemClassLoader();
 }
示例#18
0
 public java.net.URL getResource(String name) {
   return ClassLoader.getSystemResource(name);
 }
示例#19
0
 public InputStream getResourceAsStream(String name) {
   return ClassLoader.getSystemResourceAsStream(name);
 }