From f46364072a68eb040959bd289b3bbd608ced7f68 Mon Sep 17 00:00:00 2001 From: Christian Amend Date: Fri, 6 Mar 2015 18:21:02 +0100 Subject: [PATCH] [OLINGO-575] Delete unnecessary casts --- .../AbstractCollectionInvocationHandler.java | 5 +- ...ractEntityCollectionInvocationHandler.java | 7 +- .../commons/AbstractPersistenceManager.java | 22 +- .../AbstractStructuredInvocationHandler.java | 2 +- .../commons/AnnotatableInvocationHandler.java | 60 +++--- .../commons/EntityInvocationHandler.java | 12 +- .../commons/EntitySetInvocationHandler.java | 5 +- .../olingo/ext/proxy/utils/CoreUtils.java | 33 ++- .../olingo/fit/AbstractBaseTestITCase.java | 32 +-- .../v4/demo/odatademo/types/Customer.java | 6 +- .../v4/JSONFormatConformanceTestITCase.java | 2 +- .../batch/BatchRequestFactoryImpl.java | 3 +- .../request/cud/CUDRequestFactoryImpl.java | 1 + .../invoke/AbstractODataInvokeRequest.java | 8 +- .../retrieve/ODataDeltaRequestImpl.java | 25 ++- .../retrieve/RetrieveRequestFactoryImpl.java | 5 +- .../retrieve/XMLMetadataRequestImpl.java | 48 +++-- .../olingo/client/core/edm/EdmClientImpl.java | 202 ++++++++---------- .../client/core/edm/EdmComplexTypeImpl.java | 36 ++-- .../core/edm/EdmEntityContainerImpl.java | 89 +++----- .../client/core/edm/EdmEntityTypeImpl.java | 17 +- .../client/core/edm/EdmParameterImpl.java | 25 +-- .../client/core/edm/EdmPropertyImpl.java | 24 +-- .../olingo/client/core/edm/EdmSchemaImpl.java | 100 ++++----- .../core/edm/EdmStructuredTypeHelperImpl.java | 19 +- .../client/core/edm/xml/ComplexTypeImpl.java | 4 +- .../client/core/edm/xml/EntityTypeImpl.java | 4 +- .../client/core/edm/xml/XMLMetadataImpl.java | 2 +- .../http/ProxyWrappingHttpClientFactory.java | 1 + .../ClientODataDeserializerImpl.java | 4 + .../core/serialization/ODataBinderImpl.java | 49 +++-- .../core/serialization/ODataReaderImpl.java | 6 +- .../core/serialization/ODataWriterImpl.java | 8 +- .../olingo/client/core/uri/URIUtils.java | 16 +- .../olingo/client/core/v4/EntityTest.java | 90 ++++---- .../commons/api/domain/ODataProperty.java | 43 ---- .../expression/ExpressionVisitorImpl.java | 2 +- .../json/ODataJsonDeserializerEntityTest.java | 11 +- 38 files changed, 450 insertions(+), 578 deletions(-) diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractCollectionInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractCollectionInvocationHandler.java index 9cc6a2548..3f75544b1 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractCollectionInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractCollectionInvocationHandler.java @@ -36,7 +36,6 @@ import org.apache.olingo.client.api.uri.QueryOption; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.client.api.uri.URIFilter; import org.apache.olingo.commons.api.domain.ODataAnnotation; -import org.apache.olingo.commons.api.domain.ODataEntity; import org.apache.olingo.ext.proxy.AbstractService; import org.apache.olingo.ext.proxy.api.AbstractTerm; import org.apache.olingo.ext.proxy.api.EntityType; @@ -182,7 +181,7 @@ public abstract class AbstractCollectionInvocationHandler> boolean addRef(final ET element) { if (element instanceof Proxy && Proxy.getInvocationHandler(element) instanceof EntityInvocationHandler) { final EntityInvocationHandler handler = EntityInvocationHandler.class.cast(Proxy.getInvocationHandler(element)); - final URI id = ((ODataEntity) handler.getEntity()).getId(); + final URI id = handler.getEntity().getId(); if (id == null) { return false; } @@ -195,7 +194,7 @@ public abstract class AbstractCollectionInvocationHandler anns = new ArrayList(); if (isSingleton) { - final ODataRetrieveResponse res = + final ODataRetrieveResponse res = ((ODataClient) getClient()).getRetrieveRequestFactory().getSingletonRequest(uri).execute(); entities.add(res.getBody()); @@ -115,9 +116,7 @@ public abstract class AbstractEntityCollectionInvocationHandler res = new ArrayList(entities.size()); diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java index c20ad25ce..90818758d 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java @@ -156,14 +156,12 @@ abstract class AbstractPersistenceManager implements PersistenceManager { entity.getProperties().clear(); CoreUtils.addProperties(service.getClient(), handler.getPropertyChanges(), entity); - if (entity instanceof ODataEntity) { - ((ODataEntity) entity).getAnnotations().clear(); - CoreUtils.addAnnotations(service.getClient(), handler.getAnnotations(), (ODataEntity) entity); + entity.getAnnotations().clear(); + CoreUtils.addAnnotations(service.getClient(), handler.getAnnotations(), entity); - for (Map.Entry entry : handler.getPropAnnotatableHandlers().entrySet()) { - CoreUtils.addAnnotations(service.getClient(), - entry.getValue().getAnnotations(), ((ODataEntity) entity).getProperty(entry.getKey())); - } + for (Map.Entry entry : handler.getPropAnnotatableHandlers().entrySet()) { + CoreUtils.addAnnotations(service.getClient(), + entry.getValue().getAnnotations(), entity.getProperty(entry.getKey())); } } @@ -235,13 +233,11 @@ abstract class AbstractPersistenceManager implements PersistenceManager { } } - if (entity instanceof ODataEntity) { - for (Map.Entry entry : handler.getNavPropAnnotatableHandlers().entrySet()) { + for (Map.Entry entry : handler.getNavPropAnnotatableHandlers().entrySet()) { - CoreUtils.addAnnotations(service.getClient(), - entry.getValue().getAnnotations(), - (org.apache.olingo.commons.api.domain.ODataLink) entity.getNavigationLink(entry.getKey())); - } + CoreUtils.addAnnotations(service.getClient(), + entry.getValue().getAnnotations(), + entity.getNavigationLink(entry.getKey())); } final AttachedEntityStatus processedStatus = queue(handler, entity, changeset); 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 074dc3f2a..e1b735ea0 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 @@ -633,7 +633,7 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca } public void refs() { - ((URIBuilder) this.uri).appendRefSegment(); + this.uri.appendRefSegment(); } public void clearQueryOptions() { diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AnnotatableInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AnnotatableInvocationHandler.java index 16ef93284..9da95ff6f 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AnnotatableInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AnnotatableInvocationHandler.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -51,14 +51,14 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl private final AbstractStructuredInvocationHandler targetHandler; private final Map, Object> annotations = - new HashMap, Object>(); + new HashMap, Object>(); public AnnotatableInvocationHandler( - final AbstractService service, - final String propName, - final String navPropName, - final EntityInvocationHandler entityHandler, - final AbstractStructuredInvocationHandler targetHandler) { + final AbstractService service, + final String propName, + final String navPropName, + final EntityInvocationHandler entityHandler, + final AbstractStructuredInvocationHandler targetHandler) { super(service); @@ -78,20 +78,16 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl } private List internalAnnotations() { - List result = Collections.emptyList(); + List result = Collections. emptyList(); - if (entityHandler.getEntity() instanceof ODataEntity) { - if (targetHandler.getInternal() instanceof ODataEntity) { - result = propName == null - ? ((org.apache.olingo.commons.api.domain.ODataLink) ((ODataEntity) targetHandler.getInternal()). - getNavigationLink(navPropName)).getAnnotations() - : ((ODataEntity) targetHandler.getInternal()).getProperty(propName).getAnnotations(); - } else if (targetHandler.getInternal() instanceof ODataComplexValue) { - result = propName == null - ? ((org.apache.olingo.commons.api.domain.ODataLink) ((ODataComplexValue) targetHandler. - getInternal()).getNavigationLink(navPropName)).getAnnotations() - : ((ODataComplexValue) targetHandler.getInternal()).get(propName).getAnnotations(); - } + if (targetHandler.getInternal() instanceof ODataEntity) { + result = propName == null + ? ((ODataEntity) targetHandler.getInternal()).getNavigationLink(navPropName).getAnnotations() + : ((ODataEntity) targetHandler.getInternal()).getProperty(propName).getAnnotations(); + } else if (targetHandler.getInternal() instanceof ODataComplexValue) { + result = propName == null + ? ((ODataComplexValue) targetHandler.getInternal()).getNavigationLink(navPropName).getAnnotations() + : ((ODataComplexValue) targetHandler.getInternal()).get(propName).getAnnotations(); } return result; @@ -113,7 +109,7 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl if (item instanceof Proxy) { final InvocationHandler handler = Proxy.getInvocationHandler(item); if ((handler instanceof ComplexInvocationHandler) - && ((ComplexInvocationHandler) handler).getEntityHandler() == null) { + && ((ComplexInvocationHandler) handler).getEntityHandler() == null) { ((ComplexInvocationHandler) handler).setEntityHandler(entityHandler); } } @@ -146,7 +142,7 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl if (annotations.containsKey(term)) { res = annotations.get(term); - } else if (entityHandler.getEntity() instanceof ODataEntity) { + } else { try { final Term termAnn = term.getAnnotation(Term.class); final Namespace namespaceAnn = term.getAnnotation(Namespace.class); @@ -157,8 +153,8 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl } } res = annotation == null || annotation.hasNullValue() - ? null - : CoreUtils.getObjectFromODataValue(annotation.getValue(), null, targetHandler.service); + ? null + : CoreUtils.getObjectFromODataValue(annotation.getValue(), null, targetHandler.service); if (res != null) { annotations.put(term, res); } @@ -172,8 +168,6 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl @Override public Collection> readAnnotationTerms() { - return entityHandler.getEntity() instanceof ODataEntity - ? CoreUtils.getAnnotationTerms(service, internalAnnotations()) - : Collections.>emptyList(); + return CoreUtils.getAnnotationTerms(service, internalAnnotations()); } } 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 d8c099ed5..20ab3a590 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 @@ -410,12 +410,12 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler if (annotations.containsKey(term)) { res = annotations.get(term); - } else if (getEntity() instanceof ODataEntity) { + } else { try { final Term termAnn = term.getAnnotation(Term.class); final Namespace namespaceAnn = term.getAnnotation(Namespace.class); ODataAnnotation annotation = null; - for (ODataAnnotation _annotation : ((ODataEntity) getEntity()).getAnnotations()) { + for (ODataAnnotation _annotation : getEntity().getAnnotations()) { if ((namespaceAnn.value() + "." + termAnn.name()).equals(_annotation.getTerm())) { annotation = _annotation; } @@ -436,9 +436,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler @Override public Collection> readAnnotationTerms() { - return getEntity() instanceof ODataEntity - ? CoreUtils.getAnnotationTerms(service, ((ODataEntity) getEntity()).getAnnotations()) - : Collections.> emptyList(); + return CoreUtils.getAnnotationTerms(service, getEntity().getAnnotations()); } @Override @@ -450,7 +448,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler final ODataEntityRequest req = getClient().getRetrieveRequestFactory().getEntityRequest(uri.build()); - req.setPrefer(getClient().newPreferences().includeAnnotations("*")); + req.setPrefer(getClient().newPreferences().includeAnnotations("*")); final ODataRetrieveResponse res = req.execute(); @@ -492,7 +490,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler // use read- instead of get- for .invoke() to distinguish it from entity property getter. public String readEntityReferenceID() { - URI id = getEntity() == null ? null : ((ODataEntity) getEntity()).getId(); + URI id = getEntity() == null ? null : getEntity().getId(); return id == null ? null : id.toASCIIString(); } 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 2cb922602..6b7ff9c9a 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 @@ -28,7 +28,6 @@ import java.util.concurrent.Callable; import java.util.concurrent.Future; import org.apache.commons.lang3.tuple.Triple; -import org.apache.olingo.client.api.EdmEnabledODataClient; import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.commons.api.domain.ODataAnnotation; @@ -196,14 +195,14 @@ public class EntitySetInvocationHandler< @Override public Search createSearch() { - return new SearchImpl((EdmEnabledODataClient) getClient(), this.collItemRef, this.baseURI, this); + return new SearchImpl(getClient(), this.collItemRef, this.baseURI, this); } @Override @SuppressWarnings("unchecked") public > Search createSearch(final Class reference) { return new SearchImpl( - (EdmEnabledODataClient) getClient(), + getClient(), reference, baseURI, (EntitySetInvocationHandler) this); 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 bfec4eab0..4bb75ff4d 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 @@ -46,7 +46,6 @@ import org.apache.olingo.commons.api.domain.ODataComplexValue; import org.apache.olingo.commons.api.domain.ODataEntity; import org.apache.olingo.commons.api.domain.ODataEnumValue; import org.apache.olingo.commons.api.domain.ODataLink; -import org.apache.olingo.commons.api.domain.ODataObjectFactory; import org.apache.olingo.commons.api.domain.ODataPrimitiveValue; import org.apache.olingo.commons.api.domain.ODataProperty; import org.apache.olingo.commons.api.domain.ODataValue; @@ -106,8 +105,7 @@ public final class CoreUtils { if (intType.isPrimitiveType()) { value.asCollection().add(getODataValue(client, intType, collectionItem).asPrimitive()); } else if (intType.isEnumType()) { - value.asCollection().add(((org.apache.olingo.commons.api.domain.ODataValue) getODataValue( - client, intType, collectionItem)).asEnum()); + value.asCollection().add((getODataValue(client, intType, collectionItem)).asEnum()); } else if (intType.isComplexType()) { value.asCollection().add(getODataValue(client, intType, collectionItem).asComplex()); } else { @@ -139,8 +137,7 @@ public final class CoreUtils { } } else if (type.isEnumType()) { - value = ((org.apache.olingo.commons.api.domain.ODataObjectFactory) client.getObjectFactory()). - newEnumValue(type.getFullQualifiedName().toString(), ((Enum) obj).name()); + value = client.getObjectFactory().newEnumValue(type.getFullQualifiedName().toString(), ((Enum) obj).name()); } else { value = client.getObjectFactory().newPrimitiveValueBuilder().setType(type.getPrimitiveTypeKind()).setValue(obj). build(); @@ -204,8 +201,7 @@ public final class CoreUtils { : new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()). setTypeExpression(type.getFullQualifiedName().toString()).build(); - annotation = new ODataAnnotationImpl(term, - (org.apache.olingo.commons.api.domain.ODataValue) getODataValue(client, valueType, obj)); + annotation = new ODataAnnotationImpl(term, getODataValue(client, valueType, obj)); } return annotation; @@ -232,8 +228,7 @@ public final class CoreUtils { } else if (valueType.isComplexType()) { property = client.getObjectFactory().newComplexProperty(name, value.asComplex()); } else if (valueType.isEnumType()) { - property = ((ODataObjectFactory) client.getObjectFactory()).newEnumProperty(name, - ((org.apache.olingo.commons.api.domain.ODataValue) value).asEnum()); + property = client.getObjectFactory().newEnumProperty(name, value.asEnum()); } else { throw new UnsupportedOperationException("Usupported object type " + valueType.getFullQualifiedName()); } @@ -273,15 +268,15 @@ public final class CoreUtils { EdmPrimitiveTypeKind bckCandidate = null; for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) { - final Class target = EdmPrimitiveTypeFactory.getInstance(kind).getDefaultType(); + final Class target = EdmPrimitiveTypeFactory.getInstance(kind).getDefaultType(); - if (clazz.equals(target)) { - return new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression(kind.toString()).build(); - } else if (target.isAssignableFrom(clazz)) { - bckCandidate = kind; - } else if (target == Timestamp.class && kind == EdmPrimitiveTypeKind.DateTimeOffset) { - bckCandidate = kind; - } + if (clazz.equals(target)) { + return new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression(kind.toString()).build(); + } else if (target.isAssignableFrom(clazz)) { + bckCandidate = kind; + } else if (target == Timestamp.class && kind == EdmPrimitiveTypeKind.DateTimeOffset) { + bckCandidate = kind; + } } if (bckCandidate == null) { @@ -297,8 +292,8 @@ public final class CoreUtils { final ODataEntity entity) { for (Map.Entry entry : changes.entrySet()) { - ((List) entity.getProperties()).add( - getODataEntityProperty(client, entity.getTypeName(), entry.getKey(), entry.getValue())); + entity.getProperties() + .add(getODataEntityProperty(client, entity.getTypeName(), entry.getKey(), entry.getValue())); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java index 64ed4eb0d..baadf20db 100644 --- a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java @@ -1,18 +1,18 @@ -/* +/* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -73,7 +73,9 @@ public abstract class AbstractBaseTestITCase { final StringWriter writer = new StringWriter(); try { getClient().getSerializer(ODataFormat.JSON).write(writer, entity); - } catch (final ODataSerializerException e) {} + } catch (final ODataSerializerException e) { + // Debug + } writer.flush(); LOG.debug(message + "\n{}", writer.toString()); } @@ -84,7 +86,9 @@ public abstract class AbstractBaseTestITCase { final StringWriter writer = new StringWriter(); try { getClient().getSerializer(ODataFormat.JSON).write(writer, entitySet); - } catch (final ODataSerializerException e) {} + } catch (final ODataSerializerException e) { + // Debug + } writer.flush(); LOG.debug(message + "\n{}", writer.toString()); } @@ -103,14 +107,18 @@ public abstract class AbstractBaseTestITCase { StringWriter writer = new StringWriter(); try { getClient().getSerializer(ODataFormat.ATOM).write(writer, getClient().getBinder().getEntity(entity)); - } catch (final ODataSerializerException e) {} + } catch (final ODataSerializerException e) { + // Debug + } writer.flush(); LOG.debug(message + " (Atom)\n{}", writer.toString()); writer = new StringWriter(); try { getClient().getSerializer(ODataFormat.JSON).write(writer, getClient().getBinder().getEntity(entity)); - } catch (final ODataSerializerException e) {} + } catch (final ODataSerializerException e) { + // Debug + } writer.flush(); LOG.debug(message + " (JSON)\n{}", writer.toString()); } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/demo/odatademo/types/Customer.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/demo/odatademo/types/Customer.java index ec046d141..a93e04a09 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/demo/odatademo/types/Customer.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/demo/odatademo/types/Customer.java @@ -72,8 +72,9 @@ public interface Customer fcNSPrefix = "", fcNSURI = "", fcKeepInContent = false) + @Override java.lang.Integer getID(); - + @Override void setID(java.lang.Integer _iD); @@ -95,8 +96,9 @@ public interface Customer fcNSPrefix = "", fcNSURI = "", fcKeepInContent = false) + @Override java.lang.String getName(); - + @Override void setName(java.lang.String _name); diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java index e1e1edf87..b7a65e84c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java @@ -299,7 +299,7 @@ public class JSONFormatConformanceTestITCase extends AbstractTestITCase { assertEquals(Boolean.TRUE, style.getComplexValue().get("title").getPrimitiveValue().toCastValue(Boolean.class)); assertEquals(1, style.getComplexValue().get("order").getPrimitiveValue().toCastValue(Integer.class), 0); - final ODataLink orders = (ODataLink) entity.getNavigationLink("Orders"); + final ODataLink orders = entity.getNavigationLink("Orders"); assertEquals(1, orders.getAnnotations().size()); final ODataAnnotation style2 = orders.getAnnotations().get(0); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/BatchRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/BatchRequestFactoryImpl.java index b25034adc..5ce3b8b17 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/BatchRequestFactoryImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/BatchRequestFactoryImpl.java @@ -32,7 +32,6 @@ public class BatchRequestFactoryImpl implements BatchRequestFactory { @Override public ODataBatchRequest getBatchRequest(final String serviceRoot) { - return new ODataBatchRequestImpl( - (ODataClient) client, client.newURIBuilder(serviceRoot).appendBatchSegment().build()); + return new ODataBatchRequestImpl(client, client.newURIBuilder(serviceRoot).appendBatchSegment().build()); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/CUDRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/CUDRequestFactoryImpl.java index 89a0449dd..75c307603 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/CUDRequestFactoryImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/CUDRequestFactoryImpl.java @@ -245,6 +245,7 @@ public class CUDRequestFactoryImpl implements CUDRequestFactory { return new ODataReferenceAddingRequestImpl(client, HttpMethod.POST, targetURI, wrappedPayload); } + @Override public ODataReferenceAddingRequest getReferenceSingleChangeRequest(final URI serviceRoot, final URI targetURI, final URI reference) { // See OData Protocol 11.4.6.3 diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java index 6bf32820e..e9801ccc7 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java @@ -126,12 +126,8 @@ public abstract class AbstractODataInvokeRequest } else if (param.getValue().isCollection()) { property = odataClient.getObjectFactory(). newCollectionProperty(param.getKey(), param.getValue().asCollection()); - } else if (param.getValue() instanceof org.apache.olingo.commons.api.domain.ODataValue - && ((org.apache.olingo.commons.api.domain.ODataValue) param.getValue()).isEnum()) { - - property = ((ODataClient) odataClient).getObjectFactory(). - newEnumProperty(param.getKey(), - ((org.apache.olingo.commons.api.domain.ODataValue) param.getValue()).asEnum()); + } else if (param.getValue().isEnum()) { + property = odataClient.getObjectFactory().newEnumProperty(param.getKey(), param.getValue().asEnum()); } if (property != null) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataDeltaRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataDeltaRequestImpl.java index bb3ccd923..e01da68d0 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataDeltaRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataDeltaRequestImpl.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -34,7 +34,7 @@ import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest - implements ODataDeltaRequest { + implements ODataDeltaRequest { public ODataDeltaRequestImpl(final ODataClient odataClient, final URI query) { super(odataClient, query); @@ -56,7 +56,7 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest resource = ((ODataClient) odataClient). - getDeserializer(ODataFormat.fromString(getContentType())). - toDelta(res.getEntity().getContent()); + final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())). + toDelta(res.getEntity().getContent()); - delta = ((ODataClient) odataClient).getBinder().getODataDelta(resource); + delta = odataClient.getBinder().getODataDelta(resource); } catch (IOException e) { throw new HttpClientException(e); } catch (final ODataDeserializerException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/RetrieveRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/RetrieveRequestFactoryImpl.java index 6b179ae1b..f76587539 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/RetrieveRequestFactoryImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/RetrieveRequestFactoryImpl.java @@ -43,7 +43,7 @@ import org.apache.olingo.commons.api.domain.ODataSingleton; public class RetrieveRequestFactoryImpl implements RetrieveRequestFactory { protected final ODataClient client; - + public RetrieveRequestFactoryImpl(final ODataClient client) { this.client = client; } @@ -89,8 +89,7 @@ public class RetrieveRequestFactoryImpl implements RetrieveRequestFactory { @Override public XMLMetadataRequest getXMLMetadataRequest(final String serviceRoot) { - return new XMLMetadataRequestImpl(((ODataClient) client), - client.newURIBuilder(serviceRoot).appendMetadataSegment().build()); + return new XMLMetadataRequestImpl(client, client.newURIBuilder(serviceRoot).appendMetadataSegment().build()); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/XMLMetadataRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/XMLMetadataRequestImpl.java index 1f418876e..97c55e08a 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/XMLMetadataRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/XMLMetadataRequestImpl.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -39,8 +39,8 @@ import org.apache.olingo.client.core.edm.xml.SchemaImpl; import org.apache.olingo.commons.api.format.ODataFormat; public class XMLMetadataRequestImpl - extends AbstractMetadataRequestImpl - implements XMLMetadataRequest { + extends AbstractMetadataRequestImpl + implements XMLMetadataRequest { XMLMetadataRequestImpl(final ODataClient odataClient, final URI uri) { super(odataClient, uri); @@ -48,18 +48,18 @@ public class XMLMetadataRequestImpl @Override public ODataRetrieveResponse execute() { - final SingleXMLMetadatRequestImpl rootReq = new SingleXMLMetadatRequestImpl((ODataClient) odataClient, uri, null); + final SingleXMLMetadatRequestImpl rootReq = new SingleXMLMetadatRequestImpl(odataClient, uri, null); final ODataRetrieveResponse rootRes = rootReq.execute(); final XMLMetadataResponseImpl response = - new XMLMetadataResponseImpl(odataClient, httpClient, rootReq.getHttpResponse(), rootRes.getBody()); + new XMLMetadataResponseImpl(odataClient, httpClient, rootReq.getHttpResponse(), rootRes.getBody()); // process external references for (Reference reference : rootRes.getBody().getReferences()) { final SingleXMLMetadatRequestImpl includeReq = new SingleXMLMetadatRequestImpl( - (ODataClient) odataClient, - odataClient.newURIBuilder(uri.resolve(reference.getUri()).toASCIIString()).build(), - uri); + odataClient, + odataClient.newURIBuilder(uri.resolve(reference.getUri()).toASCIIString()).build(), + uri); final XMLMetadata includeMetadata = includeReq.execute().getBody(); // edmx:Include @@ -86,10 +86,10 @@ public class XMLMetadataRequestImpl // take into account only when (TargetNamespace was either not provided or matches) and // (Qualifier was either not provided or matches) if ((StringUtils.isBlank(include.getTargetNamespace()) - || include.getTargetNamespace().equals( - StringUtils.substringBeforeLast(annotationGroup.getTarget(), "."))) - && (StringUtils.isBlank(include.getQualifier()) - || include.getQualifier().equals(annotationGroup.getQualifier()))) { + || include.getTargetNamespace().equals( + StringUtils.substringBeforeLast(annotationGroup.getTarget(), "."))) + && (StringUtils.isBlank(include.getQualifier()) + || include.getQualifier().equals(annotationGroup.getQualifier()))) { final AnnotationsImpl toBeIncluded = new AnnotationsImpl(); toBeIncluded.setTarget(annotationGroup.getTarget()); @@ -128,9 +128,11 @@ public class XMLMetadataRequestImpl return httpResponse; } - /** Referenced document's URIs must only have the same scheme, host, and port as the - * main metadata document's URI but don't have to start with the service root - * as all other OData request URIs. */ + /** + * Referenced document's URIs must only have the same scheme, host, and port as the + * main metadata document's URI but don't have to start with the service root + * as all other OData request URIs. + */ @Override protected void checkRequest(final ODataClient odataClient, final HttpUriRequest request) { if (parentURI == null) { @@ -157,7 +159,7 @@ public class XMLMetadataRequestImpl public XMLMetadata getBody() { if (metadata == null) { try { - metadata = ((ODataClient) odataClient).getDeserializer(ODataFormat.XML).toMetadata(getRawResponse()); + metadata = odataClient.getDeserializer(ODataFormat.XML).toMetadata(getRawResponse()); } finally { this.close(); } @@ -173,7 +175,7 @@ public class XMLMetadataRequestImpl private final XMLMetadata metadata; private XMLMetadataResponseImpl(final ODataClient odataClient, final HttpClient httpClient, - final HttpResponse res, final XMLMetadata metadata) { + final HttpResponse res, final XMLMetadata metadata) { super(odataClient, httpClient, null); this.metadata = metadata; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java index f60898409..31a738435 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -95,7 +95,7 @@ public class EdmClientImpl extends AbstractEdm { protected Map createSchemas() { final Map _schemas = new LinkedHashMap(xmlSchemas.size()); for (Schema schema : xmlSchemas) { - _schemas.put(schema.getNamespace(), new EdmSchemaImpl(this, xmlSchemas, schema)); + _schemas.put(schema.getNamespace(), new EdmSchemaImpl(this, schema)); } return _schemas; } @@ -108,7 +108,7 @@ public class EdmClientImpl extends AbstractEdm { if (schema != null) { final EntityContainer xmlEntityContainer = schema.getDefaultEntityContainer(); if (xmlEntityContainer != null) { - result = new EdmEntityContainerImpl(this, containerName, xmlEntityContainer, xmlSchemas); + result = new EdmEntityContainerImpl(this, containerName, xmlEntityContainer); } } @@ -135,14 +135,13 @@ public class EdmClientImpl extends AbstractEdm { EdmTypeDefinition result = null; final Schema schema = xmlSchemaByNamespace.get(typeDefinitionName.getNamespace()); - if (schema instanceof Schema) { - final TypeDefinition xmlTypeDefinition = ((Schema) schema). - getTypeDefinition(typeDefinitionName.getName()); + if (schema != null) { + final TypeDefinition xmlTypeDefinition = schema. + getTypeDefinition(typeDefinitionName.getName()); if (xmlTypeDefinition != null) { result = new EdmTypeDefinitionImpl(this, typeDefinitionName, xmlTypeDefinition); } } - return result; } @@ -154,7 +153,7 @@ public class EdmClientImpl extends AbstractEdm { if (schema != null) { final EntityType xmlEntityType = schema.getEntityType(entityTypeName.getName()); if (xmlEntityType != null) { - result = EdmEntityTypeImpl.getInstance(this, entityTypeName, xmlSchemas, xmlEntityType); + result = EdmEntityTypeImpl.getInstance(this, entityTypeName, xmlEntityType); } } @@ -169,7 +168,7 @@ public class EdmClientImpl extends AbstractEdm { if (schema != null) { final ComplexType xmlComplexType = schema.getComplexType(complexTypeName.getName()); if (xmlComplexType != null) { - result = EdmComplexTypeImpl.getInstance(this, complexTypeName, xmlSchemas, xmlComplexType); + result = EdmComplexTypeImpl.getInstance(this, complexTypeName, xmlComplexType); } } @@ -181,18 +180,16 @@ public class EdmClientImpl extends AbstractEdm { EdmAction result = null; final Schema schema = xmlSchemaByNamespace.get(actionName.getNamespace()); - if (schema instanceof Schema) { - final List actions = ((Schema) schema). - getActions(actionName.getName()); - boolean found = false; - for (final Iterator itor = actions.iterator(); itor.hasNext() && !found;) { - final Action action = itor.next(); - if (!action.isBound()) { - found = true; - result = EdmActionImpl.getInstance(this, actionName, action); - } + final List actions = schema. + getActions(actionName.getName()); + boolean found = false; + for (final Iterator itor = actions.iterator(); itor.hasNext() && !found;) { + final Action action = itor.next(); + if (!action.isBound()) { + found = true; + result = EdmActionImpl.getInstance(this, actionName, action); } - } + } return result; } @@ -201,16 +198,14 @@ public class EdmClientImpl extends AbstractEdm { final List result = new ArrayList(); final Schema schema = xmlSchemaByNamespace.get(functionName.getNamespace()); - if (schema instanceof Schema) { - final List functions = ((Schema) schema). - getFunctions(functionName.getName()); - for (final Iterator itor = functions.iterator(); itor.hasNext();) { - final Function function = itor.next(); - if (!function.isBound()) { - result.add(EdmFunctionImpl.getInstance(this, functionName, function)); - } + final List functions = schema. + getFunctions(functionName.getName()); + for (final Iterator itor = functions.iterator(); itor.hasNext();) { + final Function function = itor.next(); + if (!function.isBound()) { + result.add(EdmFunctionImpl.getInstance(this, functionName, function)); } - } + } return result; } @@ -219,89 +214,83 @@ public class EdmClientImpl extends AbstractEdm { EdmFunction result = null; final Schema schema = xmlSchemaByNamespace.get(functionName.getNamespace()); - if (schema instanceof Schema) { - final List functions = ((Schema) schema). - getFunctions(functionName.getName()); - boolean found = false; - for (final Iterator itor = functions.iterator(); itor.hasNext() && !found;) { - final Function function = itor.next(); - if (!function.isBound()) { - final Set functionParamNames = new HashSet(); - for (Parameter param : function.getParameters()) { - functionParamNames.add(param.getName()); - } - found = parameterNames == null - ? functionParamNames.isEmpty() - : functionParamNames.containsAll(parameterNames); - result = EdmFunctionImpl.getInstance(this, functionName, function); + final List functions = schema. + getFunctions(functionName.getName()); + boolean found = false; + for (final Iterator itor = functions.iterator(); itor.hasNext() && !found;) { + final Function function = itor.next(); + if (!function.isBound()) { + final Set functionParamNames = new HashSet(); + for (Parameter param : function.getParameters()) { + functionParamNames.add(param.getName()); } + found = parameterNames == null + ? functionParamNames.isEmpty() + : functionParamNames.containsAll(parameterNames); + result = EdmFunctionImpl.getInstance(this, functionName, function); } - } + } return result; } @Override protected EdmAction createBoundAction(final FullQualifiedName actionName, - final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { + final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { EdmAction result = null; final Schema schema = xmlSchemaByNamespace.get(actionName.getNamespace()); - if (schema instanceof Schema) { - final List actions = - ((Schema) schema).getActions(actionName.getName()); - boolean found = false; - for (final Iterator itor = actions.iterator(); itor.hasNext() && !found;) { - final Action action = itor.next(); - if (action.isBound()) { - final EdmTypeInfo boundParam = new EdmTypeInfo.Builder().setEdm(this). - setTypeExpression(action.getParameters().get(0).getType()).build(); - if (bindingParameterTypeName.equals(boundParam.getFullQualifiedName()) - && (isBindingParameterCollection == null - || isBindingParameterCollection.booleanValue() == boundParam.isCollection())) { + final List actions = + schema.getActions(actionName.getName()); + boolean found = false; + for (final Iterator itor = actions.iterator(); itor.hasNext() && !found;) { + final Action action = itor.next(); + if (action.isBound()) { + final EdmTypeInfo boundParam = new EdmTypeInfo.Builder().setEdm(this). + setTypeExpression(action.getParameters().get(0).getType()).build(); + if (bindingParameterTypeName.equals(boundParam.getFullQualifiedName()) + && (isBindingParameterCollection == null + || isBindingParameterCollection.booleanValue() == boundParam.isCollection())) { - found = true; - result = EdmActionImpl.getInstance(this, actionName, action); - } + found = true; + result = EdmActionImpl.getInstance(this, actionName, action); } } - } + } return result; } @Override protected EdmFunction createBoundFunction(final FullQualifiedName functionName, - final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection, - final List parameterNames) { + final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection, + final List parameterNames) { EdmFunction result = null; final Schema schema = xmlSchemaByNamespace.get(functionName.getNamespace()); - if (schema instanceof Schema) { - final List functions = ((Schema) schema). - getFunctions(functionName.getName()); - boolean found = false; - for (final Iterator itor = functions.iterator(); itor.hasNext() && !found;) { - final Function function = itor.next(); - if (function.isBound()) { - final EdmTypeInfo boundParam = new EdmTypeInfo.Builder().setEdm(this). - setTypeExpression(function.getParameters().get(0).getType()).build(); - if (bindingParameterTypeName.equals(boundParam.getFullQualifiedName()) - && (isBindingParameterCollection == null - || isBindingParameterCollection.booleanValue() == boundParam.isCollection())) { + final List functions = schema. + getFunctions(functionName.getName()); + boolean found = false; + for (final Iterator itor = functions.iterator(); itor.hasNext() && !found;) { + final Function function = itor.next(); + if (function.isBound()) { + final EdmTypeInfo boundParam = new EdmTypeInfo.Builder().setEdm(this). + setTypeExpression(function.getParameters().get(0).getType()).build(); + if (bindingParameterTypeName.equals(boundParam.getFullQualifiedName()) + && (isBindingParameterCollection == null + || isBindingParameterCollection.booleanValue() == boundParam.isCollection())) { - final Set functionParamNames = new HashSet(); - for (Parameter param : function.getParameters()) { - functionParamNames.add(param.getName()); - } - found = parameterNames == null - ? functionParamNames.isEmpty() - : functionParamNames.containsAll(parameterNames); - result = EdmFunctionImpl.getInstance(this, functionName, function); + final Set functionParamNames = new HashSet(); + for (Parameter param : function.getParameters()) { + functionParamNames.add(param.getName()); } + found = parameterNames == null + ? functionParamNames.isEmpty() + : functionParamNames.containsAll(parameterNames); + result = EdmFunctionImpl.getInstance(this, functionName, function); } } - } + } return result; } @@ -310,13 +299,12 @@ public class EdmClientImpl extends AbstractEdm { EdmTerm result = null; final Schema schema = xmlSchemaByNamespace.get(termName.getNamespace()); - if (schema instanceof Schema) { - final Term term = ((Schema) schema).getTerm(termName.getName()); + if (schema != null) { + final Term term = schema.getTerm(termName.getName()); if (term != null) { result = new EdmTermImpl(this, schema.getNamespace(), term); } } - return result; } @@ -325,12 +313,10 @@ public class EdmClientImpl extends AbstractEdm { EdmAnnotationsImpl result = null; final Schema schema = xmlSchemaByNamespace.get(targetName.getNamespace()); - if (schema instanceof Schema) { - final Annotations annotationGroup = - ((Schema) schema).getAnnotationGroup(targetName.getName()); - if (annotationGroup != null) { - result = new EdmAnnotationsImpl(this, schemas.get(schema.getNamespace()), annotationGroup); - } + final Annotations annotationGroup = + schema.getAnnotationGroup(targetName.getName()); + if (annotationGroup != null) { + result = new EdmAnnotationsImpl(this, schemas.get(schema.getNamespace()), annotationGroup); } return result; @@ -341,15 +327,13 @@ public class EdmClientImpl extends AbstractEdm { List result = null; final Schema schema = xmlSchemaByNamespace.get(annotatedName.getNamespace()); - if (schema instanceof Schema) { - final Annotatable annotatable = - ((Schema) schema).getAnnotatables().get(annotatedName.getName()); - if (annotatable != null && annotatable.getAnnotations() != null) { - result = new ArrayList(); - for (Annotation annotation : annotatable.getAnnotations()) { - final EdmTerm term = getTerm(new FullQualifiedName(annotation.getTerm())); - result.add(new EdmAnnotationImpl(this, annotation)); - } + final Annotatable annotatable = + schema.getAnnotatables().get(annotatedName.getName()); + if (annotatable != null && annotatable.getAnnotations() != null) { + result = new ArrayList(); + for (Annotation annotation : annotatable.getAnnotations()) { + final EdmTerm term = getTerm(new FullQualifiedName(annotation.getTerm())); + result.add(new EdmAnnotationImpl(this, annotation)); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmComplexTypeImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmComplexTypeImpl.java index e734200ef..d985110c8 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmComplexTypeImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmComplexTypeImpl.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -22,7 +22,6 @@ import java.util.List; import java.util.Map; import org.apache.olingo.client.api.edm.xml.ComplexType; -import org.apache.olingo.client.api.edm.xml.Schema; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmAnnotation; import org.apache.olingo.commons.api.edm.EdmNavigationProperty; @@ -41,29 +40,24 @@ public class EdmComplexTypeImpl extends AbstractEdmComplexType { private EdmAnnotationHelper annotationHelper; public static EdmComplexTypeImpl getInstance(final Edm edm, final FullQualifiedName fqn, - final List xmlSchemas, final ComplexType complexType) { + final ComplexType complexType) { FullQualifiedName baseTypeName = null; - if (complexType instanceof org.apache.olingo.client.api.edm.xml.ComplexType) { - final String baseType = ((org.apache.olingo.client.api.edm.xml.ComplexType) complexType).getBaseType(); - baseTypeName = baseType == null - ? null : new EdmTypeInfo.Builder().setTypeExpression(baseType).build().getFullQualifiedName(); - } - final EdmComplexTypeImpl instance = new EdmComplexTypeImpl(edm, fqn, baseTypeName, xmlSchemas, complexType); + final String baseType = complexType.getBaseType(); + baseTypeName = baseType == null + ? null : new EdmTypeInfo.Builder().setTypeExpression(baseType).build().getFullQualifiedName(); + final EdmComplexTypeImpl instance = new EdmComplexTypeImpl(edm, fqn, baseTypeName, complexType); instance.baseType = instance.buildBaseType(baseTypeName); return instance; } private EdmComplexTypeImpl(final Edm edm, final FullQualifiedName fqn, final FullQualifiedName baseTypeName, - final List xmlSchemas, final ComplexType complexType) { + final ComplexType complexType) { super(edm, fqn, baseTypeName); - this.typeHelper = new EdmStructuredTypeHelperImpl(edm, getFullQualifiedName(), xmlSchemas, complexType); - if (complexType instanceof org.apache.olingo.client.api.edm.xml.ComplexType) { - this.annotationHelper = new EdmAnnotationHelperImpl(edm, - (org.apache.olingo.client.api.edm.xml.ComplexType) complexType); - } + this.typeHelper = new EdmStructuredTypeHelperImpl(edm, getFullQualifiedName(), complexType); + this.annotationHelper = new EdmAnnotationHelperImpl(edm, complexType); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java index 04a4e4e63..3d1a62407 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java @@ -25,7 +25,6 @@ import org.apache.olingo.client.api.edm.xml.ActionImport; import org.apache.olingo.client.api.edm.xml.EntityContainer; import org.apache.olingo.client.api.edm.xml.EntitySet; import org.apache.olingo.client.api.edm.xml.FunctionImport; -import org.apache.olingo.client.api.edm.xml.Schema; import org.apache.olingo.client.api.edm.xml.Singleton; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmActionImport; @@ -46,35 +45,29 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { private EdmAnnotationHelper helper; public EdmEntityContainerImpl(final Edm edm, final FullQualifiedName entityContainerName, - final EntityContainer xmlEntityContainer, final List xmlSchemas) { + final EntityContainer xmlEntityContainer) { super(edm, entityContainerName, xmlEntityContainer.getExtends() == null - ? null : new FullQualifiedName(xmlEntityContainer.getExtends())); + ? null : new FullQualifiedName(xmlEntityContainer.getExtends())); this.xmlEntityContainer = xmlEntityContainer; - if (xmlEntityContainer instanceof EntityContainer) { - this.helper = new EdmAnnotationHelperImpl(edm, - (EntityContainer) xmlEntityContainer); - } + this.helper = new EdmAnnotationHelperImpl(edm, xmlEntityContainer); } @Override public boolean isDefault() { - return xmlEntityContainer instanceof EntityContainer - ? true - : xmlEntityContainer.isDefaultEntityContainer(); + return true; } @Override protected EdmSingleton createSingleton(final String singletonName) { - final Singleton singleton = ((EntityContainer) xmlEntityContainer). - getSingleton(singletonName); + final Singleton singleton = xmlEntityContainer.getSingleton(singletonName); return singleton == null - ? null - : new EdmSingletonImpl(edm, this, singletonName, new EdmTypeInfo.Builder(). - setTypeExpression(singleton.getEntityType()). - setDefaultNamespace(entityContainerName.getNamespace()). - build().getFullQualifiedName(), singleton); + ? null + : new EdmSingletonImpl(edm, this, singletonName, new EdmTypeInfo.Builder(). + setTypeExpression(singleton.getEntityType()). + setDefaultNamespace(entityContainerName.getNamespace()). + build().getFullQualifiedName(), singleton); } @Override @@ -84,11 +77,8 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { final EntitySet entitySet = xmlEntityContainer.getEntitySet(entitySetName); if (entitySet != null) { final FullQualifiedName entityType = new EdmTypeInfo.Builder().setTypeExpression(entitySet.getEntityType()). - setDefaultNamespace(entityContainerName.getNamespace()).build().getFullQualifiedName(); - if (entitySet instanceof EntitySet) { - result = new EdmEntitySetImpl(edm, this, entitySetName, entityType, - (EntitySet) entitySet); - } + setDefaultNamespace(entityContainerName.getNamespace()).build().getFullQualifiedName(); + result = new EdmEntitySetImpl(edm, this, entitySetName, entityType, entitySet); } return result; @@ -98,13 +88,10 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { protected EdmActionImport createActionImport(final String actionImportName) { EdmActionImport result = null; - if (xmlEntityContainer instanceof EntityContainer) { - final ActionImport actionImport = ((EntityContainer) xmlEntityContainer). - getActionImport(actionImportName); - if (actionImport != null) { - result = new EdmActionImportImpl(edm, this, actionImportName, actionImport); - } - } + final ActionImport actionImport = xmlEntityContainer.getActionImport(actionImportName); + if (actionImport != null) { + result = new EdmActionImportImpl(edm, this, actionImportName, actionImport); + } return result; } @@ -114,10 +101,7 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { final FunctionImport functionImport = xmlEntityContainer.getFunctionImport(functionImportName); if (functionImport != null) { - if (functionImport instanceof org.apache.olingo.client.api.edm.xml.FunctionImport) { - result = new EdmFunctionImportImpl(edm, this, functionImportName, - (org.apache.olingo.client.api.edm.xml.FunctionImport) functionImport); - } + result = new EdmFunctionImportImpl(edm, this, functionImportName, functionImport); } return result; @@ -130,15 +114,11 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { for (EntitySet entitySet : localEntitySets) { EdmEntitySet edmSet; final FullQualifiedName entityType = new EdmTypeInfo.Builder().setTypeExpression(entitySet.getEntityType()). - setDefaultNamespace(entityContainerName.getNamespace()).build().getFullQualifiedName(); - if (entitySet instanceof EntitySet) { - edmSet = new EdmEntitySetImpl(edm, this, entitySet.getName(), entityType, - (EntitySet) entitySet); - entitySets.put(edmSet.getName(), edmSet); - } + setDefaultNamespace(entityContainerName.getNamespace()).build().getFullQualifiedName(); + edmSet = new EdmEntitySetImpl(edm, this, entitySet.getName(), entityType, entitySet); + entitySets.put(edmSet.getName(), edmSet); } } - } @Override @@ -146,22 +126,18 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { final List localFunctionImports = xmlEntityContainer.getFunctionImports(); for (FunctionImport functionImport : localFunctionImports) { EdmFunctionImport edmFunctionImport; - if (functionImport instanceof org.apache.olingo.client.api.edm.xml.FunctionImport) { - edmFunctionImport = new EdmFunctionImportImpl(edm, this, functionImport.getName(), - (org.apache.olingo.client.api.edm.xml.FunctionImport) functionImport); - functionImports.put(edmFunctionImport.getName(), edmFunctionImport); - } + edmFunctionImport = new EdmFunctionImportImpl(edm, this, functionImport.getName(), functionImport); + functionImports.put(edmFunctionImport.getName(), edmFunctionImport); } } @Override protected void loadAllSingletons() { - final List localSingletons = - ((EntityContainer) xmlEntityContainer).getSingletons(); + final List localSingletons = xmlEntityContainer.getSingletons(); if (localSingletons != null) { for (Singleton singleton : localSingletons) { singletons.put(singleton.getName(), new EdmSingletonImpl(edm, this, singleton.getName(), - new EdmTypeInfo.Builder(). + new EdmTypeInfo.Builder(). setTypeExpression(singleton.getEntityType()).setDefaultNamespace(entityContainerName.getNamespace()). build().getFullQualifiedName(), singleton)); } @@ -170,16 +146,13 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { @Override protected void loadAllActionImports() { - if (xmlEntityContainer instanceof EntityContainer) { - final List localActionImports = - ((EntityContainer) xmlEntityContainer).getActionImports(); - if (actionImports != null) { - for (ActionImport actionImport : localActionImports) { - actionImports.put(actionImport.getName(), - new EdmActionImportImpl(edm, this, actionImport.getName(), actionImport)); - } + final List localActionImports = xmlEntityContainer.getActionImports(); + if (actionImports != null) { + for (ActionImport actionImport : localActionImports) { + actionImports.put(actionImport.getName(), new EdmActionImportImpl(edm, this, actionImport.getName(), + actionImport)); } - } + } } @Override @@ -194,7 +167,7 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { @Override public List getAnnotations() { - return helper == null ? Collections.emptyList() : helper.getAnnotations(); + return helper == null ? Collections. emptyList() : helper.getAnnotations(); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityTypeImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityTypeImpl.java index 2dabbbf70..4fef9a288 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityTypeImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityTypeImpl.java @@ -24,7 +24,6 @@ import java.util.Map; import org.apache.olingo.client.api.edm.xml.EntityType; import org.apache.olingo.client.api.edm.xml.PropertyRef; -import org.apache.olingo.client.api.edm.xml.Schema; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmAnnotation; import org.apache.olingo.commons.api.edm.EdmEntityType; @@ -44,20 +43,19 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType { private EdmAnnotationHelper annotationHelper; - public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName fqn, - final List xmlSchemas, final EntityType entityType) { + public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName fqn, final EntityType entityType) { final FullQualifiedName baseTypeName = entityType.getBaseType() == null ? null : new EdmTypeInfo.Builder().setTypeExpression(entityType.getBaseType()).build().getFullQualifiedName(); - final EdmEntityTypeImpl instance = new EdmEntityTypeImpl(edm, fqn, baseTypeName, xmlSchemas, entityType); + final EdmEntityTypeImpl instance = new EdmEntityTypeImpl(edm, fqn, baseTypeName, entityType); instance.baseType = instance.buildBaseType(baseTypeName); if (instance.baseType == null) { instance.entityBaseType = null; final List edmKey; - //Abstract EntityTypes do not necessarily have keys + // Abstract EntityTypes do not necessarily have keys if (entityType.isAbstractType() && entityType.getKey() == null) { edmKey = new ArrayList(); } else { @@ -76,14 +74,11 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType { } private EdmEntityTypeImpl(final Edm edm, final FullQualifiedName fqn, final FullQualifiedName baseTypeName, - final List xmlSchemas, final EntityType entityType) { + final EntityType entityType) { super(edm, fqn, baseTypeName, entityType.isHasStream()); - this.typeHelper = new EdmStructuredTypeHelperImpl(edm, getFullQualifiedName(), xmlSchemas, entityType); - if (entityType instanceof EntityType) { - this.annotationHelper = new EdmAnnotationHelperImpl(edm, - (EntityType) entityType); - } + this.typeHelper = new EdmStructuredTypeHelperImpl(edm, getFullQualifiedName(), entityType); + this.annotationHelper = new EdmAnnotationHelperImpl(edm, entityType); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmParameterImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmParameterImpl.java index 4e8fc8fc6..a82e25284 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmParameterImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmParameterImpl.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -44,9 +44,7 @@ public class EdmParameterImpl extends AbstractEdmParameter { super(edm, parameter.getName(), new FullQualifiedName(parameter.getType())); this.parameter = parameter; this.typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(parameter.getType()).build(); - if (parameter instanceof Parameter) { - this.helper = new EdmAnnotationHelperImpl(edm, (Parameter) parameter); - } + this.helper = new EdmAnnotationHelperImpl(edm, parameter); } @Override @@ -81,9 +79,8 @@ public class EdmParameterImpl extends AbstractEdmParameter { @Override public SRID getSrid() { - return (parameter instanceof Parameter) - ? ((Parameter) parameter).getSrid() - : null; + return parameter.getSrid(); + } @Override @@ -93,7 +90,7 @@ public class EdmParameterImpl extends AbstractEdmParameter { @Override public List getAnnotations() { - return helper == null ? Collections.emptyList() : helper.getAnnotations(); + return helper == null ? Collections. emptyList() : helper.getAnnotations(); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmPropertyImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmPropertyImpl.java index 6b2e18914..9c34472a5 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmPropertyImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmPropertyImpl.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -48,9 +48,7 @@ public class EdmPropertyImpl extends AbstractEdmProperty { this.structuredTypeName = structuredTypeName; this.property = property; this.typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(property.getType()).build(); - if (property instanceof Property) { - this.helper = new EdmAnnotationHelperImpl(edm, (Property) property); - } + this.helper = new EdmAnnotationHelperImpl(edm, property); } @Override @@ -100,9 +98,7 @@ public class EdmPropertyImpl extends AbstractEdmProperty { @Override public SRID getSrid() { - return (property instanceof Property) - ? ((Property) property).getSrid() - : null; + return property.getSrid(); } @Override @@ -117,7 +113,7 @@ public class EdmPropertyImpl extends AbstractEdmProperty { @Override public List getAnnotations() { - return helper == null ? Collections.emptyList() : helper.getAnnotations(); + return helper == null ? Collections. emptyList() : helper.getAnnotations(); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java index 0cc1ca653..30ca77a9c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java @@ -50,10 +50,8 @@ import org.apache.olingo.commons.core.edm.AbstractEdmSchema; public class EdmSchemaImpl extends AbstractEdmSchema { - private final Edm edm; - private final List xmlSchemas; private final Schema schema; @@ -61,12 +59,11 @@ public class EdmSchemaImpl extends AbstractEdmSchema { private List entityContainers; - public EdmSchemaImpl(final Edm edm, final List xmlSchemas, final Schema schema) { + public EdmSchemaImpl(final Edm edm, final Schema schema) { super(schema.getNamespace(), schema.getAlias()); this.edm = edm; - this.xmlSchemas = xmlSchemas; this.schema = schema; } @@ -75,20 +72,9 @@ public class EdmSchemaImpl extends AbstractEdmSchema { if (entityContainers == null) { entityContainerByName = new HashMap(); - if (schema instanceof Schema) { - entityContainers = super.getEntityContainers(); - if (getEntityContainer() != null) { - entityContainerByName.put(getEntityContainer().getFullQualifiedName(), getEntityContainer()); - } - } else { - entityContainers = new ArrayList(schema.getEntityContainers().size()); - for (EntityContainer entityContainer : schema.getEntityContainers()) { - final EdmEntityContainer edmContainer = createEntityContainer(entityContainer.getName()); - if (edmContainer != null) { - entityContainers.add(edmContainer); - entityContainerByName.put(edmContainer.getFullQualifiedName(), edmContainer); - } - } + entityContainers = super.getEntityContainers(); + if (getEntityContainer() != null) { + entityContainerByName.put(getEntityContainer().getFullQualifiedName(), getEntityContainer()); } } @@ -106,7 +92,7 @@ public class EdmSchemaImpl extends AbstractEdmSchema { if (defaultContainer != null) { final FullQualifiedName entityContainerName = new FullQualifiedName(schema.getNamespace(), defaultContainer.getName()); - return new EdmEntityContainerImpl(edm, entityContainerName, defaultContainer, xmlSchemas); + return new EdmEntityContainerImpl(edm, entityContainerName, defaultContainer); } return null; } @@ -123,14 +109,12 @@ public class EdmSchemaImpl extends AbstractEdmSchema { @Override protected List createTypeDefinitions() { final List typeDefinitions = new ArrayList(); - if (schema instanceof Schema) { - final List providerTypeDefinitions = - ((Schema) schema).getTypeDefinitions(); - if (providerTypeDefinitions != null) { - for (TypeDefinition def : providerTypeDefinitions) { - typeDefinitions.add( - new EdmTypeDefinitionImpl(edm, new FullQualifiedName(namespace, def.getName()), def)); - } + final List providerTypeDefinitions = + schema.getTypeDefinitions(); + if (providerTypeDefinitions != null) { + for (TypeDefinition def : providerTypeDefinitions) { + typeDefinitions.add( + new EdmTypeDefinitionImpl(edm, new FullQualifiedName(namespace, def.getName()), def)); } } return typeDefinitions; @@ -156,7 +140,7 @@ public class EdmSchemaImpl extends AbstractEdmSchema { if (providerEntityTypes != null) { for (EntityType entityType : providerEntityTypes) { entityTypes.add(EdmEntityTypeImpl.getInstance(edm, - new FullQualifiedName(namespace, entityType.getName()), xmlSchemas, entityType)); + new FullQualifiedName(namespace, entityType.getName()), entityType)); } } return entityTypes; @@ -169,7 +153,7 @@ public class EdmSchemaImpl extends AbstractEdmSchema { if (providerComplexTypes != null) { for (ComplexType complexType : providerComplexTypes) { complexTypes.add(EdmComplexTypeImpl.getInstance(edm, new FullQualifiedName(namespace, complexType.getName()), - xmlSchemas, complexType)); + complexType)); } } return complexTypes; @@ -178,12 +162,10 @@ public class EdmSchemaImpl extends AbstractEdmSchema { @Override protected List createActions() { final List actions = new ArrayList(); - if (schema instanceof Schema) { - final List providerActions = ((Schema) schema).getActions(); - if (providerActions != null) { - for (Action action : providerActions) { - actions.add(EdmActionImpl.getInstance(edm, new FullQualifiedName(namespace, action.getName()), action)); - } + final List providerActions = schema.getActions(); + if (providerActions != null) { + for (Action action : providerActions) { + actions.add(EdmActionImpl.getInstance(edm, new FullQualifiedName(namespace, action.getName()), action)); } } return actions; @@ -192,15 +174,13 @@ public class EdmSchemaImpl extends AbstractEdmSchema { @Override protected List createFunctions() { final List functions = new ArrayList(); - if (schema instanceof Schema) { - final List providerFunctions = ((Schema) schema).getFunctions(); - if (providerFunctions != null) { - for (Function function : providerFunctions) { - functions.add( - EdmFunctionImpl.getInstance(edm, new FullQualifiedName(namespace, function.getName()), function)); - } - return functions; + final List providerFunctions = schema.getFunctions(); + if (providerFunctions != null) { + for (Function function : providerFunctions) { + functions.add( + EdmFunctionImpl.getInstance(edm, new FullQualifiedName(namespace, function.getName()), function)); } + return functions; } return functions; } @@ -208,12 +188,10 @@ public class EdmSchemaImpl extends AbstractEdmSchema { @Override protected List createTerms() { final List terms = new ArrayList(); - if (schema instanceof Schema) { - final List providerTerms = ((Schema) schema).getTerms(); - if (providerTerms != null) { - for (Term term : providerTerms) { - terms.add(new EdmTermImpl(edm, getNamespace(), term)); - } + final List providerTerms = schema.getTerms(); + if (providerTerms != null) { + for (Term term : providerTerms) { + terms.add(new EdmTermImpl(edm, getNamespace(), term)); } } return terms; @@ -222,13 +200,11 @@ public class EdmSchemaImpl extends AbstractEdmSchema { @Override protected List createAnnotationGroups() { final List annotationGroups = new ArrayList(); - if (schema instanceof Schema) { - final List providerAnnotations = - ((Schema) schema).getAnnotationGroups(); - if (providerAnnotations != null) { - for (Annotations annotationGroup : providerAnnotations) { - annotationGroups.add(new EdmAnnotationsImpl(edm, this, annotationGroup)); - } + final List providerAnnotations = + schema.getAnnotationGroups(); + if (providerAnnotations != null) { + for (Annotations annotationGroup : providerAnnotations) { + annotationGroups.add(new EdmAnnotationsImpl(edm, this, annotationGroup)); } } return annotationGroups; @@ -237,13 +213,11 @@ public class EdmSchemaImpl extends AbstractEdmSchema { @Override protected List createAnnotations() { final List annotations = new ArrayList(); - if (schema instanceof Schema) { - final List providerAnnotations = - ((Schema) schema).getAnnotations(); - if (providerAnnotations != null) { - for (Annotation annotation : providerAnnotations) { - annotations.add(new EdmAnnotationImpl(edm, annotation)); - } + final List providerAnnotations = + schema.getAnnotations(); + if (providerAnnotations != null) { + for (Annotation annotation : providerAnnotations) { + annotations.add(new EdmAnnotationImpl(edm, annotation)); } } return annotations; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmStructuredTypeHelperImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmStructuredTypeHelperImpl.java index 127dfadb7..ac983068a 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmStructuredTypeHelperImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmStructuredTypeHelperImpl.java @@ -19,14 +19,12 @@ package org.apache.olingo.client.core.edm; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import org.apache.olingo.client.api.edm.xml.ComplexType; import org.apache.olingo.client.api.edm.xml.EntityType; import org.apache.olingo.client.api.edm.xml.NavigationProperty; import org.apache.olingo.client.api.edm.xml.Property; -import org.apache.olingo.client.api.edm.xml.Schema; import org.apache.olingo.client.api.edm.xml.StructuralType; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmNavigationProperty; @@ -47,7 +45,7 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper { private Map navigationProperties; public EdmStructuredTypeHelperImpl(final Edm edm, final FullQualifiedName structuredTypeName, - final List xmlSchemas, final StructuralType structuralType) { + final StructuralType structuralType) { this.edm = edm; this.structuredTypeName = structuredTypeName; @@ -70,11 +68,8 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper { if (navigationProperties == null) { navigationProperties = new LinkedHashMap(); for (NavigationProperty navigationProperty : structuralType.getNavigationProperties()) { - if (navigationProperty instanceof org.apache.olingo.client.api.edm.xml.NavigationProperty) { - navigationProperties.put(navigationProperty.getName(), new EdmNavigationPropertyImpl( - edm, structuredTypeName, - (org.apache.olingo.client.api.edm.xml.NavigationProperty) navigationProperty)); - } + navigationProperties.put(navigationProperty.getName(), new EdmNavigationPropertyImpl( + edm, structuredTypeName, navigationProperty)); } } return navigationProperties; @@ -83,9 +78,9 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper { @Override public boolean isOpenType() { boolean isOpen = false; - if(structuralType instanceof ComplexType){ + if (structuralType instanceof ComplexType) { isOpen = ((ComplexType) structuralType).isOpenType(); - }else if(structuralType instanceof EntityType){ + } else if (structuralType instanceof EntityType) { isOpen = ((EntityType) structuralType).isOpenType(); } return isOpen; @@ -94,9 +89,9 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper { @Override public boolean isAbstract() { boolean isAbstract = false; - if(structuralType instanceof ComplexType){ + if (structuralType instanceof ComplexType) { isAbstract = ((ComplexType) structuralType).isAbstractType(); - }else if(structuralType instanceof EntityType){ + } else if (structuralType instanceof EntityType) { isAbstract = ((EntityType) structuralType).isAbstractType(); } return isAbstract; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ComplexTypeImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ComplexTypeImpl.java index 4fc0ce9ce..fdd499d0f 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ComplexTypeImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ComplexTypeImpl.java @@ -74,7 +74,7 @@ public class ComplexTypeImpl extends AbstractStructuralType implements ComplexTy @Override public Property getProperty(final String name) { - return (Property) super.getProperty(name); + return super.getProperty(name); } @Override @@ -84,7 +84,7 @@ public class ComplexTypeImpl extends AbstractStructuralType implements ComplexTy @Override public NavigationProperty getNavigationProperty(final String name) { - return (NavigationProperty) super.getNavigationProperty(name); + return super.getNavigationProperty(name); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/EntityTypeImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/EntityTypeImpl.java index 056750661..217747de0 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/EntityTypeImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/EntityTypeImpl.java @@ -97,7 +97,7 @@ public class EntityTypeImpl extends AbstractStructuralType implements EntityType @Override public Property getProperty(final String name) { - return (Property) super.getProperty(name); + return super.getProperty(name); } @Override @@ -107,7 +107,7 @@ public class EntityTypeImpl extends AbstractStructuralType implements EntityType @Override public NavigationProperty getNavigationProperty(final String name) { - return (NavigationProperty) super.getNavigationProperty(name); + return super.getNavigationProperty(name); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/XMLMetadataImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/XMLMetadataImpl.java index df633f5ba..d4709b619 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/XMLMetadataImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/XMLMetadataImpl.java @@ -69,6 +69,6 @@ public class XMLMetadataImpl extends AbstractEdmItem implements XMLMetadata { @Override public List getReferences() { - return ((Edmx) this.edmx).getReferences(); + return this.edmx.getReferences(); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/ProxyWrappingHttpClientFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/ProxyWrappingHttpClientFactory.java index 9d725121e..6b8aec224 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/ProxyWrappingHttpClientFactory.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/ProxyWrappingHttpClientFactory.java @@ -65,6 +65,7 @@ public class ProxyWrappingHttpClientFactory implements WrappingHttpClientFactory this.wrapped = wrapped; } + @Override public DefaultHttpClientFactory getWrappedHttpClientFactory() { return this.wrapped; } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ClientODataDeserializerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ClientODataDeserializerImpl.java index 4dd165851..cd5003d88 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ClientODataDeserializerImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ClientODataDeserializerImpl.java @@ -70,18 +70,22 @@ public class ClientODataDeserializerImpl implements ClientODataDeserializer { } } + @Override public ResWrap toEntitySet(final InputStream input) throws ODataDeserializerException { return deserializer.toEntitySet(input); } + @Override public ResWrap toEntity(final InputStream input) throws ODataDeserializerException { return deserializer.toEntity(input); } + @Override public ResWrap toProperty(final InputStream input) throws ODataDeserializerException { return deserializer.toProperty(input); } + @Override public ODataError toError(final InputStream input) throws ODataDeserializerException { return deserializer.toError(input); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java index ccf7c81cb..17c4403d0 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java @@ -118,11 +118,11 @@ public class ODataBinderImpl implements ODataBinder { @Override public boolean add(final ODataEntity entity, final ODataProperty property) { - return ((ODataEntity) entity).getProperties().add((ODataProperty) property); + return entity.getProperties().add(property); } protected boolean add(final ODataEntitySet entitySet, final ODataEntity entity) { - return ((ODataEntitySet) entitySet).getEntities().add((ODataEntity) entity); + return entitySet.getEntities().add(entity); } @Override @@ -212,8 +212,8 @@ public class ODataBinderImpl implements ODataBinder { entitySet.getEntities().add(getEntity(entity)); } - entitySet.setDeltaLink(((ODataEntitySet) odataEntitySet).getDeltaLink()); - annotations((ODataEntitySet) odataEntitySet, entitySet); + entitySet.setDeltaLink(odataEntitySet.getDeltaLink()); + annotations(odataEntitySet, entitySet); return entitySet; } @@ -241,7 +241,7 @@ public class ODataBinderImpl implements ODataBinder { for (Link link : linked.getNavigationLinks()) { final ODataLink odataLink = odataLinked.getNavigationLink(link.getTitle()); if (!(odataLink instanceof ODataInlineEntity) && !(odataLink instanceof ODataInlineEntitySet)) { - annotations((ODataLink) odataLink, link); + annotations(odataLink, link); } } } @@ -294,8 +294,8 @@ public class ODataBinderImpl implements ODataBinder { entity.getProperties().add(getProperty(property)); } - entity.setId(((ODataEntity) odataEntity).getId()); - annotations((ODataEntity) odataEntity, entity); + entity.setId(odataEntity.getId()); + annotations(odataEntity, entity); return entity; } @@ -327,7 +327,7 @@ public class ODataBinderImpl implements ODataBinder { @Override public Property getProperty(final ODataProperty property) { - final ODataProperty _property = (ODataProperty) property; + final ODataProperty _property = property; final Property propertyResource = new PropertyImpl(); propertyResource.setName(_property.getName()); @@ -340,8 +340,9 @@ public class ODataBinderImpl implements ODataBinder { protected Object getValue(final ODataValue value) { Object valueResource = null; if (value == null) { - valueResource = null; - } else if (value.isEnum()) { + return null; + } + if (value.isEnum()) { valueResource = value.asEnum().getValue(); } else if (value.isPrimitive()) { valueResource = value.asPrimitive().toValue(); @@ -386,8 +387,8 @@ public class ODataBinderImpl implements ODataBinder { } } - final ODataAnnotation odataAnnotation = new ODataAnnotationImpl(annotation.getTerm(), - (org.apache.olingo.commons.api.domain.ODataValue) getODataValue(fqn, annotation, null, null)); + final ODataAnnotation odataAnnotation = + new ODataAnnotationImpl(annotation.getTerm(), getODataValue(fqn, annotation, null, null)); odataAnnotatable.getAnnotations().add(odataAnnotation); } } @@ -398,7 +399,9 @@ public class ODataBinderImpl implements ODataBinder { final StringWriter writer = new StringWriter(); try { client.getSerializer(ODataFormat.JSON).write(writer, resource.getPayload()); - } catch (final ODataSerializerException e) {} + } catch (final ODataSerializerException e) { + LOG.debug("EntitySet -> ODataEntitySet:\n{}", writer.toString()); + } writer.flush(); LOG.debug("EntitySet -> ODataEntitySet:\n{}", writer.toString()); } @@ -465,9 +468,9 @@ public class ODataBinderImpl implements ODataBinder { } } - for (org.apache.olingo.commons.api.domain.ODataLink link : odataLinked.getNavigationLinks()) { + for (ODataLink link : odataLinked.getNavigationLinks()) { if (!(link instanceof ODataInlineEntity) && !(link instanceof ODataInlineEntitySet)) { - odataAnnotations(linked.getNavigationLink(link.getName()), (ODataAnnotatable) link); + odataAnnotations(linked.getNavigationLink(link.getName()), link); } } } @@ -593,7 +596,9 @@ public class ODataBinderImpl implements ODataBinder { final StringWriter writer = new StringWriter(); try { client.getSerializer(ODataFormat.JSON).write(writer, resource.getPayload()); - } catch (final ODataSerializerException e) {} + } catch (final ODataSerializerException e) { + LOG.debug("EntityResource -> ODataEntity:\n{}", writer.toString()); + } writer.flush(); LOG.debug("EntityResource -> ODataEntity:\n{}", writer.toString()); } @@ -743,11 +748,11 @@ public class ODataBinderImpl implements ODataBinder { ODataValue value = null; if (valuable.isEnum()) { - value = ((ODataClient) client).getObjectFactory().newEnumValue(type == null ? null : type.toString(), + value = client.getObjectFactory().newEnumValue(type == null ? null : type.toString(), valuable.asEnum().toString()); } else if (valuable.isComplex()) { final ODataComplexValue lcValue = - ((ODataClient) client).getObjectFactory().newComplexValue(type == null ? null : type.toString()); + client.getObjectFactory().newComplexValue(type == null ? null : type.toString()); EdmComplexType edmType = null; if (client instanceof EdmEnabledODataClient && type != null) { @@ -806,8 +811,8 @@ public class ODataBinderImpl implements ODataBinder { : EdmPrimitiveTypeKind.valueOfFQN(type.toString())). build(); } else if (valuable.isComplex()) { - final ODataComplexValue cValue = (ODataComplexValue) client.getObjectFactory(). - newComplexValue(type == null ? null : type.toString()); + final ODataComplexValue cValue = + client.getObjectFactory().newComplexValue(type == null ? null : type.toString()); if (!valuable.isNull()) { EdmComplexType edmType = null; @@ -853,8 +858,8 @@ public class ODataBinderImpl implements ODataBinder { final URI next = resource.getPayload().getNext(); final ODataDelta delta = next == null - ? ((ODataClient) client).getObjectFactory().newDelta() - : ((ODataClient) client).getObjectFactory().newDelta(URIUtils.getURI(base, next.toASCIIString())); + ? client.getObjectFactory().newDelta() + : client.getObjectFactory().newDelta(URIUtils.getURI(base, next.toASCIIString())); if (resource.getPayload().getCount() != null) { delta.setCount(resource.getPayload().getCount()); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java index 9afcb132b..1b3873203 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java @@ -158,18 +158,18 @@ public class ODataReaderImpl implements ODataReader { @Override public ODataEntitySet readEntitySet(final InputStream input, final ODataFormat format) throws ODataDeserializerException { - return ((ODataClient) client).getBinder().getODataEntitySet(client.getDeserializer(format).toEntitySet(input)); + return client.getBinder().getODataEntitySet(client.getDeserializer(format).toEntitySet(input)); } @Override public ODataEntity readEntity(final InputStream input, final ODataFormat format) throws ODataDeserializerException { - return ((ODataClient) client).getBinder().getODataEntity(client.getDeserializer(format).toEntity(input)); + return client.getBinder().getODataEntity(client.getDeserializer(format).toEntity(input)); } @Override public ODataProperty readProperty(final InputStream input, final ODataFormat format) throws ODataDeserializerException { - return ((ODataClient) client).getBinder().getODataProperty(client.getDeserializer(format).toProperty(input)); + return client.getBinder().getODataProperty(client.getDeserializer(format).toProperty(input)); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java index 79f1f075b..cdb9020fc 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java @@ -63,7 +63,7 @@ public class ODataWriterImpl implements ODataWriter { return new ByteArrayInputStream(output.toByteArray()); } finally { - IOUtils.closeQuietly(output); + IOUtils.closeQuietly(writer); } } @@ -88,7 +88,7 @@ public class ODataWriterImpl implements ODataWriter { return new ByteArrayInputStream(output.toByteArray()); } finally { - IOUtils.closeQuietly(output); + IOUtils.closeQuietly(writer); } } @@ -106,7 +106,7 @@ public class ODataWriterImpl implements ODataWriter { return new ByteArrayInputStream(output.toByteArray()); } finally { - IOUtils.closeQuietly(output); + IOUtils.closeQuietly(writer); } } @@ -125,7 +125,7 @@ public class ODataWriterImpl implements ODataWriter { return new ByteArrayInputStream(output.toByteArray()); } finally { - IOUtils.closeQuietly(output); + IOUtils.closeQuietly(writer); } } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java index 43df061c9..151b466bf 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java @@ -229,8 +229,8 @@ public final class URIUtils { : (obj instanceof Boolean) ? BooleanUtils.toStringTrueFalse((Boolean) obj) : (obj instanceof UUID) - ? obj.toString() - + ? obj.toString() + : (obj instanceof byte[]) ? EdmBinary.getInstance().toUriLiteral(Hex.encodeHexString((byte[]) obj)) : (obj instanceof Timestamp) @@ -264,7 +264,11 @@ public final class URIUtils { } } catch (Exception e) { LOG.warn("While escaping '{}', using toString()", obj, e); - value = obj.toString(); + if (obj == null) { + value = "null"; + } else { + value = obj.toString(); + } } return value; @@ -346,10 +350,8 @@ public final class URIUtils { value = param.getValue().asComplex().asJavaMap(); } else if (param.getValue().isCollection()) { value = param.getValue().asCollection().asJavaCollection(); - } else if (param.getValue() instanceof org.apache.olingo.commons.api.domain.ODataValue - && ((org.apache.olingo.commons.api.domain.ODataValue) param.getValue()).isEnum()) { - - value = ((org.apache.olingo.commons.api.domain.ODataValue) param.getValue()).asEnum().toString(); + } else if (param.getValue().isEnum()) { + value = param.getValue().asEnum().toString(); } inlineParams.append(URIUtils.escape(value)).append(','); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java index c5960a90b..99358703a 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -45,7 +45,6 @@ import org.apache.olingo.commons.api.domain.ODataValue; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset; import org.apache.olingo.commons.core.edm.primitivetype.EdmDuration; import org.junit.Ignore; @@ -79,10 +78,10 @@ public class EntityTest extends AbstractTest { }; } - private void singleton(final ODataFormat format) throws ODataDeserializerException { + private void singleton(final ODataFormat format) throws Exception { final InputStream input = getClass().getResourceAsStream("VipCustomer." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(format).toEntity(input)); assertNotNull(entity); assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString()); @@ -116,15 +115,16 @@ public class EntityTest extends AbstractTest { assertEquals(2, entity.getOperations().size()); assertEquals("#Microsoft.Test.OData.Services.ODataWCFService.ResetAddress", - entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.ResetAddress").getMetadataAnchor()); + entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.ResetAddress").getMetadataAnchor()); assertEquals("#Microsoft.Test.OData.Services.ODataWCFService.GetHomeAddress", - entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetHomeAddress").getMetadataAnchor()); + entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetHomeAddress").getMetadataAnchor()); // operations won't get serialized entity.getOperations().clear(); final ODataEntity written = getClient().getBinder().getODataEntity( - new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); + new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); assertEquals(entity, written); + input.close(); } @Test @@ -137,10 +137,10 @@ public class EntityTest extends AbstractTest { singleton(ODataFormat.JSON_FULL_METADATA); } - private void withEnums(final ODataFormat format) throws ODataDeserializerException { + private void withEnums(final ODataFormat format) throws Exception { final InputStream input = getClass().getResourceAsStream("Products_5." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(format).toEntity(input)); assertNotNull(entity); final ODataProperty skinColor = entity.getProperty("SkinColor"); @@ -158,8 +158,9 @@ public class EntityTest extends AbstractTest { // operations won't get serialized entity.getOperations().clear(); final ODataEntity written = getClient().getBinder().getODataEntity( - new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); + new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); assertEquals(entity, written); + input.close(); } @Test @@ -172,11 +173,11 @@ public class EntityTest extends AbstractTest { withEnums(ODataFormat.JSON_FULL_METADATA); } - private void withInlineEntitySet(final ODataFormat format) throws ODataDeserializerException { + private void withInlineEntitySet(final ODataFormat format) throws Exception { final InputStream input = getClass().getResourceAsStream( - "Accounts_101_expand_MyPaymentInstruments." + getSuffix(format)); + "Accounts_101_expand_MyPaymentInstruments." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(format).toEntity(input)); assertNotNull(entity); final ODataLink instruments = entity.getNavigationLink("MyPaymentInstruments"); @@ -192,8 +193,9 @@ public class EntityTest extends AbstractTest { // operations won't get serialized entity.getOperations().clear(); final ODataEntity written = getClient().getBinder().getODataEntity( - new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); + new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); assertEquals(entity, written); + input.close(); } @Test @@ -206,11 +208,11 @@ public class EntityTest extends AbstractTest { withInlineEntitySet(ODataFormat.JSON_FULL_METADATA); } - private void mediaEntity(final ODataFormat format) throws ODataDeserializerException { + private void mediaEntity(final ODataFormat format) throws Exception { final InputStream input = getClass().getResourceAsStream( - "Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7." + getSuffix(format)); + "Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(format).toEntity(input)); assertNotNull(entity); assertTrue(entity.isMediaEntity()); @@ -218,8 +220,9 @@ public class EntityTest extends AbstractTest { assertEquals("\"8zOOKKvgOtptr4gt8IrnapX3jds=\"", entity.getMediaETag()); final ODataEntity written = getClient().getBinder().getODataEntity( - new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); + new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); assertEquals(entity, written); + input.close(); } @Test @@ -232,10 +235,10 @@ public class EntityTest extends AbstractTest { mediaEntity(ODataFormat.JSON_FULL_METADATA); } - private void withStream(final ODataFormat format) throws ODataDeserializerException { + private void withStream(final ODataFormat format) throws Exception { final InputStream input = getClass().getResourceAsStream("PersonDetails_1." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(format).toEntity(input)); assertNotNull(entity); assertFalse(entity.isMediaEntity()); @@ -244,8 +247,9 @@ public class EntityTest extends AbstractTest { assertNotNull(editMedia); final ODataEntity written = getClient().getBinder().getODataEntity( - new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); + new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); assertEquals(entity, written); + input.close(); } @Test @@ -258,17 +262,18 @@ public class EntityTest extends AbstractTest { withStream(ODataFormat.JSON_FULL_METADATA); } - private void ref(final ODataFormat format) throws ODataDeserializerException { + private void ref(final ODataFormat format) throws Exception { final InputStream input = getClass().getResourceAsStream("entityReference." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(format).toEntity(input)); assertNotNull(entity); assertNotNull(entity.getId()); final ODataEntity written = getClient().getBinder().getODataEntity( - new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); + new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); assertEquals(entity, written); + input.close(); } @Test @@ -281,10 +286,10 @@ public class EntityTest extends AbstractTest { ref(ODataFormat.JSON); } - private void complexNavigationProperties(final ODataFormat format) throws ODataDeserializerException { + private void complexNavigationProperties(final ODataFormat format) throws Exception { final InputStream input = getClass().getResourceAsStream("entity.withcomplexnavigation." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(format).toEntity(input)); assertNotNull(entity); final ODataComplexValue addressValue = entity.getProperty("Address").getComplexValue(); @@ -294,8 +299,9 @@ public class EntityTest extends AbstractTest { // ETag is not serialized entity.setETag(null); final ODataEntity written = getClient().getBinder().getODataEntity( - new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); + new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); assertEquals(entity, written); + input.close(); } @Test @@ -308,10 +314,10 @@ public class EntityTest extends AbstractTest { complexNavigationProperties(ODataFormat.JSON); } - private void annotated(final ODataFormat format) throws EdmPrimitiveTypeException, ODataDeserializerException { + private void annotated(final ODataFormat format) throws EdmPrimitiveTypeException, Exception { final InputStream input = getClass().getResourceAsStream("annotated." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(format).toEntity(input)); assertNotNull(entity); assertFalse(entity.getAnnotations().isEmpty()); @@ -329,18 +335,19 @@ public class EntityTest extends AbstractTest { assertTrue(annotation.hasComplexValue()); final ODataLink orders = entity.getNavigationLink("Orders"); - assertFalse(((org.apache.olingo.commons.api.domain.ODataLink) orders).getAnnotations().isEmpty()); + assertFalse(orders.getAnnotations().isEmpty()); - annotation = ((org.apache.olingo.commons.api.domain.ODataLink) orders).getAnnotations().get(0); + annotation = orders.getAnnotations().get(0); assertEquals("com.contoso.display.style", annotation.getTerm()); assertEquals("com.contoso.display.styleType", annotation.getValue().getTypeName()); assertTrue(annotation.hasComplexValue()); assertEquals(2, - annotation.getValue().asComplex().get("order").getPrimitiveValue().toCastValue(Integer.class), 0); + annotation.getValue().asComplex().get("order").getPrimitiveValue().toCastValue(Integer.class), 0); final ODataEntity written = getClient().getBinder().getODataEntity( - new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); + new ResWrap((URI) null, null, getClient().getBinder().getEntity(entity))); assertEquals(entity, written); + input.close(); } @Test @@ -355,14 +362,15 @@ public class EntityTest extends AbstractTest { annotated(ODataFormat.JSON); } - private void derived(final ODataClient client, final ODataFormat format) throws ODataDeserializerException { + private void derived(final ODataClient client, final ODataFormat format) throws Exception { final InputStream input = getClass().getResourceAsStream("Customer." + getSuffix(format)); final ODataEntity entity = client.getBinder().getODataEntity(client.getDeserializer(format).toEntity(input)); assertNotNull(entity); assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString()); assertEquals("Microsoft.Test.OData.Services.ODataWCFService.CompanyAddress", - ((ODataValuable) entity.getProperty("HomeAddress")).getValue().getTypeName()); + ((ODataValuable) entity.getProperty("HomeAddress")).getValue().getTypeName()); + input.close(); } @Test diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataProperty.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataProperty.java index f8b91b1d5..9007626c0 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataProperty.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataProperty.java @@ -29,47 +29,4 @@ public interface ODataProperty extends ODataInvokeResult, ODataAnnotatable, ODat * @return property name. */ String getName(); - - /** - * Returns property value. - * - * @return property value. - */ - ODataValue getValue(); - - /** - * Checks if has null value. - * - * @return 'TRUE' if has null value; 'FALSE' otherwise. - */ - boolean hasNullValue(); - - /** - * Checks if has primitive value. - * - * @return 'TRUE' if has primitive value; 'FALSE' otherwise. - */ - boolean hasPrimitiveValue(); - - /** - * Gets primitive value. - * - * @return primitive value if exists; null otherwise. - */ - ODataPrimitiveValue getPrimitiveValue(); - - /** - * Checks if has collection value. - * - * @return 'TRUE' if has collection value; 'FALSE' otherwise. - */ - boolean hasCollectionValue(); - - /** - * Checks if has complex value. - * - * @return 'TRUE' if has complex value; 'FALSE' otherwise. - */ - boolean hasComplexValue(); - } diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java index b72cfecbb..3a91f49c4 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java @@ -203,7 +203,7 @@ public class ExpressionVisitorImpl implements ExpressionVisitor } } - return new TypedOperand(((Property) currentProperty).getValue(), currentType, currentEdmProperty); + return new TypedOperand(currentProperty.getValue(), currentType, currentEdmProperty); } @Override diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java index 54a998cc9..382806c6c 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java @@ -315,7 +315,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe for (Object arrayElement : asCollection) { assertTrue(arrayElement instanceof ComplexValue); - List castedArrayElement = (List) ((ComplexValue) arrayElement).getValue(); + List castedArrayElement = ((ComplexValue) arrayElement).getValue(); assertEquals(2, castedArrayElement.size()); } } @@ -340,7 +340,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe Property complexProperty = entity.getProperty("PropertyComp"); assertEquals(ValueType.COMPLEX, complexProperty.getValueType()); - List complexPropertyValues = (List) complexProperty.asComplex().getValue(); + List complexPropertyValues = complexProperty.asComplex().getValue(); assertEquals(1, complexPropertyValues.size()); Property property = entity.getProperty("CollPropertyComp"); @@ -352,7 +352,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe for (Object arrayElement : asCollection) { assertTrue(arrayElement instanceof ComplexValue); - List castedArrayElement = (List) ((ComplexValue) arrayElement).getValue(); + List castedArrayElement = ((ComplexValue) arrayElement).getValue(); assertEquals(1, castedArrayElement.size()); } } @@ -513,8 +513,9 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe assertEquals("string", defProperty.getValue()); Property complexProperty = entity.getProperty("PropertyCompMixedEnumDef"); - List value = (List) complexProperty.asComplex().getValue(); + List value = complexProperty.asComplex().getValue(); assertEquals((short) 2, value.get(0).getValue()); + stream.close(); } @Test @@ -577,7 +578,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp"))); List collPropertyComp = entity.getProperty("CollPropertyComp").asCollection(); assertNull(collPropertyComp.get(0)); - List complexPropertyProperties = (List) ((ComplexValue) collPropertyComp.get(1)).getValue(); + List complexPropertyProperties = ((ComplexValue) collPropertyComp.get(1)).getValue(); assertEquals(Short.valueOf((short) 789), complexPropertyProperties.get(0).getValue()); assertEquals("TEST 3", complexPropertyProperties.get(1).getValue()); }