예제 #1
0
  public C parse(C commandInstance, String... args) {
    Preconditions.checkNotNull(args, "args is null");

    Parser parser = new Parser(metadata);
    ParseState state = parser.parse(args);

    CommandMetadata command = MetadataLoader.loadCommand(commandInstance.getClass());

    state = state.withCommand(command);

    validate(state);

    ImmutableMap.Builder<Class<?>, Object> bindings =
        ImmutableMap.<Class<?>, Object>builder().put(GlobalMetadata.class, metadata);

    if (state.getGroup() != null) {
      bindings.put(CommandGroupMetadata.class, state.getGroup());
    }

    bindings.put(CommandMetadata.class, command);

    C c =
        (C)
            ParserUtil.injectOptions(
                commandInstance,
                command.getAllOptions(),
                state.getParsedOptions(),
                command.getArguments(),
                state.getParsedArguments(),
                command.getMetadataInjections(),
                bindings.build());

    return c;
  }
 @SuppressWarnings("unchecked")
 public <C extends MLNNamedObject> C addMlnNamedObject(C mlnNamedObject) {
   C obj = (C) getForNameNoCreation(mlnNamedObject.getClass(), mlnNamedObject.getName());
   if (obj == null) {
     mlnNamedObjects.get(mlnNamedObject.getClass()).put(mlnNamedObject.getName(), mlnNamedObject);
     return mlnNamedObject;
   } else {
     // Note: The existing version of a named MLN object is the one that is kept in the new model.
     try {
       if ((!mlnNamedObject.isUnspecified()) && obj.isUnspecified()) {
         BeanUtils.copyProperties(obj, mlnNamedObject);
       }
     } catch (IllegalAccessException e) {
       e.printStackTrace();
     } catch (InvocationTargetException e) {
       e.printStackTrace();
     }
     return obj;
   }
 }
 public <C extends MLNObject> C addMlnObject(C mlnObject) {
   MLNFormula formula;
   if (mlnObject instanceof MLNFormula) {
     formula = (MLNFormula) mlnObject;
     if (formula.getProbabilityWeight() != null || formula.getUtilityWeight() != null) {
       weightedFormulas.add(formula);
     }
     if (formula.getPlainFormula().getQuantification() != null) quantifiedFormulas.add(formula);
   }
   mlnUnnamedObjects.get(mlnObject.getClass()).add(mlnObject);
   return mlnObject;
 }
예제 #4
0
 public String entitySilentWake(C entity, boolean silent) {
   try {
     Method m = entity.getClass().getMethod("setSleeping", Boolean.class);
     Utils.callMethod(m, "réactivation de la donnée", entity, false);
   } catch (NoSuchMethodException ex) {
     ApplicationLogger.writeError(
         "La méthode \"setSleeping\" n'a pas"
             + " été trouvée pour la classe \""
             + this.entityClass.getName()
             + "\"",
         ex);
   }
   this.entityFacade.editSilent(entity, silent);
   return this.webFolder + "list";
 }
예제 #5
0
 public boolean setEntityFilePath(FilePath filePath) {
   try {
     Method m = entity.getClass().getMethod("setIdFilePath", FilePath.class);
     Utils.callMethod(m, "définition du répertoire de stockage", entity, filePath);
     return true;
   } catch (NoSuchMethodException ex) {
     ApplicationLogger.writeError(
         "La méthode \"setIdFilePath\" n'a pas"
             + " été trouvée pour la classe \""
             + this.entityClass.getName()
             + "\"",
         null);
   }
   return false;
 }
예제 #6
0
    /**
     * @see org.apache.wicket.util.convert.IConverter#convertToString(java.lang.Object,
     *     java.util.Locale)
     */
    @Override
    public String convertToString(C value, Locale locale) {
      if (value == null || "".equals(value)) {
        return "";
      }

      try {
        return Objects.convertValue(value, String.class);
      } catch (RuntimeException e) {
        throw new ConversionException(
                "Could not convert object of type: "
                    + value.getClass()
                    + " to string. Possible its #toString() returned null. "
                    + "Either install a custom converter (see IConverterLocator) or "
                    + "override #toString() to return a non-null value.",
                e)
            .setSourceValue(value)
            .setConverter(this);
      }
    }
  /**
   * Adds {@link SecurityConfigurer} ensuring that it is allowed and invoking {@link
   * SecurityConfigurer#init(SecurityBuilder)} immediately if necessary.
   *
   * @param configurer the {@link SecurityConfigurer} to add
   * @throws Exception if an error occurs
   */
  @SuppressWarnings("unchecked")
  private <C extends SecurityConfigurer<O, B>> void add(C configurer) throws Exception {
    Assert.notNull(configurer, "configurer cannot be null");

    Class<? extends SecurityConfigurer<O, B>> clazz =
        (Class<? extends SecurityConfigurer<O, B>>) configurer.getClass();
    synchronized (configurers) {
      if (buildState.isConfigured()) {
        throw new IllegalStateException("Cannot apply " + configurer + " to already built object");
      }
      List<SecurityConfigurer<O, B>> configs =
          allowConfigurersOfSameType ? this.configurers.get(clazz) : null;
      if (configs == null) {
        configs = new ArrayList<SecurityConfigurer<O, B>>(1);
      }
      configs.add(configurer);
      this.configurers.put(clazz, configs);
      if (buildState.isInitializing()) {
        this.configurersAddedInInitializing.add(configurer);
      }
    }
  }
예제 #8
0
  public static void main(String... args) throws IOException {
    try (FileOutputStream outputStream = new FileOutputStream("c:/output.txt");
        InputStream is =
            Solution.class.getClassLoader().getResourceAsStream("/user/resources/avatar.gif"); ) {;
      byte[] b = new byte[is.available()];
      outputStream.write(is.read(b));

      int value = 123_456_789;
      System.out.println(value);

      Example result = null;
      String s = "a";
      switch (s) {
        case "a":
          {
            result = new Solution().new A();
            break;
          }
        case "b":
          {
            result = new Solution().new B();
            break;
          }
        case "c":
          {
            result = new Solution().new C();
            break;
          }
      }

      if (result instanceof C) {
        C p = (C) result;
        System.out.println(p.getClass().getSimpleName());
      }

    } catch (IOException e) {
    }
  }
 private <C extends Collection<E>, E> C _convertContents(C collection, Class<E> elementClass) {
   return _convertContents(collection, (Class<C>) ((Class) collection.getClass()), elementClass);
 }
예제 #10
0
 public Tester(C container, List<Test<C>> tests) {
   this.container = container;
   this.tests = tests;
   if (container != null) headline = container.getClass().getSimpleName();
 }