/*
Internal: Static version of {@link ObjectWrapper#setSimpleValue(Property, Object)}.
342190
private static void setSimpleValue(Object obj, Property property, Object value) {
        if (property == null) {
            throw new IllegalArgumentException("Cannot set a new value to a property with a 'null' propertyName.");
        }

        property.set(obj, value);
    }
584929
public synchronized void setProperty(PropertyKey key, Object value)
    {
        if (!isValidKey(key))
            throw new IllegalArgumentException("Key " + key + " is not valid for " + getMapClass());

        //
        // Validate the value argument, based upon the property type reference by the key
        //
        Class propType = key.getPropertyType();
        if (value == null)
        {
            if (propType.isPrimitive() || propType.isAnnotation())
                throw new IllegalArgumentException("Invalid null value for key " + key);
        }
        else
        {
            if (propType.isPrimitive())
                propType = (Class)_primToObject.get(propType);

            if (!propType.isAssignableFrom(value.getClass()))
            {
                throw new IllegalArgumentException("Value class (" + value.getClass() + 
                                                   ") not of expected type: " + propType);
            }
        }
        _properties.put(key, value);
        _propertySets.add(key.getPropertySet());
    }
614701
public void setProperty(Object object, Object newValue) {
        MetaMethod setter = getSetter();
        if (setter == null) {
            if (field != null && !Modifier.isFinal(field.getModifiers())) {
                field.setProperty(object, newValue);
                return;
            }
            throw new GroovyRuntimeException("Cannot set read-only property: " + name);
        }
        newValue = DefaultTypeTransformation.castToType(newValue, getType());
        setter.invoke(object, new Object[]{newValue});
    }
876039
public void set(Writable obj) {
    instance = obj;
    Class<? extends Writable> instanceClazz = instance.getClass();
    Class<? extends Writable>[] clazzes = getTypes();
    for (int i = 0; i < clazzes.length; i++) {
      Class<? extends Writable> clazz = clazzes[i];
      if (clazz.equals(instanceClazz)) {
        type = (byte) i;
        return;
      }
    }
    throw new RuntimeException("The type of instance is: "
                               + instance.getClass() + ", which is NOT registered.");
  }
858991
private static boolean setValueForProperty(final Property property, final Object value, final Object object) {
        final Field field = fieldForPropertyName(property.getName(), object);
        if (null == field) {
            return false;
        }
        final Property.Type type = property.getType();
        final Property.Type ftype = propertyTypeFromFieldType(field.getType());
        if (ftype != property.getType()
                && !(ftype == Property.Type.String
                     && (property.getType() == Property.Type.Select ||
                         property.getType() == Property.Type.FreeSelect ||
                         property.getType() == Property.Type.Options))) {

            throw new IllegalStateException(
                    String.format(
                            "cannot map property {%s type: %s} to field {%s type: %s}",
                            property.getName(),
                            property.getType(),
                            field.getName(),
                            ftype
                    ));
        }
        final Object resolvedValue;
        if (type == Property.Type.Integer) {
            final Integer intvalue;
            if (value instanceof String) {
                intvalue = Integer.parseInt((String) value);
            } else if (value instanceof Integer) {
                intvalue = (Integer) value;
            } else {
                //XXX
                return false;
            }
            resolvedValue = intvalue;
        } else if (type == Property.Type.Long) {
            final Long longvalue;
            if (value instanceof String) {
                longvalue = Long.parseLong((String) value);
            } else if (value instanceof Long) {
                longvalue = (Long) value;
            } else if (value instanceof Integer) {
                final int val = (Integer) value;
                longvalue = (long) val;
            } else {
                //XXX
                return false;
            }
            resolvedValue = longvalue;
        } else if (type == Property.Type.Boolean) {
            final Boolean boolvalue;
            if (value instanceof String) {
                boolvalue = Boolean.parseBoolean((String) value);
            } else if (value instanceof Boolean) {
                boolvalue = (Boolean) value;
            } else {
                //XXX
                return false;
            }
            resolvedValue = boolvalue;
        } else if (type == Property.Type.Options) {
            final List<String> splitList;
            if (value instanceof String) {
                String valstring = (String) value;
                splitList = Arrays.asList(valstring.split(", *"));
            } else if (value instanceof List) {
                splitList = (List<String>) value;
            } else if (value instanceof Set) {
                splitList = new ArrayList<>((Set) value);
            } else if (value.getClass() == String[].class) {
                splitList = Arrays.asList((String[]) value);
            } else {
                return false;
            }
            Set<String> resolvedValueSet = null;
            //not a String field
            if (field.getType().isAssignableFrom(Set.class)) {
                HashSet<String> strings = new HashSet<>();
                strings.addAll(splitList);
                resolvedValueSet = strings;
                resolvedValue = strings;
            } else if (field.getType().isAssignableFrom(List.class)) {
                ArrayList<String> strings = new ArrayList<>();
                strings.addAll(splitList);
                resolvedValueSet = new HashSet<>(strings);
                resolvedValue = strings;
            } else if (field.getType() == String[].class) {
                ArrayList<String> strings = new ArrayList<>();
                strings.addAll(splitList);
                resolvedValueSet = new HashSet<>(strings);
                resolvedValue = strings.toArray(new String[strings.size()]);
            } else if (field.getType() == String.class) {
                resolvedValueSet = new HashSet<>();
                resolvedValueSet.addAll(splitList);
                resolvedValue = value;
            } else {
                return false;
            }
            if (property.getSelectValues() != null && !property.getSelectValues().containsAll(resolvedValueSet)) {
                throw new RuntimeException(String.format(
                        "Some options values were not allowed for property %s: %s",
                        property.getName(),
                        resolvedValue
                ));
            }

        } else if (type == Property.Type.String || type == Property.Type.FreeSelect) {
            if (value instanceof String) {
                resolvedValue = value;
            } else {
                //XXX
                return false;
            }
        } else if (type == Property.Type.Select) {
            if (value instanceof String) {
                resolvedValue = value;
                if (!field.getAnnotation(SelectValues.class).dynamicValues() && !property.getSelectValues().contains((String) resolvedValue)) {
                    throw new RuntimeException(
                            "value not allowed for property " + property.getName() + ": " + resolvedValue);
                }
            } else {
                //XXX
                return false;
            }
        } else {
            //XXX
            return false;
        }
        try {
            setFieldValue(field, resolvedValue, object);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Unable to configure plugin: " + e.getMessage(), e);
        }
        return true;
    }
341078
private void putValue(Object value) {
        if (value==null) {
            return;
        }
        if (value instanceof MwsObject) {
            parameterPrefix.append('.');
            ((MwsObject)value).writeFragmentTo(this);
            return;
        }
        String svalue = value.toString();
        if (svalue!=null && svalue.length()>0) {
            String name = parameterPrefix.toString();
            parameters.put(name, svalue);
        }
    }
441108
public void setValue(String value) {
        ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
        builder.put("id", id).put("value", value);
        execute(MobileCommand.SET_VALUE, builder.build());
    }
600765
public IconProviderBuilder withValue(Object value, Icon icon)
	{
		if (currentProperty == null)
			throw new IllegalStateException("You must set the property first.");
		if (!currentProperty.getAllowedValues().contains(value))
			throw new IllegalStateException("The property " + currentProperty + "(" + currentProperty.getClass().getSimpleName()
					+ ") doesn't not contain value " + value);

		stateIcons.put(currentProperty, value, checkNotNull(icon));
		return this;
	}
821016
@Override
    public final void setObjectProperty(String name, Object value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setObjectProperty", new Object[] { name, value });

        /* If the property is either JMSXUserID or JMSXAppID, we set it into the */
        /* message regardless of whether it is null. We know the value is a */
        /* String as the JMS API layer has vetted it. Moved code under d325186.1 */
        if (SIProperties.JMSXAppID.equals(name)) {
            setJmsxAppId((String) value);
        }
        else if (SIProperties.JMSXUserID.equals(name)) {
            setUserid((String) value);
        }
        /* Ditto for JMS_IBM_ArmCorrelator & JMS_TOG_ARM_Correlator */
        else if (SIProperties.JMS_IBM_ArmCorrelator.equals(name)) {
            setARMCorrelator((String) value);
        }
        else if (SIProperties.JMS_TOG_ARM_Correlator.equals(name)) {
            setARMCorrelator((String) value);
        }

        /* else, if the value is not null, set the Property */
        else if (value != null) {
            setNonNullProperty(name, value);
        }

        /* Otherwise, remove it */
        else {

            /* Maelstrom's transportVersion has its own field - the rest are in the */
            /* JmsPropertyMap */
            if (!name.startsWith(JMS_PREFIX)) {
                if (name.equals(MfpConstants.PRP_TRANSVER)) {
                    clearTransportVersion();
                }
                else {
                    if (mayHaveJmsUserProperties()) {
                        getJmsUserPropertyMap().remove(name);
                    }
                }
            }
            else {
                if (name.startsWith(JMS_IBM_MQMD_PREFIX)) {
                    deleteMQMDProperty(name);
                }
                else {
                    if (mayHaveMappedJmsSystemProperties()) {
                        getJmsSystemPropertyMap().remove(name); // 234893
                    }
                    // JMS_IBM_Character_Set and JMS_IBM_Encoding need to be cleared in the
                    // message itself too.                                          d395685
                    if (name.equals(SIProperties.JMS_IBM_Character_Set)) {
                        setCcsid(null);
                    }
                    else if (name.equals(SIProperties.JMS_IBM_Encoding)) {
                        setEncoding(null);
                    }
                }
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setObjectProperty");
    }
63429
public void setValue(Properties properties)  {
        if (properties == null) {
            throw new IllegalArgumentException("properties must not be null");
        }
        if (type == null) {
            type = ItemType.PROPERTIES;
        }
        if (!isMappableType()) {
            throw new IllegalArgumentException("The type of this item must be 'properties' or 'map'");
        }
        tokensMap = new LinkedHashMap<>();
        for (String key : properties.stringPropertyNames()) {
            Object o = properties.get(key);
            if (o instanceof Token[]) {
                tokensMap.put(key, (Token[])o);
            } else if (o instanceof Token) {
                Token[] tokens = new Token[] { (Token)o };
                tokensMap.put(key, tokens);
            } else {
                Token[] tokens = TokenParser.makeTokens(o.toString(), isTokenize());
                putValue(name, tokens);
            }
        }
    }
99710
public void setValue(final Object value) {
        if (!(value instanceof Serializable)) {
            throw new IllegalArgumentException("The value muste be a instance of " + Serializable.class.getName());
        }
        this.value = (Serializable) value;
    }
1155913
public void addValue(Object current, Object value) throws ParseException, IOException {
		// if (obj != null)
		mapper.addValue(current, value);
	}
1303203
public void setProperty(String strKey, Object objValue)
    {
        if (m_mapParams == null)
            m_mapParams = new HashMap<String,Object>();
        m_mapParams.put(strKey, objValue);
    }
570633
@Nonnull
  public CSSDeclaration setProperty (@Nonnull @Nonempty final String sProperty)
  {
    ValueEnforcer.notEmpty (sProperty, "Property");
    m_sProperty = _unifyProperty (sProperty);
    return this;
  }
845177
@Override
    public void setValue(ELContext context, Object value)
            throws PropertyNotFoundException, PropertyNotWritableException,
            ELException {
        EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
                this.varMapper);
        context.notifyBeforeEvaluation(getExpressionString());
        this.getNode().setValue(ctx, value);
        context.notifyAfterEvaluation(getExpressionString());
    }
