Builds the element collection value.

@param field
the field
@param record
the record
@param metaModel
the meta model
@param attribute
the attribute
@return the string builder
196666
private StringBuilder buildElementCollectionValue(Field field, Object record, MetamodelImpl metaModel,
            Attribute attribute)
    {
        StringBuilder elementCollectionValueBuilder = new StringBuilder();
        EmbeddableType embeddableKey = metaModel.embeddable(((AbstractAttribute) attribute).getBindableJavaType());
        ((AbstractAttribute) attribute).getJavaMember();
        Object value = PropertyAccessorHelper.getObject(record, field);
        boolean isPresent = false;
        if (Collection.class.isAssignableFrom(field.getType()))
        {

            if (value instanceof Collection)
            {
                Collection collection = ((Collection) value);
                isPresent = true;
                if (List.class.isAssignableFrom(field.getType()))
                {
                    elementCollectionValueBuilder.append(Constants.OPEN_SQUARE_BRACKET);
                }
                if (Set.class.isAssignableFrom(field.getType()))
                {
                    elementCollectionValueBuilder.append(Constants.OPEN_CURLY_BRACKET);
                }
                for (Object o : collection)
                {
                    // Allowing null values.
                    // build embedded value
                    if (o != null)
                    {

                        StringBuilder embeddedValueBuilder = new StringBuilder(Constants.OPEN_CURLY_BRACKET);

                        for (Field embeddableColumn : ((AbstractAttribute) attribute).getBindableJavaType()
                                .getDeclaredFields())
                        {
                            if (!ReflectUtils.isTransientOrStatic(embeddableColumn))
                            {
                                AbstractAttribute subAttribute = (AbstractAttribute) embeddableKey
                                        .getAttribute(embeddableColumn.getName());
                                if (metaModel.isEmbeddable(subAttribute.getBindableJavaType()))
                                {
                                    // construct map; recursive
                                    // send attribute
                                    if (embeddableColumn.getType().isAnnotationPresent(ElementCollection.class))
                                    {
                                        // build element collection value
                                        StringBuilder elementCollectionValue = buildElementCollectionValue(
                                                embeddableColumn, o, metaModel, (Attribute) subAttribute);
                                        appendColumnName(embeddedValueBuilder,
                                                ((AbstractAttribute) (embeddableKey.getAttribute(embeddableColumn
                                                        .getName()))).getJPAColumnName());
                                        embeddedValueBuilder.append(Constants.COLON);
                                        embeddedValueBuilder.append(elementCollectionValue);
                                    }
                                    else
                                    {
                                        buildEmbeddedValue(o, metaModel, embeddedValueBuilder,
                                                (SingularAttribute) subAttribute);
                                    }
                                }
                                else
                                {
                                    // append key value
                                    appendColumnName(
                                            embeddedValueBuilder,
                                            ((AbstractAttribute) (embeddableKey.getAttribute(embeddableColumn.getName())))
                                                    .getJPAColumnName());
                                    embeddedValueBuilder.append(Constants.COLON);
                                    appendColumnValue(embeddedValueBuilder, o, embeddableColumn);
                                }
                                embeddedValueBuilder.append(Constants.COMMA);
                            }
                        }
                        // strip last char and append '}'
                        embeddedValueBuilder.deleteCharAt(embeddedValueBuilder.length() - 1);
                        embeddedValueBuilder.append(Constants.CLOSE_CURLY_BRACKET);
                        // add to columnbuilder and builder
                        elementCollectionValueBuilder.append(embeddedValueBuilder);
                        // end if
                    }

                    elementCollectionValueBuilder.append(Constants.COMMA);
                }
                if (!collection.isEmpty())
                {
                    elementCollectionValueBuilder.deleteCharAt(elementCollectionValueBuilder.length() - 1);
                }
                if (List.class.isAssignableFrom(field.getType()))
                {
                    elementCollectionValueBuilder.append(Constants.CLOSE_SQUARE_BRACKET);
                }
                if (Set.class.isAssignableFrom(field.getType()))
                {
                    elementCollectionValueBuilder.append(Constants.CLOSE_CURLY_BRACKET);
                }
                return elementCollectionValueBuilder;
            }
            return null;

        }

        else if (Map.class.isAssignableFrom(field.getType()))
        {
            if (value instanceof Map)
            {
                Map map = ((Map) value);
                isPresent = true;
                elementCollectionValueBuilder.append(Constants.OPEN_CURLY_BRACKET);
                for (Object mapKey : map.keySet())
                {
                    Object mapValue = map.get(mapKey);
                    // Allowing null keys.
                    // key is basic type.. no support for embeddable keys
                    appendValue(elementCollectionValueBuilder, mapKey != null ? mapKey.getClass() : null, mapKey, false);
                    elementCollectionValueBuilder.append(Constants.COLON);
                    // Allowing null values.
                    if (mapValue != null)
                    {

                        StringBuilder embeddedValueBuilder = new StringBuilder(Constants.OPEN_CURLY_BRACKET);

                        for (Field embeddableColumn : ((AbstractAttribute) attribute).getBindableJavaType()
                                .getDeclaredFields())
                        {
                            if (!ReflectUtils.isTransientOrStatic(embeddableColumn))
                            {
                                AbstractAttribute subAttribute = (AbstractAttribute) embeddableKey
                                        .getAttribute(embeddableColumn.getName());
                                if (metaModel.isEmbeddable(subAttribute.getBindableJavaType()))
                                {
                                    // construct map; recursive
                                    // send attribute
                                    if (embeddableColumn.getType().isAnnotationPresent(ElementCollection.class))
                                    {
                                        // build element collection value
                                        StringBuilder elementCollectionValue = buildElementCollectionValue(
                                                embeddableColumn, mapValue, metaModel, (Attribute) subAttribute);
                                        appendColumnName(embeddedValueBuilder,
                                                ((AbstractAttribute) (embeddableKey.getAttribute(embeddableColumn
                                                        .getName()))).getJPAColumnName());
                                        embeddedValueBuilder.append(Constants.COLON);
                                        embeddedValueBuilder.append(elementCollectionValue);
                                    }
                                    else
                                    {
                                        buildEmbeddedValue(mapValue, metaModel, embeddedValueBuilder,
                                                (SingularAttribute) subAttribute);
                                    }
                                }
                                else
                                {
                                    // append key value
                                    appendColumnName(
                                            embeddedValueBuilder,
                                            ((AbstractAttribute) (embeddableKey.getAttribute(embeddableColumn.getName())))
                                                    .getJPAColumnName());
                                    embeddedValueBuilder.append(Constants.COLON);
                                    appendColumnValue(embeddedValueBuilder, mapValue, embeddableColumn);

                                }
                                embeddedValueBuilder.append(Constants.COMMA);
                            }

                        }
                        // strip last char and append '}'
                        embeddedValueBuilder.deleteCharAt(embeddedValueBuilder.length() - 1);
                        embeddedValueBuilder.append(Constants.CLOSE_CURLY_BRACKET);
                        // add to columnbuilder and builder
                        elementCollectionValueBuilder.append(embeddedValueBuilder);
                        // end if
                    }
                    elementCollectionValueBuilder.append(Constants.COMMA);
                }
                if (!map.isEmpty())
                {
                    elementCollectionValueBuilder.deleteCharAt(elementCollectionValueBuilder.length() - 1);
                }

                elementCollectionValueBuilder.append(Constants.CLOSE_CURLY_BRACKET);
                return elementCollectionValueBuilder;
            }
            return null;
        }
        return null;
    }
