[OLINGO-575] Delete unnecessary casts

This commit is contained in:
Christian Amend 2015-03-06 18:21:02 +01:00
parent 9a666bd957
commit f46364072a
38 changed files with 450 additions and 578 deletions

View File

@ -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<T extends Serializable
public <ET extends EntityType<?>> 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<T extends Serializable
}
public void refs() {
((URIBuilder) this.uri).appendRefSegment();
this.uri.appendRefSegment();
}
@Override

View File

@ -33,6 +33,7 @@ import org.apache.olingo.client.api.uri.URIBuilder;
import org.apache.olingo.commons.api.domain.ODataAnnotation;
import org.apache.olingo.commons.api.domain.ODataEntity;
import org.apache.olingo.commons.api.domain.ODataEntitySet;
import org.apache.olingo.commons.api.domain.ODataSingleton;
import org.apache.olingo.ext.proxy.AbstractService;
import org.apache.olingo.ext.proxy.api.AbstractEntitySet;
import org.apache.olingo.ext.proxy.api.AbstractSingleton;
@ -100,7 +101,7 @@ public abstract class AbstractEntityCollectionInvocationHandler<T extends Entity
final List<ODataAnnotation> anns = new ArrayList<ODataAnnotation>();
if (isSingleton) {
final ODataRetrieveResponse<org.apache.olingo.commons.api.domain.ODataSingleton> res =
final ODataRetrieveResponse<ODataSingleton> res =
((ODataClient) getClient()).getRetrieveRequestFactory().getSingletonRequest(uri).execute();
entities.add(res.getBody());
@ -115,9 +116,7 @@ public abstract class AbstractEntityCollectionInvocationHandler<T extends Entity
final ODataEntitySet entitySet = res.getBody();
entities.addAll(entitySet.getEntities());
next = entitySet.getNext();
if (entitySet instanceof ODataEntitySet) {
anns.addAll(((ODataEntitySet) entitySet).getAnnotations());
}
anns.addAll(entitySet.getAnnotations());
}
final List<T> res = new ArrayList<T>(entities.size());

View File

@ -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<String, AnnotatableInvocationHandler> entry : handler.getPropAnnotatableHandlers().entrySet()) {
CoreUtils.addAnnotations(service.getClient(),
entry.getValue().getAnnotations(), ((ODataEntity) entity).getProperty(entry.getKey()));
}
entry.getValue().getAnnotations(), entity.getProperty(entry.getKey()));
}
}
@ -235,13 +233,11 @@ abstract class AbstractPersistenceManager implements PersistenceManager {
}
}
if (entity instanceof ODataEntity) {
for (Map.Entry<String, AnnotatableInvocationHandler> entry : handler.getNavPropAnnotatableHandlers().entrySet()) {
CoreUtils.addAnnotations(service.getClient(),
entry.getValue().getAnnotations(),
(org.apache.olingo.commons.api.domain.ODataLink) entity.getNavigationLink(entry.getKey()));
}
entity.getNavigationLink(entry.getKey()));
}
final AttachedEntityStatus processedStatus = queue(handler, entity, changeset);

View File

@ -633,7 +633,7 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca
}
public void refs() {
((URIBuilder) this.uri).appendRefSegment();
this.uri.appendRefSegment();
}
public void clearQueryOptions() {

View File

@ -80,19 +80,15 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl
private List<ODataAnnotation> internalAnnotations() {
List<ODataAnnotation> result = Collections.<ODataAnnotation> 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()).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()).getNavigationLink(navPropName).getAnnotations()
: ((ODataComplexValue) targetHandler.getInternal()).get(propName).getAnnotations();
}
}
return result;
}
@ -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);
@ -172,8 +168,6 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl
@Override
public Collection<Class<? extends AbstractTerm>> readAnnotationTerms() {
return entityHandler.getEntity() instanceof ODataEntity
? CoreUtils.getAnnotationTerms(service, internalAnnotations())
: Collections.<Class<? extends AbstractTerm>>emptyList();
return CoreUtils.getAnnotationTerms(service, internalAnnotations());
}
}

