/*
Note: UtilEvalError here comes from lhs.getValue().
A Variable can represent an LHS for the case of an imported class or
object field.
485383
Object getValue()
        throws UtilEvalError
    {
        if ( lhs != null )
            return type == null ?
                lhs.getValue() : Primitive.wrap( lhs.getValue(), type );

        return value;
    }
279397
private Object consumeNextObjectField(
        CallStack callstack, Interpreter interpreter,
        boolean forceClass, boolean autoAllocateThis )
        throws UtilEvalError
    {
        /*
            Is it a simple variable name?
            Doing this first gives the correct Java precedence for vars
            vs. imported class names (at least in the simple case - see
            tests/precedence1.bsh).  It should also speed things up a bit.
        */
        if ( evalBaseObject == null && !isCompound(evalName) && !forceClass ) {
            Object obj = resolveThisFieldReference(
                callstack, namespace, interpreter, evalName, false );

            if ( obj != Primitive.VOID )
                return completeRound( evalName, FINISHED, obj );
        }

        /*
            Is it a bsh script variable reference?
            If we're just starting the eval of name (no base object)
            or we're evaluating relative to a This type reference check.
        */
        String varName = prefix(evalName, 1);
        if ( ( evalBaseObject == null || evalBaseObject instanceof This  )
            && !forceClass )
        {
            Object obj;
            // switch namespace and special var visibility
            if ( evalBaseObject == null ) {
                obj = resolveThisFieldReference(
                    callstack, namespace, interpreter, varName, false );
            } else {
                obj = resolveThisFieldReference(
                    callstack, ((This)evalBaseObject).namespace,
                    interpreter, varName, true );
            }

            if ( obj != Primitive.VOID )
            {
                // Resolved the variable
                return completeRound( varName, suffix(evalName), obj );
            }
        }

        /*
            Is it a class name?
            If we're just starting eval of name try to make it, else fail.
        */
        if ( evalBaseObject == null )
        {
            Interpreter.debug( "trying class: ", evalName);

            /*
                Keep adding parts until we have a class
            */
            Class clas = null;
            int i = 1;
            String className = null;
            for(; i <= countParts(evalName); i++)
            {
                className = prefix(evalName, i);
                if ( (clas = namespace.getClass(className)) != null )
                    break;
            }

            if ( clas != null )  {
                return completeRound(
                    className,
                    suffix( evalName, countParts(evalName)-i ),
                    new ClassIdentifier(clas)
                );
            }
            // not a class (or variable per above)
            Interpreter.debug( "not a class, trying var prefix ", evalName );
        }

        // No variable or class found in 'this' type ref.
        // if autoAllocateThis then create one; a child 'this'.
        if ( ( evalBaseObject == null || evalBaseObject instanceof This  )
            && !forceClass && autoAllocateThis )
        {
            NameSpace targetNameSpace =
                ( evalBaseObject == null ) ?
                    namespace : ((This)evalBaseObject).namespace;
            Object obj = new NameSpace(
                targetNameSpace, "auto: "+varName ).getThis( interpreter );
            targetNameSpace.setVariable( varName, obj, false, evalBaseObject == null );
            return completeRound( varName, suffix(evalName), obj );
        }

        /*
            If we didn't find a class or variable name (or prefix) above
            there are two possibilities:

            - If we are a simple name then we can check if we are an imported
              property or pass as a void variable reference.
            - If we are compound then we must fail at this point.
        */
        if ( evalBaseObject == null ) {
            if ( !isCompound(evalName) ) {
                Object obj = namespace.getPropertyValue(varName, interpreter);
                return completeRound( evalName, FINISHED, obj );
            } else
                throw new UtilEvalError(
                    "Class or variable not found: " + evalName);
        }

        /*
            --------------------------------------------------------
            After this point we're definitely evaluating relative to
            a base object.
            --------------------------------------------------------
        */

        /*
            Do some basic validity checks.
        */

        if ( evalBaseObject == Primitive.NULL) // previous round produced null
            throw new UtilTargetError( new NullPointerException(
                "Null Pointer while evaluating: " +value ) );

        if ( evalBaseObject == Primitive.VOID) // previous round produced void
            throw new UtilEvalError(
                "Undefined variable or class name while evaluating: "+value);

        if ( evalBaseObject instanceof Primitive)
            throw new UtilEvalError("Can't treat primitive like an object. "+
            "Error while evaluating: "+value);

        /*
            Resolve relative to a class type
            static field, inner class, ?
        */
        if ( evalBaseObject instanceof ClassIdentifier )
        {
            Class clas = ((ClassIdentifier)evalBaseObject).getTargetClass();
            String field = prefix(evalName, 1);

            // Class qualified 'this' reference from inner class.
            // e.g. 'MyOuterClass.this'
            if ( field.equals("this") )
            {
                // find the enclosing class instance space of the class name
                NameSpace ns = namespace;
                while ( ns != null )
                {
                    // getClassInstance() throws exception if not there
                    if ( ns.classInstance != null
                        && ns.classInstance.getClass() == clas
                    )
                        return completeRound(
                            field, suffix(evalName), ns.classInstance );
                    ns=ns.getParent();
                }
                throw new UtilEvalError(
                    "Can't find enclosing 'this' instance of class: "+clas);
            }

            Object obj = null;
            // static field?
            try {
                Interpreter.debug("Name call to getStaticFieldValue, class: ",
                        clas, ", field:", field);
                obj = Reflect.getStaticFieldValue(clas, field);
            } catch( ReflectError e ) {
                Interpreter.debug("field reflect error: ", e);
            }

            // inner class?
            if ( obj == null ) {
                String iclass = clas.getName()+"$"+field;
                Class c = namespace.getClass( iclass );

                if (null == namespace.classInstance
                        && Reflect.isGeneratedClass(c)
                        && !Reflect.getClassModifiers(c).hasModifier("static"))
                    throw new UtilEvalError("an enclosing instance that contains "
                            + clas.getName() + "." + field + " is required");

                if ( c != null )
                    obj = new ClassIdentifier(c);
            }

            // static bean property
            if ( obj == null )
                obj = Reflect.getObjectProperty(clas, field);

            return completeRound( field, suffix(evalName), obj );
        }

        /*
            If we've fallen through here we are no longer resolving to
            a class type.
        */
        if ( forceClass )
            throw new UtilEvalError(
                value +" does not resolve to a class name." );

        /*
            Some kind of field access?
        */

        String field = prefix(evalName, 1);

        // length access on array?
        if ( field.equals("length") && evalBaseObject.getClass().isArray() )
        {
            Object obj = new Primitive(Array.getLength(evalBaseObject));
            return completeRound( field, suffix(evalName), obj );
        }

        // Check for field on object
        // Note: could eliminate throwing the exception somehow
        try {
            Object obj = Reflect.getObjectFieldValue(evalBaseObject, field);
            return completeRound( field, suffix(evalName), obj );
        } catch(ReflectError e) { /* not a field */ }

        Object obj = Reflect.getObjectProperty(evalBaseObject, field);
        return completeRound( field, suffix(evalName), obj );

    }
