/**
   * Converts the argument(s) to the target type (specified by {@code MappedFieldPath}) and then to
   * a Mongo object.
   *
   * @param arguments Single or multiple arguments in a list.
   * @param mfp The mapped field path.
   * @param singleValue Whether a single argument is expected.
   * @return An argument(s) converted to Mongo value.
   * @throws cz.jirutka.rsql.mongodb.morphia.RSQLArgumentFormatException
   */
  protected Object convertToMappedValue(
      List<String> arguments, MappedFieldPath mfp, boolean singleValue) {

    Object value =
        singleValue
            ? converter.convert(arguments.get(0), mfp.getTargetValueType())
            : converter.convert(arguments, mfp.getTargetValueType());

    return mapper.toMongoObject(mfp.getMappedField(), null, value);
  }
예제 #2
0
파일: IOFacade.java 프로젝트: elazarg/tvla
  /**
   * Prints a strucutre with an associated message. If the message stream is not null, output is
   * directed to the messagfe stream. Otherwise, it is printed into the outputstream.
   */
  public void printStrucutreWithMessages(String header, Object tvs, Collection messages) {
    for (Iterator i = implementations.values().iterator(); i.hasNext(); ) {
      ImplementationsBundle bundle = (ImplementationsBundle) i.next();

      ///////////
      PrintStream printTo = null;
      StringConverter c = bundle.structureConverter;
      if (c != null) {
        if (bundle.messagesEnabled) printTo = bundle.messagesStream;
        else if (bundle.outputEnabled) printTo = bundle.outputStream;
      }

      if (printTo == null) continue;

      StringBuffer msgs = new StringBuffer(header + ": ");
      Iterator messagesItr = messages.iterator();

      int msgNum = 1;
      while (messagesItr.hasNext()) {
        String msg = (String) messagesItr.next();
        msgs.append(StringUtils.newLine + msgNum + ". " + msg);
        msgNum++;
      }

      // print the structure with the accompnied messages to the messages stream
      //    String quotedMsgs = c.quote(msgs.toString());
      String tvsWithMessages = c.convert(tvs, msgs.toString());
      printTo.println(tvsWithMessages);
      messages = null; // Opportunity for compile-time GC.
    }
  }
예제 #3
0
파일: IOFacade.java 프로젝트: elazarg/tvla
 public void printVocabulary() {
   for (Iterator i = implementations.values().iterator(); i.hasNext(); ) {
     ImplementationsBundle bundle = (ImplementationsBundle) i.next();
     StringConverter c = bundle.vocabularyConverter;
     if (bundle.outputEnabled && c != null) {
       String converted = c.convert(null);
       bundle.outputStream.println(converted);
     }
   }
 }
예제 #4
0
파일: IOFacade.java 프로젝트: elazarg/tvla
 /**
  * Prints a structure to all desired outputs.
  *
  * @param structure A TVS.
  * @param header An optional header.
  */
 protected void printStructure(Object structure, String header, String breachedHeader) {
   for (Iterator i = implementations.values().iterator(); i.hasNext(); ) {
     ImplementationsBundle bundle = (ImplementationsBundle) i.next();
     StringConverter c = bundle.structureConverter;
     if (bundle.outputEnabled && c != null) {
       String converted = c.convert(structure, header);
       bundle.outputStream.println(converted);
     }
   }
 }
예제 #5
0
파일: IOFacade.java 프로젝트: elazarg/tvla
  /** Prints general information, such as the TVLA version, to all output files. */
  private void printHeader() {
    String version =
        new PropertiesEx("/tvla/version.properties").getProperty("version", "Unknown TVLA version");
    String header = version;

    for (Iterator i = implementations.values().iterator(); i.hasNext(); ) {
      ImplementationsBundle bundle = (ImplementationsBundle) i.next();
      StringConverter c = bundle.commentConverter;
      if (bundle.outputEnabled && c != null) {
        String convertedHeader = c.convert(header);
        bundle.outputStream.println(convertedHeader);
      }
    }
  }