View File

@ -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<Class<? extends AbstractTerm>> readAnnotationTerms() {
return getEntity() instanceof ODataEntity
? CoreUtils.getAnnotationTerms(service, ((ODataEntity) getEntity()).getAnnotations())
: Collections.<Class<? extends AbstractTerm>> emptyList();
return CoreUtils.getAnnotationTerms(service, getEntity().getAnnotations());
}
@Override
@ -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();
}

View File

@ -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<T, EC> createSearch() {
return new SearchImpl<T, EC>((EdmEnabledODataClient) getClient(), this.collItemRef, this.baseURI, this);
return new SearchImpl<T, EC>(getClient(), this.collItemRef, this.baseURI, this);
}
@Override
@SuppressWarnings("unchecked")
public <S extends T, SEC extends EntityCollection<S, ?, ?>> Search<S, SEC> createSearch(final Class<SEC> reference) {
return new SearchImpl<S, SEC>(
(EdmEnabledODataClient) getClient(),
getClient(),
reference,
baseURI,
(EntitySetInvocationHandler<S, ?, SEC>) this);

View File

@ -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());
}
@ -297,8 +292,8 @@ public final class CoreUtils {
final ODataEntity entity) {
for (Map.Entry<String, Object> entry : changes.entrySet()) {
((List<ODataProperty>) entity.getProperties()).add(
getODataEntityProperty(client, entity.getTypeName(), entry.getKey(), entry.getValue()));
entity.getProperties()
.add(getODataEntityProperty(client, entity.getTypeName(), entry.getKey(), entry.getValue()));
}
}

View File

@ -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());
}

View File

@ -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);

View File

@ -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);

View File

@ -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());
}
}

View File

@ -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

View File