834468
private _ValueReferenceWrapper getValueReference(
            final ValueExpression valueExpression, final FacesContext context)
    {
        ELContext elCtx = context.getELContext();
        if (_ExternalSpecifications.isUnifiedELAvailable())
        {
            // unified el 2.2 is available --> we can use ValueExpression.getValueReference()
            // we can't access ValueExpression.getValueReference() directly here, because
            // Class loading would fail in applications with el-api versions prior to 2.2
            _ValueReferenceWrapper wrapper = _BeanValidatorUELUtils.getUELValueReferenceWrapper(valueExpression, elCtx);
            if (wrapper != null)
            {
                if (wrapper.getProperty() == null)
                {
                    // Fix for issue in Glassfish EL-impl-2.2.3
                    if (firstValueReferenceWarning && log.isLoggable(Level.WARNING))
                    {
                        firstValueReferenceWarning = false;
                        log.warning("ValueReference.getProperty() is null. " +
                                    "Falling back to classic ValueReference resolving. " +
                                    "This fallback may hurt performance. " +
                                    "This may be caused by a bug your EL implementation. " +
                                    "Glassfish EL-impl-2.2.3 is known for this issue. " +
                                    "Try switching to a different EL implementation.");
                    }
                }
                else
                {
                    return wrapper;
                }
            }
        }

        // get base object and property name the "old-fashioned" way
        return _ValueReferenceResolver.resolve(valueExpression, elCtx);
    }
555133
@SuppressWarnings("unchecked")
  private <T> T getStaticFieldValue(JavaClass javaClazz, JavaField javaField, ClassLoader compileClassLoader, Class<T> fieldType) {
    try {
      Class<?> clazz = compileClassLoader.loadClass(javaClazz.getFullyQualifiedName());
      Field field = clazz.getField(javaField.getName());
      return (T)field.get(fieldType);
    }
    catch (ClassNotFoundException | NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
      throw new RuntimeException("Unable to get contanst value of field '" + javaClazz.getName() + "#" + javaField.getName() + ":\n" + ex.getMessage(), ex);
    }
  }
576631
function getScopeValue(scope, field) {
        if (!scope || !field) { return null; }

        var fieldParts = field.split('.');
        var pntr = scope;

        _.each(fieldParts, function (fieldPart) {
            if (pntr) {
                pntr = pntr[fieldPart];
            }
        });

        return pntr;
    }
