More white noise: format, final and some TODO
This commit is contained in:
parent
3cee9228d9
commit
e6728fdd9f
|
@ -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);
|
|
@ -19,5 +19,6 @@
|
|||
package org.apache.olingo.odata4.client.api.deserializer;
|
||||
|
||||
public interface AnnotationProperty extends Property {
|
||||
|
||||
String getValue();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -19,5 +19,6 @@
|
|||
package org.apache.olingo.odata4.client.api.deserializer;
|
||||
|
||||
public interface Property {
|
||||
|
||||
String getName();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
Property readProperty(InputStream in) throws ClientException;
|
||||
}
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.olingo.odata4.client.api.deserializer;
|
||||
|
||||
public interface Value {
|
||||
|
||||
boolean isComplex();
|
||||
|
||||
Object getContent();
|
||||
|
|
|
@ -1,14 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
|
||||
license agreements. See the NOTICE file distributed with this work for additional
|
||||
information regarding copyright ownership. The ASF licenses this file to
|
||||
you under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
|
||||
by applicable law or agreed to in writing, software distributed under the
|
||||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
|
||||
OF ANY KIND, either express or implied. See the License for the specific
|
||||
language governing permissions and limitations under the License. -->
|
||||
<!--
|
||||
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -35,14 +45,7 @@
|
|||
<artifactId>olingo-odata4-commons-core-incubating</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
|
@ -55,5 +58,14 @@
|
|||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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<String, AnnotationProperty> annotationProperties,
|
||||
final Map<String, NavigationProperty> navigationProperties,
|
||||
final Map<String, StructuralProperty> 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;
|
||||
}
|
||||
|
|
|
@ -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<String, AnnotationProperty> annotationProperties,
|
||||
final Map<String, NavigationProperty> navigationProperties,
|
||||
final Map<String, StructuralProperty> 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 extends Property> T getProperty(final String name, final Class<T> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,25 +39,29 @@ 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);
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -31,9 +31,13 @@ import com.fasterxml.jackson.core.JsonParseException;
|
|||
public class EntitySetImpl implements EntitySet, Iterator<Entity> {
|
||||
|
||||
private String odataContext;
|
||||
|
||||
private Long odataCount;
|
||||
|
||||
private String odataNextLink;
|
||||
|
||||
private String odataDeltaLink;
|
||||
|
||||
private List<Entity> entities = null;
|
||||
|
||||
private PropertyCollectionBuilder propertyCollectionsBuilder;
|
||||
|
@ -91,7 +95,9 @@ public class EntitySetImpl implements EntitySet, Iterator<Entity> {
|
|||
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<Entity> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void remove() {}
|
||||
public void remove() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Entity> iterator() {
|
||||
|
|
|
@ -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<String, StructuralProperty> properties = entity.getStructuralProperties();
|
||||
final Map<String, StructuralProperty> properties = entity.getStructuralProperties();
|
||||
if (properties.size() == 1) {
|
||||
return properties.values().iterator().next();
|
||||
}
|
||||
|
|
|
@ -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,7 +63,7 @@ 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 {
|
||||
|
|
|
@ -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<String, AnnotationProperty> annotationProperties = new HashMap<String, AnnotationProperty>();
|
||||
|
||||
protected Map<String, NavigationProperty> navigationProperties = new HashMap<String, NavigationProperty>();
|
||||
|
||||
protected Map<String, StructuralProperty> structuralProperties = new HashMap<String, StructuralProperty>();
|
||||
|
||||
public PropertyCollection() {}
|
||||
public PropertyCollection() {
|
||||
}
|
||||
|
||||
protected PropertyCollection(final Map<String, AnnotationProperty> annotationProperties,
|
||||
final Map<String, NavigationProperty> navigationProperties,
|
||||
final Map<String, StructuralProperty> structuralProperties) {
|
||||
|
||||
this.annotationProperties = annotationProperties;
|
||||
this.navigationProperties = navigationProperties;
|
||||
this.structuralProperties = structuralProperties;
|
||||
}
|
||||
|
||||
public List<Property> getProperties() {
|
||||
int initialCapacity = annotationProperties.size() + navigationProperties.size() + structuralProperties.size();
|
||||
final int initialCapacity = annotationProperties.size() + navigationProperties.size() + structuralProperties.size();
|
||||
|
||||
List<Property> properties = new ArrayList<Property>(initialCapacity);
|
||||
final List<Property> properties = new ArrayList<Property>(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) {
|
||||
|
|
|
@ -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<String, StructuralProperty>();
|
||||
}
|
||||
|
||||
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();
|
||||
|
@ -110,6 +114,7 @@ public class PropertyCollectionBuilder extends PropertyCollection {
|
|||
*/
|
||||
private PropertyCollectionBuilder parseNextObject(final JsonParser jp, final PropertyCollectionBuilder builder)
|
||||
throws JsonParseException, IOException {
|
||||
|
||||
boolean endReached = readToStartObjectOrEnd(jp);
|
||||
if (endReached) {
|
||||
return null;
|
||||
|
@ -120,11 +125,11 @@ public class PropertyCollectionBuilder extends PropertyCollection {
|
|||
List<Value> 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();
|
||||
final ComplexValue cvp = parseNextObject(jp, new PropertyCollectionBuilder()).buildComplexValue();
|
||||
if (values == null) {
|
||||
builder.addProperty(new StructuralPropertyImpl(currentFieldName, cvp));
|
||||
} else {
|
||||
|
@ -176,7 +181,7 @@ 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) {
|
||||
|
@ -188,6 +193,7 @@ public class PropertyCollectionBuilder extends PropertyCollection {
|
|||
case VALUE_STRING:
|
||||
enclosingEntitySet.addAnnotation(jp.getCurrentName(), jp.getValueAsString());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,9 @@ import org.apache.olingo.odata4.client.api.deserializer.Value;
|
|||
public class StructuralPropertyImpl implements StructuralProperty {
|
||||
|
||||
private final List<Value> 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<Value> values) {
|
||||
// XXX: ugly -> refactore
|
||||
// XXX: ugly -> refactor
|
||||
this(name, true, values.toArray(new Value[0]));
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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());
|
||||
|
|
|
@ -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 {
|
||||
|
@ -99,12 +97,12 @@ public class StringHelper {
|
|||
* @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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue