Java Code Examples for org.apache.olingo.odata2.api.edm.EdmTyped#getType()

The following examples show how to use org.apache.olingo.odata2.api.edm.EdmTyped#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JPAEntity.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
protected void setComplexProperty(Method accessModifier, final Object jpaEntity,
    final EdmStructuralType edmComplexType, final HashMap<String, Object> propertyValue, String propertyName)
    throws EdmException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
    InstantiationException, ODataJPARuntimeException, NoSuchMethodException, SecurityException, SQLException {

  JPAEdmMapping mapping = (JPAEdmMapping) edmComplexType.getMapping();
  Object embeddableObject = mapping.getJPAType().newInstance();
  if (propertyName != null) {
  	accessModifier.invoke(jpaEntity, propertyName, embeddableObject);
  } else {
  	accessModifier.invoke(jpaEntity, embeddableObject);
  }

  HashMap<String, Method> accessModifiers =
      jpaEntityParser.getAccessModifiers(embeddableObject, edmComplexType,
          JPAEntityParser.ACCESS_MODIFIER_SET);

  for (String edmPropertyName : edmComplexType.getPropertyNames()) {
    if (propertyValue != null) {
      EdmTyped edmTyped = edmComplexType.getProperty(edmPropertyName);
      accessModifier = accessModifiers.get(edmPropertyName);
      EdmType type = edmTyped.getType();
      if (type.getKind().toString().equals(EdmTypeKind.COMPLEX.toString())) {
        setComplexProperty(accessModifier, embeddableObject, (EdmStructuralType) type,
            (HashMap<String, Object>) propertyValue.get(edmPropertyName), propertyName);
      } else {
        EdmSimpleType simpleType = (EdmSimpleType) type;
        EdmProperty edmProperty = (EdmProperty)edmComplexType.getProperty(edmPropertyName);
        boolean isNullable = edmProperty.getFacets() == null ? true
            : edmProperty.getFacets().isNullable() == null ? true : edmProperty.getFacets().isNullable();
  		  if (propertyName != null) {
          setProperty(accessModifier, embeddableObject, propertyValue.get(edmPropertyName),
              simpleType, isNullable);
        } else {
          setProperty(accessModifier, embeddableObject, propertyValue.get(edmPropertyName),
              simpleType, isNullable);
        }
      }
    }
  }
}
 
Example 2
Source File: UriParserImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private void handleFunctionImport(final EdmFunctionImport functionImport, final String emptyParentheses,
    final String keyPredicate) throws UriSyntaxException, UriNotMatchingException, EdmException {
  final EdmTyped returnType = functionImport.getReturnType();
  
  if (returnType != null && returnType.getType() != null) {
    final EdmType type = returnType.getType();
    final boolean isCollection = returnType.getMultiplicity() == EdmMultiplicity.MANY;

    if (type.getKind() == EdmTypeKind.ENTITY && isCollection) {
      handleEntitySet(functionImport.getEntitySet(), keyPredicate);
      return;
    }

    if (emptyParentheses != null) {
      throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(emptyParentheses));
    }

    uriResult.setTargetType(type);
    switch (type.getKind()) {
    case SIMPLE:
      uriResult.setUriType(isCollection ? UriType.URI13 : UriType.URI14);
      break;
    case COMPLEX:
      uriResult.setUriType(isCollection ? UriType.URI11 : UriType.URI12);
      break;
    case ENTITY:
      uriResult.setUriType(UriType.URI10);
      break;
    default:
      throw new UriSyntaxException(UriSyntaxException.INVALIDRETURNTYPE.addContent(type.getKind()));
    }

    if (!pathSegments.isEmpty()) {
      if (uriResult.getUriType() == UriType.URI14) {
        currentPathSegment = pathSegments.remove(0);
        if ("$value".equals(percentDecode(currentPathSegment))) {
          uriResult.setValue(true);
        } else {
          throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(currentPathSegment));
        }
      }
    }
  } else {
    uriResult.setUriType(UriType.URI14);
  }
  ensureLastSegment();
}