本文整理汇总了Java中org.apache.olingo.commons.api.edm.EdmPrimitiveType.valueToString方法的典型用法代码示例。如果您正苦于以下问题:Java EdmPrimitiveType.valueToString方法的具体用法?Java EdmPrimitiveType.valueToString怎么用?Java EdmPrimitiveType.valueToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.olingo.commons.api.edm.EdmPrimitiveType
的用法示例。
在下文中一共展示了EdmPrimitiveType.valueToString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readPrimitiveValueInString
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; //导入方法依赖的package包/类
/**
* This method returns the object which is the value of the property.
*
* @param edmProperty EdmProperty
* @param value String value
* @return Object
* @throws ODataApplicationException
*/
private String readPrimitiveValueInString(EdmProperty edmProperty, Object value) throws ODataApplicationException {
if (value == null) {
return null;
}
try {
EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmProperty.getType();
return edmPrimitiveType.valueToString(value, edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(),
edmProperty.isUnicode());
} catch (EdmPrimitiveTypeException e) {
throw new ODataApplicationException("Invalid value: " + value + " for property: " + edmProperty.getName(),
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(),
Locale.getDefault());
}
}
示例2: expectErrorInValueToString
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; //导入方法依赖的package包/类
private void expectErrorInValueToString(final EdmPrimitiveType instance,
final Object value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode,
final String message) {
try {
instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertThat(e.getLocalizedMessage(), containsString(message));
}
}
示例3: expectErrorInValueToString
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; //导入方法依赖的package包/类
private void expectErrorInValueToString(final EdmPrimitiveType instance, final Object value,
final Boolean isNullable, final String message) {
try {
instance.valueToString(value, isNullable, null, null, null, null);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertThat(e.getLocalizedMessage(), containsString(message));
}
}
示例4: entityMatchesAllKeys
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; //导入方法依赖的package包/类
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams)
throws ODataApplicationException {
// loop over all keys
for (final UriParameter key : keyParams) {
// key
String keyName = key.getName();
String keyText = key.getText();
// Edm: we need this info for the comparison below
EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
Boolean isNullable = edmKeyProperty.isNullable();
Integer maxLength = edmKeyProperty.getMaxLength();
Integer precision = edmKeyProperty.getPrecision();
Boolean isUnicode = edmKeyProperty.isUnicode();
Integer scale = edmKeyProperty.getScale();
// get the EdmType in order to compare
EdmType edmType = edmKeyProperty.getType();
EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;
// Runtime data: the value of the current entity
// don't need to check for null, this is done in olingo library
Object valueObject = entity.getProperty(keyName).getValue();
// now need to compare the valueObject with the keyText String
// this is done using the type.valueToString
String valueAsString;
try {
valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
} catch (EdmPrimitiveTypeException e) {
throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
.getStatusCode(), Locale.ENGLISH, e);
}
if (valueAsString == null) {
return false;
}
boolean matches = valueAsString.equals(keyText);
if (!matches) {
// if any of the key properties is not found in the entity, we don't need to search further
return false;
}
}
return true;
}
示例5: writePrimitiveValue
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; //导入方法依赖的package包/类
protected void writePrimitiveValue(final String name, final EdmPrimitiveType type, final Object primitiveValue,
final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
final Boolean isUnicode, final JsonGenerator json) throws EdmPrimitiveTypeException, IOException {
final String value = type.valueToString(primitiveValue,
isNullable, maxLength, precision, scale, isUnicode);
if (value == null) {
json.writeNull();
} else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean)) {
json.writeBoolean(Boolean.parseBoolean(value));
} else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Double)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Single)
|| (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64))
&& !isIEEE754Compatible) {
json.writeNumber(value);
} else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Stream)) {
if (primitiveValue instanceof Link) {
Link stream = (Link)primitiveValue;
if (!isODataMetadataNone) {
if (stream.getMediaETag() != null) {
json.writeStringField(name+constants.getMediaEtag(), stream.getMediaETag());
}
if (stream.getType() != null) {
json.writeStringField(name+constants.getMediaContentType(), stream.getType());
}
}
if (isODataMetadataFull) {
if (stream.getRel() != null && stream.getRel().equals(Constants.NS_MEDIA_READ_LINK_REL)) {
json.writeStringField(name+constants.getMediaReadLink(), stream.getHref());
}
if (stream.getRel() == null || stream.getRel().equals(Constants.NS_MEDIA_EDIT_LINK_REL)) {
json.writeStringField(name+constants.getMediaEditLink(), stream.getHref());
}
}
}
} else {
json.writeString(value);
}
}
示例6: primitiveValue
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; //导入方法依赖的package包/类
protected void primitiveValue(final JsonGenerator json, final EdmPrimitiveType valueType, final String typeName,
final EdmProperty edmProperty, final Object value) throws IOException, SerializerException {
EdmPrimitiveType type = valueType;
if (type == null) {
final EdmPrimitiveTypeKind kind =
typeName == null ? EdmTypeInfo.determineTypeKind(value) : new EdmTypeInfo.Builder().setTypeExpression(
typeName).build().getPrimitiveTypeKind();
type = kind == null ? null : EdmPrimitiveTypeFactory.getInstance(kind);
}
if (value == null) {
json.writeNull();
} else if (type == null) {
throw new SerializerException("The primitive type could not be determined.",
MessageKeys.INCONSISTENT_PROPERTY_TYPE, "");
} else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean)) {
json.writeBoolean((Boolean) value);
} else {
String serialized = null;
try {
serialized = type.valueToString(value,
edmProperty == null ? null : edmProperty.isNullable(),
edmProperty == null ? null : edmProperty.getMaxLength(),
edmProperty == null ? Constants.DEFAULT_PRECISION : edmProperty.getPrecision(),
edmProperty == null ? Constants.DEFAULT_SCALE : edmProperty.getScale(),
edmProperty == null ? null : edmProperty.isUnicode());
} catch (final EdmPrimitiveTypeException e) {
final String name = edmProperty == null ? "" : edmProperty.getName();
throw new SerializerException("Wrong value for property '" + name + "'!", e,
SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, name, value.toString());
}
if (isIEEE754Compatible &&
(type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal))
|| type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)
&& type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte)
&& type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Single)
&& type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Double)
&& type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16)
&& type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32)
&& type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64)
&& type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal)) {
json.writeString(serialized);
} else {
json.writeNumber(serialized);
}
}
}
示例7: writePrimitiveValue
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; //导入方法依赖的package包/类
protected void writePrimitiveValue(final String name, final EdmPrimitiveType type, final Object primitiveValue,
final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
final Boolean isUnicode, final JsonGenerator json) throws EdmPrimitiveTypeException, IOException {
final String value = type.valueToString(primitiveValue,
isNullable, maxLength, precision, scale, isUnicode);
if (value == null) {
json.writeNull();
} else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean)) {
json.writeBoolean(Boolean.parseBoolean(value));
} else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Double)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Single)
|| (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64))
&& !isIEEE754Compatible) {
json.writeNumber(value);
} else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Stream)) {
if (primitiveValue instanceof Link) {
Link stream = (Link) primitiveValue;
if (!isODataMetadataNone) {
if (stream.getMediaETag() != null) {
json.writeStringField(name + Constants.JSON_MEDIA_ETAG, stream.getMediaETag());
}
if (stream.getType() != null) {
json.writeStringField(name + Constants.JSON_MEDIA_CONTENT_TYPE, stream.getType());
}
}
if (isODataMetadataFull) {
if (stream.getRel() != null && stream.getRel().equals(Constants.NS_MEDIA_READ_LINK_REL)) {
json.writeStringField(name + Constants.JSON_MEDIA_READ_LINK, stream.getHref());
}
if (stream.getRel() == null || stream.getRel().equals(Constants.NS_MEDIA_EDIT_LINK_REL)) {
json.writeStringField(name + Constants.JSON_MEDIA_EDIT_LINK, stream.getHref());
}
}
}
} else {
json.writeString(value);
}
}
示例8: entityMatchesAllKeys
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; //导入方法依赖的package包/类
public static boolean
entityMatchesAllKeys(EdmEntityType edmEntityType, Entity rt_entity, List<UriParameter> keyParams)
throws ODataApplicationException {
// loop over all keys
for (final UriParameter key : keyParams) {
// key
String keyName = key.getName();
String keyText = key.getText();
// Edm: we need this info for the comparison below
EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
Boolean isNullable = edmKeyProperty.isNullable();
Integer maxLength = edmKeyProperty.getMaxLength();
Integer precision = edmKeyProperty.getPrecision();
Boolean isUnicode = edmKeyProperty.isUnicode();
Integer scale = edmKeyProperty.getScale();
// get the EdmType in order to compare
EdmType edmType = edmKeyProperty.getType();
// if(EdmType instanceof EdmPrimitiveType) // do we need this?
EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;
// Runtime data: the value of the current entity
// don't need to check for null, this is done in olingo library
Object valueObject = rt_entity.getProperty(keyName).getValue();
// now need to compare the valueObject with the keyText String
// this is done using type.valueToString
String valueAsString = null;
try {
valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
} catch (EdmPrimitiveTypeException e) {
throw new ODataApplicationException("Failed to retrieve String value",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ENGLISH, e);
}
if (valueAsString == null) {
return false;
}
boolean matches = valueAsString.equals(keyText);
if (!matches) {
// if any of the key properties is not found in the entity, we don't need to search further
return false;
}
}
return true;
}
示例9: entityMatchesAllKeys
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; //导入方法依赖的package包/类
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams)
throws ODataApplicationException {
// loop over all keys
for (final UriParameter key : keyParams) {
// key
String keyName = key.getName();
String keyText = key.getText();
// Edm: we need this info for the comparison below
EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
Boolean isNullable = edmKeyProperty.isNullable();
Integer maxLength = edmKeyProperty.getMaxLength();
Integer precision = edmKeyProperty.getPrecision();
Boolean isUnicode = edmKeyProperty.isUnicode();
Integer scale = edmKeyProperty.getScale();
// get the EdmType in order to compare
EdmType edmType = edmKeyProperty.getType();
EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;
// Runtime data: the value of the current entity
// don't need to check for null, this is done in olingo library
Object valueObject = entity.getProperty(keyName).getValue();
// now need to compare the valueObject with the keyText String
// this is done using the type.valueToString //
String valueAsString = null;
try {
valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
} catch (EdmPrimitiveTypeException e) {
throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
.getStatusCode(), Locale.ENGLISH, e);
}
if (valueAsString == null) {
return false;
}
boolean matches = valueAsString.equals(keyText);
if (!matches) {
// if any of the key properties is not found in the entity, we don't need to search further
return false;
}
}
return true;
}
示例10: entityMatchesAllKeys
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; //导入方法依赖的package包/类
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity rt_entity,
List<UriParameter> keyParams) {
// loop over all keys
for (final UriParameter key : keyParams) {
// key
String keyName = key.getName();
String keyText = key.getText();
// note: below line doesn't consider: keyProp can be part of a complexType in V4
// in such case, it would be required to access it via getKeyPropertyRef()
// but since this isn't the case in our model, we ignore it in our implementation
EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
// Edm: we need this info for the comparison below
Boolean isNullable = edmKeyProperty.isNullable();
Integer maxLength = edmKeyProperty.getMaxLength();
Integer precision = edmKeyProperty.getPrecision();
Boolean isUnicode = edmKeyProperty.isUnicode();
Integer scale = edmKeyProperty.getScale();
// get the EdmType in order to compare
EdmType edmType = edmKeyProperty.getType();
// if(EdmType instanceof EdmPrimitiveType) // do we need this?
EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;
// Runtime data: the value of the current entity
// don't need to check for null, this is done in FWK
Object valueObject = rt_entity.getProperty(keyName).getValue();
// TODO if the property is a complex type
// now need to compare the valueObject with the keyText String
// this is done using the type.valueToString
String valueAsString = null;
try {
valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable,
maxLength, precision, scale, isUnicode);
} catch (EdmPrimitiveTypeException e) {
return false; // TODO proper Exception handling
}
if (valueAsString == null) {
return false;
}
boolean matches = valueAsString.equals(keyText);
// if any of the key properties is not found in the entity, we don't need to search further
if (!matches) {
return false;
}
// if the given key value is found in the current entity, continue with the next key
}
return true;
}
示例11: entityMatchesAllKeys
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; //导入方法依赖的package包/类
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keyParams)
throws ODataApplicationException {
// loop over all keys
for (final UriParameter key : keyParams) {
// key
String keyName = key.getName();
String keyText = key.getText();
// Edm: we need this info for the comparison below
EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
Boolean isNullable = edmKeyProperty.isNullable();
Integer maxLength = edmKeyProperty.getMaxLength();
Integer precision = edmKeyProperty.getPrecision();
Boolean isUnicode = edmKeyProperty.isUnicode();
Integer scale = edmKeyProperty.getScale();
// get the EdmType in order to compare
EdmType edmType = edmKeyProperty.getType();
EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;
// Runtime data: the value of the current entity
// don't need to check for null, this is done in olingo library
Object valueObject = entity.getProperty(keyName).getValue();
// now need to compare the valueObject with the keyText String
// this is done using the type.valueToString //
String valueAsString = null;
try {
valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable, maxLength, precision, scale, isUnicode);
} catch (EdmPrimitiveTypeException e) {
throw new ODataApplicationException("Failed to retrieve String value", HttpStatusCode.INTERNAL_SERVER_ERROR
.getStatusCode(), Locale.ENGLISH, e);
}
if (valueAsString == null) {
return false;
}
boolean matches = valueAsString.equals(keyText);
if (!matches) {
// if any of the key properties is not found in the entity, we don't need to search further
return false;
}
}
return true;
}
示例12: entityMatchesAllKeys
import org.apache.olingo.commons.api.edm.EdmPrimitiveType; //导入方法依赖的package包/类
public static boolean entityMatchesAllKeys(EdmEntityType edmEntityType, Entity rt_entity,
List<UriParameter> keyParams) {
// loop over all keys
for (final UriParameter key : keyParams) {
// key
String keyName = key.getName();
String keyText = key.getText();
// note: below line doesn't consider: keyProp can be part of a complexType in V4
// in such case, it would be required to access it via getKeyPropertyRef()
// but since this isn't the case in our model, we ignore it in our implementation
EdmProperty edmKeyProperty = (EdmProperty) edmEntityType.getProperty(keyName);
// Edm: we need this info for the comparison below
Boolean isNullable = edmKeyProperty.isNullable();
Integer maxLength = edmKeyProperty.getMaxLength();
Integer precision = edmKeyProperty.getPrecision();
Boolean isUnicode = edmKeyProperty.isUnicode();
Integer scale = edmKeyProperty.getScale();
// get the EdmType in order to compare
EdmType edmType = edmKeyProperty.getType();
// if(EdmType instanceof EdmPrimitiveType) // do we need this?
EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;
// Runtime data: the value of the current entity
// don't need to check for null, this is done in FWK
Object valueObject = rt_entity.getProperty(keyName).getValue();
// TODO if the property is a complex type
// now need to compare the valueObject with the keyText String
// this is done using the type.valueToString
String valueAsString = null;
try {
valueAsString = edmPrimitiveType.valueToString(valueObject, isNullable,
maxLength, precision, scale, isUnicode);
} catch (EdmPrimitiveTypeException e) {
return false; // TODO proper Exception handling
}
if (valueAsString == null) {
return false;
}
boolean matches = valueAsString.equals(keyText);
if (matches) {
// if the given key value is found in the current entity, continue with the next key
continue;
} else {
// if any of the key properties is not found in the entity, we don't need to search further
return false;
}
}
return true;
}