Java Code Examples for org.apache.uima.jcas.cas.Sofa#setMimeType()

The following examples show how to use org.apache.uima.jcas.cas.Sofa#setMimeType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BinaryCasSerDes.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param fs
 * @param feat
 * @param s
 * @param fixups4forwardFsRefs
 * @return true if caller needs to do an appropriate fs._setStringValue...
 */
private boolean updateStringFeature(TOP fs, FeatureImpl feat, String s, List<Runnable> fixups4forwardFsRefs) {
  if (null == s) {
    return false;  // null is the default value, no need to set it
  }
  if (fs instanceof Sofa) {
    if (feat == tsi.sofaId) {
      return false;  // do nothing, this value was already used
    }
    Sofa sofa = (Sofa)fs;
    if (feat == tsi.sofaMime) {
      sofa.setMimeType(s);
      return false;
    }
    if (feat == tsi.sofaUri) {
      sofa.setRemoteSofaURI(s);
      return false;
    }
    if (feat == tsi.sofaString) {
      if (fixups4forwardFsRefs != null) {
        // has to be deferred because it updates docAnnot which might not be deser yet.
        //   TODO no longer needed, calls the version which doesn't update docAnnot 9/2017
        Sofa capturedSofa = sofa;
        String capturedString = s;
        fixups4forwardFsRefs.add(() -> capturedSofa.setLocalSofaDataNoDocAnnotUpdate(capturedString));
      } else {
        sofa.setLocalSofaData(s);
      }
      return false;
    }
  }
  return true; //    fs._setStringValueNcNj(feat, s);
}
 
Example 2
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
   * Supports setting slots to "0" for null values
   * @param fs The feature structure to update
   * @param feat the feature to update-
   * @param s the string representation of the value, could be null
   */
  public static void setFeatureValueFromString(FeatureStructureImplC fs, FeatureImpl feat, String s) {
    final TypeImpl range = feat.getRangeImpl();
    if (fs instanceof Sofa) {
      // sofa has special setters
      Sofa sofa = (Sofa) fs;
      switch (feat.getCode()) {
      case sofaMimeFeatCode : sofa.setMimeType(s); break;
      case sofaStringFeatCode: sofa.setLocalSofaData(s); break;
      case sofaUriFeatCode: sofa.setRemoteSofaURI(s); break;
      default: // left empty - ignore trying to set final fields
      }
      return;
    }
    
    if (feat.isInInt) {
      switch (range.getCode()) {
      case floatTypeCode :   fs.setFloatValue(feat, (s == null) ? 0F : Float.parseFloat(s)); break;
      case booleanTypeCode : fs.setBooleanValue(feat, (s == null) ? false : Boolean.parseBoolean(s)); break;
      case longTypeCode :    fs.setLongValue(feat, (s == null) ? 0L : Long.parseLong(s)); break;
      case doubleTypeCode :  fs.setDoubleValue(feat, (s == null) ? 0D : Double.parseDouble(s)); break;
      case byteTypeCode :  fs.setByteValue(feat, (s == null) ? 0 : Byte.parseByte(s)); break;
      case shortTypeCode :  fs.setShortValue(feat, (s == null) ? 0 : Short.parseShort(s)); break;
      case intTypeCode :  fs.setIntValue(feat, (s == null) ? 0 : Integer.parseInt(s)); break;
      default:                              fs.setIntValue(feat, (s == null) ? 0 : Integer.parseInt(s));
      }
    } else if (range.isRefType) {
      if (s == null) {
        fs.setFeatureValue(feat,  null);
      } else {
        // Setting a reference value "{0}" from a string is not supported. 
        throw new CASRuntimeException(CASRuntimeException.SET_REF_FROM_STRING_NOT_SUPPORTED, feat.getName());
      }
    } else if (range.isStringOrStringSubtype()) {  // includes TypeImplSubString
      // is String or Substring
      fs.setStringValue(feat, (s == null) ? null : s);
//    } else if (range == getTypeSystemImpl().javaObjectType) {
//      fs.setJavaObjectValue(feat, (s == null) ? null : deserializeJavaObject(s));
    } else {
      Misc.internalError();
    }    
  }