@ -126,12 +126,8 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult>
} 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) {

View File

@ -65,11 +65,10 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest<ODataDel
public ODataDelta getBody() {
if (delta == null) {
try {
final ResWrap<Delta> resource = ((ODataClient) odataClient).
getDeserializer(ODataFormat.fromString(getContentType())).
final ResWrap<Delta> 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) {

View File

@ -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

View File

@ -48,7 +48,7 @@ public class XMLMetadataRequestImpl
@Override
public ODataRetrieveResponse<XMLMetadata> execute() {
final SingleXMLMetadatRequestImpl rootReq = new SingleXMLMetadatRequestImpl((ODataClient) odataClient, uri, null);
final SingleXMLMetadatRequestImpl rootReq = new SingleXMLMetadatRequestImpl(odataClient, uri, null);
final ODataRetrieveResponse<XMLMetadata> rootRes = rootReq.execute();
final XMLMetadataResponseImpl response =
@ -57,7 +57,7 @@ public class XMLMetadataRequestImpl
// process external references
for (Reference reference : rootRes.getBody().getReferences()) {
final SingleXMLMetadatRequestImpl includeReq = new SingleXMLMetadatRequestImpl(
(ODataClient) odataClient,
odataClient,
odataClient.newURIBuilder(uri.resolve(reference.getUri()).toASCIIString()).build(),
uri);
final XMLMetadata includeMetadata = includeReq.execute().getBody();
@ -128,9 +128,11 @@ public class XMLMetadataRequestImpl
return httpResponse;
}
/** Referenced document's URIs must only have the same scheme, host, and port as the
/**
* 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. */
* 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();
}

View File

@ -95,7 +95,7 @@ public class EdmClientImpl extends AbstractEdm {
protected Map<String, EdmSchema> createSchemas() {
final Map<String, EdmSchema> _schemas = new LinkedHashMap<String, EdmSchema>(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).
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,8 +180,7 @@ public class EdmClientImpl extends AbstractEdm {
EdmAction result = null;
final Schema schema = xmlSchemaByNamespace.get(actionName.getNamespace());
if (schema instanceof Schema) {
final List<Action> actions = ((Schema) schema).
final List<Action> actions = schema.
getActions(actionName.getName());
boolean found = false;
for (final Iterator<Action> itor = actions.iterator(); itor.hasNext() && !found;) {
@ -192,7 +190,6 @@ public class EdmClientImpl extends AbstractEdm {
result = EdmActionImpl.getInstance(this, actionName, action);
}
}
}
return result;
}
@ -201,8 +198,7 @@ public class EdmClientImpl extends AbstractEdm {
final List<EdmFunction> result = new ArrayList<EdmFunction>();
final Schema schema = xmlSchemaByNamespace.get(functionName.getNamespace());
if (schema instanceof Schema) {
final List<Function> functions = ((Schema) schema).
final List<Function> functions = schema.
getFunctions(functionName.getName());
for (final Iterator<Function> itor = functions.iterator(); itor.hasNext();) {
final Function function = itor.next();
@ -210,7 +206,6 @@ public class EdmClientImpl extends AbstractEdm {
result.add(EdmFunctionImpl.getInstance(this, functionName, function));
}
}
}
return result;
}
@ -219,8 +214,7 @@ public class EdmClientImpl extends AbstractEdm {
EdmFunction result = null;
final Schema schema = xmlSchemaByNamespace.get(functionName.getNamespace());
if (schema instanceof Schema) {
final List<Function> functions = ((Schema) schema).
final List<Function> functions = schema.
getFunctions(functionName.getName());
boolean found = false;
for (final Iterator<Function> itor = functions.iterator(); itor.hasNext() && !found;) {
@ -236,7 +230,6 @@ public class EdmClientImpl extends AbstractEdm {
result = EdmFunctionImpl.getInstance(this, functionName, function);
}
}
}
return result;
}
@ -247,9 +240,8 @@ public class EdmClientImpl extends AbstractEdm {
EdmAction result = null;
final Schema schema = xmlSchemaByNamespace.get(actionName.getNamespace());
if (schema instanceof Schema) {
final List<Action> actions =
((Schema) schema).getActions(actionName.getName());
schema.getActions(actionName.getName());
boolean found = false;
for (final Iterator<Action> itor = actions.iterator(); itor.hasNext() && !found;) {
final Action action = itor.next();
@ -265,7 +257,6 @@ public class EdmClientImpl extends AbstractEdm {
}
}
}
}
return result;
}
@ -277,8 +268,7 @@ public class EdmClientImpl extends AbstractEdm {
EdmFunction result = null;
final Schema schema = xmlSchemaByNamespace.get(functionName.getNamespace());
if (schema instanceof Schema) {
final List<Function> functions = ((Schema) schema).
final List<Function> functions = schema.
getFunctions(functionName.getName());
boolean found = false;
for (final Iterator<Function> itor = functions.iterator(); itor.hasNext() && !found;) {
@ -301,7 +291,6 @@ public class EdmClientImpl extends AbstractEdm {
}
}
}
}
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,13 +313,11 @@ 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());
schema.getAnnotationGroup(targetName.getName());
if (annotationGroup != null) {
result = new EdmAnnotationsImpl(this, schemas.get(schema.getNamespace()), annotationGroup);
}
}
return result;
}
@ -341,9 +327,8 @@ public class EdmClientImpl extends AbstractEdm {
List<EdmAnnotation> result = null;
final Schema schema = xmlSchemaByNamespace.get(annotatedName.getNamespace());
if (schema instanceof Schema) {
final Annotatable annotatable =
((Schema) schema).getAnnotatables().get(annotatedName.getName());
schema.getAnnotatables().get(annotatedName.getName());
if (annotatable != null && annotatable.getAnnotations() != null) {
result = new ArrayList<EdmAnnotation>();
for (Annotation annotation : annotatable.getAnnotations()) {
@ -351,7 +336,6 @@ public class EdmClientImpl extends AbstractEdm {
result.add(new EdmAnnotationImpl(this, annotation));
}
}
}
return result;
}

View File

@ -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<? extends Schema> 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();
final String baseType = complexType.getBaseType();
baseTypeName = baseType == null
? null : new EdmTypeInfo.Builder().setTypeExpression(baseType).build().getFullQualifiedName();
}
final EdmComplexTypeImpl instance = new EdmComplexTypeImpl(edm, fqn, baseTypeName, xmlSchemas, complexType);
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<? extends Schema> 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

View File

@ -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,29 +45,23 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
private EdmAnnotationHelper helper;
public EdmEntityContainerImpl(final Edm edm, final FullQualifiedName entityContainerName,
final EntityContainer xmlEntityContainer, final List<? extends Schema> xmlSchemas) {
final EntityContainer xmlEntityContainer) {
super(edm, entityContainerName, xmlEntityContainer.getExtends() == null
? 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().
@ -85,10 +78,7 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
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);
}
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);
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;
@ -131,33 +115,25 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
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);
edmSet = new EdmEntitySetImpl(edm, this, entitySet.getName(), entityType, entitySet);
entitySets.put(edmSet.getName(), edmSet);
}
}
}
}
@Override
protected void loadAllFunctionImports() {
final List<? extends FunctionImport> 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);
edmFunctionImport = new EdmFunctionImportImpl(edm, this, functionImport.getName(), functionImport);
functionImports.put(edmFunctionImport.getName(), edmFunctionImport);
}
}
}
@Override
protected void loadAllSingletons() {
final List<Singleton> localSingletons =
((EntityContainer) xmlEntityContainer).getSingletons();
final List<Singleton> localSingletons = xmlEntityContainer.getSingletons();
if (localSingletons != null) {
for (Singleton singleton : localSingletons) {
singletons.put(singleton.getName(), new EdmSingletonImpl(edm, this, singleton.getName(),
@ -170,14 +146,11 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
@Override
protected void loadAllActionImports() {
if (xmlEntityContainer instanceof EntityContainer) {
final List<ActionImport> localActionImports =
((EntityContainer) xmlEntityContainer).getActionImports();
final List<ActionImport> localActionImports = xmlEntityContainer.getActionImports();
if (actionImports != null) {
for (ActionImport actionImport : localActionImports) {
actionImports.put(actionImport.getName(),
new EdmActionImportImpl(edm, this, actionImport.getName(), actionImport));
}
actionImports.put(actionImport.getName(), new EdmActionImportImpl(edm, this, actionImport.getName(),
actionImport));
}
}
}

View File

@ -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,13 +43,12 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
private EdmAnnotationHelper annotationHelper;
public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName fqn,
final List<? extends Schema> 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) {
@ -76,14 +74,11 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
}
private EdmEntityTypeImpl(final Edm edm, final FullQualifiedName fqn, final FullQualifiedName baseTypeName,
final List<? extends Schema> 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

View File

@ -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

View File

@ -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

View File

@ -50,10 +50,8 @@ import org.apache.olingo.commons.core.edm.AbstractEdmSchema;
public class EdmSchemaImpl extends AbstractEdmSchema {
private final Edm edm;
private final List<Schema> xmlSchemas;
private final Schema schema;
@ -61,12 +59,11 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
private List<EdmEntityContainer> entityContainers;
public EdmSchemaImpl(final Edm edm, final List<Schema> 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,21 +72,10 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
if (entityContainers == null) {
entityContainerByName = new HashMap<FullQualifiedName, EdmEntityContainer>();
if (schema instanceof Schema) {
entityContainers = super.getEntityContainers();
if (getEntityContainer() != null) {
entityContainerByName.put(getEntityContainer().getFullQualifiedName(), getEntityContainer());
}
} else {
entityContainers = new ArrayList<EdmEntityContainer>(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);
}
}
}
}
return entityContainers;
@ -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,16 +109,14 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
@Override
protected List<EdmTypeDefinition> createTypeDefinitions() {
final List<EdmTypeDefinition> typeDefinitions = new ArrayList<EdmTypeDefinition>();
if (schema instanceof Schema) {
final List<TypeDefinition> providerTypeDefinitions =
((Schema) schema).getTypeDefinitions();
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,22 +162,19 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
@Override
protected List<EdmAction> createActions() {
final List<EdmAction> actions = new ArrayList<EdmAction>();
if (schema instanceof Schema) {
final List<Action> providerActions = ((Schema) schema).getActions();
final List<Action> providerActions = schema.getActions();
if (providerActions != null) {
for (Action action : providerActions) {
actions.add(EdmActionImpl.getInstance(edm, new FullQualifiedName(namespace, action.getName()), action));
}
}
}
return actions;
}
@Override
protected List<EdmFunction> createFunctions() {
final List<EdmFunction> functions = new ArrayList<EdmFunction>();
if (schema instanceof Schema) {
final List<Function> providerFunctions = ((Schema) schema).getFunctions();
final List<Function> providerFunctions = schema.getFunctions();
if (providerFunctions != null) {
for (Function function : providerFunctions) {
functions.add(
@ -201,51 +182,44 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
}
return functions;
}
}
return functions;
}
@Override
protected List<EdmTerm> createTerms() {
final List<EdmTerm> terms = new ArrayList<EdmTerm>();
if (schema instanceof Schema) {
final List<Term> providerTerms = ((Schema) schema).getTerms();
final List<Term> providerTerms = schema.getTerms();
if (providerTerms != null) {
for (Term term : providerTerms) {
terms.add(new EdmTermImpl(edm, getNamespace(), term));
}
}
}
return terms;
}
@Override
protected List<EdmAnnotations> createAnnotationGroups() {
final List<EdmAnnotations> annotationGroups = new ArrayList<EdmAnnotations>();
if (schema instanceof Schema) {
final List<Annotations> providerAnnotations =
((Schema) schema).getAnnotationGroups();
schema.getAnnotationGroups();
if (providerAnnotations != null) {
for (Annotations annotationGroup : providerAnnotations) {
annotationGroups.add(new EdmAnnotationsImpl(edm, this, annotationGroup));
}
}
}
return annotationGroups;
}
@Override
protected List<EdmAnnotation> createAnnotations() {
final List<EdmAnnotation> annotations = new ArrayList<EdmAnnotation>();
if (schema instanceof Schema) {
final List<Annotation> providerAnnotations =
((Schema) schema).getAnnotations();
schema.getAnnotations();
if (providerAnnotations != null) {
for (Annotation annotation : providerAnnotations) {
annotations.add(new EdmAnnotationImpl(edm, annotation));
}
}
}
return annotations;
}

View File

@ -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<String, EdmNavigationProperty> navigationProperties;
public EdmStructuredTypeHelperImpl(final Edm edm, final FullQualifiedName structuredTypeName,
final List<? extends Schema> 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<String, EdmNavigationProperty>();
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));
}
edm, structuredTypeName, navigationProperty));
}
}
return navigationProperties;

View File

@ -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

View File

@ -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

View File

@ -69,6 +69,6 @@ public class XMLMetadataImpl extends AbstractEdmItem implements XMLMetadata {
@Override
public List<Reference> getReferences() {
return ((Edmx) this.edmx).getReferences();
return this.edmx.getReferences();
}
}

View File

@ -65,6 +65,7 @@ public class ProxyWrappingHttpClientFactory implements WrappingHttpClientFactory
this.wrapped = wrapped;
}
@Override
public DefaultHttpClientFactory getWrappedHttpClientFactory() {
return this.wrapped;
}

View File

@ -70,18 +70,22 @@ public class ClientODataDeserializerImpl implements ClientODataDeserializer {
}
}
@Override
public ResWrap<EntitySet> toEntitySet(final InputStream input) throws ODataDeserializerException {
return deserializer.toEntitySet(input);
}
@Override
public ResWrap<Entity> toEntity(final InputStream input) throws ODataDeserializerException {
return deserializer.toEntity(input);
}
@Override
public ResWrap<Property> toProperty(final InputStream input) throws ODataDeserializerException {
return deserializer.toProperty(input);
}
@Override
public ODataError toError(final InputStream input) throws ODataDeserializerException {
return deserializer.toError(input);
}

