本文整理了Java中com.haulmont.chile.core.datatypes.Datatype
类的一些代码示例,展示了Datatype
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Datatype
类的具体详情如下:
包路径:com.haulmont.chile.core.datatypes.Datatype
类名称:Datatype
[英]Represents a data type of an entity property.
[中]表示实体属性的数据类型。
代码示例来源:origin: com.haulmont.cuba/cuba-global
@Override
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
String formattedDate = dateDatatype.format(src);
return new JsonPrimitive(formattedDate);
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
protected <T> void register(Datatype datatype, Aggregation<T> aggregation) {
aggregationByDatatype.put(datatype.getJavaClass(), aggregation);
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String formattedDate = json.getAsJsonPrimitive().getAsString();
try {
return Strings.isNullOrEmpty(formattedDate) ? null : dateDatatype.parse(formattedDate);
} catch (ParseException e) {
throw new EntitySerializationException("Cannot parse date " + formattedDate);
}
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
protected Object readSimpleProperty(JsonElement valueElement, Datatype propertyType) {
String value = valueElement.getAsString();
if (value == null) return null;
try {
Class javaClass = propertyType.getJavaClass();
if (BigDecimal.class.isAssignableFrom(javaClass)) {
return valueElement.getAsBigDecimal();
} else if (Long.class.isAssignableFrom(javaClass)) {
return valueElement.getAsLong();
} else if (Integer.class.isAssignableFrom(javaClass)) {
return valueElement.getAsInt();
} else if (Double.class.isAssignableFrom(javaClass)) {
return valueElement.getAsDouble();
}
return propertyType.parse(value);
} catch (ParseException e) {
throw new EntitySerializationException(String.format("An error occurred while parsing property. Type [%s]. Value [%s].", propertyType, value), e);
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
if (metaPropertyPath != null
&& metaPropertyPath.getRange().isDatatype()) {
Class javaClass = metaPropertyPath.getRange().asDatatype().getJavaClass();
if (Boolean.class.equals(javaClass)) {
cellValue = false;
str = createSpaceString(level) + datatype.format(n);
cell.setCellValue(str);
} else {
try {
str = datatype.format(n);
Number result = (Number) datatype.parse(str);
if (result != null) {
if (n instanceof Integer || n instanceof Long || n instanceof Byte || n instanceof Short) {
MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
if (metaProperty.getRange().isDatatype()) {
javaClass = metaProperty.getRange().asDatatype().getJavaClass();
String str = Datatypes.getNN(Date.class).format(date);
sizers[sizersIndex].notifyCellValue(str, stdFont);
代码示例来源:origin: com.haulmont.cuba/cuba-gui
v = datatype.parse(e.getValue(), userSessionSource1.getLocale());
} catch (ValueConversionException ex) {
showParseExceptionNotification(ex.getLocalizedMessage());
field.setValue(datatype.format(_getValue(valueProperty), sessionSource.getLocale()));
return field;
代码示例来源:origin: com.haulmont.cuba/cuba-gui
Datatype datatype = Datatypes.getNN(javaClass);
if (datatype.getJavaClass().equals(Date.class)) {
try {
value = datatype.parse(text);
} catch (ParseException e) {
try {
value = datatype.parse(text);
} catch (ParseException e) {
throw new RuntimeException("Parse exception for string " + text, e);
代码示例来源:origin: com.haulmont.charts/charts-web
protected String getDateTimeFormattedValue(Object value, Locale locale) {
return Datatypes.getNN(Date.class).format(value, locale);
}
代码示例来源:origin: com.haulmont.reports/reports-core
protected Object readSimpleProperty(JsonReader in, Class<?> propertyType) throws IOException {
String value = in.nextString();
Object parsedValue = null;
try {
Datatype<?> datatype = Datatypes.get(propertyType);
if (datatype != null) {
parsedValue = datatype.parse(value);
}
return parsedValue;
} catch (ParseException e) {
throw new RuntimeException(
format("An error occurred while parsing property. Class [%s]. Value [%s].", propertyType, value), e);
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
@Override
public String getIdByJavaClass(Class<?> javaClass) {
for (Map.Entry<String, Datatype> entry : datatypeById.entrySet()) {
if (entry.getValue().getJavaClass().equals(javaClass))
return entry.getKey();
}
throw new IllegalArgumentException("No datatype registered for " + javaClass);
}
代码示例来源:origin: com.haulmont.cuba/cuba-rest-api
Class type = property.getRange().asDatatype().getJavaClass();
if (!type.equals(String.class) && "null".equals(xmlValue)) {
value = null;
} else {
value = property.getRange().asDatatype().parse(xmlValue);
代码示例来源:origin: com.haulmont.cuba/cuba-global
protected JsonArray serializeSimpleCollection(Collection fieldValue, MetaProperty property) {
JsonArray jsonArray = new JsonArray();
fieldValue.stream()
.forEach(item -> {
if (item instanceof Number) {
jsonArray.add((Number) item);
} else if (item instanceof Boolean) {
jsonArray.add((Boolean) item);
} else {
Datatype datatype = property.getRange().asDatatype();
jsonArray.add(datatype.format(item));
}
});
return jsonArray;
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-rest-api
private static Object parseByDatatype(String value, Class<?> type) throws ParseException {
Datatype datatype = Datatypes.getNN(type);
return datatype.parse(value);
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
public KeyValueMetaProperty(MetaClass metaClass, String name, Datatype datatype) {
this.name = name;
this.javaClass = datatype.getJavaClass();
this.metaClass = metaClass;
this.mandatory = false;
this.range = new DatatypeRange(datatype);
this.type = Type.DATATYPE;
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
/**
* Format Date (date without time) using {@code dateFormat} string specified in the main message pack.
* @return string representation or empty string if the value is null
*/
public String formatDate(@Nullable Date value) {
return datatypeRegistry.getNN(java.sql.Date.class).format(value, uss.getLocale());
}
代码示例来源:origin: com.haulmont.cuba/cuba-rest-api
/**
* Parses string value into specific type
*
* @param value value to parse
* @param typeName Datatype name
* @return parsed object
*/
public static Object parseByTypename(String value, String typeName) {
Datatype datatype = Datatypes.get(typeName);
try {
return datatype.parse(value);
} catch (ParseException e) {
throw new IllegalArgumentException(String.format("Cannot parse specified parameter of type '%s'", typeName), e);
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
@Override
public void register(Datatype datatype, String id, boolean defaultForJavaClass) {
Preconditions.checkNotNullArgument(datatype, "datatype is null");
Preconditions.checkNotNullArgument(id, "id is null");
log.trace("Register datatype: {}, id: {}, defaultForJavaClass: {}", datatype.getClass(), id, defaultForJavaClass);
if (defaultForJavaClass) {
datatypeByClass.put(datatype.getJavaClass(), datatype);
}
datatypeById.put(id, datatype);
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
/**
* Format BigDecimal using {@code decimalFormat} string specified in the main message pack.
* @return string representation or empty string if the value is null
*/
public String formatBigDecimal(@Nullable BigDecimal value) {
return datatypeRegistry.getNN(BigDecimal.class).format(value, uss.getLocale());
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
/**
* Parse Long using {@code integerFormat} string specified in the main message pack.
* @return Long value or null if a blank string is provided
*/
@Nullable
public Long parseLong(String str) throws ParseException {
return datatypeRegistry.getNN(Long.class).parse(str, uss.getLocale());
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
public static ListEditor.ItemType itemTypeFromDatatype(Datatype datatype) {
Class type = datatype.getJavaClass();
if (type.equals(String.class)) {
return STRING;
} else if (type.equals(Integer.class)) {
return INTEGER;
} else if (type.equals(BigDecimal.class)) {
return BIGDECIMAL;
} else if (type.equals(Double.class)) {
return DOUBLE;
} else if (type.equals(Long.class)) {
return LONG;
} else if (type.equals(java.sql.Date.class)) {
return DATE;
} else if (type.equals(Date.class)) {
return DATETIME;
} else if (type.equals(Boolean.class)) {
return BOOLEAN;
} else if (type.equals(java.util.UUID.class)) {
return UUID;
} else {
throw new IllegalArgumentException("Datatype " + datatype + " is not supported");
}
}
内容来源于网络,如有侵权,请联系作者删除!