本文整理汇总了Java中org.apache.olingo.commons.api.edm.EdmProperty.getType方法的典型用法代码示例。如果您正苦于以下问题:Java EdmProperty.getType方法的具体用法?Java EdmProperty.getType怎么用?Java EdmProperty.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.olingo.commons.api.edm.EdmProperty
的用法示例。
在下文中一共展示了EdmProperty.getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validatePropertyValue
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
private void validatePropertyValue(final Property property, final EdmProperty edmProperty,
final EdmBindingTarget edmBindingTarget, final List<String> path)
throws DataProviderException {
final ArrayList<String> newPath = new ArrayList<String>(path);
newPath.add(edmProperty.getName());
if (edmProperty.isCollection()) {
if (edmProperty.getType() instanceof EdmComplexType && property != null) {
for (final Object value : property.asCollection()) {
validateComplexValue((ComplexValue) value, edmBindingTarget,
(EdmComplexType) edmProperty.getType(), newPath);
}
}
} else if (edmProperty.getType() instanceof EdmComplexType) {
validateComplexValue((property == null) ? null : property.asComplex(), edmBindingTarget,
(EdmComplexType) edmProperty.getType(), newPath);
}
}
示例2: createComplexValue
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
private ComplexValue createComplexValue(final EdmProperty edmProperty,
final ComplexValue complexValue, final boolean patch) throws DataProviderException {
final ComplexValue result = new ComplexValue();
final EdmComplexType edmType = (EdmComplexType) edmProperty.getType();
final List<Property> givenProperties = complexValue.getValue();
// Create ALL properties, even if no value is given. Check if null is allowed
for (final String propertyName : edmType.getPropertyNames()) {
final EdmProperty innerEdmProperty = (EdmProperty) edmType.getProperty(propertyName);
final Property currentProperty = findProperty(propertyName, givenProperties);
final Property newProperty = createProperty(innerEdmProperty, propertyName);
result.getValue().add(newProperty);
if (currentProperty != null) {
updateProperty(innerEdmProperty, newProperty, currentProperty, patch);
} else if (innerEdmProperty.isNullable()) {
// Check complex properties ... may be null is not allowed
if (edmProperty.getType().getKind() == EdmTypeKind.COMPLEX) {
updateProperty(innerEdmProperty, newProperty, null, patch);
}
}
}
return result;
}
示例3: getTypeReturnsComplexType
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
@Test
public void getTypeReturnsComplexType() throws Exception {
CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
EdmProviderImpl edm = new EdmProviderImpl(provider);
final FullQualifiedName complexTypeName = new FullQualifiedName("ns", "complex");
CsdlComplexType complexTypeProvider = new CsdlComplexType();
when(provider.getComplexType(complexTypeName)).thenReturn(complexTypeProvider);
CsdlProperty propertyProvider = new CsdlProperty();
propertyProvider.setType(complexTypeName);
final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
assertFalse(property.isCollection());
assertFalse(property.isPrimitive());
final EdmType type = property.getType();
assertEquals(EdmTypeKind.COMPLEX, type.getKind());
assertEquals("ns", type.getNamespace());
assertEquals("complex", type.getName());
}
示例4: getTypeReturnsEnumType
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
@Test
public void getTypeReturnsEnumType() throws Exception {
CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
EdmProviderImpl edm = new EdmProviderImpl(provider);
final FullQualifiedName enumTypeName = new FullQualifiedName("ns", "enum");
CsdlEnumType enumTypeProvider = new CsdlEnumType();
when(provider.getEnumType(enumTypeName)).thenReturn(enumTypeProvider);
CsdlProperty propertyProvider = new CsdlProperty();
propertyProvider.setType(enumTypeName);
final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
assertFalse(property.isCollection());
assertFalse(property.isPrimitive());
final EdmType type = property.getType();
assertEquals(EdmTypeKind.ENUM, type.getKind());
assertEquals("ns", type.getNamespace());
assertEquals("enum", type.getName());
}
示例5: getMatch
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
private List<Entity> getMatch(UriParameter param, List<Entity> es)
throws ODataApplicationException {
ArrayList<Entity> list = new ArrayList<Entity>();
for (Entity entity : es) {
EdmEntityType entityType = this.metadata.getEdm().getEntityType(
new FullQualifiedName(entity.getType()));
EdmProperty property = (EdmProperty) entityType.getProperty(param.getName());
EdmType type = property.getType();
if (type.getKind() == EdmTypeKind.PRIMITIVE) {
Object match = readPrimitiveValue(property, param.getText());
Property entityValue = entity.getProperty(param.getName());
if (match.equals(entityValue.asPrimitive())) {
list.add(entity);
}
} else {
throw new RuntimeException("Can not compare complex objects");
}
}
return list;
}
示例6: createUriParameter
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
private static UriParameter createUriParameter(final EdmProperty edmProperty, final String parameterName,
final String literalValue, final Edm edm, final EdmType referringType,
final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException {
final AliasQueryOption alias = literalValue.startsWith("@") ?
getKeyAlias(literalValue, edmProperty, edm, referringType, aliases) :
null;
final String value = alias == null ? literalValue : alias.getText();
final EdmPrimitiveType primitiveType = (EdmPrimitiveType) edmProperty.getType();
try {
if (!(primitiveType.validate(primitiveType.fromUriLiteral(value), edmProperty.isNullable(),
edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode()))) {
throw new UriValidationException("Invalid key property",
UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, parameterName);
}
} catch (final EdmPrimitiveTypeException e) {
throw new UriValidationException("Invalid key property", e,
UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, parameterName);
}
return new UriParameterImpl()
.setName(parameterName)
.setText("null".equals(literalValue) ? null : literalValue)
.setAlias(alias == null ? null : literalValue)
.setExpression(alias == null ? null :
alias.getValue() == null ? new LiteralImpl(value, primitiveType) : alias.getValue());
}
示例7: read
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
public Entity read(final EdmEntityType edmEntityType, final EntityCollection entitySet,
final List<UriParameter> keys) throws DataProviderException {
try {
for (final Entity entity : entitySet.getEntities()) {
boolean found = true;
for (final UriParameter key : keys) {
final EdmProperty property = (EdmProperty) edmEntityType.getProperty(key.getName());
final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
final Object value = entity.getProperty(key.getName()).getValue();
final Object keyValue =
type.valueOfString(type.fromUriLiteral(key.getText()), property.isNullable(),
property.getMaxLength(), property.getPrecision(), property.getScale(),
property.isUnicode(), Calendar.class.isAssignableFrom(value.getClass())
? Calendar.class : value.getClass());
if (!value.equals(keyValue)) {
found = false;
break;
}
}
if (found) {
return entity;
}
}
return null;
} catch (final EdmPrimitiveTypeException e) {
throw new DataProviderException("Wrong key!", e);
}
}
示例8: updateProperty
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void updateProperty(final EdmProperty edmProperty, Property property,
final Property newProperty, final boolean patch) throws DataProviderException {
if (edmProperty.isPrimitive()) {
if (newProperty != null || !patch) {
final Object value = newProperty == null ? null : newProperty.getValue();
updatePropertyValue(property, value);
}
} else if (edmProperty.isCollection()) {
// Updating collection properties means replacing all entries with the given ones.
property.asCollection().clear();
if (newProperty != null) {
if (edmProperty.getType().getKind() == EdmTypeKind.COMPLEX) {
// Complex type
final List<ComplexValue> complexValues = (List<ComplexValue>) newProperty.asCollection();
// Create each complex value
for (final ComplexValue complexValue : complexValues) {
((List<ComplexValue>) property.asCollection())
.add(createComplexValue(edmProperty, complexValue, patch));
}
} else {
// Primitive type
final List<Object> values = (List<Object>) newProperty.asCollection();
((List<Object>) property.asCollection()).addAll(values);
}
}
} else {
final EdmComplexType type = (EdmComplexType) edmProperty.getType();
for (final String propertyName : type.getPropertyNames()) {
final List<Property> newProperties = newProperty == null || newProperty.asComplex() == null
? null : newProperty.asComplex().getValue();
updateProperty(type.getStructuralProperty(propertyName),
findProperty(propertyName, property.asComplex().getValue()),
newProperties == null ? null : findProperty(propertyName, newProperties), patch);
}
}
}
示例9: read
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
public Entity read(final EdmEntityType edmEntityType, final EntityCollection entitySet,
final List<UriParameter> keys) throws DataProviderException {
try {
for (final Entity entity : entitySet.getEntities()) {
boolean found = true;
for (final UriParameter key : keys) {
EdmKeyPropertyRef refType = edmEntityType.getKeyPropertyRef(key.getName());
Object value = findPropertyRefValue(entity, refType);
final EdmProperty property = refType.getProperty();
final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
if (key.getExpression() != null && !(key.getExpression() instanceof Literal)) {
throw new DataProviderException("Expression in key value is not supported yet!",
HttpStatusCode.NOT_IMPLEMENTED);
}
final String text = key.getAlias() == null ? key.getText() : ((Literal) key.getExpression()).getText();
final Object keyValue = type.valueOfString(type.fromUriLiteral(text),
property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
property.isUnicode(),
Calendar.class.isAssignableFrom(value.getClass()) ? Calendar.class : value.getClass());
if (!value.equals(keyValue)) {
found = false;
break;
}
}
if (found) {
return entity;
}
}
return null;
} catch (final EdmPrimitiveTypeException e) {
throw new DataProviderException("Wrong key!", HttpStatusCode.BAD_REQUEST, e);
}
}
示例10: writePropertyValue
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
private void writePropertyValue(final ServiceMetadata metadata, final EdmProperty edmProperty,
final Property property, final Set<List<String>> selectedPaths, final JsonGenerator json)
throws IOException, SerializerException {
final EdmType type = edmProperty.getType();
try {
if (edmProperty.isPrimitive()
|| type.getKind() == EdmTypeKind.ENUM || type.getKind() == EdmTypeKind.DEFINITION) {
if (edmProperty.isCollection()) {
writePrimitiveCollection((EdmPrimitiveType) type, property,
edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json);
} else {
writePrimitive((EdmPrimitiveType) type, property,
edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json);
}
} else if (property.isComplex()) {
if (edmProperty.isCollection()) {
writeComplexCollection(metadata, (EdmComplexType) type, property, selectedPaths, json);
} else {
writeComplex(metadata, (EdmComplexType) type, property, selectedPaths, json);
}
} else {
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
}
} catch (final EdmPrimitiveTypeException e) {
throw new SerializerException("Wrong value for property!", e,
SerializerException.MessageKeys.WRONG_PROPERTY_VALUE,
edmProperty.getName(), property.getValue().toString());
}
}
示例11: updateProperty
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void updateProperty(final EdmProperty edmProperty, Property property, final Property newProperty,
final boolean patch) throws DataProviderException {
if(property == null){
throw new DataProviderException("Cannot update type of the entity",
HttpStatusCode.BAD_REQUEST);
}
final EdmType type = edmProperty.getType();
if (edmProperty.isCollection()) {
// Updating collection properties means replacing all entries with the given ones.
property.asCollection().clear();
if (newProperty != null) {
if (type.getKind() == EdmTypeKind.COMPLEX) {
// Create each complex value.
for (final ComplexValue complexValue : (List<ComplexValue>) newProperty.asCollection()) {
((List<ComplexValue>) property.asCollection()).add(createComplexValue(edmProperty, complexValue, patch));
}
} else {
// Primitive type
((List<Object>) property.asCollection()).addAll(newProperty.asCollection());
}
}
} else if (type.getKind() == EdmTypeKind.COMPLEX) {
for (final String propertyName : ((EdmComplexType) type).getPropertyNames()) {
final List<Property> newProperties = newProperty == null || newProperty.asComplex() == null ? null :
newProperty.asComplex().getValue();
updateProperty(((EdmComplexType) type).getStructuralProperty(propertyName),
findProperty(propertyName, property.asComplex().getValue()),
newProperties == null ? null : findProperty(propertyName, newProperties),
patch);
}
} else {
if (newProperty != null || !patch) {
final Object value = newProperty == null ? null : newProperty.getValue();
updatePropertyValue(property, value);
}
}
}
示例12: createComplexValue
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
private ComplexValue createComplexValue(final EdmProperty edmProperty, final ComplexValue complexValue,
final boolean patch) throws DataProviderException {
final ComplexValue result = new ComplexValue();
EdmComplexType edmType = (EdmComplexType) edmProperty.getType();
final List<Property> givenProperties = complexValue.getValue();
if(complexValue.getTypeName()!=null){
EdmComplexType derivedType = edm.getComplexType(new FullQualifiedName(complexValue.getTypeName()));
if(derivedType.getBaseType()!=null && edmType.getFullQualifiedName().getFullQualifiedNameAsString()
.equals(derivedType.getBaseType().getFullQualifiedName().getFullQualifiedNameAsString())){
edmType = derivedType;
}
}
// Create ALL properties, even if no value is given. Check if null is allowed
for (final String propertyName : edmType.getPropertyNames()) {
final EdmProperty innerEdmProperty = (EdmProperty) edmType.getProperty(propertyName);
final Property currentProperty = findProperty(propertyName, givenProperties);
final Property newProperty = createProperty(innerEdmProperty, propertyName);
result.getValue().add(newProperty);
if (currentProperty != null) {
updateProperty(innerEdmProperty, newProperty, currentProperty, patch);
} else {
if (innerEdmProperty.isNullable()) {
// Check complex properties ... may be null is not allowed
if (edmProperty.getType().getKind() == EdmTypeKind.COMPLEX) {
updateProperty(innerEdmProperty, newProperty, null, patch);
}
}
}
}
result.setTypeName(edmType.getFullQualifiedName().getFullQualifiedNameAsString());
return result;
}
示例13: getTypeReturnsNoTypeKind
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
@Test(expected = EdmException.class)
public void getTypeReturnsNoTypeKind() throws Exception {
CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
EdmProviderImpl edm = new EdmProviderImpl(provider);
final CsdlProperty propertyProvider = new CsdlProperty()
.setType(new FullQualifiedName(EdmPrimitiveType.EDM_NAMESPACE, "type"));
final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
property.getType();
fail();
}
示例14: toProperty
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static Property toProperty(
String propertyName, Object sourceValue, EdmProperty description) {
ValueType valueType;
Object value;
EdmTypeKind kind = description.getType().getKind();
switch (kind) {
case COMPLEX:
if (description.isCollection()) {
valueType = ValueType.COLLECTION_COMPLEX;
value = toCollection(
(EdmComplexType) description.getType(), sourceValue);
} else if (sourceValue instanceof List) {
valueType = ValueType.COMPLEX;
List<Map<String, Object>> list = (List<Map<String, Object>>) sourceValue;
if (list.isEmpty()) {
value = null;
} else {
log.warn("Discarded all elements from list {} except first", propertyName);
value = toComplexValue(
(EdmComplexType) description.getType(), list.get(0));
}
} else {
valueType = ValueType.COMPLEX;
value = toComplexValue(
(EdmComplexType) description.getType(), (Map<String, Object>) sourceValue);
}
break;
case PRIMITIVE:
valueType = ValueType.PRIMITIVE;
if (description.getType() instanceof EdmBinary) {
value = toByteArray((String) sourceValue);
} else if (description.getType() instanceof EdmDateTimeOffset) {
value = toDate((String) sourceValue);
} else if (description.getType() instanceof EdmGeographyPoint) {
value = toPoint((Map<String, Double>) sourceValue);
} else {
value = sourceValue;
}
break;
default:
throw new UnsupportedOperationException("Cannot convert from EdmTypeKind " + kind);
}
return new Property(null, propertyName, valueType, value);
}
示例15: readPrimitiveOrValue
import org.apache.olingo.commons.api.edm.EdmProperty; //导入方法依赖的package包/类
private void readPrimitiveOrValue(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType responseFormat, Boolean isValue) throws ODataApplicationException, SerializerException {
// 1. Retrieve info from URI
// 1.1. retrieve the info about the requested entity set
List<UriResource> resourceParts = uriInfo.getUriResourceParts();
UriResourceEntitySet uriEntityset = (UriResourceEntitySet) resourceParts.get(0);
EdmEntitySet edmEntitySet = uriEntityset.getEntitySet();
// 1.2. retrieve the requested (Edm) property
// the second to last segment is the Property, if the last is $value
UriResource lastResourcePart = resourceParts.get(resourceParts.size() - 1);
int minSize = 1;
if (lastResourcePart.getSegmentValue().equals("$value")) {
minSize++;
}
UriResourceProperty uriProperty = (UriResourceProperty) resourceParts.get(resourceParts.size() - minSize);
EdmProperty edmProperty = uriProperty.getProperty();
String edmPropertyName = edmProperty.getName();
EdmPrimitiveType edmPropertyType = (EdmPrimitiveType) edmProperty.getType();
// 2. retrieve data from backend
// 2.1. retrieve the entity data, for which the property has to be read
Entity entity = null;
try {
entity = SparqlBaseCommand.readEntity(rdfEdmProvider, uriInfo, UriType.URI5);
} catch (EdmException | OData2SparqlException | ODataException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(),
Locale.ENGLISH);
}
if (entity == null) {
throw new ODataApplicationException("Property not found", HttpStatusCode.NOT_FOUND.getStatusCode(),
Locale.ENGLISH);
}
// 2.2. retrieve the property data from the entity
Property property = entity.getProperty(edmPropertyName);
if (property == null) {
throw new ODataApplicationException("Property not found", HttpStatusCode.NOT_FOUND.getStatusCode(),
Locale.ENGLISH);
}
// 3. serialize
if (isValue) {
writePropertyValue(response, property);
} else {
writeProperty(request, response, responseFormat, edmEntitySet, edmPropertyName, edmPropertyType, property);
}
}
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:49,代码来源:SparqlPrimitiveValueProcessor.java