make sure compound fields have their type & value set (to prevent mistakes such as vcard.addAttribute('email', 'foo@bar.baz')
346181
function validateCompoundWithType(attribute, values) {
		            for(var i in values) {
		                var value = values[i];
		                if(typeof(value) !== 'object') {
			                  errors.push([attribute + '-' + i, "not-an-object"]);
		                } else if(! value.type) {
			                  errors.push([attribute + '-' + i, "missing-type"]);
		                } else if(! value.value) { // empty values are not allowed.
			                  errors.push([attribute + '-' + i, "missing-value"]);
		                }
		            }
	          }
235652
public static BasicDBObject getCompoundKeyColumns(EntityMetadata m, Object id, EmbeddableType compoundKey,
            MetamodelImpl metaModel)
    {
        BasicDBObject compoundKeyObj = new BasicDBObject();

        Set<Attribute> attribs = compoundKey.getDeclaredAttributes();

        Field[] fields = m.getIdAttribute().getBindableJavaType().getDeclaredFields();

        // To ensure order.
        for (Attribute attr : attribs)
        {
            Field f = (Field) attr.getJavaMember();
            if (!ReflectUtils.isTransientOrStatic(f))
            {
                if (f.getAnnotation(Embedded.class) != null)
                {
                    EmbeddableType emb = metaModel.embeddable(f.getType());
                    Object val = PropertyAccessorHelper.getObject(id, f);
                    BasicDBObject dbVal = getCompoundKeyColumns(m, val, emb, metaModel);
                    compoundKeyObj.put(((AbstractAttribute) attr).getJPAColumnName(), dbVal);
                }
                else
                {
                    compoundKeyObj.put(
                            ((AbstractAttribute) attr).getJPAColumnName(),
                            populateValue(PropertyAccessorHelper.getObject(id, (Field) attr.getJavaMember()),
                                    ((AbstractAttribute) attr).getBindableJavaType()));

                }
            }
        }
        return compoundKeyObj;
    }
95072
function validatorBarcode(fieldValue, fieldDefinition, previousFieldValues, cb) {
      if (typeof(fieldValue) !== "object" || fieldValue === null) {
        return cb(new Error("Expected object but got " + typeof(fieldValue)));
      }

      if (typeof(fieldValue.text) !== "string" || fieldValue.text.length === 0) {
        return cb(new Error("Expected text parameter."));
      }

      if (typeof(fieldValue.format) !== "string" || fieldValue.format.length === 0) {
        return cb(new Error("Expected format parameter."));
      }

      return cb();
    }
20785
private static void setListParam(Field field, List<?> values) {
        try {
            // Find method: clear() and call it
            Class<?> fieldClass = field.getType();
            Method clearMethod = fieldClass.getMethod("clear");
            clearMethod.invoke(field.get(config));
            
            // Find List method: add(Object) 
            Method addMethod = fieldClass.getMethod("add", Object.class);
            
            // Add each map key/value to field value
            for (Object subParam : values) {
                if (subParam instanceof String) {
                    addMethod.invoke(field.get(config), subParam);
                } else {
                    throw new RuntimeException("Unexpected parameter type for '" + field.getName() + ":" + subParam);
                }
            }
        } catch (NoSuchMethodException  | IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
            throw new RuntimeException("Error setting configuration parameter '" + field.getName() + "'", e);
        }
    }
849172
private Method[] settersMethodForField(Field field) {
    List<Method> methods = new ArrayList<>();
    for (Method method : field.getDeclaringClass().getDeclaredMethods()) {
      if (Ascii.toLowerCase(method.getName()).equals("set" + Ascii.toLowerCase(field.getName()))
          && method.getParameterTypes().length == 1) {
        methods.add(method);
      }
    }
    return methods.toArray(new Method[0]);
  }
281701
function validateField (fields, key) {
  var value = fields[key] = castShorthand(fields[key])

  if (typeof value !== 'object')
    throw new TypeError('The definition of "' + key + '" must be an object.')

  if (key === primaryKey)
    throw new Error('Can not define primary key "' + primaryKey + '".')

  if (key in plainObject)
    throw new Error('Can not define field name "' + key +
      '" which is in Object.prototype.')

  if (!value[typeKey] && !value[linkKey])
    throw new Error('The definition of "' + key + '" must contain either ' +
      'the "' + typeKey + '" or "' + linkKey + '" property.')

  if (value[typeKey] && value[linkKey])
    throw new Error('Can not define both "' + typeKey + '" and "' + linkKey +
      '" on "' + key + '".')

  if (value[typeKey]) {
    if (typeof value[typeKey] === 'string')
      value[typeKey] = nativeTypes[
        stringifiedTypes.indexOf(value[typeKey].toLowerCase())]

    if (typeof value[typeKey] !== 'function')
      throw new Error('The "' + typeKey + '" on "' + key +
        '" must be a function.')

    if (!find(nativeTypes, function (type) {
      var hasMatch = type === value[typeKey] ||
        type.name === value[typeKey].name

      // In case this errors due to security sandboxing, just skip this check.
      if (!hasMatch)
        try {
          hasMatch = Object.create(value[typeKey]) instanceof type
        }
        catch (e) {
          hasMatch = true
        }

      return hasMatch
    }))
      throw new Error('The "' + typeKey + '" on "' + key + '" must be or ' +
        'inherit from a valid native type.')

    if (value[inverseKey])
      throw new Error('The field "' + inverseKey + '" may not be defined ' +
        'on "' + key + '".')
  }

  if (value[linkKey]) {
    if (typeof value[linkKey] !== 'string')
      throw new TypeError('The "' + linkKey + '" on "' + key +
        '" must be a string.')

    if (value[inverseKey] && typeof value[inverseKey] !== 'string')
      throw new TypeError('The "' + inverseKey + '" on "' + key + '" ' +
        'must be a string.')
  }

  if (value[isArrayKey] && typeof value[isArrayKey] !== 'boolean')
    throw new TypeError('The key "' + isArrayKey + '" on "' + key + '" ' +
        'must be a boolean.')
}
1207474
public void calcFillSettings(String field, Map<String,Object> attributes) {
        String capitalizedFieldName = StringUtils.capitalize(field);
        String methodName = "doFill" + capitalizedFieldName + "Items";
        Method method = ReflectionUtils.getPublicMethodNamed(getClass(), methodName);
        if(method==null)
            throw new IllegalStateException(String.format("%s doesn't have the %s method for filling a drop-down list", getClass(), methodName));

        // build query parameter line by figuring out what should be submitted
        List<String> depends = buildFillDependencies(method, new ArrayList<>());

        if (!depends.isEmpty())
            attributes.put("fillDependsOn",Util.join(depends," "));
        attributes.put("fillUrl", String.format("%s/%s/fill%sItems", getCurrentDescriptorByNameUrl(), getDescriptorUrl(), capitalizedFieldName));
    }
568347
private Object getCompoundKey(Attribute attribute, Object entity)
        throws InstantiationException, IllegalAccessException {
        Object compoundKeyObject = null;
        if (entity != null) {
            compoundKeyObject = PropertyAccessorHelper.getObject(entity, (Field) attribute.getJavaMember());
            if (compoundKeyObject == null) {
                compoundKeyObject = ((AbstractAttribute) attribute).getBindableJavaType().newInstance();
            }
        }

        return compoundKeyObject;
    }
121039
def resolve_compound_var_object_fields(var, attrs):
    
    attr_list = attrs.split('\t')

    for k in attr_list:
        type, _typeName, resolver = get_type(var)
        var = resolver.resolve(var, k)

    try:
        type, _typeName, resolver = get_type(var)
        return resolver.get_dictionary(var)
    except:
        pydev_log.exception()
81092
def setFieldValue( fieldName, fieldValue, dbid = nil, rid = nil, key =nil )
      @dbid ||= dbid
      @rid ||= rid
      @key ||= key
      if @dbid and (@rid or @key)
         clearFieldValuePairList
         addFieldValuePair( fieldName, nil, nil, fieldValue )
         editRecord( @dbid, @rid, @fvlist, nil, nil, nil, nil, nil, @key )
      end
   end
409944
private void handleScriptField(MethodField method) throws SqlParseException {
		List<KVValue> params = method.getParams();
		if (params.size() == 2) {
            String f = params.get(0).value.toString();
            fieldNames.add(f);
            request.addScriptField(f, new Script(params.get(1).value.toString()));
        } else if (params.size() == 3) {
            String f = params.get(0).value.toString();
            fieldNames.add(f);
            request.addScriptField(f,
									new Script(
											ScriptType.INLINE,
											params.get(1).value.toString(),
											params.get(2).value.toString(),
											Collections.emptyMap()
									)
			);
		} else {
			throw new SqlParseException("scripted_field only allows script(name,script) or script(name,lang,script)");
		}
	}
818057
private void setFieldValue(Object entity, Object thriftColumnValue, Attribute attribute)
    {
        if (attribute != null)
        {
            try
            {
                if (thriftColumnValue.getClass().isAssignableFrom(String.class))
                {
                    PropertyAccessorHelper.set(entity, (Field) attribute.getJavaMember(), (String) thriftColumnValue);
                }
                else if (CassandraDataTranslator.isCassandraDataTypeClass(((AbstractAttribute) attribute)
                        .getBindableJavaType()))
                {
                    Object decomposed = null;
                    try
                    {
                        Class<?> clazz = ((AbstractAttribute) attribute).getBindableJavaType();
                        decomposed = CassandraDataTranslator.decompose(clazz, thriftColumnValue, false);
                    }
                    catch (Exception e)
                    {
                        String tableName = entity.getClass().getSimpleName();
                        String fieldName = attribute.getName();
                        String msg = "Decomposing failed for `" + tableName + "`.`" + fieldName
                                + "`, did you set the correct type in your entity class?";
                        log.error(msg, e);
                        throw new KunderaException(msg, e);
                    }
                    PropertyAccessorHelper.set(entity, (Field) attribute.getJavaMember(), decomposed);
                }
                else
                {
                    PropertyAccessorHelper.set(entity, (Field) attribute.getJavaMember(), (byte[]) thriftColumnValue);
                }

            }
            catch (PropertyAccessException pae)
            {
                log.warn("Error while setting field value, Caused by: .", pae);
            }
        }
    }
274459
def attributes= (attrs)
      attrs.each_pair do |name, value|
        field = schema.fields[name.to_s] || FieldDefinition.new(name, :type => value.class)
        setter = "#{name}=".to_sym
        if respond_to?(setter)
          send(setter, value)
        else
          write_attribute(field, value, self)
        end
      end
    end
948067
function handleAttributeContext(attrNode, context) {
    if (!attrNode.type && attrNode.inherit !== 'inherit') attrNode.type = 'string';

    if (attrNode.map) {
        Object.keys(attrNode.map).forEach(mappingName => {
            const mapping = attrNode.map[mappingName];

            Object.keys(mapping).forEach(dataSourceName => {
                if (!context.dataSourceAttributes[dataSourceName]) {
                    throw new ImplementationError(
                        `Unknown DataSource "${dataSourceName}" in map${context.errorContext}`
                    );
                }

                context.dataSourceAttributes[dataSourceName].push(mapping[dataSourceName]);
            });
        });

        if ('value' in attrNode) {
            throw new ImplementationError(
                'Static "value" in combination with "map" makes no sense' + context.errorContext
            );
        }
    }
}
1202657
private static void setBasicValue(Object entity, Field member, String columnName, UDTValue row,
            CassandraType dataType, MetamodelImpl metamodel)
    {
    	if(row.isNull(columnName)){
        	return;
        }
        Object retVal = null;
        switch (dataType)
        {
        case BYTES:
            // case CUSTOM:
            retVal = row.getBytes(columnName);
            if (retVal != null)
            {
                setFieldValue(entity, member, ((ByteBuffer) retVal).array());
            }
            break;

        case BOOLEAN:
            retVal = row.getBool(columnName);
            setFieldValue(entity, member, retVal);
            break;

        case BIGINT:
            // bigints in embeddables and element collections are mapped/defined
            // by Long
        case LONG:
        case COUNTER:
            retVal = row.getLong(columnName);
            setFieldValue(entity, member, retVal);
            break;

        case DECIMAL:
            retVal = row.getDecimal(columnName);
            setFieldValue(entity, member, retVal);
            break;

        case DOUBLE:
            retVal = row.getDouble(columnName);
            setFieldValue(entity, member, retVal);
            break;

        case FLOAT:
            retVal = row.getFloat(columnName);
            setFieldValue(entity, member, retVal);
            break;

        case INET:
            retVal = row.getInet(columnName);
            setFieldValue(entity, member, retVal);
            break;

        case INT:
            retVal = row.getInt(columnName);
            retVal = setIntValue(member, retVal);
            setFieldValue(entity, member, retVal);
            break;

        case ASCII:
        case STRING:
        case CHARACTER:
            try
            {
                row.getBytes(columnName);
            }
            catch (Exception e)
            {
                // do nothing
            }
            retVal = row.getString(columnName);
            retVal = setTextValue(entity, member, retVal);
            setFieldValue(entity, member, retVal);
            break;

        case TIMESTAMP:
            retVal = row.getTimestamp(columnName);
            if (retVal != null && member != null)
                retVal = CassandraDataTranslator.decompose(member.getType(),
                        ByteBufferUtil.bytes(((Date) retVal).getTime()).array(), true);
            setFieldValue(entity, member, retVal);
            break;

        case UUID:
            // case TIMEUUID:
            retVal = row.getUUID(columnName);
            setFieldValue(entity, member, retVal);
            break;

        case LIST:
            Class listAttributeTypeClass = PropertyAccessorHelper.getGenericClass(member);
            Class listClazz = null;
            boolean isElementCollectionList = false;
            if (listAttributeTypeClass.isAssignableFrom(byte[].class))
            {

                listClazz = ByteBuffer.class;
            }
            else if (listAttributeTypeClass.isAnnotationPresent(Embeddable.class))
            {
                isElementCollectionList = true;
                listClazz = UDTValue.class;
            }
            else
            {
                listClazz = listAttributeTypeClass;
            }
            retVal = row.getList(columnName, listClazz);
            Collection resultList = new ArrayList();
            if (isElementCollectionList)
            {
                Iterator collectionItems = ((Collection) retVal).iterator();
                while (collectionItems.hasNext())
                {
                    resultList.add(setUDTValue(entity, listAttributeTypeClass, (UDTValue) collectionItems.next(),
                            metamodel));
                }
            }

            if (retVal != null && !((List) retVal).isEmpty() && !isElementCollectionList)
            {
                if (listAttributeTypeClass.isAssignableFrom(byte[].class))
                {
                    setFieldValue(entity, member, CassandraDataTranslator.marshalCollection(BytesType.class,
                            (Collection) retVal, listAttributeTypeClass, ArrayList.class));
                }
                else
                {
                    Iterator collectionItems = ((Collection) retVal).iterator();
                    while (collectionItems.hasNext())
                    {
                        resultList.add(collectionItems.next());
                    }
                    setFieldValue(entity, member, resultList);
                }

            }
            else if (retVal != null && !((Collection) retVal).isEmpty())
            {
                setFieldValue(entity, member, resultList);
            }
            break;

        case SET:
            Class setAttributeTypeClass = PropertyAccessorHelper.getGenericClass(member);
            Class setClazz = null;
            boolean isElementCollectionSet = false;
            if (setAttributeTypeClass.isAssignableFrom(byte[].class))
            {

                setClazz = ByteBuffer.class;
            }
            else if (setAttributeTypeClass.isAnnotationPresent(Embeddable.class))
            {
                isElementCollectionSet = true;
                setClazz = UDTValue.class;
            }
            else
            {
                setClazz = setAttributeTypeClass;
            }
            retVal = row.getSet(columnName, setClazz);
            Collection resultSet = new HashSet();
            if (isElementCollectionSet)
            {
                Iterator collectionItems = ((Collection) retVal).iterator();
                while (collectionItems.hasNext())
                {
                    resultSet.add(setUDTValue(entity, setAttributeTypeClass, (UDTValue) collectionItems.next(),
                            metamodel));
                }
            }

            if (retVal != null && !((Set) retVal).isEmpty() && !isElementCollectionSet)
            {
                if (setAttributeTypeClass.isAssignableFrom(byte[].class))
                {
                    setFieldValue(entity, member, CassandraDataTranslator.marshalCollection(BytesType.class,
                            (Collection) retVal, setAttributeTypeClass, HashSet.class));
                }
                else
                {
                    Iterator collectionItems = ((Collection) retVal).iterator();
                    while (collectionItems.hasNext())
                    {
                        resultSet.add(collectionItems.next());
                    }
                    setFieldValue(entity, member, resultSet);
                }
            }
            else if (retVal != null && !((Collection) retVal).isEmpty())
            {
                setFieldValue(entity, member, resultSet);
            }
            break;
        /*
         * ASCII, BIGINT, BLOB, BOOLEAN, COUNTER, DECIMAL, DOUBLE, FLOAT, INET,
         * INT, TEXT, TIMESTAMP, UUID, VARCHAR, VARINT, TIMEUUID, LIST, SET,
         * MAP, CUSTOM;
         */
        case MAP:
            List<Class<?>> mapGenericClasses = PropertyAccessorHelper.getGenericClasses(member);

            Class keyClass = CassandraValidationClassMapper.getValidationClassInstance(mapGenericClasses.get(0), true);
            Class valueClass = CassandraValidationClassMapper
                    .getValidationClassInstance(mapGenericClasses.get(1), true);
            Class mapValueClazz = null;
            boolean isElementCollectionMap = false;
            if (mapGenericClasses.get(1).isAssignableFrom(byte[].class))
            {

                mapValueClazz = ByteBuffer.class;
            }
            else if (mapGenericClasses.get(1).isAnnotationPresent(Embeddable.class))
            {
                isElementCollectionMap = true;
                mapValueClazz = UDTValue.class;
            }
            else
            {
                mapValueClazz = mapGenericClasses.get(1);
            }
            retVal = row.getMap(columnName, mapGenericClasses.get(0).isAssignableFrom(byte[].class) ? ByteBuffer.class
                    : mapGenericClasses.get(0), mapValueClazz);

            Map resultMap = new HashMap();

            if (isElementCollectionMap)
            {
                Iterator keys = ((Map) retVal).keySet().iterator();
                while (keys.hasNext())
                {
                    Object keyValue = keys.next();
                    resultMap.put(
                            keyValue,
                            setUDTValue(entity, mapGenericClasses.get(1), (UDTValue) ((Map) retVal).get(keyValue),
                                    metamodel));
                }
            }

            boolean isByteBuffer = mapGenericClasses.get(0).isAssignableFrom(byte[].class)
                    || mapGenericClasses.get(1).isAssignableFrom(byte[].class);

            // set the values.
            if (retVal != null && !((Map) retVal).isEmpty() && !isElementCollectionMap)
            {
                if (isByteBuffer)
                {
                    setFieldValue(entity, member,
                            CassandraDataTranslator.marshalMap(mapGenericClasses, keyClass, valueClass, (Map) retVal));
                }
                else
                {
                    Iterator keys = ((Map) retVal).keySet().iterator();
                    while (keys.hasNext())
                    {
                        Object keyValue = keys.next();
                        resultMap.put(keyValue, ((Map) retVal).get(keyValue));
                    }
                    setFieldValue(entity, member, resultMap);
                }
            }
            else if (retVal != null && !((Map) retVal).isEmpty())
            {
                setFieldValue(entity, member, resultMap);
            }
            break;
        }

    }
1109384
private void mergeAllFieldValues(DBObject srcDBObj, DBObject tgtDBObj) {
        for (String fieldName : srcDBObj.getUpdatedFieldNames()) {
            FieldDefinition fieldDef = m_tableDef.getFieldDef(fieldName);
            if (fieldDef != null && (fieldDef.isCollection() || fieldDef.isLinkField())) {
                Set<String> newValueSet =
                    ScalarFieldUpdater.mergeMVFieldValues(tgtDBObj.getFieldValues(fieldName),
                                                          srcDBObj.getRemoveValues(fieldName),
                                                          srcDBObj.getFieldValues(fieldName));
                tgtDBObj.clearValues(fieldName);
                tgtDBObj.addFieldValues(fieldName, newValueSet);
            } else {
                tgtDBObj.clearValues(fieldName);
                tgtDBObj.addFieldValue(fieldName, srcDBObj.getFieldValue(fieldName));
            }
        }
    }
183144
void writeCompoundAttribute(Attribute.Compound c) {
        databuf.appendChar(pool.put(typeSig(c.type)));
        databuf.appendChar(c.values.length());
        for (Pair<Symbol.MethodSymbol,Attribute> p : c.values) {
            databuf.appendChar(pool.put(p.fst.name));
            p.snd.accept(awriter);
        }
    }