481339
public static Builder set(String field, Object value) {
        return new Builder().set(field, value);
    }
290186
public function getMeta($id, $name = null, $field = 'value') {
        if ($name) {
            $values = $this->get([$this->metaIdField => intval($id), $this->metaNameField => $name])->get($field);
        } else {
            $values = $this->findAll([$this->metaIdField => intval($id)], [
                $field,
                $this->metaNameField
            ])->toArray($field, $this->metaNameField);
        }

        return $values;
    }
767151
public AnnotatedTypeBuilder<X> addToField(Field field, Annotation annotation) {
       if (fields.get(field) == null) {
           fields.put(field, new AnnotationBuilder());
       }
       fields.get(field).add(annotation);
       return this;
   }
1059953
public AnnotationMetadata buildDeclared(T element) {
        final AnnotationMetadata existing = MUTATED_ANNOTATION_METADATA.get(element);
        if (existing != null) {
            return existing;
        } else {

            DefaultAnnotationMetadata annotationMetadata = new DefaultAnnotationMetadata();

            try {
                AnnotationMetadata metadata = buildInternal(null, element, annotationMetadata, true, true);
                if (metadata.isEmpty()) {
                    return AnnotationMetadata.EMPTY_METADATA;
                }
                return metadata;
            } catch (RuntimeException e) {
                if ("org.eclipse.jdt.internal.compiler.problem.AbortCompilation".equals(e.getClass().getName())) {
                    // workaround for a bug in the Eclipse APT implementation. See bug 541466 on their Bugzilla.
                    return AnnotationMetadata.EMPTY_METADATA;
                } else {
                    throw e;
                }
            }
        }
    }
943506
@Override
    public TextMapper build(String field) {
        return new TextMapper(field, column, validated, analyzer);
    }
