Java Code Examples for org.apache.uima.cas.CASRuntimeException#INAPPROP_RANGE
The following examples show how to use
org.apache.uima.cas.CASRuntimeException#INAPPROP_RANGE .
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: FeatureStructureImplC.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * All 3 checks * @param fi - the feature * @param v - the value */ protected void _setIntValueCJ(FeatureImpl fi, int v) { if (!fi.isInInt) { /** Trying to access value of feature "{0}" as "{1}", but range of feature is "{2}".*/ throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, fi.getName(), "boolean, byte, short, int, or float", fi.getRange().getName()); } if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) _Check_feature_defined_for_this_type(fi); _casView.setWithCheckAndJournal((TOP)this, fi.getCode(), () -> _setIntValueCommon(fi, v)); }
Example 2
Source File: FeatureStructureImplC.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * All 3 checks for long * @param fi - the feature * @param v - the value */ protected void _setLongValueCJ(FeatureImpl fi, long v) { if (!fi.isInInt) { /** Trying to access value of feature "{0}" as "{1}", but range of feature is "{2}".*/ throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, fi.getName(), "long or double", fi.getRange().getName()); } if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) _Check_feature_defined_for_this_type(fi); _casView.setLongValue(this, fi, v); }
Example 3
Source File: FeatureStructureImplC.java From uima-uimaj with Apache License 2.0 | 5 votes |
protected void _setRefValueCJ(FeatureImpl fi, Object v) { if (fi.isInInt) { /** Trying to access value of feature "{0}" as "{1}", but range of feature is "{2}".*/ throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, fi.getName(), "int", fi.getRange().getName()); } if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) _Check_feature_defined_for_this_type(fi); _casView.setWithCheckAndJournal((TOP)this, fi.getCode(), () -> _setRefValueCommon(fi, v)); }
Example 4
Source File: FeatureStructureImplC.java From uima-uimaj with Apache License 2.0 | 5 votes |
private void featureValueValidation(Feature feat, Object v) { TypeImpl range = (TypeImpl)feat.getRange(); if ((range.isArray() && !isOkArray(range, v)) || (!range.isArray() && (!range.subsumesValue(v)))) { throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, feat.getName(), range.getName(), (v == null) ? "null" : v.getClass().getName()); } }
Example 5
Source File: CASImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Handle some unusual backwards compatibility cases * featureCode = 0 - implies getting the type code * feature range is int - normal * feature range is a fs reference, return the id * feature range is a string: add the string if not already present to the string heap, return the int handle. * @param fsRef - * @param featureCode - * @return - */ @Override public final int ll_getIntValue(int fsRef, int featureCode) { TOP fs = getFsFromId_checked(fsRef); if (featureCode == 0) { return fs._getTypeImpl().getCode(); // case where the type is being requested } FeatureImpl fi = getFeatFromCode_checked(featureCode); SlotKind kind = fi.getSlotKind(); switch(kind) { case Slot_HeapRef: return fs.getFeatureValue(fi)._id; case Slot_Boolean: case Slot_Byte: case Slot_Short: case Slot_Int: case Slot_Float: return fs._getIntValueNc(fi); case Slot_StrRef: return getCodeForString(fs._getStringValueNc(fi)); case Slot_LongRef: return getCodeForLong(fs._getLongValueNc(fi)); case Slot_DoubleRef: return getCodeForLong(CASImpl.double2long(fs._getDoubleValueNc(fi))); default: throw new CASRuntimeException( CASRuntimeException.INAPPROP_RANGE, fi.getName(), "int", fi.getRange().getName()); } }
Example 6
Source File: CASImpl.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * Special considerations: * Interface with corruption checking * For backwards compatibility: * handle cases where feature is: * int - normal * 0 - change type code * a ref: treat int as FS "addr" * not an int: handle like v2 where reasonable */ @Override public final void ll_setIntValue(int fsRef, int featureCode, int value) { TOP fs = getFsFromId_checked(fsRef); if (featureCode == 0) { switchFsType(fs, value); return; } FeatureImpl fi = getFeatFromCode_checked(featureCode); if (fs._getTypeImpl().isArray()) { throw new UnsupportedOperationException("ll_setIntValue not permitted to set a feature of an array"); } SlotKind kind = fi.getSlotKind(); switch(kind) { case Slot_HeapRef: if (fi.getCode() == annotBaseSofaFeatCode) { // setting the sofa ref of an annotationBase // can't change this so just verify it's the same TOP sofa = fs.getFeatureValue(fi); if (sofa._id != value) { throw new UnsupportedOperationException("ll_setIntValue not permitted to change a sofaRef feature"); } return; // if the same, just ignore, already set } TOP ref = fs._casView.getFsFromId_checked(value); fs.setFeatureValue(fi, ref); // does the right feature check, too return; case Slot_Boolean: case Slot_Byte: case Slot_Short: case Slot_Int: case Slot_Float: fs._setIntValueCJ(fi, value); break; case Slot_StrRef: String s = getStringForCode(value); if (s == null && value != 0) { Misc.internalError(new Exception("ll_setIntValue got null string for non-0 handle: " + value)); } fs._setRefValueNfcCJ(fi, getStringForCode(value)); break; case Slot_LongRef: case Slot_DoubleRef: Long lng = getLongForCode(value); if (lng == null) { Misc.internalError(new Exception("ll_setIntValue got null Long/Double for handle: " + value)); } fs._setLongValueNfcCJ(fi, lng); break; default: CASRuntimeException e = new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, fi.getName(), "int", fi.getRange().getName()); // System.err.println("debug " + e); throw e; } }
Example 7
Source File: FeatureStructureImplC.java From uima-uimaj with Apache License 2.0 | 3 votes |
/************************************** * S E T T E R S * 4 levels of checking: * - check feature for validity (fv) * -- this is skipped with feature comes from fs type info (internal calls) * - check for setting something which could corrupt indexes (ci) * -- this is skipped when the caller knows * --- the FS is not in the index, perhaps because they just created it * -- skipped when the range is not a valid index key * - check for needing to log (journal) setting (jrnl) * -- this is skipped when the caller knows * --- no journalling is enabled or * --- the FS is a new (above-the-line) FS * - check the value is suitable * -- this can be skipped if Java is doing the checking (via the type of the argument) * -- done for string subtypes and Feature References * --- skipped if the caller knows the value is OK (e.g., it is copying an existing FS) * * The jrnl and ic checks require the FeatureImpl. * For setters using these checks, there are two versions: * - one with the arg being the FeatureImpl (if it is available at the caller) and * - one with the int offset (common code coverts this to the Feature Impl). * * all 4 checks are normally done by the standard API call in the FeatureStructure interface * setXyzValue(Feature, value) * * Besides the standard API call, other setter methods have suffixes and prefixes to the setter name * - prefix is "_" to avoid conflicting with existing other names * - suffixes are: * -- Nfc: skip feature validity checking, ( ! fv, jrnl, ci ) (int/Feat) * -- NcNj: implies Nfc, ( ! fv, ! jrnl, ! ci ) (int/Feat) * -- NcWj: implies Nfc, ( ! fv, jrnl, ! ci ) (int) * The is for setters where value checking might be needed (i.e., Java checking isn't sufficient) * -- NcNjNv: implies Nfc, skips all checks * * For JCas setters: convert offset to feature **************************************/ private void checkFeatRange(Feature feat, String shortRangeName) { if ( ! (feat.getRange().getShortName().equals(shortRangeName))) { /*Trying to access value of feature "{0}" as "{1}", but range of feature is "{2}".*/ throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, feat.getName(), "uima.cas." + shortRangeName, feat.getRange().getName()); } }