You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/05/19 15:28:21 UTC

[32/50] [abbrv] git commit: [OLINGO-261][OLINGO-260] Improving singleton handling

[OLINGO-261][OLINGO-260] Improving singleton handling


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/f17482ae
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/f17482ae
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/f17482ae

Branch: refs/heads/master
Commit: f17482ae4a41485e8a0ff673f1887ed24cb06ccf
Parents: 6852f40
Author: Francesco Chicchiriccò <--global>
Authored: Wed May 14 15:45:26 2014 +0200
Committer: Stephan Klevenz <st...@sap.com>
Committed: Mon May 19 14:34:00 2014 +0200

----------------------------------------------------------------------
 .../commons/AbstractInvocationHandler.java      |  22 ++--
 .../AbstractStructuredInvocationHandler.java    |  20 ++-
 .../ComplexFactoryInvocationHandler.java        |  43 ++----
 .../proxy/commons/ComplexInvocationHandler.java |  22 ++--
 .../olingo/ext/proxy/commons/ContainerImpl.java |  36 ++---
 .../EntityContainerInvocationHandler.java       |  11 +-
 .../proxy/commons/EntityInvocationHandler.java  |  17 +--
 .../commons/EntitySetInvocationHandler.java     | 130 +++++++------------
 .../commons/OperationInvocationHandler.java     |   8 +-
 .../commons/SingletonInvocationHandler.java     |  12 +-
 .../ext/proxy/context/AttachedEntity.java       |   8 +-
 .../olingo/ext/proxy/context/EntityContext.java |  28 ++--
 .../ext/proxy/context/EntityLinkDesc.java       |  20 +--
 .../olingo/ext/proxy/utils/CoreUtils.java       |  10 +-
 .../olingo/fit/proxy/v3/ContextTestITCase.java  |  16 +--
 .../v4/BoundOperationInvokeTestITCase.java      |   6 +-
 .../fit/proxy/v4/SingletonTestITCase.java       |  15 +--
 .../odatawcfservice/types/OrderDetail.java      |   2 +
 18 files changed, 174 insertions(+), 252 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java
index 516664d..5181b48 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java
@@ -26,7 +26,6 @@ import java.lang.reflect.Proxy;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -50,22 +49,22 @@ import org.apache.olingo.ext.proxy.api.annotations.Parameter;
 import org.apache.olingo.ext.proxy.utils.ClassUtils;
 import org.apache.olingo.ext.proxy.utils.CoreUtils;
 