213698
public static String getJPAColumnName(String field, EntityMetadata entityMetadata, MetamodelImpl metaModel)
    {
        if (field.indexOf('.') > 0)
        {
            return ((AbstractAttribute) metaModel.entity(entityMetadata.getEntityClazz()).getAttribute(
                    field.substring(field.indexOf('.') + 1,
                            field.indexOf(')') > 0 ? field.indexOf(')') : field.length()))).getJPAColumnName();
        }
        else
        {
            return ((AbstractAttribute) entityMetadata.getIdAttribute()).getJPAColumnName();
        }
    }
121444
static void extractFieldValue(Object entity, DBObject dbObj, Attribute column) throws PropertyAccessException
    {
        try
        {
            Object valueObject = PropertyAccessorHelper.getObject(entity, (Field) column.getJavaMember());

            if (valueObject != null)
            {
                Class javaType = column.getJavaType();
                switch (AttributeType.getType(javaType))
                {
                case MAP:
                    Map mapObj = (Map) valueObject;
                    // BasicDBObjectBuilder builder =
                    // BasicDBObjectBuilder.start(mapObj);
                    BasicDBObjectBuilder b = new BasicDBObjectBuilder();
                    Iterator i = mapObj.entrySet().iterator();
                    while (i.hasNext())
                    {
                        Map.Entry entry = (Map.Entry) i.next();
                        b.add(entry.getKey().toString(),
                                MongoDBUtils.populateValue(entry.getValue(), entry.getValue().getClass()));
                    }
                    dbObj.put(((AbstractAttribute) column).getJPAColumnName(), b.get());
                    break;
                case SET:
                case LIST:
                    Collection collection = (Collection) valueObject;
                    BasicDBList basicDBList = new BasicDBList();
                    for (Object o : collection)
                    {
                        basicDBList.add(o);
                    }
                    dbObj.put(((AbstractAttribute) column).getJPAColumnName(), basicDBList);
                    break;
                case POINT:

                    Point p = (Point) valueObject;
                    double[] coordinate = new double[] { p.getX(), p.getY() };
                    dbObj.put(((AbstractAttribute) column).getJPAColumnName(), coordinate);
                    break;
                case ENUM:
                case PRIMITIVE:
                    dbObj.put(((AbstractAttribute) column).getJPAColumnName(),
                            MongoDBUtils.populateValue(valueObject, javaType));
                    break;
                }
            }
        }
        catch (PropertyAccessException paex)
        {
            log.error("Error while getting column {} value, caused by : .",
                    ((AbstractAttribute) column).getJPAColumnName(), paex);
            throw new PersistenceException(paex);
        }
    }
566358
public static <T> List<T> getFieldValues(Iterable<?> collection, final String fieldName, final Class<T> elementType) {
		List<Object> fieldValues = getFieldValues(collection, fieldName);
		return Convert.toList(elementType, fieldValues);
	}
703138
def build_record
      record = MARC::Record.new
      data_field = nil
      control_field = nil
      subfield = nil
      text = '' 
      attrs = nil
      if Module.constants.index('Nokogiri') and @parser.is_a?(Nokogiri::XML::Reader)
        datafield = nil
        cursor = nil
        open_elements = []
        @parser.each do | node |
          if node.value? && cursor
            if cursor.is_a?(Symbol) and cursor == :leader
              record.leader = node.value
            else
              cursor.value = node.value
            end
            cursor = nil
          end
          next unless node.namespace_uri == @ns
          if open_elements.index(node.local_name.downcase)
            open_elements.delete(node.local_name.downcase)
            next
          else
            open_elements << node.local_name.downcase
          end
          case node.local_name.downcase
          when "leader"
            cursor = :leader
          when "controlfield"
            record << datafield if datafield
            datafield = nil
            control_field = MARC::ControlField.new(node.attribute('tag'))
            record << control_field
            cursor = control_field
          when "datafield"  
            record << datafield if datafield
            datafield = nil
            data_field = MARC::DataField.new(node.attribute('tag'), node.attribute('ind1'), node.attribute('ind2'))
            datafield = data_field
          when "subfield"
            raise "No datafield to add to" unless datafield
            subfield = MARC::Subfield.new(node.attribute('code'))
            datafield.append(subfield)
            cursor = subfield
          when "record"
            record << datafield if datafield
            return record
          end          
          #puts node.name
        end
        
      else
        while @parser.has_next?
          event = @parser.pull

          if event.text?
            text += REXML::Text::unnormalize(event[0])
            next
          end

          if event.start_element?
            text = ''
            attrs = event[1]
            case strip_ns(event[0])
            when 'controlfield'
              text = ''
              control_field = MARC::ControlField.new(attrs['tag'])
            when 'datafield'
              text = ''
              data_field = MARC::DataField.new(attrs['tag'], attrs['ind1'], 
                attrs['ind2'])
            when 'subfield'
              text = ''
              subfield = MARC::Subfield.new(attrs['code'])
            end
          end

          if event.end_element?
            case strip_ns(event[0])
            when 'leader'
              record.leader = text
            when 'record'
              return record
            when 'controlfield'
              control_field.value = text
              record.append(control_field)
            when 'datafield'
              record.append(data_field)
            when 'subfield'
              subfield.value = text
              data_field.append(subfield)
            end
          end
        end
      end
    end
