From e6728fdd9f9e31d7a864a3d563168b3cfb3c9669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Thu, 20 Feb 2014 11:47:11 +0100 Subject: [PATCH] More white noise: format, final and some TODO --- .../{ODataConsumer.java => ODataClient.java} | 13 +- .../api/deserializer/AnnotationProperty.java | 1 + ...merException.java => ClientException.java} | 10 +- .../client/api/deserializer/Property.java | 1 + .../client/api/deserializer/Reader.java | 8 +- .../odata4/client/api/deserializer/Value.java | 1 + odata4-lib/odata4-client-core/pom.xml | 118 ++++++++------- ...ConsumerImpl.java => ODataClientImpl.java} | 4 +- .../deserializer/AnnotationPropertyImpl.java | 1 + .../core/deserializer/ComplexValueImpl.java | 12 +- .../client/core/deserializer/EntityImpl.java | 32 ++-- .../core/deserializer/EntitySetBuilder.java | 38 ++--- .../core/deserializer/EntitySetImpl.java | 11 +- .../client/core/deserializer/JsonReader.java | 28 ++-- .../deserializer/NavigationPropertyImpl.java | 12 +- .../core/deserializer/PropertyCollection.java | 19 ++- .../PropertyCollectionBuilder.java | 138 +++++++++--------- .../deserializer/StructuralPropertyImpl.java | 6 +- ...ConsumerTest.java => ODataClientTest.java} | 8 +- .../deserializer/JsonReaderPerformance.java | 2 - .../core/deserializer/JsonReaderTest.java | 21 ++- .../client/core/testutil/StringHelper.java | 22 ++- 22 files changed, 272 insertions(+), 234 deletions(-) rename odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/{ODataConsumer.java => ODataClient.java} (82%) rename odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/{ConsumerException.java => ClientException.java} (77%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/{ODataConsumerImpl.java => ODataClientImpl.java} (88%) rename odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/{ODataConsumerTest.java => ODataClientTest.java} (84%) diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/ODataConsumer.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/ODataClient.java similarity index 82% rename from odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/ODataConsumer.java rename to odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/ODataClient.java index 31a6f76fa..8ee21465d 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/ODataConsumer.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/ODataClient.java @@ -18,24 +18,23 @@ */ package org.apache.olingo.odata4.client.api; - //TODO: Exceptionhandling -public abstract class ODataConsumer { +public abstract class ODataClient { - private static final String IMPLEMENTATION = "org.apache.olingo.odata4.client.core.ODataConsumerImpl"; + private static final String IMPLEMENTATION = "org.apache.olingo.odata4.client.core.ODataClientImpl"; - public static ODataConsumer create() { - ODataConsumer instance; + public static ODataClient create() { + ODataClient instance; try { - final Class clazz = Class.forName(ODataConsumer.IMPLEMENTATION); + final Class clazz = Class.forName(ODataClient.IMPLEMENTATION); /* * We explicitly do not use the singleton pattern to keep the server state free * and avoid class loading issues also during hot deployment. */ final Object object = clazz.newInstance(); - instance = (ODataConsumer) object; + instance = (ODataClient) object; } catch (final Exception e) { throw new RuntimeException(e); diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/AnnotationProperty.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/AnnotationProperty.java index 1b330dd83..47f641d21 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/AnnotationProperty.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/AnnotationProperty.java @@ -19,5 +19,6 @@ package org.apache.olingo.odata4.client.api.deserializer; public interface AnnotationProperty extends Property { + String getValue(); } diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/ConsumerException.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/ClientException.java similarity index 77% rename from odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/ConsumerException.java rename to odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/ClientException.java index 49052d816..04e07147f 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/ConsumerException.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/ClientException.java @@ -18,19 +18,19 @@ */ package org.apache.olingo.odata4.client.api.deserializer; -public class ConsumerException extends Exception { +public class ClientException extends Exception { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 5148670827051750921L; - public ConsumerException() { + public ClientException() { super(); } - public ConsumerException(final String message) { + public ClientException(final String message) { super(message); } - public ConsumerException(final String message, final Throwable cause) { + public ClientException(final String message, final Throwable cause) { super(message, cause); } } diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/Property.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/Property.java index 4d69c2751..45c063f69 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/Property.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/Property.java @@ -19,5 +19,6 @@ package org.apache.olingo.odata4.client.api.deserializer; public interface Property { + String getName(); } diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/Reader.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/Reader.java index 54306ea2e..af526bc98 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/Reader.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/Reader.java @@ -22,9 +22,9 @@ import java.io.InputStream; public interface Reader { - public abstract EntitySet readEntitySet(InputStream in) throws ConsumerException; + EntitySet readEntitySet(InputStream in) throws ClientException; - public abstract Entity readEntity(InputStream in) throws ConsumerException; + Entity readEntity(InputStream in) throws ClientException; - public abstract Property readProperty(InputStream in) throws ConsumerException; -} \ No newline at end of file + Property readProperty(InputStream in) throws ClientException; +} diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/Value.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/Value.java index aec70ee2d..70e23e96e 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/Value.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/deserializer/Value.java @@ -19,6 +19,7 @@ package org.apache.olingo.odata4.client.api.deserializer; public interface Value { + boolean isComplex(); Object getContent(); diff --git a/odata4-lib/odata4-client-core/pom.xml b/odata4-lib/odata4-client-core/pom.xml index e3395f41d..1a4a4b24f 100644 --- a/odata4-lib/odata4-client-core/pom.xml +++ b/odata4-lib/odata4-client-core/pom.xml @@ -1,59 +1,71 @@ - + - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - olingo-odata4-client-core-incubating - jar - ${project.artifactId} + olingo-odata4-client-core-incubating + jar + ${project.artifactId} - - org.apache.olingo - olingo-odata4-lib-incubating - 0.1.0-SNAPSHOT - .. - + + org.apache.olingo + olingo-odata4-lib-incubating + 0.1.0-SNAPSHOT + .. + - - - org.apache.olingo - olingo-odata4-client-api-incubating - ${project.version} - - - org.apache.olingo - olingo-odata4-commons-core-incubating - ${project.version} - - - junit - junit - - - org.mockito - mockito-all - - - com.fasterxml.jackson.core - jackson-core - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.core - jackson-annotations - - + + + org.apache.olingo + olingo-odata4-client-api-incubating + ${project.version} + + + org.apache.olingo + olingo-odata4-commons-core-incubating + ${project.version} + + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-annotations + + + + junit + junit + + + org.mockito + mockito-all + + diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/ODataConsumerImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/ODataClientImpl.java similarity index 88% rename from odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/ODataConsumerImpl.java rename to odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/ODataClientImpl.java index 3b972457c..9af91b343 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/ODataConsumerImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/ODataClientImpl.java @@ -18,8 +18,8 @@ */ package org.apache.olingo.odata4.client.core; -import org.apache.olingo.odata4.client.api.ODataConsumer; +import org.apache.olingo.odata4.client.api.ODataClient; -public class ODataConsumerImpl extends ODataConsumer { +public class ODataClientImpl extends ODataClient { } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/AnnotationPropertyImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/AnnotationPropertyImpl.java index 29ea6319f..1afc9964e 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/AnnotationPropertyImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/AnnotationPropertyImpl.java @@ -23,6 +23,7 @@ import org.apache.olingo.odata4.client.api.deserializer.AnnotationProperty; public class AnnotationPropertyImpl implements AnnotationProperty { private final String name; + private final String value; public AnnotationPropertyImpl(final String name, final String value) { diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/ComplexValueImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/ComplexValueImpl.java index e344b0ea6..331259152 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/ComplexValueImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/ComplexValueImpl.java @@ -29,17 +29,19 @@ import org.apache.olingo.odata4.client.api.deserializer.Value; public class ComplexValueImpl extends PropertyCollection implements ComplexValue { - public ComplexValueImpl() {} + public ComplexValueImpl() { + } public ComplexValueImpl(final Map annotationProperties, - final Map navigationProperties, - final Map structuralProperties) { + final Map navigationProperties, + final Map structuralProperties) { + super(annotationProperties, navigationProperties, structuralProperties); } @Override public Value getValue(final String name) { - StructuralProperty property = structuralProperties.get(name); + final StructuralProperty property = structuralProperties.get(name); if (property == null) { return null; } @@ -75,6 +77,6 @@ public class ComplexValueImpl extends PropertyCollection implements ComplexValue @Override public String toString() { return "ComplexValueImpl [annotations=" + annotationProperties + ", navigationProperties=" + navigationProperties - + ", properties=" + structuralProperties + "]"; + + ", properties=" + structuralProperties + "]"; } } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/EntityImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/EntityImpl.java index 4c0906280..abd5d4ba8 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/EntityImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/EntityImpl.java @@ -28,11 +28,13 @@ import org.apache.olingo.odata4.client.api.deserializer.StructuralProperty; public class EntityImpl extends PropertyCollection implements Entity { - public EntityImpl() {} + public EntityImpl() { + } public EntityImpl(final Map annotationProperties, - final Map navigationProperties, - final Map structuralProperties) { + final Map navigationProperties, + final Map structuralProperties) { + super(annotationProperties, navigationProperties, structuralProperties); } @@ -88,7 +90,7 @@ public class EntityImpl extends PropertyCollection implements Entity { @Override public Object getPropertyContent(final String name) { - StructuralProperty property = structuralProperties.get(name); + final StructuralProperty property = structuralProperties.get(name); if (property != null) { return property.getValue().getContent(); } @@ -97,28 +99,28 @@ public class EntityImpl extends PropertyCollection implements Entity { @Override public Property getProperty(final String name) { - Property p = structuralProperties.get(name); - if (p == null) { - p = annotationProperties.get(name); + Property property = structuralProperties.get(name); + if (property == null) { + property = annotationProperties.get(name); } - if (p == null) { - p = navigationProperties.get(name); + if (property == null) { + property = navigationProperties.get(name); } - return p; + return property; } @SuppressWarnings("unchecked") @Override public T getProperty(final String name, final Class clazz) { - Property p = getProperty(name); - return (T) p; + final Property property = getProperty(name); + return (T) property; } private String getAnnotationValue(final String key) { - AnnotationProperty prop = annotationProperties.get(key); - if (prop == null) { + final AnnotationProperty property = annotationProperties.get(key); + if (property == null) { return null; } - return prop.getValue(); + return property.getValue(); } } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/EntitySetBuilder.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/EntitySetBuilder.java index 09607999b..8d4faadf2 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/EntitySetBuilder.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/EntitySetBuilder.java @@ -39,27 +39,31 @@ public class EntitySetBuilder { } private EntitySet parseEntitySet(final JsonParser jp) throws JsonParseException, IOException { - EntitySetImpl entitySet = new EntitySetImpl(); + final EntitySetImpl entitySet = new EntitySetImpl(); boolean arrayStarted = false; while (jp.nextToken() != null) { - JsonToken token = jp.getCurrentToken(); + final JsonToken token = jp.getCurrentToken(); switch (token) { - case START_ARRAY: - PropertyCollectionBuilder builder = new PropertyCollectionBuilder(jp, entitySet); - entitySet.setPropertyCollectionBuilder(builder); - arrayStarted = true; - break; - case START_OBJECT: - if (arrayStarted) { - return entitySet; - } - break; - case VALUE_NUMBER_INT: - case VALUE_STRING: - entitySet.addAnnotation(jp.getCurrentName(), jp.getValueAsString()); - default: - break; + case START_ARRAY: + final PropertyCollectionBuilder builder = new PropertyCollectionBuilder(jp, entitySet); + entitySet.setPropertyCollectionBuilder(builder); + arrayStarted = true; + break; + + case START_OBJECT: + if (arrayStarted) { + return entitySet; + } + break; + + case VALUE_NUMBER_INT: + case VALUE_STRING: + entitySet.addAnnotation(jp.getCurrentName(), jp.getValueAsString()); + break; + + default: + break; } } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/EntitySetImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/EntitySetImpl.java index 53be2b45f..1c9dd668f 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/EntitySetImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/EntitySetImpl.java @@ -31,9 +31,13 @@ import com.fasterxml.jackson.core.JsonParseException; public class EntitySetImpl implements EntitySet, Iterator { private String odataContext; + private Long odataCount; + private String odataNextLink; + private String odataDeltaLink; + private List entities = null; private PropertyCollectionBuilder propertyCollectionsBuilder; @@ -91,7 +95,9 @@ public class EntitySetImpl implements EntitySet, Iterator { public boolean hasNext() { try { return propertyCollectionsBuilder.hasNext(); - } catch (JsonParseException e) {} catch (IOException e) {} + } catch (JsonParseException e) { + } catch (IOException e) { + } return false; } @@ -104,7 +110,8 @@ public class EntitySetImpl implements EntitySet, Iterator { } @Override - public void remove() {} + public void remove() { + } @Override public Iterator iterator() { diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/JsonReader.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/JsonReader.java index 80ce83470..1cbe6c140 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/JsonReader.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/JsonReader.java @@ -22,7 +22,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Map; -import org.apache.olingo.odata4.client.api.deserializer.ConsumerException; +import org.apache.olingo.odata4.client.api.deserializer.ClientException; import org.apache.olingo.odata4.client.api.deserializer.Entity; import org.apache.olingo.odata4.client.api.deserializer.EntitySet; import org.apache.olingo.odata4.client.api.deserializer.Property; @@ -36,36 +36,36 @@ import com.fasterxml.jackson.core.JsonParser; public class JsonReader implements Reader { @Override - public EntitySet readEntitySet(final InputStream in) throws ConsumerException { + public EntitySet readEntitySet(final InputStream in) throws ClientException { - JsonFactory jsonFactory = new JsonFactory(); + final JsonFactory jsonFactory = new JsonFactory(); // or, for data binding, org.codehaus.jackson.mapper.MappingJsonFactory try { JsonParser jp = jsonFactory.createParser(in); EntitySetBuilder entitySet = new EntitySetBuilder(jp); return entitySet.buildEntitySet(); } catch (JsonParseException e) { - throw new ConsumerException("JSON Parsing failed.", e); + throw new ClientException("JSON Parsing failed.", e); } catch (IOException e) { - throw new ConsumerException("JSON Parsing failed.", e); + throw new ClientException("JSON Parsing failed.", e); } } @Override - public Entity readEntity(final InputStream in) throws ConsumerException { + public Entity readEntity(final InputStream in) throws ClientException { Entity entity = null; - JsonFactory jsonFactory = new JsonFactory(); + final JsonFactory jsonFactory = new JsonFactory(); // or, for data binding, org.codehaus.jackson.mapper.MappingJsonFactory try { - JsonParser jp = jsonFactory.createParser(in); - PropertyCollectionBuilder builder = new PropertyCollectionBuilder(jp); + final JsonParser jp = jsonFactory.createParser(in); + final PropertyCollectionBuilder builder = new PropertyCollectionBuilder(jp); builder.parseNext(); entity = builder.buildEntity(); } catch (JsonParseException e) { - throw new ConsumerException("JSON Parsing failed.", e); + throw new ClientException("JSON Parsing failed.", e); } catch (IOException e) { - throw new ConsumerException("JSON Parsing failed.", e); + throw new ClientException("JSON Parsing failed.", e); } return entity; @@ -77,10 +77,10 @@ public class JsonReader implements Reader { * @see org.apache.olingo.core.consumer.Reader#parseProperty(java.io.InputStream) */ @Override - public Property readProperty(final InputStream in) throws ConsumerException { - Entity entity = readEntity(in); + public Property readProperty(final InputStream in) throws ClientException { + final Entity entity = readEntity(in); - Map properties = entity.getStructuralProperties(); + final Map properties = entity.getStructuralProperties(); if (properties.size() == 1) { return properties.values().iterator().next(); } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/NavigationPropertyImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/NavigationPropertyImpl.java index b049ca092..c16dafb10 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/NavigationPropertyImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/NavigationPropertyImpl.java @@ -23,7 +23,9 @@ import org.apache.olingo.odata4.client.api.deserializer.NavigationProperty; public class NavigationPropertyImpl implements NavigationProperty { private final String name; + private String associationLink; + private String navigationLink; public NavigationPropertyImpl(final String name) { @@ -51,8 +53,8 @@ public class NavigationPropertyImpl implements NavigationProperty { } public void updateLink(final String name, final String link) { - String regexNavigationLink = ".*@odata.navigationLink$"; - String regexAssociationLink = ".*@odata.associationLink$"; + final String regexNavigationLink = ".*@odata.navigationLink$"; + final String regexAssociationLink = ".*@odata.associationLink$"; if (name.matches(regexNavigationLink)) { navigationLink = link; } else if (name.matches(regexAssociationLink)) { @@ -61,12 +63,12 @@ public class NavigationPropertyImpl implements NavigationProperty { } private String parseName(final String nameToParse) { - String[] split = nameToParse.split("@"); + final String[] split = nameToParse.split("@"); if (split.length == 2) { return split[0]; } else { throw new IllegalArgumentException("Got OData Navigation with unparseable format '" - + nameToParse + "'."); + + nameToParse + "'."); } } @@ -82,6 +84,6 @@ public class NavigationPropertyImpl implements NavigationProperty { @Override public String toString() { return "NavigationPropertyImpl [name=" + name + ", associationLink=" + associationLink - + ", navigationLink=" + navigationLink + "]"; + + ", navigationLink=" + navigationLink + "]"; } } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/PropertyCollection.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/PropertyCollection.java index 07904c4ed..0784ea47d 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/PropertyCollection.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/PropertyCollection.java @@ -30,24 +30,29 @@ import org.apache.olingo.odata4.client.api.deserializer.Property; import org.apache.olingo.odata4.client.api.deserializer.StructuralProperty; abstract class PropertyCollection { + protected Map annotationProperties = new HashMap(); + protected Map navigationProperties = new HashMap(); + protected Map structuralProperties = new HashMap(); - public PropertyCollection() {} + public PropertyCollection() { + } protected PropertyCollection(final Map annotationProperties, - final Map navigationProperties, - final Map structuralProperties) { + final Map navigationProperties, + final Map structuralProperties) { + this.annotationProperties = annotationProperties; this.navigationProperties = navigationProperties; this.structuralProperties = structuralProperties; } public List getProperties() { - int initialCapacity = annotationProperties.size() + navigationProperties.size() + structuralProperties.size(); + final int initialCapacity = annotationProperties.size() + navigationProperties.size() + structuralProperties.size(); - List properties = new ArrayList(initialCapacity); + final List properties = new ArrayList(initialCapacity); properties.addAll(annotationProperties.values()); properties.addAll(navigationProperties.values()); properties.addAll(structuralProperties.values()); @@ -73,11 +78,11 @@ abstract class PropertyCollection { } if (property instanceof NavigationPropertyImpl) { - NavigationPropertyImpl navProperty = (NavigationPropertyImpl) navigationProperties.get(property.getName()); + final NavigationPropertyImpl navProperty = (NavigationPropertyImpl) navigationProperties.get(property.getName()); if (navProperty == null) { navigationProperties.put(property.getName(), (NavigationPropertyImpl) property); } else { - NavigationProperty temp = (NavigationProperty) property; + final NavigationProperty temp = (NavigationProperty) property; navProperty.updateLink(temp); } } else if (property instanceof AnnotationPropertyImpl) { diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/PropertyCollectionBuilder.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/PropertyCollectionBuilder.java index d98fc1861..90733b226 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/PropertyCollectionBuilder.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/PropertyCollectionBuilder.java @@ -36,14 +36,19 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; public class PropertyCollectionBuilder extends PropertyCollection { + private JsonParser parser; + private EntitySetImpl enclosingEntitySet; + private PropertyCollectionBuilder next = null; + public PropertyCollectionBuilder(final JsonParser parser) { this.parser = parser; } - private PropertyCollectionBuilder() {}; + private PropertyCollectionBuilder() { + } public PropertyCollectionBuilder(final JsonParser jp, final EntitySetImpl entitySet) { this(jp); @@ -51,15 +56,15 @@ public class PropertyCollectionBuilder extends PropertyCollection { } public Entity buildEntity() { - Entity v = new EntityImpl(annotationProperties, navigationProperties, structuralProperties); + final Entity entity = new EntityImpl(annotationProperties, navigationProperties, structuralProperties); resetProperties(); - return v; + return entity; } public ComplexValue buildComplexValue() { - ComplexValue v = new ComplexValueImpl(annotationProperties, navigationProperties, structuralProperties); + final ComplexValue value = new ComplexValueImpl(annotationProperties, navigationProperties, structuralProperties); resetProperties(); - return v; + return value; } private void resetProperties() { @@ -68,8 +73,6 @@ public class PropertyCollectionBuilder extends PropertyCollection { structuralProperties = new HashMap(); } - private PropertyCollectionBuilder next = null; - public boolean hasNext() throws JsonParseException, IOException { if (parser.isClosed()) { return false; @@ -92,6 +95,7 @@ public class PropertyCollectionBuilder extends PropertyCollection { return true; } } catch (JsonParseException e) { + // TODO: SLF4J Logging! e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); @@ -101,7 +105,7 @@ public class PropertyCollectionBuilder extends PropertyCollection { } /** - * + * * @param jp * @param builder * @return @@ -109,7 +113,8 @@ public class PropertyCollectionBuilder extends PropertyCollection { * @throws JsonParseException */ private PropertyCollectionBuilder parseNextObject(final JsonParser jp, final PropertyCollectionBuilder builder) - throws JsonParseException, IOException { + throws JsonParseException, IOException { + boolean endReached = readToStartObjectOrEnd(jp); if (endReached) { return null; @@ -120,55 +125,55 @@ public class PropertyCollectionBuilder extends PropertyCollection { List values = null; while (jp.nextToken() != null) { - JsonToken token = jp.getCurrentToken(); + final JsonToken token = jp.getCurrentToken(); switch (token) { - case START_OBJECT: - if (currentFieldName != null) { - ComplexValue cvp = parseNextObject(jp, new PropertyCollectionBuilder()).buildComplexValue(); - if (values == null) { - builder.addProperty(new StructuralPropertyImpl(currentFieldName, cvp)); - } else { - values.add(cvp); + case START_OBJECT: + if (currentFieldName != null) { + final ComplexValue cvp = parseNextObject(jp, new PropertyCollectionBuilder()).buildComplexValue(); + if (values == null) { + builder.addProperty(new StructuralPropertyImpl(currentFieldName, cvp)); + } else { + values.add(cvp); + } } - } - break; - case END_OBJECT: - return builder; - case START_ARRAY: - values = new ArrayList(); - break; - case END_ARRAY: - if (values != null) { - builder.addProperty(new StructuralPropertyImpl(currentFieldName, values)); - values = null; - } - break; - case FIELD_NAME: - currentFieldName = jp.getCurrentName(); - break; - case NOT_AVAILABLE: - break; - case VALUE_EMBEDDED_OBJECT: - break; - case VALUE_NULL: - Property nullProperty = createProperty(jp.getCurrentName(), null); - builder.addProperty(nullProperty); - break; - case VALUE_FALSE: - case VALUE_NUMBER_FLOAT: - case VALUE_NUMBER_INT: - case VALUE_STRING: - case VALUE_TRUE: - if (values == null) { - Property property = createProperty(jp.getCurrentName(), jp.getValueAsString()); - builder.addProperty(property); - } else { - PrimitiveValue value = new PrimitiveValue(jp.getValueAsString()); - values.add(value); - } - break; - default: - break; + break; + case END_OBJECT: + return builder; + case START_ARRAY: + values = new ArrayList(); + break; + case END_ARRAY: + if (values != null) { + builder.addProperty(new StructuralPropertyImpl(currentFieldName, values)); + values = null; + } + break; + case FIELD_NAME: + currentFieldName = jp.getCurrentName(); + break; + case NOT_AVAILABLE: + break; + case VALUE_EMBEDDED_OBJECT: + break; + case VALUE_NULL: + Property nullProperty = createProperty(jp.getCurrentName(), null); + builder.addProperty(nullProperty); + break; + case VALUE_FALSE: + case VALUE_NUMBER_FLOAT: + case VALUE_NUMBER_INT: + case VALUE_STRING: + case VALUE_TRUE: + if (values == null) { + Property property = createProperty(jp.getCurrentName(), jp.getValueAsString()); + builder.addProperty(property); + } else { + PrimitiveValue value = new PrimitiveValue(jp.getValueAsString()); + values.add(value); + } + break; + default: + break; } } @@ -176,20 +181,21 @@ public class PropertyCollectionBuilder extends PropertyCollection { } private boolean readToStartObjectOrEnd(final JsonParser jp) throws IOException, JsonParseException { - JsonToken endToken = JsonToken.START_OBJECT; + final JsonToken endToken = JsonToken.START_OBJECT; JsonToken token = jp.getCurrentToken() == null ? jp.nextToken() : jp.getCurrentToken(); while (token != null && token != endToken) { if (enclosingEntitySet != null) { switch (token) { - case VALUE_FALSE: - case VALUE_NUMBER_FLOAT: - case VALUE_NUMBER_INT: - case VALUE_TRUE: - case VALUE_STRING: - enclosingEntitySet.addAnnotation(jp.getCurrentName(), jp.getValueAsString()); - break; - default: - break; + case VALUE_FALSE: + case VALUE_NUMBER_FLOAT: + case VALUE_NUMBER_INT: + case VALUE_TRUE: + case VALUE_STRING: + enclosingEntitySet.addAnnotation(jp.getCurrentName(), jp.getValueAsString()); + break; + + default: + break; } } // diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/StructuralPropertyImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/StructuralPropertyImpl.java index 7e38ab5aa..8e4f62e80 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/StructuralPropertyImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/deserializer/StructuralPropertyImpl.java @@ -28,7 +28,9 @@ import org.apache.olingo.odata4.client.api.deserializer.Value; public class StructuralPropertyImpl implements StructuralProperty { private final List values; + private final String name; + private final boolean containsCollection; public StructuralPropertyImpl(final String name, final Value value) { @@ -36,7 +38,7 @@ public class StructuralPropertyImpl implements StructuralProperty { } public StructuralPropertyImpl(final String name, final List values) { - // XXX: ugly -> refactore + // XXX: ugly -> refactor this(name, true, values.toArray(new Value[0])); } @@ -76,6 +78,6 @@ public class StructuralPropertyImpl implements StructuralProperty { @Override public String toString() { return "StructuralPropertyImpl [name=" + name + ", containsCollection=" + containsCollection - + ", values=" + values + "]"; + + ", values=" + values + "]"; } } diff --git a/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/ODataConsumerTest.java b/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/ODataClientTest.java similarity index 84% rename from odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/ODataConsumerTest.java rename to odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/ODataClientTest.java index 11feb9cfb..814435b24 100644 --- a/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/ODataConsumerTest.java +++ b/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/ODataClientTest.java @@ -20,14 +20,14 @@ package org.apache.olingo.odata4.client.core; import static org.junit.Assert.assertNotNull; -import org.apache.olingo.odata4.client.api.ODataConsumer; +import org.apache.olingo.odata4.client.api.ODataClient; import org.junit.Test; -public class ODataConsumerTest { +public class ODataClientTest { @Test public void before() { - ODataConsumer consumer = ODataConsumer.create(); - assertNotNull(consumer); + ODataClient client = ODataClient.create(); + assertNotNull(client); } } diff --git a/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/deserializer/JsonReaderPerformance.java b/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/deserializer/JsonReaderPerformance.java index 073c10f82..ff4d6c32e 100644 --- a/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/deserializer/JsonReaderPerformance.java +++ b/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/deserializer/JsonReaderPerformance.java @@ -29,7 +29,6 @@ import org.apache.olingo.odata4.client.api.deserializer.ComplexValue; import org.apache.olingo.odata4.client.api.deserializer.Property; import org.apache.olingo.odata4.client.api.deserializer.StructuralProperty; import org.apache.olingo.odata4.client.api.deserializer.Value; -import org.apache.olingo.odata4.client.core.deserializer.JsonReader; import org.apache.olingo.odata4.client.core.testutil.StringHelper; import org.junit.Test; @@ -55,7 +54,6 @@ public class JsonReaderPerformance { // long duration = endTime - startTime; // System.out.println("Duration: " + duration + " ms"); // System.out.println("Duration per run: " + (duration / (float) runs) + " ms"); - testComplexProperty(complex); } diff --git a/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/deserializer/JsonReaderTest.java b/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/deserializer/JsonReaderTest.java index fca91c76c..353ee1a26 100644 --- a/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/deserializer/JsonReaderTest.java +++ b/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/deserializer/JsonReaderTest.java @@ -29,8 +29,6 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; -import junit.framework.Assert; - import org.apache.olingo.odata4.client.api.deserializer.ComplexValue; import org.apache.olingo.odata4.client.api.deserializer.Entity; import org.apache.olingo.odata4.client.api.deserializer.EntitySet; @@ -38,7 +36,6 @@ import org.apache.olingo.odata4.client.api.deserializer.Property; import org.apache.olingo.odata4.client.api.deserializer.Reader; import org.apache.olingo.odata4.client.api.deserializer.StructuralProperty; import org.apache.olingo.odata4.client.api.deserializer.Value; -import org.apache.olingo.odata4.client.core.deserializer.JsonReader; import org.junit.Test; public class JsonReaderTest { @@ -48,7 +45,7 @@ public class JsonReaderTest { Reader consumer = new JsonReader(); EntitySet entitySet = consumer.readEntitySet( - JsonReaderTest.class.getResourceAsStream("/fullEntitySet.json")); + JsonReaderTest.class.getResourceAsStream("/fullEntitySet.json")); List entities = entitySet.getEntities(); validateEntitySet(entitySet); @@ -243,8 +240,8 @@ public class JsonReaderTest { InputStream content = JsonReaderTest.class.getResourceAsStream("/setOfComplexProperties.json"); Property property = consumer.readProperty(content); - Assert.assertEquals("PhoneNumbers", property.getName()); - Assert.assertTrue(property instanceof StructuralProperty); + assertEquals("PhoneNumbers", property.getName()); + assertTrue(property instanceof StructuralProperty); StructuralProperty structuralProperty = (StructuralProperty) property; assertTrue(structuralProperty.containsCollection()); @@ -262,7 +259,7 @@ public class JsonReaderTest { assertEquals("Cell", phoneNumberTwo.getValue("Type").getContent()); assertEquals("Sprint", phoneNumberTwo.getValue("Carrier").getContent()); assertEquals("#Model.CellPhoneNumber", - phoneNumberTwo.getAnnotationProperties().get("odata.type").getValue()); + phoneNumberTwo.getAnnotationProperties().get("odata.type").getValue()); // ComplexValue complex = consumer.parseComplexValue(content); // @@ -283,12 +280,12 @@ public class JsonReaderTest { assertNotNull(entity.getNavigationProperties()); assertTrue(entity.getNavigationProperties().containsKey("Orders")); assertEquals("Customers('ALFKI')/Orders", - entity.getNavigationProperties().get("Orders").getNavigationLink()); + entity.getNavigationProperties().get("Orders").getNavigationLink()); assertNotNull(entity.getNavigationProperties()); assertTrue(entity.getNavigationProperties().containsKey("Orders")); assertEquals("Customers('ALFKI')/Orders/$ref", - entity.getNavigationProperties().get("Orders").getAssociationLink()); + entity.getNavigationProperties().get("Orders").getAssociationLink()); assertNotNull(entity.getPropertyContent("ID")); assertEquals("ALFKI", entity.getPropertyContent("ID")); @@ -314,7 +311,7 @@ public class JsonReaderTest { assertNotNull(entity.getNavigationProperties()); assertTrue(entity.getNavigationProperties().containsKey("Orders")); assertEquals("Customers('MUSKI')/Orders/$ref", - entity.getNavigationProperties().get("Orders").getAssociationLink()); + entity.getNavigationProperties().get("Orders").getAssociationLink()); assertNotNull(entity.getPropertyContent("ID")); assertEquals("MUSKI", entity.getPropertyContent("ID")); @@ -345,12 +342,12 @@ public class JsonReaderTest { assertNotNull(complex.getNavigationProperties()); assertTrue(complex.getNavigationProperties().containsKey("Country")); assertEquals("Customers('ALFKI')/Address/Country", - complex.getNavigationProperties().get("Country").getNavigationLink()); + complex.getNavigationProperties().get("Country").getNavigationLink()); assertNotNull(complex.getNavigationProperties()); assertTrue(complex.getNavigationProperties().containsKey("Country")); assertEquals("Customers('ALFKI')/Address/Country/$ref", - complex.getNavigationProperties().get("Country").getAssociationLink()); + complex.getNavigationProperties().get("Country").getAssociationLink()); } private void validateEntitySet(final EntitySet entitySet) { diff --git a/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/testutil/StringHelper.java b/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/testutil/StringHelper.java index bd785fea6..90b747955 100644 --- a/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/testutil/StringHelper.java +++ b/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/testutil/StringHelper.java @@ -26,9 +26,7 @@ import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; -/** - * @author SAP AG - */ +// TODO: remove this class in favor of StringUtils, IOUtils, ... public class StringHelper { public static String inputStreamToString(final InputStream in, final boolean preserveLineBreaks) throws IOException { @@ -56,7 +54,7 @@ public class StringHelper { /** * Encapsulate given content in an {@link InputStream} with charset UTF-8. - * + * * @param content to encapsulate content * @return content as stream */ @@ -71,20 +69,20 @@ public class StringHelper { /** * Encapsulate given content in an {@link InputStream} with given charset. - * + * * @param content to encapsulate content * @param charset to be used charset * @return content as stream * @throws UnsupportedEncodingException if charset is not supported */ public static InputStream encapsulate(final String content, final String charset) - throws UnsupportedEncodingException { + throws UnsupportedEncodingException { return new ByteArrayInputStream(content.getBytes(charset)); } /** * Generate a string with given length containing random upper case characters ([A-Z]). - * + * * @param len length of to generated string * @return random upper case characters ([A-Z]). */ @@ -94,17 +92,17 @@ public class StringHelper { /** * Generate a string with given length containing random upper case characters ([A-Z]). - * + * * @param len length of to generated string * @return random upper case characters ([A-Z]). */ public static String generateData(final int len) { - StringBuilder b = new StringBuilder(len); + final StringBuilder builder = new StringBuilder(len); for (int j = 0; j < len; j++) { - char c = (char) (Math.random() * 26 + 65); - b.append(c); + final char c = (char) (Math.random() * 26 + 65); + builder.append(c); } - return b.toString(); + return builder.toString(); } }