Beispiel #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;
  }
  /**
   * 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;
  }
  public List<?> distinct(String field) throws Exception {
    assert skip == 0;
    assert limit == 0;
    assert select == null;

    Type toto = store.type.getField(field).getGenericType();
    Class<?> to = store.type.getField(field).getType();
    if (to.isArray()) {
      toto = to.getComponentType();
    } else if (Collection.class.isAssignableFrom(to) && toto instanceof ParameterizedType) {
      toto = ((ParameterizedType) toto).getActualTypeArguments()[0];
    } else if (GenericArrayType.class.isAssignableFrom(to)) {
      toto = ((GenericArrayType) toto).getGenericComponentType();
    }

    List<?> list;

    // Do we have a sub selection? Then use the filter
    // otherwise use the call without where clause
    if (where == null) list = store.collection.distinct(field);
    else list = store.collection.distinct(field, where);

    List<Object> result = new ArrayList<Object>(list.size());
    for (Object o : list) {
      result.add(converter.convert(toto, o));
    }
    return result;
  }
  /** We parse the -runremote and create sessions for each one of them */
  @Override
  public void prepare() throws Exception {
    if (prepared) return;

    prepared = true;

    updateFromProject();

    Map<String, Object> properties = new HashMap<String, Object>(getRunProperties());

    calculatedProperties(properties);

    Collection<String> embeddedActivators = getActivators();
    if (embeddedActivators != null && !embeddedActivators.isEmpty()) {
      properties.put("biz.aQute.remote.embedded", Strings.join(embeddedActivators));
    }

    for (Entry<String, Attrs> entry : runremote.entrySet()) {
      RunRemoteDTO dto = converter.convert(RunRemoteDTO.class, entry.getValue());
      dto.name = entry.getKey();

      Map<String, Object> sessionProperties = new HashMap<String, Object>(properties);
      sessionProperties.putAll(entry.getValue());
      sessionProperties.put("session.name", dto.name);

      if (dto.jmx != null) {
        tryJMXDeploy(dto.jmx, "biz.aQute.remote.agent");
      }

      RunSessionImpl session = new RunSessionImpl(this, dto, properties);
      sessions.add(session);
    }
  }
  @Modified
  void modified(Map<String, Object> map) throws Exception {

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

    current = new State(config.cron("@hourly"), config.duration());
  }
Beispiel #6
0
  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());
      }
  }
 static {
   converter.setFatalIsException(false);
 }