예제 #1
0
  /**
   * Return a native data type that represents the dropped object
   *
   * <pre>
   *    URLTransfer             URI
   *    FileTransfer            File[]
   *    TextTransfer            String
   *    ImageTransfer           ImageData
   * </pre>
   *
   * @param data the dropped object
   * @return a native data type that represents the dropped object, or null when the data type is
   *     unknown
   * @throws Exception upon error
   */
  Object toJava(TransferData data) throws Exception {
    if (URLTransfer.getInstance().isSupportedType(data))
      return Converter.cnv(URI.class, URLTransfer.getInstance().nativeToJava(data));
    else if (FileTransfer.getInstance().isSupportedType(data)) {
      return Converter.cnv(File[].class, FileTransfer.getInstance().nativeToJava(data));
    } else if (TextTransfer.getInstance().isSupportedType(data)) {
      return TextTransfer.getInstance().nativeToJava(data);
    }
    // Need to write the transfer code since the ImageTransfer turns it into
    // something very Eclipsy
    //        else if (ImageTransfer.getInstance().isSupportedType(data))
    //            return ImageTransfer.getInstance().nativeToJava(data);

    return null;
  }
예제 #2
0
  /**
   * Copy from the copy method in StructUtil. Did not want to drag that code in. maybe this actually
   * should go to struct.
   *
   * @param from
   * @param to
   * @param excludes
   * @return
   * @throws Exception
   */
  public static <T extends struct> T xcopy(struct from, T to, String... excludes) throws Exception {
    Arrays.sort(excludes);
    for (Field f : from.fields()) {
      if (Arrays.binarySearch(excludes, f.getName()) >= 0) continue;

      Object o = f.get(from);
      if (o == null) continue;

      Field tof = to.getField(f.getName());
      if (tof != null)
        try {
          tof.set(to, Converter.cnv(tof.getGenericType(), o));
        } catch (Exception e) {
          System.out.println(
              "Failed to convert "
                  + f.getName()
                  + " from "
                  + from.getClass()
                  + " to "
                  + to.getClass()
                  + " value "
                  + o
                  + " exception "
                  + e);
        }
    }

    return to;
  }
예제 #3
0
  @Modified
  void modified(Map<String, Object> map) throws Exception {

    config = Converter.cnv(ScheduleConfig.class, map);
    cancel();

    current = new State(config.cron("@hourly"), config.duration());
  }
예제 #4
0
파일: CapReqBuilder.java 프로젝트: kwin/bnd
  public CapReqBuilder addAttribute(String name, Object value) throws Exception {
    if (value == null) return this;

    if (value.getClass().isArray()) {
      value = Converter.cnv(List.class, value);
    }

    if ("version".equals(name)) {
      value = toVersions(value);
    }

    attributes.put(name, value);
    return this;
  }
  /**
   * Called when a change in the IDE is detected. We will then upate from the project and then
   * update the remote framework.
   */
  @Override
  public void update() throws Exception {
    updateFromProject();

    Parameters runremote = new Parameters(getProject().getProperty(Constants.RUNREMOTE));

    for (RunSessionImpl session : sessions)
      try {
        Attrs attrs = runremote.get(session.getName());
        RunRemoteDTO dto = Converter.cnv(RunRemoteDTO.class, attrs);
        session.update(dto);
      } catch (Exception e) {
        getProject().exception(e, "Failed to update session %s", session.getName());
      }
  }