View File

@ -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());

View File

@ -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));
}
}

View File

@ -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);
}
}
}

View File

@ -264,8 +264,12 @@ public final class URIUtils {
}
} catch (Exception e) {
LOG.warn("While escaping '{}', using toString()", obj, e);
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(',');

View File

@ -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,7 +78,7 @@ 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));
@ -125,6 +124,7 @@ public class EntityTest extends AbstractTest {
final ODataEntity written = getClient().getBinder().getODataEntity(
new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
input.close();
}
@Test
@ -137,7 +137,7 @@ 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));
@ -160,6 +160,7 @@ public class EntityTest extends AbstractTest {
final ODataEntity written = getClient().getBinder().getODataEntity(
new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
input.close();
}
@Test
@ -172,7 +173,7 @@ 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));
final ODataEntity entity = getClient().getBinder().getODataEntity(
@ -194,6 +195,7 @@ public class EntityTest extends AbstractTest {
final ODataEntity written = getClient().getBinder().getODataEntity(
new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
input.close();
}
@Test
@ -206,7 +208,7 @@ 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));
final ODataEntity entity = getClient().getBinder().getODataEntity(
@ -220,6 +222,7 @@ public class EntityTest extends AbstractTest {
final ODataEntity written = getClient().getBinder().getODataEntity(
new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
input.close();
}
@Test
@ -232,7 +235,7 @@ 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));
@ -246,6 +249,7 @@ public class EntityTest extends AbstractTest {
final ODataEntity written = getClient().getBinder().getODataEntity(
new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
input.close();
}
@Test
@ -258,7 +262,7 @@ 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));
@ -269,6 +273,7 @@ public class EntityTest extends AbstractTest {
final ODataEntity written = getClient().getBinder().getODataEntity(
new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
input.close();
}
@Test
@ -281,7 +286,7 @@ 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));
@ -296,6 +301,7 @@ public class EntityTest extends AbstractTest {
final ODataEntity written = getClient().getBinder().getODataEntity(
new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
input.close();
}
@Test
@ -308,7 +314,7 @@ 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));
@ -329,9 +335,9 @@ 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());
@ -341,6 +347,7 @@ public class EntityTest extends AbstractTest {
final ODataEntity written = getClient().getBinder().getODataEntity(
new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
input.close();
}
@Test
@ -355,7 +362,7 @@ 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);
@ -363,6 +370,7 @@ public class EntityTest extends AbstractTest {
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.CompanyAddress",
((ODataValuable) entity.getProperty("HomeAddress")).getValue().getTypeName());
input.close();
}
@Test

