converts an Object to an {@link EntryElement} so its Bean-data can be saved to the DB
547361
public static EntryElement makeEntryElement(Object value) {
        Class<?> type = ClassUtils.primitiveToWrapper(value.getClass());
        return new EntryElement(type.getName(), value.toString());
    }
553914
public Object mapRowToReturnType() {

        Object resultObject = null;
        if (_columnCount == 1) {

            final int typeId = _tmf.getTypeId(_returnTypeClass);

            try {
                if (typeId != TypeMappingsFactory.TYPE_UNKNOWN) {
                    return extractColumnValue(1, typeId);
                } else {
                    // we still might want a single value (i.e. java.util.Date)
                    Object val = extractColumnValue(1, typeId);
                    if (_returnTypeClass.isAssignableFrom(val.getClass())) {
                        return val;
                    }
                }
            } catch (SQLException e) {
                throw new ControlException(e.getMessage(), e);
            }
        }

        if (_setterMethods == null) {
            try {
                getResultSetMappings();
            } catch (SQLException e) {
                throw new ControlException(e.getMessage(), e);
            }
        }

        resultObject = XmlObject.Factory.newInstance(new XmlOptions().setDocumentType(_schemaType));

        for (int i = 1; i < _setterMethods.length; i++) {
            Method setterMethod = _setterMethods[i].getSetter();
            Object resultValue = null;

            try {
                resultValue = extractColumnValue(i, _setterMethods[i].getParameterType());

                // if the setter is for an xmlbean enum type, convert the extracted resultset column
                // value to the proper xmlbean enum type. All xmlbean enums are derived from the class
                // StringEnumAbstractBase
                if (_setterMethods[i].getParameterType() == TypeMappingsFactory.TYPE_XMLBEAN_ENUM) {
                    Class parameterClass = _setterMethods[i].getParameterClass();
                    Method m = parameterClass.getMethod("forString", new Class[]{String.class});
                    resultValue = m.invoke(null, new Object[]{resultValue});
                }

                _args[0] = resultValue;
                setterMethod.invoke(resultObject, _args);

                if (_setterMethods[i].getNilable() != null) {
                    if (_resultSet.wasNull()) {
                        _setterMethods[i].getNilable().invoke(resultObject, (Object[]) null);
                    }
                }
            } catch (SQLException se) {
                throw new ControlException(se.getMessage(), se);
            } catch (IllegalArgumentException iae) {
                try {
                    ResultSetMetaData md = _resultSet.getMetaData();
                    throw new ControlException("The declared Java type for method " + setterMethod.getName()
                                               + setterMethod.getParameterTypes()[0].toString()
                                               + " is incompatible with the SQL format of column " + md.getColumnName(i).toString()
                                               + md.getColumnTypeName(i).toString()
                                               + " which returns objects of type " + resultValue.getClass().getName());
                } catch (SQLException e) {
                    throw new ControlException(e.getMessage(), e);
                }
            } catch (IllegalAccessException e) {
                throw new ControlException("IllegalAccessException when trying to access method " + setterMethod.getName(), e);
            } catch (NoSuchMethodException e) {
                throw new ControlException("NoSuchMethodException when trying to map schema enum value using Enum.forString().", e);
            } catch (InvocationTargetException e) {
                throw new ControlException("IllegalInvocationException when trying to access method " + setterMethod.getName(), e);
            }
        }
        return resultObject;
    }
600369
public static @Nonnull Entry<String,JsonElement> field(String key, JsonElement value) {
        Entry<String, JsonElement> entry = new Entry<String,JsonElement>() {

            @Override
            public String getKey() {
                return key;
            }

            @Override
            public JsonElement getValue() {
                return value;
            }

            @Override
            public JsonElement setValue(JsonElement value) {
                throw new UnsupportedOperationException("entries are immutable");
            }};
            return entry;
    }
792541
private Entry<E> getEntry(int index) {
    Entry<E> entry = indexToEntry.get(index);
    return entry;
  }
401344
private static List<EntryElement> convertAllObjectsToEntryElements(Collection<? extends Object> collection) {
        List<EntryElement> result = new ArrayList<EntryElement>();
        for (Object o : collection) {
            result.add(transformObjectToEntryElement(o));
        }
        return result;
    }
614377
@Nullable
    public static EntryType convertEntryType(com.linecorp.centraldogma.common.EntryType type) {
        if (type == null) {
            return null;
        }

        switch (type) {
            case JSON:
                return EntryType.JSON;
            case TEXT:
                return EntryType.TEXT;
            case DIRECTORY:
                return EntryType.DIRECTORY;
        }

        throw new Error();
    }
689471
public final <T> T saveObject(final T obj) throws Exception {
        return executeInTransaction(new Runnable<T>() {
            @Override
            public T run(final EntityManager entityManager) {
                return persist(obj, entityManager);
            }
        });
    }
135023
public Object javaToSql(Object source) throws ConversionException
    {

        if (source == null)
        {
            return NULLVALUE;
        }

        try
        {
            List stringList = (List) source;
            if (stringList.isEmpty())
            {
                return NULLVALUE;
            }

            StringBuffer result = new StringBuffer();
            for (int i = 0; i < stringList.size(); i++)
            {
                String newSt = (String) stringList.get(i);
                // introduced in JDK 1.4, replace with commons-lang
                // newSt = newSt.replaceAll("#", "##");
                newSt = StringUtils.replace(newSt, "#", "##");
                if (i > 0)
                {
                    result.append("#");
                }
                result.append(newSt);
            }
            return result.toString();
        }
        catch (ClassCastException e)
        {
            throw new ConversionException("Object is not a List of String it is a"
                    + source.getClass().getName());
        }
    }
