in ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/InvokerInvocationHandler.java [111:218]
public T execute() {
if (operation == null || uri == null) {
throw new IllegalStateException("Invalid operation");
}
try {
// 1. IMPORTANT: flush any pending change *before* invoke if this operation is side effecting
if (operation.type() == OperationType.ACTION) {
service.getPersistenceManager().flush();
}
// 2. invoke
final ClientInvokeResult result = service.getClient().getInvokeRequestFactory().getInvokeRequest(
edmOperation instanceof EdmFunction ? HttpMethod.GET : HttpMethod.POST,
uri.build(),
getResultReference(edmOperation.getReturnType()),
parameters).
execute().getBody();
// 3. process invoke result
if (StringUtils.isBlank(operation.returnType())) {
return (T) ClassUtils.returnVoid();
}
final EdmTypeInfo returnType = new EdmTypeInfo.Builder().
setEdm(service.getClient().getCachedEdm()).setTypeExpression(operation.returnType()).build();
if (returnType.isEntityType()) {
if (returnType.isCollection()) {
final Class<?> collItemType = ClassUtils.extractTypeArg(targetRef, EntityCollection.class);
return (T) ProxyUtils.getEntityCollectionProxy(
service,
collItemType,
targetRef,
null,
(ClientEntitySet) result,
this.baseURI,
false);
} else {
return (T) ProxyUtils.getEntityProxy(
service,
(ClientEntity) result,
null,
targetRef,
null,
false);
}
} else {
Object res;
final Class<?> ref = ClassUtils.getTypeClass(targetRef);
final ClientProperty property = (ClientProperty) result;
if (property == null || property.hasNullValue()) {
res = null;
} else if (returnType.isCollection()) {
if (returnType.isComplexType()) {
final Class<?> itemRef = ClassUtils.extractTypeArg(ref, ComplexCollection.class);
final List items = new ArrayList();
for (ClientValue item : property.getValue().asCollection()) {
items.add(ProxyUtils.getComplexProxy(
service,
property.getName(),
item,
itemRef,
null,
null,
true));
}
res = Proxy.newProxyInstance(
Thread.currentThread().getContextClassLoader(),
new Class<?>[] {ref}, new ComplexCollectionInvocationHandler(
service,
items,
itemRef,
null));
} else {
final List items = new ArrayList();
for (ClientValue item : property.getValue().asCollection()) {
items.add(item.asPrimitive().toValue());
}
res = Proxy.newProxyInstance(
Thread.currentThread().getContextClassLoader(),
new Class<?>[] {PrimitiveCollection.class}, new PrimitiveCollectionInvocationHandler(
service,
items,
null,
null));
}
} else {
if (returnType.isComplexType()) {
res = ProxyUtils.getComplexProxy(
service, property.getName(), property.getValue().asComplex(), ref, null, null, false);
} else {
res = CoreUtils.getObjectFromODataValue(property.getValue(), targetRef, service);
}
}
return (T) res;
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
}