Example #1
0
  /**
   * 填充模型对象
   *
   * @param cursor
   * @param m
   */
  private void fillField(Cursor cursor, M m) {
    Field[] fields = m.getClass().getDeclaredFields();
    for (Field item : fields) {
      item.setAccessible(true);
      Column column = item.getAnnotation(Column.class);
      if (column != null) {
        int columnIndex = cursor.getColumnIndex(column.value());
        String value = cursor.getString(columnIndex);

        try {

          if (item.getType() == int.class) {
            item.set(m, Integer.valueOf(value));
          } else if (item.getType() == long.class) {
            item.set(m, Long.valueOf(value));
          } else {
            item.set(m, value);
          }

        } catch (IllegalAccessException e) {
          e.printStackTrace();
        } catch (IllegalArgumentException e) {
          e.printStackTrace();
        }
      }
    }
  }
Example #2
0
  /**
   * 模型对象转化为ContentValues对象
   *
   * @param m
   * @param values
   */
  private void fillColumn(M m, ContentValues values) {
    Field[] fields = m.getClass().getDeclaredFields();
    for (Field item : fields) {
      item.setAccessible(true);

      Column column = item.getAnnotation(Column.class);
      if (column != null) {
        String key = column.value();

        try {

          String value = item.get(m).toString();

          if (value.length() > 0) {
            values.put(key, value);
          }

        } catch (IllegalAccessException e) {
          e.printStackTrace();
        } catch (IllegalArgumentException e) {
          e.printStackTrace();
        }
      }
    }
  }
Example #3
0
  /**
   * 获取表名
   *
   * @return
   */
  private String getTableName() {
    M m = getInstantce();

    TableName tableName = m.getClass().getAnnotation(TableName.class);
    if (tableName != null) {
      return tableName.value();
    }
    return "";
  }
Example #4
0
 private <M extends Object & PPSReportColumnService> boolean serviceEnabled(M service) {
   RunIfEnabled runIfEnabled = service.getClass().getAnnotation(RunIfEnabled.class);
   if (runIfEnabled == null) {
     return true;
   }
   for (String pluginIdentifier : runIfEnabled.value()) {
     if (!PluginUtils.isEnabled(pluginIdentifier)) {
       return false;
     }
   }
   return true;
 }
Example #5
0
 @Override
 public <G1, G2> void putToJSON(
     Class<M> valType,
     Class<G1> genericArg1,
     Class<G2> genericArg2,
     JSONObject obj,
     String key,
     M val)
     throws Exception {
   Class<M> cls = (Class<M>) val.getClass();
   JSONObject valStr = ((JSONSerializer<M>) getJSONSerializer(cls, null)).serialize(val);
   obj.put(key, valStr);
 }
 /**
  * Converts the message to raw bytes, and caches the converted value.
  *
  * @return converted value, which may be null in case of null message or error.
  */
 private byte[] serialize() {
   if (messageBytes == null && message != null) {
     checkConverter();
     messageBytes = converter.toBytes(message);
     if (messageBytes == null) {
       // should we throw an IOException instead?
       LOG.warn("Could not serialize " + message.getClass());
     } else {
       message = null; // so that message and messageBytes don't go out of
       // sync.
     }
   }
   return messageBytes;
 }
Example #7
0
  /**
   * Convert The url of fxml files to allow local and path loading.
   *
   * @param model the model class that will be used for relative loading
   * @param fxmlPath the path of the fxml file (relative or absolute)
   * @return the FXML file URL
   * @param <M> the model type that will manage this fxml node
   */
  private static <M extends Model> URL convertFxmlUrl(final M model, final String fxmlPath) {
    URL fxmlUrl = null;
    // Replace all '.' separator by path separator '/'
    if (model != null) {
      // Try to load the resource from the same path as the model class
      fxmlUrl = model.getClass().getResource(fxmlPath);
    }
    if (fxmlUrl == null) {
      // Try to load the resource from the full path org/jrebirth/core/ui/Test.fxml
      fxmlUrl = Thread.currentThread().getContextClassLoader().getResource(fxmlPath);
    }

    return fxmlUrl;
  }
Example #8
0
  /**
   * 获取主键
   *
   * @param m
   * @return
   */
  private String getId(M m) {

    Field[] fields = m.getClass().getDeclaredFields();
    for (Field item : fields) {
      item.setAccessible(true);
      ID id = item.getAnnotation(ID.class);

      if (id != null) {

        try {

          return item.get(m).toString();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        } catch (IllegalArgumentException e) {
          e.printStackTrace();
        }
      }
    }

    return "";
  }
 private <K, V, M extends Map<K, V>> M _convertContents(
     M map, Class<K> keyClass, Class<V> valueClass) {
   return _convertContents(map, (Class<M>) ((Class) map.getClass()), keyClass, valueClass);
 }
 public <M extends com.opengamma.language.connector.Custom> T1 visit(
     final M message, final T2 data) {
   return this.<CustomMessageVisitor<M, T1, T2>>getVisitor(message.getClass())
       .visit(message, data);
 }