Cleaning up EntityContainerFactory#getServiceRoot
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/3c0b8ad2 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/3c0b8ad2 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/3c0b8ad2 Branch: refs/heads/master Commit: 3c0b8ad2658cf84f002e3b10c9b93d6ea1ccc9c5 Parents: 72d894c Author: Francesco Chicchiriccò <--global> Authored: Thu May 22 08:55:43 2014 +0200 Committer: Francesco Chicchiriccò <--global> Committed: Thu May 22 08:55:43 2014 +0200 ---------------------------------------------------------------------- .../ext/proxy/EntityContainerFactory.java | 30 ++++++-------------- .../AbstractStructuredInvocationHandler.java | 10 +++---- .../proxy/commons/ComplexInvocationHandler.java | 4 +-- .../olingo/ext/proxy/commons/ContainerImpl.java | 16 +++++------ .../proxy/commons/EntityInvocationHandler.java | 5 ++-- .../commons/OperationInvocationHandler.java | 9 ++---- 6 files changed, 25 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3c0b8ad2/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java index 9de2d4f..b0d2ff9 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java @@ -21,7 +21,6 @@ package org.apache.olingo.ext.proxy; import java.lang.reflect.Proxy; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.apache.commons.lang3.StringUtils; import org.apache.olingo.client.api.CommonEdmEnabledODataClient; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.format.ODataPubFormat; @@ -46,8 +45,6 @@ public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient< private final CommonEdmEnabledODataClient<?> client; - private final String serviceRoot; - public static Context getContext() { synchronized (MONITOR) { if (context == null) { @@ -59,33 +56,31 @@ public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient< } @SuppressWarnings("unchecked") - private static <C extends CommonEdmEnabledODataClient<?>> EntityContainerFactory<C> getInstance( - final C client, final String serviceRoot) { + private static <C extends CommonEdmEnabledODataClient<?>> EntityContainerFactory<C> getInstance(final C client) { - if (!FACTORY_PER_SERVICEROOT.containsKey(serviceRoot)) { + if (!FACTORY_PER_SERVICEROOT.containsKey(client.getServiceRoot())) { client.getConfiguration().setDefaultPubFormat(ODataPubFormat.JSON_FULL_METADATA); - final EntityContainerFactory<C> instance = new EntityContainerFactory<C>(client, serviceRoot); - FACTORY_PER_SERVICEROOT.put(serviceRoot, instance); + final EntityContainerFactory<C> instance = new EntityContainerFactory<C>(client); + FACTORY_PER_SERVICEROOT.put(client.getServiceRoot(), instance); } - return (EntityContainerFactory<C>) FACTORY_PER_SERVICEROOT.get(serviceRoot); + return (EntityContainerFactory<C>) FACTORY_PER_SERVICEROOT.get(client.getServiceRoot()); } public static EntityContainerFactory<org.apache.olingo.client.api.v3.EdmEnabledODataClient> getV3( final String serviceRoot) { - return getInstance(ODataClientFactory.getEdmEnabledV3(serviceRoot), serviceRoot); + return getInstance(ODataClientFactory.getEdmEnabledV3(serviceRoot)); } public static EntityContainerFactory<org.apache.olingo.client.api.v4.EdmEnabledODataClient> getV4( final String serviceRoot) { - return getInstance(ODataClientFactory.getEdmEnabledV4(serviceRoot), serviceRoot); + return getInstance(ODataClientFactory.getEdmEnabledV4(serviceRoot)); } - private EntityContainerFactory(final CommonEdmEnabledODataClient<?> client, final String serviceRoot) { + private EntityContainerFactory(final CommonEdmEnabledODataClient<?> client) { this.client = client; - this.serviceRoot = serviceRoot; } @SuppressWarnings("unchecked") @@ -93,24 +88,15 @@ public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient< return (C) client; } - public String getServiceRoot() { - return serviceRoot; - } - /** * Return an initialized concrete implementation of the passed EntityContainer interface. * * @param <T> interface annotated as EntityContainer * @param reference class object of the EntityContainer annotated interface * @return an initialized concrete implementation of the passed reference - * @throws IllegalStateException if <tt>serviceRoot</tt> was not set * @throws IllegalArgumentException if the passed reference is not an interface annotated as EntityContainer */ public <T> T getEntityContainer(final Class<T> reference) throws IllegalStateException, IllegalArgumentException { - if (StringUtils.isBlank(serviceRoot)) { - throw new IllegalStateException("serviceRoot was not set"); - } - if (!ENTITY_CONTAINERS.containsKey(reference)) { final Object entityContainer = Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3c0b8ad2/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 5f04408..f208e83 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 @@ -219,9 +219,7 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca protected abstract Object getNavigationPropertyValue(final NavigationProperty property, final Method getter); - protected Object retrieveNavigationProperty( - final NavigationProperty property, final Method getter, final String serviceRoot) { - + protected Object retrieveNavigationProperty(final NavigationProperty property, final Method getter) { final Class<?> type = getter.getReturnType(); final Class<?> collItemType; if (AbstractEntityCollection.class.isAssignableFrom(type)) { @@ -241,7 +239,7 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca null, ((ODataInlineEntity) link).getEntity(), property.targetContainer(), - client.newURIBuilder(serviceRoot).appendEntitySetSegment(property.targetEntitySet()).build(), + client.newURIBuilder().appendEntitySetSegment(property.targetEntitySet()).build(), type, false); } else if (link instanceof ODataInlineEntitySet) { @@ -255,7 +253,7 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca false); } else { // navigate - final URI uri = URIUtils.getURI(containerHandler.getFactory().getServiceRoot(), link.getLink().toASCIIString()); + final URI uri = URIUtils.getURI(client.getServiceRoot(), link.getLink().toASCIIString()); if (AbstractEntityCollection.class.isAssignableFrom(type)) { navPropValue = getEntityCollectionProxy( collItemType, @@ -278,7 +276,7 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca uri, res.getBody(), property.targetContainer(), - client.newURIBuilder(serviceRoot).appendEntitySetSegment(property.targetEntitySet()).build(), + client.newURIBuilder().appendEntitySetSegment(property.targetEntitySet()).build(), type, res.getETag(), true); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3c0b8ad2/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 a207e68..2a7e946 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 @@ -174,7 +174,7 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle throw new UnsupportedOperationException("Internal object is not navigable"); } - return retrieveNavigationProperty(property, getter, containerHandler.getFactory().getServiceRoot()); + return retrieveNavigationProperty(property, getter); } @Override @@ -186,7 +186,7 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle @Override public void removeAdditionalProperty(final String name) { final CommonODataProperty property = getComplex().get(name); - if(property !=null && !property.hasNullValue()){ + if (property != null && !property.hasNullValue()) { setPropertyValue(name, null, null); attach(AttachedEntityStatus.CHANGED); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3c0b8ad2/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 1a6e6d9..f7abf9b 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 @@ -336,7 +336,6 @@ class ContainerImpl implements Container { : ODataLinkType.ENTITY_NAVIGATION; final Set<EntityInvocationHandler> toBeLinked = new HashSet<EntityInvocationHandler>(); - final String serviceRoot = factory.getServiceRoot(); for (Object proxy : type == ODataLinkType.ENTITY_SET_NAVIGATION ? (Collection) property.getValue() : Collections.singleton(property.getValue())) { @@ -352,7 +351,7 @@ class ContainerImpl implements Container { if ((status == AttachedEntityStatus.ATTACHED || status == AttachedEntityStatus.LINKED) && !target.isChanged()) { entity.addLink(buildNavigationLink( property.getKey().name(), - URIUtils.getURI(serviceRoot, editLink.toASCIIString()), type)); + URIUtils.getURI(client.getServiceRoot(), editLink.toASCIIString()), type)); } else { if (!items.contains(target)) { pos = processEntityContext(target, pos, items, delayedUpdates, changeset); @@ -367,7 +366,7 @@ class ContainerImpl implements Container { } else if (status == AttachedEntityStatus.CHANGED) { entity.addLink(buildNavigationLink( property.getKey().name(), - URIUtils.getURI(serviceRoot, editLink.toASCIIString()), type)); + URIUtils.getURI(client.getServiceRoot(), editLink.toASCIIString()), type)); } else { // create the link for the current object LOG.debug("'{}' from '{}' to (${}) '{}'", type.name(), handler, targetPos, target); @@ -406,7 +405,7 @@ class ContainerImpl implements Container { if (!handler.getPropertyChanges().isEmpty()) { final URI targetURI = currentStatus == AttachedEntityStatus.NEW ? URI.create("$" + startingPos) - : URIUtils.getURI(factory.getServiceRoot(), handler.getEntity().getEditLink().toASCIIString()); + : URIUtils.getURI(client.getServiceRoot(), handler.getEntity().getEditLink().toASCIIString()); batchUpdate(handler, targetURI, entity, changeset); pos++; items.put(handler, pos); @@ -417,7 +416,7 @@ class ContainerImpl implements Container { final URI targetURI = currentStatus == AttachedEntityStatus.NEW ? URI.create("$" + startingPos + "/$value") : URIUtils.getURI( - factory.getServiceRoot(), handler.getEntity().getEditLink().toASCIIString() + "/$value"); + client.getServiceRoot(), handler.getEntity().getEditLink().toASCIIString() + "/$value"); batchUpdateMediaEntity(handler, targetURI, handler.getStreamChanges(), changeset); @@ -430,7 +429,7 @@ class ContainerImpl implements Container { for (Map.Entry<String, InputStream> streamedChanges : handler.getStreamedPropertyChanges().entrySet()) { final URI targetURI = currentStatus == AttachedEntityStatus.NEW ? URI.create("$" + startingPos) : URIUtils.getURI( - factory.getServiceRoot(), + client.getServiceRoot(), CoreUtils.getMediaEditLink(streamedChanges.getKey(), entity).toASCIIString()); batchUpdateMediaResource(handler, targetURI, streamedChanges.getValue(), changeset); @@ -482,7 +481,7 @@ class ContainerImpl implements Container { final URI sourceURI; if (status == AttachedEntityStatus.CHANGED) { sourceURI = URIUtils.getURI( - factory.getServiceRoot(), + client.getServiceRoot(), delayedUpdate.getSource().getEntity().getEditLink().toASCIIString()); } else { int sourcePos = items.get(delayedUpdate.getSource()); @@ -494,8 +493,7 @@ class ContainerImpl implements Container { final URI targetURI; if (status == AttachedEntityStatus.CHANGED) { - targetURI = URIUtils.getURI( - factory.getServiceRoot(), target.getEntity().getEditLink().toASCIIString()); + targetURI = URIUtils.getURI(client.getServiceRoot(), target.getEntity().getEditLink().toASCIIString()); } else { int targetPos = items.get(target); targetURI = URI.create("$" + targetPos); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3c0b8ad2/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 2d9065a..4c2fa36 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 @@ -338,8 +338,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler try { if (res == null) { final URI link = URIUtils.getURI( - containerHandler.getFactory().getServiceRoot(), - CoreUtils.getMediaEditLink(name, getEntity()).toASCIIString()); + client.getServiceRoot(), CoreUtils.getMediaEditLink(name, getEntity()).toASCIIString()); final ODataMediaRequest req = client.getRetrieveRequestFactory().getMediaRequest(link); res = req.execute().getBody(); @@ -369,7 +368,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler if (linkChanges.containsKey(property)) { navPropValue = linkChanges.get(property); } else { - navPropValue = retrieveNavigationProperty(property, getter, containerHandler.getFactory().getServiceRoot()); + navPropValue = retrieveNavigationProperty(property, getter); } if (navPropValue != null) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3c0b8ad2/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 d28a319..1a3e1be 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 @@ -48,8 +48,6 @@ final class OperationInvocationHandler extends AbstractInvocationHandler impleme private final FullQualifiedName targetFQN; - private final String serviceRoot; - static OperationInvocationHandler getInstance(final EntityContainerInvocationHandler containerHandler) { return new OperationInvocationHandler(containerHandler); } @@ -69,8 +67,6 @@ final class OperationInvocationHandler extends AbstractInvocationHandler impleme this.targetFQN = new FullQualifiedName(containerHandler.getSchemaName(), containerHandler.getEntityContainerName()); - - this.serviceRoot = containerHandler.getFactory().getServiceRoot(); } private OperationInvocationHandler(final EntityInvocationHandler entityHandler) { @@ -78,7 +74,6 @@ final class OperationInvocationHandler extends AbstractInvocationHandler impleme this.target = entityHandler; this.targetFQN = entityHandler.getEntity().getTypeName(); - this.serviceRoot = containerHandler.getFactory().getServiceRoot(); } private OperationInvocationHandler(final EntityCollectionInvocationHandler<?> collectionHandler) { @@ -90,7 +85,6 @@ final class OperationInvocationHandler extends AbstractInvocationHandler impleme final String typeNamespace = ClassUtils.getNamespace(collectionHandler.getEntityReference()); this.targetFQN = new FullQualifiedName(typeNamespace, typeName); - this.serviceRoot = containerHandler.getFactory().getServiceRoot(); } @Override @@ -144,6 +138,7 @@ final class OperationInvocationHandler extends AbstractInvocationHandler impleme private Map.Entry<URI, EdmOperation> getUnboundOperation( final Operation operation, final List<String> parameterNames) { + final EdmEntityContainer container = client.getCachedEdm().getEntityContainer(targetFQN); final EdmOperation edmOperation; @@ -153,7 +148,7 @@ final class OperationInvocationHandler extends AbstractInvocationHandler impleme edmOperation = container.getActionImport(operation.name()).getUnboundAction(); } - final CommonURIBuilder<?> uriBuilder = getClient().newURIBuilder(this.serviceRoot). + final CommonURIBuilder<?> uriBuilder = getClient().newURIBuilder(). appendOperationCallSegment(edmOperation.getName()); return new AbstractMap.SimpleEntry<URI, EdmOperation>(uriBuilder.build(), edmOperation);