845235
@SuppressWarnings("unchecked")
    static <P> MutableLightMetaProperty<P> of(
            MetaBean metaBean,
            final Field field,
            final String propertyName,
            int constructorIndex) {
        
        PropertyGetter getter = new PropertyGetter() {
            @Override
            public Object get(Bean bean) {
                try {
                    return field.get(bean);
                } catch (IllegalArgumentException | IllegalAccessException ex) {
                    throw new UnsupportedOperationException("Property cannot be read: " + propertyName, ex);
                }
            }
        };
        PropertySetter setter = new PropertySetter() {
            @Override
            public void set(Bean bean, Object value) {
                try {
                    field.set(bean, value);
                } catch (IllegalArgumentException | IllegalAccessException ex) {
                    throw new UnsupportedOperationException("Property cannot be read: " + propertyName, ex);
                }
            }
        };
        return new MutableLightMetaProperty<>(
                metaBean, 
                propertyName, 
                (Class<P>) field.getType(), 
                field.getGenericType(), 
                Arrays.asList(field.getAnnotations()), 
                getter,
                setter,
                constructorIndex);
    }
623974
private String serializeIdAttributeValue(final EntityMetadata m, MetamodelImpl metaModel, Object id)
    {
        if (!metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()))
        {
            return null;
        }

        Class<?> embeddableClass = m.getIdAttribute().getBindableJavaType();
        String idUniqueValue = "";

        for (Field embeddedField : embeddableClass.getDeclaredFields())
        {
            if (!ReflectUtils.isTransientOrStatic(embeddedField))
            {

                Object value = PropertyAccessorHelper.getObject(id, embeddedField);
                if (value != null && !StringUtils.isEmpty(value.toString()))
                    idUniqueValue = idUniqueValue + value + COMPOSITE_KEY_SEPARATOR;
            }
        }

        if (idUniqueValue.endsWith(COMPOSITE_KEY_SEPARATOR))
            idUniqueValue = idUniqueValue.substring(0, idUniqueValue.length() - COMPOSITE_KEY_SEPARATOR.length());
        return idUniqueValue;
    }
475552
private static Object generateValue(Field field) {
    Class<?> rawType = field.getType();

    //TODO Objects other than Lists might need parametrized types.
    if (List.class.isAssignableFrom(rawType)) {
      ParameterizedType genericType = (ParameterizedType) field.getGenericType();
      return createListObject(genericType);
    }

    return generateValue(rawType);
  }
1079886
@Override
    public StringMapper build(String field) {
        return new StringMapper(field, column, validated, caseSensitive);
    }
109208
public <V> DynamoDBMapperFieldModel<T,V> field(String attributeName) {
        return this.model.field(attributeName);
    }
176867
public void build(final Field field, final DeviceImpl device, final Object businessObject) throws DevFailed {
        xlogger.entry();
        final String name = field.getName();
        logger.debug("Has a DynamicAttributeManagement : {}", name);
        BuilderUtils.checkStatic(field);

        final String setterName = BuilderUtils.SET + name.substring(0, 1).toUpperCase(Locale.ENGLISH)
                + name.substring(1);
        try {
            final String deviceName = device.getName().toLowerCase(Locale.ENGLISH);
            final Method setter = businessObject.getClass().getMethod(setterName, DynamicManager.class);
            if (DYN_MNGRS.containsKey(deviceName)) {
                setter.invoke(businessObject, DYN_MNGRS.get(deviceName));
            } else {
                final DynamicManager mnger = new DynamicManager(device);
                setter.invoke(businessObject, mnger);
                DYN_MNGRS.put(deviceName, mnger);
            }
        } catch (final IllegalArgumentException e) {
            throw DevFailedUtils.newDevFailed(e);
        } catch (final IllegalAccessException e) {
            throw DevFailedUtils.newDevFailed(e);
        } catch (final InvocationTargetException e) {
            throw DevFailedUtils.newDevFailed(e);
        } catch (final NoSuchMethodException e) {
            throw DevFailedUtils.newDevFailed(e);
        } catch (final SecurityException e) {
            throw DevFailedUtils.newDevFailed(e);
        }
        xlogger.exit();
    }
163516
public static Builder addToSet(String field, List<?> values) {
        return new Builder().addToSet(field, values);
    }