796568
@SuppressWarnings("unchecked")
    private <T> Optional<T> getValue(Object object, Supplier<Object> method, Class<T> cls) {

        T source = null;
        if (cls.isInstance(method.get())) {
            source = (T) method.get();
        } else {
            if (CoreParameters.DEVELOPER_MODE.get()) {
                throw new CoreRuntimeException("Cannot cast object " + method.get() + " to " + cls.toGenericString());
            }
        }
        return Optional.ofNullable(source);
    }
1311059
function creareSetGet( classProto ) {
			// Storing key:value in separate variable as using original object will
			// create infinit loop.
			var valueStorage = {};
			// Static is not supported.... will not support ie < 9;
			// Adding setter and getter
			classProto.prototype.$add = function( obj, key, val, isConst ) {

				// val has a value for it's original object.
				if (val != undefined) {
					valueStorage[key] = val;
				}

				function setter( newval ) {
					if (isConst) {
						throw this + "." + key + " can not be changed.";
					}
					valueStorage[key] = newval;
				}

				function getter( ) {
					return valueStorage[key];
				}
				/// ie dont include key created by setter getter if not intialized before
				obj[key] = null;
				if (Object.defineProperty && isGetterSetterSupported) {
					Object.defineProperty(obj, key, {
					    get : getter,
					    set : setter
					});
				}
				else if (obj.__defineGetter__) {
					obj.__defineGetter__(key, getter);
					obj.__defineSetter__(key, setter);
				}
				else {
					obj[key] == undefined && (obj[key] = valueStorage[key]);
				}
			};
		}
356462
public static void setFieldValue(Object obj, String fieldName, Object value) throws UtilException {
		Assert.notNull(obj);
		Assert.notBlank(fieldName);
		setFieldValue(obj, getField(obj.getClass(), fieldName), value);
	}
1001900
function getObjectToStringValue(value) {
            var result = objectToString.call(value);
            switch (result) {
                case '[object Undefined]':
                    return '#Undefined';
                case '[object Null]':
                    return '#Null';
                case '[object Object]':
                    return 'Object';
                case '[object Function]':
                    return 'Function';
                case '[object String]':
                    return 'String';
                case '[object Number]':
                    return (value != +value) ? '#NaN' : 'Number';
                case '[object Array]':
                    return 'Array';
                case '[object Boolean]':
                    return 'Boolean';
                case '[object RegExp]':
                    return 'RegExp';
                case '[object Symbol]':
                    return 'Symbol';
                case '[object Map]':
                    return 'Map';
                case '[object WeakMap]':
                    return 'WeakMap';
                case '[object Set]':
                    return 'Set';
                case '[object WeakSet]':
                    return 'WeakSet';
                case '[object Int8Array]':
                    return 'Int8Array';
                case '[object Uint8Array]':
                    return 'Uint8Array';
                case '[object Uint8ClampedArray]':
                    return 'Uint8ClampedArray';
                case '[object Int16Array]':
                    return 'Int16Array';
                case '[object Uint16Array]':
                    return 'Uint16Array';
                case '[object Int32Array]':
                    return 'Int32Array';
                case '[object Uint32Array]':
                    return 'Uint32Array';
                case '[object Float32Array]':
                    return 'Float32Array';
                case '[object Float64Array]':
                    return 'Float64Array';
                case '[object ArrayBuffer]':
                    return 'ArrayBuffer';
                case '[object DataView]':
                    return 'DataView';
                case '[object Error]':
                    return 'Error';
                case '[object Arguments]':
                    return 'Arguments';
                case '[object JSON]':
                    return 'JSON';
                case '[object Math]':
                    return 'Math';
                case '[object Date]':
                    return 'Date';
                default: //handle the rest (HTML element, future global objects,...)
                    return result.slice(8, -1);
            }
        }
904181
private Object collectJsValue(Object jsValue) {
        if ( jsValue == null ) {
             return null;
             
        } else if ( jsValue instanceof NativeFunction ) {
            return ((NativeFunction)jsValue).getEncodedSource();
            
        } else if ( jsValue instanceof NativeArray ) {
            NativeArray jsArr = (NativeArray) jsValue;
            List<Object> retVal = new ArrayList<>((int)jsArr.getLength());
            for ( int idx=0; idx<jsArr.getLength(); idx++ ) {
                retVal.add( collectJsValue(jsArr.get(idx)) );
            }
            return retVal;
            
        } else if ( jsValue instanceof ScriptableObject ) {
            ScriptableObject jsObj = (ScriptableObject) jsValue;
            Map<Object, Object> retVal = new HashMap<>();
            for ( Object key:jsObj.getIds() ) {
                retVal.put(key, collectJsValue(jsObj.get(key)) );
            }
            return retVal;
            
        } else if ( jsValue instanceof ConsString ) {
            return ((ConsString)jsValue).toString();
            
        } else if ( jsValue instanceof NativeJavaObject ) {
            NativeJavaObject jsJavaObj = (NativeJavaObject) jsValue;
            Object obj = jsJavaObj.unwrap();
            return obj;
            
        } else {
            String cn = jsValue.getClass().getCanonicalName();
            if ( !cn.startsWith("java.") && (!cn.startsWith("il.ac.bgu")) ) {
                System.out.println("collectJsValue: blind translation to java: " + jsValue + " (" + jsValue.getClass() + ")");
            }
            return jsValue;
        }
        
    }
1308108
public static Object getVariableEL(PageContext pc, String var, Object defaultValue) {
	StringList list = parse(pc, new ParserString(var), false);
	if (list == null) return defaultValue;

	int scope = scopeString2Int(pc.ignoreScopes(), list.next());
	Object coll = null;
	if (scope == Scope.SCOPE_UNDEFINED) {
	    coll = pc.undefinedScope().get(KeyImpl.init(list.current()), NullSupportHelper.NULL());
	    if (coll == NullSupportHelper.NULL()) return defaultValue;
	}
	else {
	    try {
		coll = VariableInterpreter.scope(pc, scope, list.hasNext());
		// coll=pc.scope(scope);
	    }
	    catch (PageException e) {
		return defaultValue;
	    }
	}

	while (list.hasNext()) {
	    coll = pc.getVariableUtil().get(pc, coll, KeyImpl.init(list.next()), NullSupportHelper.NULL());
	    if (coll == NullSupportHelper.NULL()) return defaultValue;
	}
	return coll;
    }
1171133
function() {
      
      var str_value;
      
      // StringField getValue (handles typeInvite and trim options)
      str_value = inputEx.IntegerField.superclass.getValue.call(this);
      
      // don't return NaN if empty field
      if (str_value === '') {
         return '';
      }
      
      return parseInt(str_value, 10);
   }
912310
private Object getObjectValue(Node node, String fieldName) {
        // we have to take into account the fact that fieldName will be in the lower case
        if (node != null) {
            String name = node.getLocalName();
            switch (node.getNodeType()) {
                case Node.ATTRIBUTE_NODE:
                    return name.equalsIgnoreCase(fieldName) ? node : null;
                case Node.ELEMENT_NODE: {
                    if (name.equalsIgnoreCase(fieldName)) {
                        return new NodeArray(node.getChildNodes());
                    } else {
                        NamedNodeMap namedNodeMap = node.getAttributes();
                        for (int attributeIndex = 0; attributeIndex < namedNodeMap.getLength(); ++attributeIndex) {
                            Node attribute = namedNodeMap.item(attributeIndex);
                            if (attribute.getLocalName().equalsIgnoreCase(fieldName)) {
                                return attribute;
                            }
                        }
                        return null;
                    }
                }
                default:
                    return null;
            }
        }
        return null;
    }
482275
function() {
	
      var str_value;
      
      // StringField getValue (handles typeInvite and trim options)
      str_value = inputEx.NumberField.superclass.getValue.call(this);
      
      // don't return NaN if empty field
      if (str_value === '') {
         return '';
      }
      
      return parseFloat(str_value);
   }
1185543
@Override
  public Object getValue(final String optionObjectName,
                         final String optionName) throws OptionsException {
    if (useSystemwideValues) {
      // No screwing round with them
      throw new OptionsException("cannot.set.values");
    }

    try {
      /* Find the bean */
      Object opts = getProperty(optionObjectName);

      /* ... and its getter */
      Method meth = findGetter(opts, optionName);

      /* ... now the value */
      return meth.invoke(opts, (Object[])null);
    } catch (OptionsException ce) {
      throw ce;
    } catch (Throwable t) {
      throw new OptionsException(t);
    }
  }
287520
public float getValue() {
    if (VariableAssignment_Type.featOkTst && ((VariableAssignment_Type)jcasType).casFeat_value == null)
      jcasType.jcas.throwFeatMissing("value", "ch.epfl.bbp.uima.types.VariableAssignment");
    return jcasType.ll_cas.ll_getFloatValue(addr, ((VariableAssignment_Type)jcasType).casFeatCode_value);}
1374307
public static Integer getIntegerValue(QuerySolution resultRow, String variableName) {

        if (resultRow != null) {
            Resource res = resultRow.getResource(variableName);
            if (res != null && res.isLiteral()) {
                Literal val = res.asLiteral();
                if (val != null) {
                    return Integer.valueOf(val.getInt());
                }
            }
        }

        return null;
    }