-abstract class AbstractInvocationHandler<C extends CommonEdmEnabledODataClient<?>> implements InvocationHandler {
+abstract class AbstractInvocationHandler implements InvocationHandler {
 
   private static final long serialVersionUID = 358520026931462958L;
 
-  protected final C client;
+  protected final CommonEdmEnabledODataClient<?> client;
 
-  protected EntityContainerInvocationHandler<C> containerHandler;
+  protected EntityContainerInvocationHandler containerHandler;
 
   protected AbstractInvocationHandler(
-          final C client, final EntityContainerInvocationHandler<C> containerHandler) {
+          final CommonEdmEnabledODataClient<?> client, final EntityContainerInvocationHandler containerHandler) {
 
     this.client = client;
     this.containerHandler = containerHandler;
   }
 
-  protected C getClient() {
+  protected CommonEdmEnabledODataClient<?> getClient() {
     return client;
   }
 
@@ -106,7 +105,7 @@ abstract class AbstractInvocationHandler<C extends CommonEdmEnabledODataClient<?
     return Proxy.newProxyInstance(
             Thread.currentThread().getContextClassLoader(),
             new Class<?>[] {typeCollectionRef},
-            new EntityCollectionInvocationHandler(containerHandler, items, typeRef, entityContainerName, uri));
+            new EntityCollectionInvocationHandler(containerHandler, items, typeRef, uri));
   }
 
   protected <T> T getEntityProxy(
@@ -128,8 +127,8 @@ abstract class AbstractInvocationHandler<C extends CommonEdmEnabledODataClient<?
           final String eTag,
           final boolean checkInTheContext) {
 
-    EntityTypeInvocationHandler<C> handler = (EntityTypeInvocationHandler<C>) EntityTypeInvocationHandler.getInstance(
-            entity, entitySetName, type, containerHandler);
+    EntityTypeInvocationHandler handler =
+            EntityTypeInvocationHandler.getInstance(entity, entitySetName, type, containerHandler);
 
     if (StringUtils.isNotBlank(eTag)) {
       // override ETag into the wrapped object.
@@ -137,8 +136,7 @@ abstract class AbstractInvocationHandler<C extends CommonEdmEnabledODataClient<?
     }
 
     if (checkInTheContext && EntityContainerFactory.getContext().entityContext().isAttached(handler)) {
-      handler = (EntityTypeInvocationHandler<C>) EntityContainerFactory.getContext().entityContext().
-              getEntity(handler.getUUID());
+      handler = EntityContainerFactory.getContext().entityContext().getEntity(handler.getUUID());
     }
 
     return (T) Proxy.newProxyInstance(
@@ -157,7 +155,7 @@ abstract class AbstractInvocationHandler<C extends CommonEdmEnabledODataClient<?
           IllegalArgumentException, InvocationTargetException {
 
     // 1. invoke params (if present)
-    final Map<String, ODataValue> parameterValues = new HashMap<String, ODataValue>();
+    final Map<String, ODataValue> parameterValues = new LinkedHashMap<String, ODataValue>();
     if (!parameters.isEmpty()) {
       for (Map.Entry<Parameter, Object> parameter : parameters.entrySet()) {
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java
index d9a9d85..4fd5a7e 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java
@@ -47,8 +47,7 @@ import org.apache.olingo.ext.proxy.utils.ClassUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?>>
-        extends AbstractInvocationHandler<C> {
+public abstract class AbstractTypeInvocationHandler extends AbstractInvocationHandler {
 
   private static final long serialVersionUID = 2629912294765040037L;
 
@@ -61,16 +60,15 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
 
   protected final EntityContext entityContext = EntityContainerFactory.getContext().entityContext();
 
-  protected final EntityTypeInvocationHandler<C> targetHandler;
+  protected final EntityTypeInvocationHandler targetHandler;
 
   protected Object internal;
 
-  @SuppressWarnings("unchecked")
   protected AbstractTypeInvocationHandler(
-          final C client,
+          final CommonEdmEnabledODataClient<?> client,
           final Class<?> typeRef,
           final Object internal,
-          final EntityContainerInvocationHandler<C> containerHandler) {
+          final EntityContainerInvocationHandler containerHandler) {
 
     super(client, containerHandler);
     this.internal = internal;
@@ -79,10 +77,10 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
   }
 
   protected AbstractTypeInvocationHandler(
-          final C client,
+          final CommonEdmEnabledODataClient<?> client,
           final Class<?> typeRef,
           final Object internal,
-          final EntityTypeInvocationHandler<C> targetHandler) {
+          final EntityTypeInvocationHandler targetHandler) {
 
     super(client, targetHandler == null ? null : targetHandler.containerHandler);
     this.internal = internal;
@@ -97,7 +95,6 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
   }
 
   @Override
-  @SuppressWarnings("unchecked")
   public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
     if (isSelfMethod(method, args)) {
       return invokeSelfMethod(method, args);
@@ -163,7 +160,7 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
 
       return ClassUtils.returnVoid();
     } else {
-      throw new UnsupportedOperationException("Method not found: " + method);
+      throw new NoSuchMethodException(method.getName());
     }
   }
 
@@ -282,8 +279,7 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
         throw new IllegalArgumentException("Invalid argument type");
       }
 
-      @SuppressWarnings("unchecked")
-      final EntityTypeInvocationHandler<C> linkedHandler = (EntityTypeInvocationHandler<C>) etih;
+      final EntityTypeInvocationHandler linkedHandler = (EntityTypeInvocationHandler) etih;
       if (!linkedHandler.getTypeRef().isAnnotationPresent(EntityType.class)) {
         throw new IllegalArgumentException("Invalid argument type " + linkedHandler.getTypeRef().getSimpleName());
       }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java
index 74ea465..150b59d 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java
@@ -20,46 +20,30 @@ package org.apache.olingo.ext.proxy.commons;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
 import org.apache.olingo.ext.proxy.api.OperationExecutor;
 import org.apache.olingo.ext.proxy.api.annotations.Property;
 import org.apache.olingo.ext.proxy.utils.ClassUtils;
 
-class ComplexFactoryInvocationHandler extends AbstractInvocationHandler implements OperationExecutor {
+class FactoryInvocationHandler extends AbstractInvocationHandler implements OperationExecutor {
 
   private static final long serialVersionUID = 2629912294765040027L;
 
-  private final EntityInvocationHandler entityHandler;
+  private final EntityTypeInvocationHandler entityHandler;
 
-  private final AbstractStructuredInvocationHandler invokerHandler;
+  private final AbstractTypeInvocationHandler invokerHandler;
 
-  static ComplexFactoryInvocationHandler getInstance(
-          final CommonEdmEnabledODataClient<?> client,
-          final EntityContainerInvocationHandler containerHandler,
-          final EntityInvocationHandler entityHandler,
-          final AbstractStructuredInvocationHandler targetHandler) {
+  static FactoryInvocationHandler getInstance(
+          final EntityTypeInvocationHandler entityHandler,
+          final AbstractTypeInvocationHandler targetHandler) {
 
-    return new ComplexFactoryInvocationHandler(client, containerHandler, entityHandler, targetHandler);
+    return new FactoryInvocationHandler(entityHandler, targetHandler);
   }
 
-  static ComplexFactoryInvocationHandler getInstance(
-          final EntityInvocationHandler entityHandler,
-          final AbstractStructuredInvocationHandler targetHandler) {
-    return new ComplexFactoryInvocationHandler(
-            entityHandler == null ? null : entityHandler.containerHandler.client,
-            targetHandler == null
-            ? entityHandler == null ? null : entityHandler.containerHandler : targetHandler.containerHandler,
-            entityHandler,
-            targetHandler);
-  }
-
-  private ComplexFactoryInvocationHandler(
-          final CommonEdmEnabledODataClient<?> client,
-          final EntityContainerInvocationHandler containerHandler,
-          final EntityInvocationHandler entityHandler,
-          final AbstractStructuredInvocationHandler targetHandler) {
+  private FactoryInvocationHandler(
+          final EntityTypeInvocationHandler entityHandler,
+          final AbstractTypeInvocationHandler targetHandler) {
 
-    super(client, containerHandler);
+    super(targetHandler.containerHandler.getClient(), targetHandler.containerHandler);
     this.invokerHandler = targetHandler;
     this.entityHandler = entityHandler;
   }
@@ -69,7 +53,8 @@ class ComplexFactoryInvocationHandler extends AbstractInvocationHandler implemen
     if (isSelfMethod(method, args)) {
       return invokeSelfMethod(method, args);
     } else if (method.getName().startsWith("new")) {
-      final Method getter = proxy.getClass().getInterfaces()[0].getMethod(method.getName());
+      final String getterName = method.getName().replaceFirst("new", "get");
+      final Method getter = invokerHandler.getTypeRef().getMethod(getterName);
       final Property property = ClassUtils.getAnnotation(Property.class, getter);
       if (property == null) {
         throw new UnsupportedOperationException("Unsupported method " + method.getName());
@@ -78,7 +63,7 @@ class ComplexFactoryInvocationHandler extends AbstractInvocationHandler implemen
       return Proxy.newProxyInstance(
               Thread.currentThread().getContextClassLoader(),
               new Class<?>[] {method.getReturnType()},
-              ComplexInvocationHandler.getInstance(client, property.name(), method.getReturnType(), entityHandler));
+              ComplexTypeInvocationHandler.getInstance(client, property.name(), method.getReturnType(), entityHandler));
     } else {
       throw new NoSuchMethodException(method.getName());
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java
index fe645ae..69de2ea 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java
@@ -41,17 +41,16 @@ import org.apache.olingo.ext.proxy.context.AttachedEntityStatus;
 import org.apache.olingo.ext.proxy.utils.ClassUtils;
 import org.apache.olingo.ext.proxy.utils.CoreUtils;
 
-public class ComplexTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?>>
-        extends AbstractTypeInvocationHandler<C> {
+public class ComplexTypeInvocationHandler extends AbstractTypeInvocationHandler {
 
   private static final long serialVersionUID = 2629912294765040037L;
 
-  public static ComplexTypeInvocationHandler<?> getInstance(
+  public static ComplexTypeInvocationHandler getInstance(
           final CommonEdmEnabledODataClient<?> client,
           final String propertyName,
           final Class<?> reference,
-          final EntityTypeInvocationHandler<?> handler) {
-    
+          final EntityTypeInvocationHandler handler) {
+
     final Class<?> complexTypeRef;
     if (Collection.class.isAssignableFrom(reference)) {
       complexTypeRef = ClassUtils.extractTypeArg(reference);
@@ -70,25 +69,24 @@ public class ComplexTypeInvocationHandler<C extends CommonEdmEnabledODataClient<
     final ODataComplexValue<? extends CommonODataProperty> complex =
             client.getObjectFactory().newComplexValue(typeName.toString());
 
-    return (ComplexTypeInvocationHandler<?>) ComplexTypeInvocationHandler.getInstance(
+    return (ComplexTypeInvocationHandler) ComplexTypeInvocationHandler.getInstance(
             client, complex, complexTypeRef, handler);
   }
 
-  @SuppressWarnings({"unchecked", "rawtypes"})
-  public static ComplexTypeInvocationHandler<?> getInstance(
+  public static ComplexTypeInvocationHandler getInstance(
           final CommonEdmEnabledODataClient<?> client,
           final ODataComplexValue<?> complex,
           final Class<?> typeRef,
-          final EntityTypeInvocationHandler<?> handler) {
+          final EntityTypeInvocationHandler handler) {
 
     return new ComplexTypeInvocationHandler(client, complex, typeRef, handler);
   }
 
   public ComplexTypeInvocationHandler(
-          final C client,
+          final CommonEdmEnabledODataClient<?> client,
           final ODataComplexValue<?> complex,
           final Class<?> typeRef,
-          final EntityTypeInvocationHandler<C> handler) {
+          final EntityTypeInvocationHandler handler) {
 
     super(client, typeRef, complex, handler);
   }
@@ -163,7 +161,7 @@ public class ComplexTypeInvocationHandler<C extends CommonEdmEnabledODataClient<
 
     final EdmTypeInfo type = new EdmTypeInfo.Builder().
             setEdm(client.getCachedEdm()).setTypeExpression(
-            edmProperty.isCollection() ? "Collection(" + property.type() + ")" : property.type()).build();
+                    edmProperty.isCollection() ? "Collection(" + property.type() + ")" : property.type()).build();
 
     client.getBinder().add(
             getComplex(), CoreUtils.getODataProperty(client, property.name(), type, toBeAdded));

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
index 49c1c9f..ab824ec 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
@@ -138,7 +138,7 @@ class ContainerImpl implements Container {
           throw new IllegalStateException("Transaction failed: " + res.getStatusMessage());
         }
 
-        final EntityTypeInvocationHandler<?> handler = items.get(changesetItemId);
+        final EntityTypeInvocationHandler handler = items.get(changesetItemId);
 
         if (handler != null) {
           if (res instanceof ODataEntityCreateResponse) {
@@ -156,7 +156,7 @@ class ContainerImpl implements Container {
   }
 
   private void batch(
-          final EntityTypeInvocationHandler<?> handler,
+          final EntityTypeInvocationHandler handler,
           final CommonODataEntity entity,
           final ODataChangeset changeset) {
 
@@ -181,7 +181,7 @@ class ContainerImpl implements Container {
   }
 
   private void batchCreate(
-          final EntityTypeInvocationHandler<?> handler,
+          final EntityTypeInvocationHandler handler,
           final CommonODataEntity entity,
           final ODataChangeset changeset) {
 
@@ -193,7 +193,7 @@ class ContainerImpl implements Container {
   }
 
   private void batchUpdateMediaEntity(
-          final EntityTypeInvocationHandler<?> handler,
+          final EntityTypeInvocationHandler handler,
           final URI uri,
           final InputStream input,
           final ODataChangeset changeset) {
@@ -215,7 +215,7 @@ class ContainerImpl implements Container {
   }
 
   private void batchUpdateMediaResource(
-          final EntityTypeInvocationHandler<?> handler,
+          final EntityTypeInvocationHandler handler,
           final URI uri,
           final InputStream input,
           final ODataChangeset changeset) {
@@ -232,7 +232,7 @@ class ContainerImpl implements Container {
   }
 
   private void batchUpdate(
-          final EntityTypeInvocationHandler<?> handler,
+          final EntityTypeInvocationHandler handler,
           final CommonODataEntity changes,
           final ODataChangeset changeset) {
 
@@ -255,7 +255,7 @@ class ContainerImpl implements Container {
   }
 
   private void batchUpdate(
-          final EntityTypeInvocationHandler<?> handler,
+          final EntityTypeInvocationHandler handler,
           final URI uri,
           final CommonODataEntity changes,
           final ODataChangeset changeset) {
@@ -281,7 +281,7 @@ class ContainerImpl implements Container {
   }
 
   private void batchDelete(
-          final EntityTypeInvocationHandler<?> handler,
+          final EntityTypeInvocationHandler handler,
           final CommonODataEntity entity,
           final ODataChangeset changeset) {
 
@@ -298,7 +298,7 @@ class ContainerImpl implements Container {
   }
 
   private int processEntityContext(
-          final EntityTypeInvocationHandler<?> handler,
+          final EntityTypeInvocationHandler handler,
           int pos,
           final TransactionItems items,
           final List<EntityLinkDesc> delayedUpdates,
@@ -323,13 +323,13 @@ class ContainerImpl implements Container {
               ? ODataLinkType.ENTITY_SET_NAVIGATION
               : ODataLinkType.ENTITY_NAVIGATION;
 
-      final Set<EntityTypeInvocationHandler<?>> toBeLinked = new HashSet<EntityTypeInvocationHandler<?>>();
+      final Set<EntityTypeInvocationHandler> toBeLinked = new HashSet<EntityTypeInvocationHandler>();
       final String serviceRoot = factory.getServiceRoot();
 
       for (Object proxy : type == ODataLinkType.ENTITY_SET_NAVIGATION
               ? (Collection) property.getValue() : Collections.singleton(property.getValue())) {
 
-        final EntityTypeInvocationHandler<?> target =
+        final EntityTypeInvocationHandler target =
                 (EntityTypeInvocationHandler) Proxy.getInvocationHandler(proxy);
 
         final AttachedEntityStatus status =
@@ -467,7 +467,7 @@ class ContainerImpl implements Container {
         sourceURI = URI.create("$" + sourcePos);
       }
 
-      for (EntityTypeInvocationHandler<?> target : delayedUpdate.getTargets()) {
+      for (EntityTypeInvocationHandler target : delayedUpdate.getTargets()) {
         status = EntityContainerFactory.getContext().entityContext().getStatus(target);
 
         final URI targetURI;
@@ -492,11 +492,11 @@ class ContainerImpl implements Container {
 
   private class TransactionItems {
 
-    private final List<EntityTypeInvocationHandler<?>> keys = new ArrayList<EntityTypeInvocationHandler<?>>();
+    private final List<EntityTypeInvocationHandler> keys = new ArrayList<EntityTypeInvocationHandler>();
 
     private final List<Integer> values = new ArrayList<Integer>();
 
-    public EntityTypeInvocationHandler<?> get(final Integer value) {
+    public EntityTypeInvocationHandler get(final Integer value) {
       if (value != null && values.contains(value)) {
         return keys.get(values.indexOf(value));
       } else {
@@ -504,7 +504,7 @@ class ContainerImpl implements Container {
       }
     }
 
-    public Integer get(final EntityTypeInvocationHandler<?> key) {
+    public Integer get(final EntityTypeInvocationHandler key) {
       if (key != null && keys.contains(key)) {
         return values.get(keys.indexOf(key));
       } else {
@@ -512,14 +512,14 @@ class ContainerImpl implements Container {
       }
     }
 
-    public void remove(final EntityTypeInvocationHandler<?> key) {
+    public void remove(final EntityTypeInvocationHandler key) {
       if (keys.contains(key)) {
         values.remove(keys.indexOf(key));
         keys.remove(key);
       }
     }
 
-    public void put(final EntityTypeInvocationHandler<?> key, final Integer value) {
+    public void put(final EntityTypeInvocationHandler key, final Integer value) {
       // replace just in case of null current value; otherwise add the new entry
       if (key != null && keys.contains(key) && values.get(keys.indexOf(key)) == null) {
         remove(key);
@@ -534,7 +534,7 @@ class ContainerImpl implements Container {
       return sortedValues;
     }
 
-    public boolean contains(final EntityTypeInvocationHandler<?> key) {
+    public boolean contains(final EntityTypeInvocationHandler key) {
       return keys.contains(key);
     }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
index 17f2f5c..e6b1bfe 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
@@ -96,13 +96,6 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
               Thread.currentThread().getContextClassLoader(),
               new Class<?>[] {returnType},
               OperationInvocationHandler.getInstance(this));
-    } else if ("complexFactory".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
-      final Class<?> returnType = method.getReturnType();
-
-      return Proxy.newProxyInstance(
-              Thread.currentThread().getContextClassLoader(),
-              new Class<?>[] {returnType},
-              ComplexFactoryInvocationHandler.getInstance(getClient(), this, null, null));
     } else {
       final Class<?> returnType = method.getReturnType();
 
@@ -113,13 +106,13 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
           return Proxy.newProxyInstance(
                   Thread.currentThread().getContextClassLoader(),
                   new Class<?>[] {returnType},
-                  SingletonInvocationHandler.getInstance(returnType, this, singleton.name()));
+                  SingletonInvocationHandler.getInstance(returnType, this));
         }
       } else {
         return Proxy.newProxyInstance(
                 Thread.currentThread().getContextClassLoader(),
                 new Class<?>[] {returnType},
-                EntitySetInvocationHandler.getInstance(returnType, this, entitySet.name()));
+                EntitySetInvocationHandler.getInstance(returnType, this));
       }
 
       throw new NoSuchMethodException(method.getName());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
index afafeb3..884fb1c 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
@@ -30,7 +30,6 @@ import java.util.Map;
 import java.util.Set;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
 import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest;
 import org.apache.olingo.client.core.uri.URIUtils;
 import org.apache.olingo.commons.api.domain.CommonODataEntity;
@@ -46,8 +45,7 @@ import org.apache.olingo.ext.proxy.context.AttachedEntityStatus;
 import org.apache.olingo.ext.proxy.context.EntityUUID;
 import org.apache.olingo.ext.proxy.utils.CoreUtils;
 
-public class EntityTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?>>
-        extends AbstractTypeInvocationHandler<C> {
+public class EntityTypeInvocationHandler extends AbstractTypeInvocationHandler {
 
   private static final long serialVersionUID = 2629912294765040037L;
 
@@ -65,9 +63,9 @@ public class EntityTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?
 
   private EntityUUID uuid;
 
-  static EntityTypeInvocationHandler<?> getInstance(
+  static EntityTypeInvocationHandler getInstance(
           final CommonODataEntity entity,
-          final EntitySetInvocationHandler<?, ?, ?, ?> entitySet,
+          final EntitySetInvocationHandler<?, ?, ?> entitySet,
           final Class<?> typeRef) {
 
     return getInstance(
@@ -77,12 +75,11 @@ public class EntityTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?
             entitySet.containerHandler);
   }
 
-  @SuppressWarnings({"unchecked", "rawtypes"})
-  static EntityTypeInvocationHandler<?> getInstance(
+  static EntityTypeInvocationHandler getInstance(
           final CommonODataEntity entity,
           final String entitySetName,
           final Class<?> typeRef,
-          final EntityContainerInvocationHandler<?> containerHandler) {
+          final EntityContainerInvocationHandler containerHandler) {
 
     return new EntityTypeInvocationHandler(entity, entitySetName, typeRef, containerHandler);
   }
@@ -91,7 +88,7 @@ public class EntityTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?
           final CommonODataEntity entity,
           final String entitySetName,
           final Class<?> typeRef,
-          final EntityContainerInvocationHandler<C> containerHandler) {
+          final EntityContainerInvocationHandler containerHandler) {
 
     super(containerHandler.getClient(), typeRef, (ODataLinked) entity, containerHandler);
 
@@ -305,7 +302,7 @@ public class EntityTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?
 
   private void setStreamedProperty(final Property property, final InputStream input) {
     final Object obj = propertyChanges.get(property.name());
-    if (obj != null && obj instanceof InputStream) {
+    if (obj instanceof InputStream) {
       IOUtils.closeQuietly((InputStream) obj);
     }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
index 209c8ea..bee8d12 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
@@ -33,7 +33,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 import org.apache.commons.lang3.ArrayUtils;
-import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
 import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
 import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
 import org.apache.olingo.client.api.uri.CommonURIBuilder;
@@ -45,12 +44,11 @@ import org.apache.olingo.commons.api.format.ODataValueFormat;
 import org.apache.olingo.ext.proxy.EntityContainerFactory;
 import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
 import org.apache.olingo.ext.proxy.api.AbstractEntitySet;
+import org.apache.olingo.ext.proxy.api.AbstractSingleton;
 import org.apache.olingo.ext.proxy.api.Query;
 import org.apache.olingo.ext.proxy.api.annotations.CompoundKey;
 import org.apache.olingo.ext.proxy.api.annotations.CompoundKeyElement;
 import org.apache.olingo.ext.proxy.api.annotations.EntitySet;
-import org.apache.olingo.ext.proxy.api.annotations.EntityType;
-import org.apache.olingo.ext.proxy.api.annotations.Singleton;
 import org.apache.olingo.ext.proxy.context.AttachedEntityStatus;
 import org.apache.olingo.ext.proxy.context.EntityContext;
 import org.apache.olingo.ext.proxy.context.EntityUUID;
@@ -59,9 +57,9 @@ import org.apache.olingo.ext.proxy.utils.CoreUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T extends Serializable, 
-        KEY extends Serializable, EC extends AbstractEntityCollection<T>>
-        extends AbstractInvocationHandler<C>
+class EntitySetInvocationHandler<
+        T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
+        extends AbstractInvocationHandler
         implements AbstractEntitySet<T, KEY, EC> {
 
   private static final long serialVersionUID = 2629912294765040027L;
@@ -71,53 +69,38 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
    */
   private static final Logger LOG = LoggerFactory.getLogger(EntitySetInvocationHandler.class);
 
+  private final String entitySetName;
+
+  private final boolean isSingleton;
+
   private final Class<T> typeRef;
 
   private final Class<EC> collTypeRef;
 
-  private final String entitySetName;
-
   private final URI uri;
 
-  private boolean isSingleton = false;
-
   @SuppressWarnings({"rawtypes", "unchecked"})
   static EntitySetInvocationHandler getInstance(
           final Class<?> ref, final EntityContainerInvocationHandler containerHandler) {
 
-    return new EntitySetInvocationHandler(ref, containerHandler);
+    return new EntitySetInvocationHandler(ref, containerHandler, (ref.getAnnotation(EntitySet.class)).name());
   }
 
   @SuppressWarnings("unchecked")
-  private EntitySetInvocationHandler(
+  protected EntitySetInvocationHandler(
           final Class<?> ref,
-          final EntityContainerInvocationHandler<C> containerHandler) {
+          final EntityContainerInvocationHandler containerHandler,
+          final String entitySetName) {
 
     super(containerHandler.getClient(), containerHandler);
+    
+    this.entitySetName = entitySetName;
+    this.isSingleton = AbstractSingleton.class.isAssignableFrom(ref);
 
-    Annotation annotation = ref.getAnnotation(EntitySet.class);
-    if (annotation == null) {
-      annotation = ref.getAnnotation(Singleton.class);
-
-      if (annotation == null) {
-        throw new IllegalArgumentException("Return type " + ref.getName()
-                + " is not annotated as @" + EntitySet.class.getSimpleName());
-      }
-
-      this.entitySetName = ((Singleton) annotation).name();
-      isSingleton = true;
-    } else {
-      this.entitySetName = ((EntitySet) annotation).name();
-    }
-
-    final Type[] abstractEntitySetParams =
-            ((ParameterizedType) ref.getGenericInterfaces()[0]).getActualTypeArguments();
+    final Type[] entitySetParams = ((ParameterizedType) ref.getGenericInterfaces()[0]).getActualTypeArguments();
 
-    this.typeRef = (Class<T>) abstractEntitySetParams[0];
-    if (typeRef.getAnnotation(EntityType.class) == null) {
-      throw new IllegalArgumentException("Invalid entity '" + typeRef.getSimpleName() + "'");
-    }
-    this.collTypeRef = (Class<EC>) abstractEntitySetParams[2];
+    this.typeRef = (Class<T>) entitySetParams[0];
+    this.collTypeRef = (Class<EC>) entitySetParams[2];
 
     final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(containerHandler.getFactory().getServiceRoot());
 
@@ -131,19 +114,19 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
     this.uri = uriBuilder.build();
   }
 
-  Class<T> getTypeRef() {
+  protected Class<T> getTypeRef() {
     return typeRef;
   }
 
-  Class<EC> getCollTypeRef() {
+  protected Class<EC> getCollTypeRef() {
     return collTypeRef;
   }
 
-  String getEntitySetName() {
+  protected String getEntitySetName() {
     return entitySetName;
   }
 
-  URI getUri() {
+  protected URI getURI() {
     return uri;
   }
 
@@ -159,7 +142,7 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
         return newEntity(method.getReturnType());
       }
     } else {
-      throw new UnsupportedOperationException("Method not found: " + method);
+      throw new NoSuchMethodException(method.getName());
     }
   }
 
@@ -168,7 +151,7 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
     final CommonODataEntity entity = client.getObjectFactory().newEntity(
             new FullQualifiedName(containerHandler.getSchemaName(), ClassUtils.getEntityTypeName(reference)));
 
-    final EntityTypeInvocationHandler<?> handler =
+    final EntityTypeInvocationHandler handler =
             EntityTypeInvocationHandler.getInstance(entity, entitySetName, reference, containerHandler);
     EntityContainerFactory.getContext().entityContext().attachNew(handler);
 
@@ -183,27 +166,15 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
     return (NEC) Proxy.newProxyInstance(
             Thread.currentThread().getContextClassLoader(),
             new Class<?>[] {reference},
-            new EntityCollectionInvocationHandler<T, C>(
-            containerHandler, new ArrayList<T>(), typeRef, containerHandler.getEntityContainerName()));
+            new EntityCollectionInvocationHandler<T>(containerHandler, new ArrayList<T>(), typeRef));
   }
 
   @Override
   public Long count() {
-    if (isSingleton) {
-      final ODataRetrieveResponse<org.apache.olingo.commons.api.domain.v4.Singleton> res =
-              ((ODataClient) client).getRetrieveRequestFactory().getSingletonRequest(uri).execute();
-
-      if (res.getBody() == null) {
-        return 0l;
-      } else {
-        return 1l;
-      }
-    } else {
-      final ODataValueRequest req = client.getRetrieveRequestFactory().
-              getValueRequest(client.getURIBuilder(this.uri.toASCIIString()).count().build());
-      req.setFormat(ODataValueFormat.TEXT);
-      return Long.valueOf(req.execute().getBody().asPrimitive().toString());
-    }
+    final ODataValueRequest req = client.getRetrieveRequestFactory().
+            getValueRequest(client.getURIBuilder(this.uri.toASCIIString()).count().build());
+    req.setFormat(ODataValueFormat.TEXT);
+    return Long.valueOf(req.execute().getBody().asPrimitive().toString());
   }
 
   @Override
@@ -219,7 +190,7 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
     return result;
   }
 
-  private LinkedHashMap<String, Object> getCompoundKey(final Object key) {
+  private Map<String, Object> getCompoundKey(final Object key) {
     final Set<CompoundKeyElementWrapper> elements = new TreeSet<CompoundKeyElementWrapper>();
 
     for (Method method : key.getClass().getMethods()) {
@@ -258,8 +229,7 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
     final EntityUUID uuid = new EntityUUID(containerHandler.getEntityContainerName(), entitySetName, typeRef, key);
     LOG.debug("Ask for '{}({})'", typeRef.getSimpleName(), key);
 
-    EntityTypeInvocationHandler<?> handler =
-            EntityContainerFactory.getContext().entityContext().getEntity(uuid);
+    EntityTypeInvocationHandler handler = EntityContainerFactory.getContext().entityContext().getEntity(uuid);
 
     if (handler == null) {
       // not yet attached: search against the service
@@ -277,25 +247,14 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
 
         LOG.debug("Execute query '{}'", uriBuilder.toString());
 
-        final CommonODataEntity entity;
-        final String etag;
-
-        if (isSingleton) {
-          final ODataRetrieveResponse<org.apache.olingo.commons.api.domain.v4.Singleton> res =
-                  ((ODataClient) client).getRetrieveRequestFactory().getSingletonRequest(uri).execute();
-
-          entity = res.getBody();
-          etag = res.getETag();
-        } else {
-          final ODataRetrieveResponse<CommonODataEntity> res =
-                  client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()).execute();
+        final ODataRetrieveResponse<CommonODataEntity> res =
+                client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()).execute();
 
-          etag = res.getETag();
-          entity = res.getBody();
+        final String etag = res.getETag();
+        final CommonODataEntity entity = res.getBody();
 
-          if (entity == null || !key.equals(CoreUtils.getKey(client, typeRef, entity))) {
-            throw new IllegalArgumentException("Invalid singleton " + typeRef.getSimpleName() + "(" + key + ")");
-          }
+        if (entity == null || !key.equals(CoreUtils.getKey(client, typeRef, entity))) {
+          throw new IllegalArgumentException("Invalid singleton " + typeRef.getSimpleName() + "(" + key + ")");
         }
 
         handler = EntityTypeInvocationHandler.getInstance(entity, this, typeRef);
@@ -338,9 +297,9 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
     final List<S> items = new ArrayList<S>(entities.size());
 
     for (CommonODataEntity entity : entities) {
-      final EntityTypeInvocationHandler<?> handler = EntityTypeInvocationHandler.getInstance(entity, this, typeRef);
+      final EntityTypeInvocationHandler handler = EntityTypeInvocationHandler.getInstance(entity, this, typeRef);
 
-      final EntityTypeInvocationHandler<?> handlerInTheContext =
+      final EntityTypeInvocationHandler handlerInTheContext =
               EntityContainerFactory.getContext().entityContext().getEntity(handler.getUUID());
 
       items.add((S) Proxy.newProxyInstance(
@@ -368,8 +327,7 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
     return (SEC) Proxy.newProxyInstance(
             Thread.currentThread().getContextClassLoader(),
             new Class<?>[] {collTypeRef},
-            new EntityCollectionInvocationHandler<S, C>(
-            containerHandler, items, typeRef, containerHandler.getEntityContainerName(), entitySetURI));
+            new EntityCollectionInvocationHandler<S>(containerHandler, items, typeRef, entitySetURI));
   }
 
   @Override
@@ -412,7 +370,7 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
   public void delete(final KEY key) throws IllegalArgumentException {
     final EntityContext entityContext = EntityContainerFactory.getContext().entityContext();
 
-    EntityTypeInvocationHandler<?> entity = entityContext.getEntity(new EntityUUID(
+    EntityTypeInvocationHandler entity = entityContext.getEntity(new EntityUUID(
             containerHandler.getEntityContainerName(),
             entitySetName,
             typeRef,
@@ -421,7 +379,7 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
     if (entity == null) {
       // search for entity
       final T searched = get(key);
-      entity = (EntityTypeInvocationHandler<?>) Proxy.getInvocationHandler(searched);
+      entity = (EntityTypeInvocationHandler) Proxy.getInvocationHandler(searched);
       entityContext.attach(entity, AttachedEntityStatus.DELETED);
     } else {
       entityContext.setStatus(entity, AttachedEntityStatus.DELETED);
@@ -433,7 +391,7 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
     final EntityContext entityContext = EntityContainerFactory.getContext().entityContext();
 
     for (T en : entities) {
-      final EntityTypeInvocationHandler<?> entity = (EntityTypeInvocationHandler<?>) Proxy.getInvocationHandler(en);
+      final EntityTypeInvocationHandler entity = (EntityTypeInvocationHandler) Proxy.getInvocationHandler(en);
       if (entityContext.isAttached(entity)) {
         entityContext.setStatus(entity, AttachedEntityStatus.DELETED);
       } else {
@@ -442,7 +400,7 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext
     }
   }
 
-  private boolean isDeleted(final EntityTypeInvocationHandler<?> handler) {
+  private boolean isDeleted(final EntityTypeInvocationHandler handler) {
     return EntityContainerFactory.getContext().entityContext().getStatus(handler) == AttachedEntityStatus.DELETED;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
index 69e1f9b..cdc0bfb 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
@@ -55,7 +55,7 @@ class OperationInvocationHandler extends AbstractInvocationHandler implements Op
     return new OperationInvocationHandler(containerHandler);
   }
 
-  static OperationInvocationHandler getInstance(final EntityInvocationHandler entityHandler) {
+  static OperationInvocationHandler getInstance(final EntityTypeInvocationHandler entityHandler) {
     return new OperationInvocationHandler(entityHandler);
   }
 
@@ -74,7 +74,7 @@ class OperationInvocationHandler extends AbstractInvocationHandler implements Op
     this.serviceRoot = containerHandler.getFactory().getServiceRoot();
   }
 
-  private OperationInvocationHandler(final EntityInvocationHandler entityHandler) {
+  private OperationInvocationHandler(final EntityTypeInvocationHandler entityHandler) {
     super(entityHandler.getClient(), entityHandler.containerHandler);
 
     this.target = entityHandler;
@@ -128,7 +128,7 @@ class OperationInvocationHandler extends AbstractInvocationHandler implements Op
         final Map.Entry<URI, EdmOperation> edmOperation;
         if (target instanceof EntityContainerInvocationHandler) {
           edmOperation = getUnboundOperation(operation, parameterNames);
-        } else if (target instanceof EntityInvocationHandler) {
+        } else if (target instanceof EntityTypeInvocationHandler) {
           edmOperation = getBoundOperation(operation, parameterNames);
         } else if (target instanceof EntityCollectionInvocationHandler) {
           edmOperation = getCollectionBoundOperation(operation, parameterNames);
@@ -161,7 +161,7 @@ class OperationInvocationHandler extends AbstractInvocationHandler implements Op
   }
 
   private Map.Entry<URI, EdmOperation> getBoundOperation(final Operation operation, final List<String> parameterNames) {
-    final CommonODataEntity entity = ((EntityInvocationHandler) target).getEntity();
+    final CommonODataEntity entity = ((EntityTypeInvocationHandler) target).getEntity();
 
     ODataOperation boundOp = entity.getOperation(operation.name());
     if (boundOp == null) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
index 57b1b39..4ec75eb 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
@@ -22,6 +22,7 @@ import java.io.Serializable;
 import java.lang.reflect.Method;
 import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
 import org.apache.olingo.ext.proxy.api.AbstractSingleton;
+import org.apache.olingo.ext.proxy.api.annotations.Singleton;
 
 public class SingletonInvocationHandler<
         T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
@@ -32,19 +33,18 @@ public class SingletonInvocationHandler<
 
   @SuppressWarnings({"rawtypes", "unchecked"})
   static SingletonInvocationHandler getInstance(
-          final Class<?> ref, final EntityContainerInvocationHandler containerHandler, final String singletonName) {
+          final Class<?> ref, final EntityContainerInvocationHandler containerHandler) {
 
-    return new SingletonInvocationHandler(ref, containerHandler, singletonName);
+    return new SingletonInvocationHandler(ref, containerHandler);
   }
 
   private final EntitySetInvocationHandler<?, ?, ?> entitySetHandler;
 
   @SuppressWarnings({"rawtypes", "unchecked"})
-  private SingletonInvocationHandler(
-          final Class<?> ref, final EntityContainerInvocationHandler containerHandler, final String singletonName) {
-
+  private SingletonInvocationHandler(final Class<?> ref, final EntityContainerInvocationHandler containerHandler) {
     super(containerHandler.getClient(), containerHandler);
-    this.entitySetHandler = EntitySetInvocationHandler.getInstance(ref, containerHandler, singletonName);
+    this.entitySetHandler =
+            new EntitySetInvocationHandler(ref, containerHandler, (ref.getAnnotation(Singleton.class)).name());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/AttachedEntity.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/AttachedEntity.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/AttachedEntity.java
index 8126bcc..96cad42 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/AttachedEntity.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/AttachedEntity.java
@@ -18,20 +18,20 @@
  */
 package org.apache.olingo.ext.proxy.context;
 
-import org.apache.olingo.ext.proxy.commons.EntityInvocationHandler;
+import org.apache.olingo.ext.proxy.commons.EntityTypeInvocationHandler;
 
 public class AttachedEntity {
 
-  private final EntityInvocationHandler entity;
+  private final EntityTypeInvocationHandler entity;
 
   private final AttachedEntityStatus status;
 
-  public AttachedEntity(final EntityInvocationHandler entity, final AttachedEntityStatus status) {
+  public AttachedEntity(final EntityTypeInvocationHandler entity, final AttachedEntityStatus status) {
     this.entity = entity;
     this.status = status;
   }
 
-  public EntityInvocationHandler getEntity() {
+  public EntityTypeInvocationHandler getEntity() {
     return entity;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityContext.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityContext.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityContext.java
index 2b42cd1..ab2c9a8 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityContext.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityContext.java
@@ -24,7 +24,7 @@ import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import org.apache.olingo.ext.proxy.commons.EntityInvocationHandler;
+import org.apache.olingo.ext.proxy.commons.EntityTypeInvocationHandler;
 
 /**
  * Entity context.
@@ -36,16 +36,16 @@ public class EntityContext implements Iterable<AttachedEntity> {
    * <br/>
    * This map have to be used to search for entities by key.
    */
-  private final Map<EntityUUID, EntityInvocationHandler> searchableEntities =
-          new HashMap<EntityUUID, EntityInvocationHandler>();
+  private final Map<EntityUUID, EntityTypeInvocationHandler> searchableEntities =
+          new HashMap<EntityUUID, EntityTypeInvocationHandler>();
 
   /**
    * All attached entities (new entities included).
    * <br/>
    * Attachment order will be maintained.
    */
-  private final Map<EntityInvocationHandler, AttachedEntityStatus> allAttachedEntities =
-          new LinkedHashMap<EntityInvocationHandler, AttachedEntityStatus>();
+  private final Map<EntityTypeInvocationHandler, AttachedEntityStatus> allAttachedEntities =
+          new LinkedHashMap<EntityTypeInvocationHandler, AttachedEntityStatus>();
 
   /**
    * Attaches an entity with status <tt>NEW</tt>.
@@ -55,7 +55,7 @@ public class EntityContext implements Iterable<AttachedEntity> {
    * @see AttachedEntityStatus
    * @param entity entity to be attached.
    */
-  public void attachNew(final EntityInvocationHandler entity) {
+  public void attachNew(final EntityTypeInvocationHandler entity) {
     if (allAttachedEntities.containsKey(entity)) {
       throw new IllegalStateException("An entity with the same key has already been attached");
     }
@@ -70,7 +70,7 @@ public class EntityContext implements Iterable<AttachedEntity> {
    * @see AttachedEntityStatus
    * @param entity entity to be attached.
    */
-  public void attach(final EntityInvocationHandler entity) {
+  public void attach(final EntityTypeInvocationHandler entity) {
     attach(entity, AttachedEntityStatus.ATTACHED);
   }
 
@@ -83,7 +83,7 @@ public class EntityContext implements Iterable<AttachedEntity> {
    * @param entity entity to be attached.
    * @param status status.
    */
-  public void attach(final EntityInvocationHandler entity, final AttachedEntityStatus status) {
+  public void attach(final EntityTypeInvocationHandler entity, final AttachedEntityStatus status) {
     if (isAttached(entity)) {
       throw new IllegalStateException("An entity with the same profile has already been attached");
     }
@@ -100,7 +100,7 @@ public class EntityContext implements Iterable<AttachedEntity> {
    *
    * @param entity entity to be detached.
    */
-  public void detach(final EntityInvocationHandler entity) {
+  public void detach(final EntityTypeInvocationHandler entity) {
     if (searchableEntities.containsKey(entity.getUUID())) {
       searchableEntities.remove(entity.getUUID());
     }
@@ -123,7 +123,7 @@ public class EntityContext implements Iterable<AttachedEntity> {
    * @param uuid entity key.
    * @return retrieved entity.
    */
-  public EntityInvocationHandler getEntity(final EntityUUID uuid) {
+  public EntityTypeInvocationHandler getEntity(final EntityUUID uuid) {
     return searchableEntities.get(uuid);
   }
 
@@ -133,7 +133,7 @@ public class EntityContext implements Iterable<AttachedEntity> {
    * @param entity entity to be retrieved.
    * @return attached entity status.
    */
-  public AttachedEntityStatus getStatus(final EntityInvocationHandler entity) {
+  public AttachedEntityStatus getStatus(final EntityTypeInvocationHandler entity) {
     if (!isAttached(entity)) {
       throw new IllegalStateException("Entity is not in the context");
     }
@@ -147,7 +147,7 @@ public class EntityContext implements Iterable<AttachedEntity> {
    * @param entity attached entity to be modified.
    * @param status new status.
    */
-  public void setStatus(final EntityInvocationHandler entity, final AttachedEntityStatus status) {
+  public void setStatus(final EntityTypeInvocationHandler entity, final AttachedEntityStatus status) {
     if (!isAttached(entity)) {
       throw new IllegalStateException("Entity is not in the context");
     }
@@ -177,7 +177,7 @@ public class EntityContext implements Iterable<AttachedEntity> {
    * @param entity entity.
    * @return <tt>true</tt> if is attached; <tt>false</tt> otherwise.
    */
-  public boolean isAttached(final EntityInvocationHandler entity) {
+  public boolean isAttached(final EntityTypeInvocationHandler entity) {
     return allAttachedEntities.containsKey(entity)
             || (entity.getUUID().getKey() != null && searchableEntities.containsKey(entity.getUUID()));
   }
@@ -190,7 +190,7 @@ public class EntityContext implements Iterable<AttachedEntity> {
   @Override
   public Iterator<AttachedEntity> iterator() {
     final List<AttachedEntity> res = new ArrayList<AttachedEntity>();
-    for (Map.Entry<EntityInvocationHandler, AttachedEntityStatus> attachedEntity : allAttachedEntities.
+    for (Map.Entry<EntityTypeInvocationHandler, AttachedEntityStatus> attachedEntity : allAttachedEntities.
             entrySet()) {
       res.add(new AttachedEntity(attachedEntity.getKey(), attachedEntity.getValue()));
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityLinkDesc.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityLinkDesc.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityLinkDesc.java
index 3c8dadd..791f471 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityLinkDesc.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityLinkDesc.java
@@ -26,7 +26,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 import org.apache.olingo.commons.api.domain.ODataLinkType;
-import org.apache.olingo.ext.proxy.commons.EntityInvocationHandler;
+import org.apache.olingo.ext.proxy.commons.EntityTypeInvocationHandler;
 
 public class EntityLinkDesc implements Serializable {
 
@@ -34,16 +34,16 @@ public class EntityLinkDesc implements Serializable {
 
   private final String sourceName;
 
-  private final EntityInvocationHandler source;
+  private final EntityTypeInvocationHandler source;
 
-  private final Collection<EntityInvocationHandler> targets;
+  private final Collection<EntityTypeInvocationHandler> targets;
 
   private final ODataLinkType type;
 
   public EntityLinkDesc(
           final String sourceName,
-          final EntityInvocationHandler source,
-          final Collection<EntityInvocationHandler> target,
+          final EntityTypeInvocationHandler source,
+          final Collection<EntityTypeInvocationHandler> target,
           final ODataLinkType type) {
     this.sourceName = sourceName;
     this.source = source;
@@ -53,12 +53,12 @@ public class EntityLinkDesc implements Serializable {
 
   public EntityLinkDesc(
           final String sourceName,
-          final EntityInvocationHandler source,
-          final EntityInvocationHandler target,
+          final EntityTypeInvocationHandler source,
+          final EntityTypeInvocationHandler target,
           final ODataLinkType type) {
     this.sourceName = sourceName;
     this.source = source;
-    this.targets = Collections.<EntityInvocationHandler>singleton(target);
+    this.targets = Collections.<EntityTypeInvocationHandler>singleton(target);
     this.type = type;
   }
 
@@ -66,11 +66,11 @@ public class EntityLinkDesc implements Serializable {
     return sourceName;
   }
 
-  public EntityInvocationHandler getSource() {
+  public EntityTypeInvocationHandler getSource() {
     return source;
   }
 
-  public Collection<EntityInvocationHandler> getTargets() {
+  public Collection<EntityTypeInvocationHandler> getTargets() {
     return targets;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
index e8fa91b..9f35182 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
@@ -109,12 +109,12 @@ public final class CoreUtils {
         oo = obj;
       }
 
-      if (oo instanceof ComplexTypeInvocationHandler<?>) {
-        final Class<?> typeRef = ((ComplexTypeInvocationHandler<?>) oo).getTypeRef();
+      if (oo instanceof ComplexTypeInvocationHandler) {
+        final Class<?> typeRef = ((ComplexTypeInvocationHandler) oo).getTypeRef();
         final Object complex = Proxy.newProxyInstance(
                 Thread.currentThread().getContextClassLoader(),
                 new Class<?>[] {typeRef},
-                (ComplexTypeInvocationHandler<?>) oo);
+                (ComplexTypeInvocationHandler) oo);
 
         for (Method method : typeRef.getMethods()) {
           final Property complexPropertyAnn = method.getAnnotation(Property.class);
@@ -325,7 +325,7 @@ public final class CoreUtils {
       if (bean instanceof Proxy) {
         final InvocationHandler handler = Proxy.getInvocationHandler(bean);
         if (handler instanceof AbstractTypeInvocationHandler) {
-          typeRef = ((ComplexTypeInvocationHandler<?>) handler).getTypeRef();
+          typeRef = ((ComplexTypeInvocationHandler) handler).getTypeRef();
         } else {
           throw new IllegalStateException("Invalid bean " + bean);
         }
@@ -410,7 +410,7 @@ public final class CoreUtils {
           final CommonEdmEnabledODataClient<?> client,
           final CommonODataProperty property,
           final Type typeRef,
-          final EntityTypeInvocationHandler<?> entityHandler)
+          final EntityTypeInvocationHandler entityHandler)
           throws InstantiationException, IllegalAccessException {
 
     Class<?> internalRef;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java
index c7e2948..b1b2e75 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java
@@ -218,16 +218,14 @@ public class ContextTestITCase extends AbstractTestITCase {
     assertNotNull(customer.getOrders());
     assertEquals(3, customer.getOrders().size());
 
-    final EntityTypeInvocationHandler<?> source =
-            (EntityTypeInvocationHandler<?>) Proxy.getInvocationHandler(customer);
+    final EntityTypeInvocationHandler source = (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer);
 
     assertTrue(entityContext.isAttached(source));
     assertEquals(AttachedEntityStatus.NEW, entityContext.getStatus(source));
     assertEquals(3, ((Collection) (source.getLinkChanges().entrySet().iterator().next().getValue())).size());
 
     for (Order order : toBeLinked) {
-      final EntityTypeInvocationHandler<?> target =
-              (EntityTypeInvocationHandler<?>) Proxy.getInvocationHandler(order);
+      final EntityTypeInvocationHandler target = (EntityTypeInvocationHandler) Proxy.getInvocationHandler(order);
 
       assertTrue(entityContext.isAttached(target));
       assertEquals(AttachedEntityStatus.NEW, entityContext.getStatus(target));
@@ -423,7 +421,7 @@ public class ContextTestITCase extends AbstractTestITCase {
 
   private void checkUnlink(
           final String sourceName,
-          final EntityTypeInvocationHandler<?> source) {
+          final EntityTypeInvocationHandler source) {
 
     boolean found = false;
     for (Map.Entry<NavigationProperty, Object> property : source.getLinkChanges().entrySet()) {
@@ -436,8 +434,8 @@ public class ContextTestITCase extends AbstractTestITCase {
 
   private void checkLink(
           final String sourceName,
-          final EntityTypeInvocationHandler<?> source,
-          final EntityTypeInvocationHandler<?> target,
+          final EntityTypeInvocationHandler source,
+          final EntityTypeInvocationHandler target,
           final boolean isCollection) {
 
     boolean found = false;
@@ -461,9 +459,9 @@ public class ContextTestITCase extends AbstractTestITCase {
 
   private void checkUnidirectional(
           final String sourceName,
-          final EntityTypeInvocationHandler<?> source,
+          final EntityTypeInvocationHandler source,
           final String targetName,
-          final EntityTypeInvocationHandler<?> target,
+          final EntityTypeInvocationHandler target,
           final boolean isCollection) {
 
     checkLink(sourceName, source, target, isCollection);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/fit/src/test/java/org/apache/olingo/fit/proxy/v4/BoundOperationInvokeTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/BoundOperationInvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/BoundOperationInvokeTestITCase.java
index 7fe47ce..7ee2234 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/BoundOperationInvokeTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/BoundOperationInvokeTestITCase.java
@@ -41,7 +41,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
 
   @Test
   public void getEmployeesCount() {
-    assertNotNull(container.getCompany().get(0).operations().getEmployeesCount());
+    assertNotNull(container.getCompany().get().operations().getEmployeesCount());
   }
 
   @Test
@@ -80,7 +80,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
 
   @Test
   public void increaseRevenue() {
-    final Long result = container.getCompany().get(0).operations().increaseRevenue(12L);
+    final Long result = container.getCompany().get().operations().increaseRevenue(12L);
     assertNotNull(result);
   }
 
@@ -103,7 +103,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
             resetAddress(Collections.singletonList(address), 0);
     assertEquals(2, person.getPersonID(), 0);
   }
-  
+
   @Test
   public void refreshDefaultPI() {
     final PaymentInstrument pi = container.getAccounts().get(101).operations().refreshDefaultPI(Calendar.getInstance());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java
index b4bdda7..d9467bc 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java
@@ -19,30 +19,27 @@
 package org.apache.olingo.fit.proxy.v4;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 
 import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Company;
+import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CompanyCategory;
 import org.junit.Test;
 
 public class SingletonTestITCase extends AbstractTestITCase {
 
   @Test
   public void read() {
-    assertNotNull(container.getCompany().get(0));
-    entityContext.detachAll();
-    assertNotNull(container.getCompany().iterator().next());
-    entityContext.detachAll();
-    assertEquals(1, container.getCompany().count(), 0);
-    entityContext.detachAll();
+    final Company company = container.getCompany().get();
+    assertEquals(0, company.getCompanyID(), 0);
+    assertEquals(CompanyCategory.IT, company.getCompanyCategory());
   }
 
   @Test
   public void update() {
-    final Company company = container.getCompany().get(0);
+    final Company company = container.getCompany().get();
     company.setRevenue(132520L);
 
     container.flush();
 
-    assertEquals(132520L, container.getCompany().get(0).getRevenue(), 0);
+    assertEquals(132520L, container.getCompany().get().getRevenue(), 0);
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f17482ae/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/OrderDetail.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/OrderDetail.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/OrderDetail.java
index ce4fa9c..15a0b9b 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/OrderDetail.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/OrderDetail.java
@@ -59,6 +59,8 @@ import javax.xml.datatype.Duration;
 public interface OrderDetail 
   extends Serializable {
 
+        
+    @Key
     @Property(name = "OrderID", 
                 type = "Edm.Int32", 
                 nullable = false,