Java Class Examples

Java Class - 30 examples found. These are the top rated real world Java examples of Class extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 private static void initFields(Class<?> clazz) {
   Field[] srcFields = clazz.getDeclaredFields();
   for (Field field : srcFields) {
     Log.d(TAG, "modify " + clazz.getName() + "." + field.getName() + " flag:");
     setFieldFlag(field);
   }
 }
  @Override
  public void afterCompletion(
      HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
      throws Exception {
    if (ex == null) {
      return;
    }

    if (excludedExceptions.contains(ex.getClass())) {
      return;
    }
    for (Class<? extends Exception> excludedException : excludedExceptions) {
      if (excludedException.isInstance(ex)) {
        return;
      }
    }

    if (handler instanceof HandlerMethod) {
      HandlerMethod handlerMethod = (HandlerMethod) handler;
      Logger controllerLogger = Logger.getLogger(handlerMethod.getBeanType());
      controllerLogger.error(String.format("uncaught exception from %s", handlerMethod), ex);
    } else {
      logger.error(
          String.format("uncaught exception from a handler of unknown type: %s", handler), ex);
    }
  }
  protected void processConfigurationClass(ConfigurationClass configClass) throws IOException {
    AnnotationMetadata metadata = configClass.getMetadata();
    if (this.environment != null && ProfileHelper.isProfileAnnotationPresent(metadata)) {
      if (!this.environment.acceptsProfiles(ProfileHelper.getCandidateProfiles(metadata))) {
        return;
      }
    }

    while (metadata != null) {
      doProcessConfigurationClass(configClass, metadata);
      String superClassName = metadata.getSuperClassName();
      if (superClassName != null && !Object.class.getName().equals(superClassName)) {
        if (metadata instanceof StandardAnnotationMetadata) {
          Class<?> clazz = ((StandardAnnotationMetadata) metadata).getIntrospectedClass();
          metadata = new StandardAnnotationMetadata(clazz.getSuperclass());
        } else {
          MetadataReader reader = this.metadataReaderFactory.getMetadataReader(superClassName);
          metadata = reader.getAnnotationMetadata();
        }
      } else {
        metadata = null;
      }
    }
    if (this.configurationClasses.contains(configClass) && configClass.getBeanName() != null) {
      // Explicit bean definition found, probably replacing an import.
      // Let's remove the old one and go with the new one.
      this.configurationClasses.remove(configClass);
    }

    this.configurationClasses.add(configClass);
  }
  private static void checkMongoClient(
      Configuration configuration, Class<?> mappedClass, String clientName, String dbName) {
    Configuration mongodbClientConfiguration =
        getMongoClientConfiguration(configuration, clientName);

    if (mongodbClientConfiguration.isEmpty()) {
      throw SeedException.createNew(MongoDbErrorCodes.UNKNOWN_CLIENT_SPECIFIED)
          .put("aggregate", mappedClass.getName())
          .put("clientName", clientName)
          .put("dbName", dbName);
    }

    boolean async = mongodbClientConfiguration.getBoolean("async", false);
    if (async) {
      throw SeedException.createNew(MorphiaErrorCodes.ERROR_ASYNC_CLIENT)
          .put("aggregate", mappedClass.getName())
          .put("clientName", clientName)
          .put("dbName", dbName);
    }

    String[] dbNames = mongodbClientConfiguration.getStringArray("databases");
    boolean found = false;
    for (String nameToCheck : dbNames) {
      if (nameToCheck.equals(resolveDatabaseAlias(mongodbClientConfiguration, dbName))) {
        found = true;
        break;
      }
    }
    if (!found) {
      throw SeedException.createNew(MorphiaErrorCodes.UNKNOW_DATABASE_NAME)
          .put("aggregate", mappedClass.getName())
          .put("clientName", clientName)
          .put("dbName", dbName);
    }
  }
Example #5
0
  private static RetryPolicy instantiateRetryPolicy(
      String policyClassName, Object[] args, String raw) throws Exception {

    Class<?> policyClass = Class.forName(policyClassName);

    for (Constructor<?> con : policyClass.getConstructors()) {
      Class<?>[] parameterClasses = con.getParameterTypes();
      if (args.length == parameterClasses.length) {
        boolean allInts = true;
        for (Class<?> pc : parameterClasses) {
          if (!pc.equals(int.class)) {
            allInts = false;
            break;
          }
        }

        if (!allInts) {
          break;
        }

        log.debug("About to instantiate class {} with {} arguments", con.toString(), args.length);

        return (RetryPolicy) con.newInstance(args);
      }
    }

    throw new Exception(
        "Failed to identify a class matching the Astyanax Retry Policy config string \""
            + raw
            + "\"");
  }
Example #6
0
 public <T extends AbstractTask> T createTask(Class<T> type, Project project, String name) {
   Task task =
       TASK_FACTORY.createTask(
           (ProjectInternal) project, GUtil.map(Task.TASK_TYPE, type, Task.TASK_NAME, name));
   assertTrue(type.isAssignableFrom(task.getClass()));
   return type.cast(task);
 }