1312721
protected Class<?> getValueType(AnnotatedElement element) {
        if (element instanceof Field) {
            return ((Field) element).getType();
        }
        if (element instanceof Method) {
            return ((Method) element).getReturnType();
        }
        throw new PropertyLoaderException("Could not get element type");
    }
420158
public <T> T datastoreToJava(Entity entity) {
		try {
			if (entity == null) {
				return null;
			}
			T result = (T) persistentClass.newInstance();
			populate(entity, result);
			return result;
		} catch (InstantiationException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		}
	}
373626
public static org.w3c.dom.Element convert(org.jdom2.Element node) throws JDOMException
	{
		if (node == null)
			return null; // Convert null->null

		try
		{
			DOMOutputter outputter = new DOMOutputter();

			return outputter.output(node);
		}
		catch (JDOMException e)
		{
			throw new RuntimeException("Error converting JDOM to DOM: " + e.getMessage(), e);
		}
	}
875007
private ModelElementInstance findElementToInsertAfter(ModelElementInstance elementToInsert) {
    List<ModelElementType> childElementTypes = elementType.getAllChildElementTypes();
    List<DomElement> childDomElements = domElement.getChildElements();
    Collection<ModelElementInstance> childElements = ModelUtil.getModelElementCollection(childDomElements, modelInstance);

    ModelElementInstance insertAfterElement = null;
    int newElementTypeIndex = ModelUtil.getIndexOfElementType(elementToInsert, childElementTypes);
    for (ModelElementInstance childElement : childElements) {
      int childElementTypeIndex = ModelUtil.getIndexOfElementType(childElement, childElementTypes);
      if (newElementTypeIndex >= childElementTypeIndex) {
        insertAfterElement = childElement;
      }
      else {
        break;
      }
    }
    return insertAfterElement;
  }
988590
private void parseConfig(Element property, BeanDefinitionBuilder propertyBuilder) {
        Element config = (Element) getTagChildren("config", property).item(0);

        if (config != null) {
            Properties properties = new Properties();
            NodeList entries = getTagChildren("entry", config);

            for (int i = 0; i < entries.getLength(); i++) {
                Element entry = (Element) entries.item(i);
                String key = entry.getAttribute("key");
                String value = entry.getTextContent().trim();
                properties.put(key, value);
            }

            propertyBuilder.addPropertyValue("config", properties);
        }
    }
803082
private void put(Object obj, Element node) throws Exception {
		if (!(obj instanceof Map)) {
			throw new IllegalArgumentException("Object for put is not a Map: "
					+ obj);
		}
		@SuppressWarnings("unchecked")
		Map<Object, Object> map = (Map<Object, Object>) obj;

		String name = getAttribute(node, "name");
		Object value = value(obj, node);
		map.put(name, value);
		if (LOG.isDebugEnabled()) {
			LOG.debug("XML " + obj + ".put(" + name + "," + value + ")");
		}
	}
817423
@Override
    protected Cells transformElement(Map<String, Object> entity) {
        return UtilJdbc.getCellsFromObject(entity, jdbcDeepJobConfig);
    }
986863
public Object sqlToJava(Object source) throws ConversionException
    {

        if (source == null)
        {
            return null;
        }
        if (!(source instanceof String))
        {
            throw new ConversionException("Object is not a String it is a"
                    + source.getClass().getName());
        }
        if (source.toString().equals(NULLVALUE))
        {
            return null;
        }
        if (source.toString().equals(EMPTYCOLLEC))
        {
            return new ArrayList();
        }

        List v = new ArrayList();
        String input = source.toString();
        int pos = input.indexOf("#");

        while (pos >= 0)
        {
            if (pos == 0)
            {
                v.add("");
            }
            else
            {
                v.add(Integer.valueOf(input.substring(0, pos)));
            }

            if (pos + 1 > input.length())
            {
                //# at end causes outof bounds
                break;
            }

            input = input.substring(pos + 1, input.length());
            pos = input.indexOf("#");
        }
        return v;
    }
376182
@Override
	public String convert(ObjectType sourceObject)
	{
		if(sourceObject == null)
			return null;
		
		String methodName = null;
		Object value =null;
		StringBuilder csv = new StringBuilder();
		Object[] args = {};
		Method m;

		
		for (Entry<String,Method> entry : this.methods.entrySet())
		{
			m = entry.getValue();
			methodName = m.getName();
			
			if(methodName.equals("getClass"))
				continue;
			
			try
			{
				value = m.invoke(sourceObject, args);
				
				if(csv.length() != 0)
					csv.append(SEPARATOR);
				
				csv.append(QUOTE).append(format(value)).append(QUOTE);
				
			}
			catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException e)
			{
				throw new RuntimeException("Unable to get property for method:"+methodName+" error:"+e.getMessage(),e);
			}
		}
		
		csv.append(NEWLINE);
		
		return csv.toString();
		
	}