542500
private static void setValue(Object obj, String propertyPattern, Object value, ObjectWrapper options) {
        if (propertyPattern == null) {
            throw new IllegalArgumentException("Cannot set a new value to a property with a 'null' propertyPattern.");
        }

        if (obj == null) {
            // NullPointerException as it is throwed only when traversing a null object (ex: "foo.null.bar")
            throw new NullPointerException("Cannot set the value of '" + propertyPattern + "' to a 'null' object.");
        }

        // '.' position if positive, '[' inverse position if negative
        int position = indexOfDotOrSquare(propertyPattern);

        // (propertyPattern.contains("."))
        if (position > 0) {
            String leftPattern = propertyPattern.substring(0, position);
            String rightPattern = propertyPattern.substring(position + 1, propertyPattern.length());
            Object leftValue = getValue(obj, leftPattern, options);

            if (leftValue == null) {
                Property leftProperty = getPropertyOrThrow(Bean.forClass(obj.getClass()), leftPattern);

                if (options.isAutoInstancing) {
                    try {
                        leftValue = leftProperty.getType().newInstance();
                    } catch (Exception e) {
                        throw new ReflectionException("The value of " + leftProperty + " was 'null' in the object "
                                                              + obj.getClass().getName() + ". An attempt to invoke its 'no-args constructor'" +
                                                              " was made, but an error occurs.", e);
                    }

                    leftProperty.set(obj, leftValue);
                }
            }

            setValue(leftValue, rightPattern, value, options);
            // if (propertyPattern.contains("["))
        } else if (position < 0) {
            int squarePosition = -position;

            String leftPattern = propertyPattern.substring(0, squarePosition);
            String indexOrKey = propertyPattern.substring(squarePosition + 1, propertyPattern.length() - 1);// removes ']'
            Property leftProperty = getPropertyOrThrow(Bean.forClass(obj.getClass()), leftPattern);

            if (leftProperty.getType().isAssignableFrom(Map.class)) {
                setMappedValue(obj, leftProperty, indexOrKey, value, options);
            } else {
                try {
                    setIndexedValue(obj, leftProperty, Integer.parseInt(indexOrKey), value, options);
                } catch (NumberFormatException e) {
                    throw new IllegalArgumentException("The pattern '" + indexOrKey + "' for the indexed "
                                                               + leftProperty + " is invalid. Cannot parse the string to a valid integer index.");
                }
            }
        } else {
            setSimpleValue(obj, getPropertyOrThrow(Bean.forClass(obj.getClass()), propertyPattern), value);
        }
    }
567417
public static void setPropertyEL(Object obj, String prop, Object value) {

	// first check for field
	Field[] fields = getFieldsIgnoreCase(obj.getClass(), prop, null);
	if (!ArrayUtil.isEmpty(fields)) {
	    try {
		fields[0].set(obj, value);
		return;
	    }
	    catch (Throwable t) {
		ExceptionUtil.rethrowIfNecessary(t);
	    }
	}

	// then check for setter
	try {
	    getSetter(obj, prop, value).invoke(obj);
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	}

    }