Java Class.getClass Examples

Java Class.getClass - 30 examples found. These are the top rated real world Java examples of Class.getClass extracted from open source projects. You can rate examples to help us improve the quality of examples.
 @SuppressWarnings({"rawtypes", "unchecked"})
 public static void assertExists(Class myClass, Class myAnnotation) throws Exception {
   // Checks if an annotation is present
   if (!myClass.isAnnotationPresent(myAnnotation.getClass())) {
     throw new Exception("Annotation : " + myAnnotation.getClass() + " not found.");
   }
 }
Example #2
0
  private void checkDataBinding(Class<? extends AbstractField> class1) {
    boolean ok = false;
    AbstractField b;
    try {
      b = class1.newInstance();
      b.setCaption("Button of type " + class1.getSimpleName());
      try {
        b.setWriteThrough(true);
        b.setReadThrough(true);
        ObjectProperty<String> prop = new ObjectProperty<String>("ABC 123");
        /*
         * This should throw an exception or somehow tell that the
         * property was invalid (wrong type). See #2223.
         */
        b.setPropertyDataSource(prop);
      } catch (Exception e) {
        e.printStackTrace();
      }
    } catch (Exception e1) {
      e1.printStackTrace();
      return;
    }

    if (ok) {
      status.setValue(status.getValue() + " " + class1.getClass().getSimpleName() + "/DB: OK");
    } else {
      status.setValue(status.getValue() + " " + class1.getClass().getSimpleName() + "/DB: FAILED");
    }
  }
  /**
   * Create a Java3D node which does not have a default constructor
   *
   * <p>parameterTypes must contain the classes required by the constructor, use Interger.TYPE,
   * Float.TYPE etc to specifiy primitive types
   *
   * <p>paramters should contain the list of parameters for the constructor, primitive types should
   * be wrapped in the appropriate class (ie Integer, Float )
   */
  protected SceneGraphObject createNode(
      Class j3dClass, Class[] parameterTypes, Object[] parameters) {
    SceneGraphObject ret;
    Constructor constructor;

    try {
      constructor = j3dClass.getConstructor(parameterTypes);
      ret = (SceneGraphObject) constructor.newInstance(parameters);
    } catch (IllegalAccessException e2) {
      throw new SGIORuntimeException(
          "Broken State class for " + j3dClass.getClass().getName() + " - IllegalAccess");
    } catch (InstantiationException e3) {
      throw new SGIORuntimeException("Broken State class for " + j3dClass.getClass().getName());
    } catch (java.lang.reflect.InvocationTargetException e4) {
      throw new SGIORuntimeException(
          "InvocationTargetException for " + j3dClass.getClass().getName());
    } catch (NoSuchMethodException e5) {
      for (int i = 0; i < parameterTypes.length; i++)
        System.err.println(parameterTypes[i].getName());
      System.err.println("------");
      throw new SGIORuntimeException("Invalid constructor for " + j3dClass.getClass().getName());
    }

    return ret;
  }
 /**
  * Creates new entity instance connected with opened database
  *
  * @param <T>
  * @param type The type of the required entity
  * @return New entity instance
  */
 public <T extends ActiveRecordBase> T newEntity(Class<T> type) throws ActiveRecordException {
   T entity = null;
   try {
     entity = type.newInstance();
     entity.setDatabase(m_Database);
   } catch (IllegalAccessException e) {
     throw new ActiveRecordException("Can't instantiate " + type.getClass());
   } catch (InstantiationException e) {
     throw new ActiveRecordException("Can't instantiate " + type.getClass());
   }
   return entity;
 }
Example #5
0
 public void registerEntityType(String suffix, Class<?> entityType) {
   if (entityType.isAssignableFrom(EntityType.class)) {
     entityMapping.put(suffix, entityType);
     if (appName != null) {
       appEntityCache.put(
           entityType,
           CacheManager.getInstance()
               .getCache(appName + "_" + suffix, String.class, entityType.getClass()));
     }
     sysEntityCache.put(
         entityType,
         CacheManager.getInstance().getCache(suffix, String.class, entityType.getClass()));
   }
   throw new IllegalArgumentException("Entity class must extend from EntityType.class");
 }
 /**
  * Method that tries to create specialized type given base type, and a sub-class thereof (which is
  * assumed to use same parametrization as supertype). Similar to calling {@link
  * JavaType#narrowBy(Class)}, but can change underlying {@link JavaType} (from simple to Map, for
  * example), unliked <code>narrowBy</code> which assumes same logical type.
  */
 public static JavaType specialize(JavaType baseType, Class<?> subclass) {
   // Currently only SimpleType instances can become something else
   if (baseType instanceof SimpleType) {
     // and only if subclass is an array, Collection or Map
     if (subclass.isArray()
         || Map.class.isAssignableFrom(subclass)
         || Collection.class.isAssignableFrom(subclass)) {
       // need to assert type compatibility...
       if (!baseType.getRawClass().isAssignableFrom(subclass)) {
         throw new IllegalArgumentException(
             "Class " + subclass.getClass().getName() + " not subtype of " + baseType);
       }
       // this _should_ work, right?
       JavaType subtype = instance._fromClass(subclass, new TypeBindings(baseType.getRawClass()));
       // one more thing: handlers to copy?
       Object h = baseType.getValueHandler();
       if (h != null) {
         subtype.setValueHandler(h);
       }
       h = baseType.getTypeHandler();
       if (h != null) {
         subtype = subtype.withTypeHandler(h);
       }
       return subtype;
     }
   }
   // otherwise regular narrowing should work just fine
   return baseType.narrowBy(subclass);
 }