View File

@ -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();
}

View File

@ -203,7 +203,7 @@ public class ExpressionVisitorImpl implements ExpressionVisitor<VisitorOperand>
}
}
return new TypedOperand(((Property) currentProperty).getValue(), currentType, currentEdmProperty);
return new TypedOperand(currentProperty.getValue(), currentType, currentEdmProperty);
}
@Override

View File

@ -315,7 +315,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
for (Object arrayElement : asCollection) {
assertTrue(arrayElement instanceof ComplexValue);
List<Property> castedArrayElement = (List<Property>) ((ComplexValue) arrayElement).getValue();
List<Property> 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<Property> complexPropertyValues = (List<Property>) complexProperty.asComplex().getValue();
List<Property> 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<Property> castedArrayElement = (List<Property>) ((ComplexValue) arrayElement).getValue();
List<Property> 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<Property> value = (List<Property>) complexProperty.asComplex().getValue();
List<Property> 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<Property> complexPropertyProperties = (List<Property>) ((ComplexValue) collPropertyComp.get(1)).getValue();
List<Property> complexPropertyProperties = ((ComplexValue) collPropertyComp.get(1)).getValue();
assertEquals(Short.valueOf((short) 789), complexPropertyProperties.get(0).getValue());
assertEquals("TEST 3", complexPropertyProperties.get(1).getValue());
}