Java Class.getClasses Examples

Java Class.getClasses - 17 examples found. These are the top rated real world Java examples of Class.getClasses extracted from open source projects. You can rate examples to help us improve the quality of examples.
 /** INTERNAL: Load a class from a given class name. (XMLEntityMappings calls this one) */
 public static Class getClassForName(String classname, ClassLoader loader) {
   try {
     if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
       try {
         return (Class)
             AccessController.doPrivileged(new PrivilegedClassForName(classname, true, loader));
       } catch (PrivilegedActionException exception) {
         throw ValidationException.unableToLoadClass(classname, exception.getException());
       }
     } else {
       return PrivilegedAccessHelper.getClassForName(classname, true, loader);
     }
   } catch (ClassNotFoundException exception) {
     if (classname.indexOf('$') != -1) {
       String outer = classname.substring(0, classname.indexOf('$'));
       Class outerClass = getClassForName(outer, loader);
       for (int index = 0; index < outerClass.getClasses().length; index++) {
         if (outerClass.getClasses()[index].getName().equals(classname)) {
           return outerClass.getClasses()[index];
         }
       }
     }
     throw ValidationException.unableToLoadClass(classname, exception);
   }
 }
  private Class<?> getNestedClass(Class<?> clazz, String nested) {
    for (Class<?> nestedClass : clazz.getClasses()) {
      if (nestedClass.getSimpleName().equals(nested)) return nestedClass;
    }

    throw new AssertionError("No such nested class: " + nested);
  }
  public static int getResourseIdByName(String packageName, String className, String name) {
    Class r = null;
    int id = 0;
    try {
      r = Class.forName(packageName + ".R");

      Class[] classes = r.getClasses();
      Class desireClass = null;

      for (int i = 0; i < classes.length; i++) {
        if (classes[i].getName().split("\\$")[1].equals(className)) {
          desireClass = classes[i];

          break;
        }
      }

      if (desireClass != null) id = desireClass.getField(name).getInt(desireClass);
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (NoSuchFieldException e) {
      e.printStackTrace();
    }

    return id;
  }
 public void testCreateInstanceWithReflection() throws Exception {
   Class klass = Class.forName("org.openehr.schemas.v1.DVTEXT");
   Class factoryClass = klass.getClasses()[0];
   Method factoryMethod = factoryClass.getMethod("newInstance", null);
   Object obj = factoryMethod.invoke(null, null);
   assertTrue(obj instanceof DVTEXT);
 }
Example #5
0
  public boolean endCall() {
    if (_prevRingerMode == null) {
      _prevRingerMode = _audioManager.getRingerMode();
    }

    _audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);

    try {
      String serviceManagerName = "android.os.ServiceManager";
      String serviceManagerNativeName = "android.os.ServiceManagerNative";
      String telephonyName = "com.android.internal.telephony.ITelephony";

      Class<?> telephonyClass = Class.forName(telephonyName);
      Class<?> telephonyStubClass = telephonyClass.getClasses()[0];
      Class<?> serviceManagerClass = Class.forName(serviceManagerName);
      Class<?> serviceManagerNativeClass = Class.forName(serviceManagerNativeName);

      Binder tmpBinder = new Binder();
      tmpBinder.attachInterface(null, "fake");
      Method tempInterfaceMethod =
          serviceManagerNativeClass.getMethod("asInterface", IBinder.class);
      Object serviceManagerObject = tempInterfaceMethod.invoke(null, tmpBinder);
      Method getService = serviceManagerClass.getMethod("getService", String.class);
      IBinder retbinder = (IBinder) getService.invoke(serviceManagerObject, "phone");

      Method serviceMethod = telephonyStubClass.getMethod("asInterface", IBinder.class);
      Object telephonyObject = serviceMethod.invoke(null, retbinder);
      Method telephonyEndCall = telephonyClass.getMethod("endCall");
      telephonyEndCall.invoke(telephonyObject);
      return true;
    } catch (Exception e) {
      Log.e(TAG, "Could not connect to telephony subsystem", e);
      return false;
    }
  }
Example #6
0
 /**
  * Retrieve the names of all the public static classes in the clazz
  *
  * @param clazz the object to inspect
  * @return list of all the names of public statics
  */
 public String[] getPublicStaticClassNames(Class<?> clazz) {
   Class<?>[] classes = clazz.getClasses();
   Set<String> classNames = new HashSet<String>();
   for (Class<?> clazz2 : classes) {
     if (Modifier.isPublic(clazz2.getModifiers()) && Modifier.isStatic(clazz2.getModifiers())) {
       classNames.add(clazz2.getSimpleName());
     }
   }
   return (String[]) classNames.toArray(new String[classNames.size()]);
 }