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;
|
package org.apache.olingo.odata4.client.api;
|
||||||
|
|
||||||
|
|
||||||
//TODO: Exceptionhandling
|
//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() {
|
public static ODataClient create() {
|
||||||
ODataConsumer instance;
|
ODataClient instance;
|
||||||
|
|
||||||
try {
|
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
|
* We explicitly do not use the singleton pattern to keep the server state free
|
||||||
* and avoid class loading issues also during hot deployment.
|
* and avoid class loading issues also during hot deployment.
|
||||||
*/
|
*/
|
||||||
final Object object = clazz.newInstance();
|
final Object object = clazz.newInstance();
|
||||||
instance = (ODataConsumer) object;
|
instance = (ODataClient) object;
|
||||||
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
|
@ -19,5 +19,6 @@
|
||||||
package org.apache.olingo.odata4.client.api.deserializer;
|
package org.apache.olingo.odata4.client.api.deserializer;
|
||||||
|
|
||||||
public interface AnnotationProperty extends Property {
|
public interface AnnotationProperty extends Property {
|
||||||
|
|
||||||
String getValue();
|
String getValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,19 +18,19 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.odata4.client.api.deserializer;
|
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();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConsumerException(final String message) {
|
public ClientException(final String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConsumerException(final String message, final Throwable cause) {
|
public ClientException(final String message, final Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,5 +19,6 @@
|
||||||
package org.apache.olingo.odata4.client.api.deserializer;
|
package org.apache.olingo.odata4.client.api.deserializer;
|
||||||
|
|
||||||
public interface Property {
|
public interface Property {
|
||||||
|
|
||||||
String getName();
|
String getName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@ import java.io.InputStream;
|
||||||
|
|
||||||
public interface Reader {
|
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;
|
package org.apache.olingo.odata4.client.api.deserializer;
|
||||||
|
|
||||||
public interface Value {
|
public interface Value {
|
||||||
|
|
||||||
boolean isComplex();
|
boolean isComplex();
|
||||||
|
|
||||||
Object getContent();
|
Object getContent();
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
you under the Apache License, Version 2.0 (the "License"); you may not use
|
or more contributor license agreements. See the NOTICE file
|
||||||
this file except in compliance with the License. You may obtain a copy of
|
distributed with this work for additional information
|
||||||
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
|
regarding copyright ownership. The ASF licenses this file
|
||||||
by applicable law or agreed to in writing, software distributed under the
|
to you under the Apache License, Version 2.0 (the
|
||||||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
|
"License"); you may not use this file except in compliance
|
||||||
OF ANY KIND, either express or implied. See the License for the specific
|
with the License. You may obtain a copy of the License at
|
||||||
language governing permissions and limitations under the License. -->
|
|
||||||
|
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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -35,14 +45,7 @@
|
||||||
<artifactId>olingo-odata4-commons-core-incubating</artifactId>
|
<artifactId>olingo-odata4-commons-core-incubating</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-all</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-core</artifactId>
|
<artifactId>jackson-core</artifactId>
|
||||||
|
@ -55,5 +58,14 @@
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-annotations</artifactId>
|
<artifactId>jackson-annotations</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-all</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.odata4.client.core;
|
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 {
|
public class AnnotationPropertyImpl implements AnnotationProperty {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
public AnnotationPropertyImpl(final String name, 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 class ComplexValueImpl extends PropertyCollection implements ComplexValue {
|
||||||
|
|
||||||
public ComplexValueImpl() {}
|
public ComplexValueImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
public ComplexValueImpl(final Map<String, AnnotationProperty> annotationProperties,
|
public ComplexValueImpl(final Map<String, AnnotationProperty> annotationProperties,
|
||||||
final Map<String, NavigationProperty> navigationProperties,
|
final Map<String, NavigationProperty> navigationProperties,
|
||||||
final Map<String, StructuralProperty> structuralProperties) {
|
final Map<String, StructuralProperty> structuralProperties) {
|
||||||
|
|
||||||
super(annotationProperties, navigationProperties, structuralProperties);
|
super(annotationProperties, navigationProperties, structuralProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Value getValue(final String name) {
|
public Value getValue(final String name) {
|
||||||
StructuralProperty property = structuralProperties.get(name);
|
final StructuralProperty property = structuralProperties.get(name);
|
||||||
if (property == null) {
|
if (property == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,13 @@ import org.apache.olingo.odata4.client.api.deserializer.StructuralProperty;
|
||||||
|
|
||||||
public class EntityImpl extends PropertyCollection implements Entity {
|
public class EntityImpl extends PropertyCollection implements Entity {
|
||||||
|
|
||||||
public EntityImpl() {}
|
public EntityImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
public EntityImpl(final Map<String, AnnotationProperty> annotationProperties,
|
public EntityImpl(final Map<String, AnnotationProperty> annotationProperties,
|
||||||
final Map<String, NavigationProperty> navigationProperties,
|
final Map<String, NavigationProperty> navigationProperties,
|
||||||
final Map<String, StructuralProperty> structuralProperties) {
|
final Map<String, StructuralProperty> structuralProperties) {
|
||||||
|
|
||||||
super(annotationProperties, navigationProperties, structuralProperties);
|
super(annotationProperties, navigationProperties, structuralProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +90,7 @@ public class EntityImpl extends PropertyCollection implements Entity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getPropertyContent(final String name) {
|
public Object getPropertyContent(final String name) {
|
||||||
StructuralProperty property = structuralProperties.get(name);
|
final StructuralProperty property = structuralProperties.get(name);
|
||||||
if (property != null) {
|
if (property != null) {
|
||||||
return property.getValue().getContent();
|
return property.getValue().getContent();
|
||||||
}
|
}
|
||||||
|
@ -97,28 +99,28 @@ public class EntityImpl extends PropertyCollection implements Entity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Property getProperty(final String name) {
|
public Property getProperty(final String name) {
|
||||||
Property p = structuralProperties.get(name);
|
Property property = structuralProperties.get(name);
|
||||||
if (p == null) {
|
if (property == null) {
|
||||||
p = annotationProperties.get(name);
|
property = annotationProperties.get(name);
|
||||||
}
|
}
|
||||||
if (p == null) {
|
if (property == null) {
|
||||||
p = navigationProperties.get(name);
|
property = navigationProperties.get(name);
|
||||||
}
|
}
|
||||||
return p;
|
return property;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T extends Property> T getProperty(final String name, final Class<T> clazz) {
|
public <T extends Property> T getProperty(final String name, final Class<T> clazz) {
|
||||||
Property p = getProperty(name);
|
final Property property = getProperty(name);
|
||||||
return (T) p;
|
return (T) property;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getAnnotationValue(final String key) {
|
private String getAnnotationValue(final String key) {
|
||||||
AnnotationProperty prop = annotationProperties.get(key);
|
final AnnotationProperty property = annotationProperties.get(key);
|
||||||
if (prop == null) {
|
if (property == null) {
|
||||||
return 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 {
|
private EntitySet parseEntitySet(final JsonParser jp) throws JsonParseException, IOException {
|
||||||
EntitySetImpl entitySet = new EntitySetImpl();
|
final EntitySetImpl entitySet = new EntitySetImpl();
|
||||||
boolean arrayStarted = false;
|
boolean arrayStarted = false;
|
||||||
|
|
||||||
while (jp.nextToken() != null) {
|
while (jp.nextToken() != null) {
|
||||||
JsonToken token = jp.getCurrentToken();
|
final JsonToken token = jp.getCurrentToken();
|
||||||
switch (token) {
|
switch (token) {
|
||||||
case START_ARRAY:
|
case START_ARRAY:
|
||||||
PropertyCollectionBuilder builder = new PropertyCollectionBuilder(jp, entitySet);
|
final PropertyCollectionBuilder builder = new PropertyCollectionBuilder(jp, entitySet);
|
||||||
entitySet.setPropertyCollectionBuilder(builder);
|
entitySet.setPropertyCollectionBuilder(builder);
|
||||||
arrayStarted = true;
|
arrayStarted = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case START_OBJECT:
|
case START_OBJECT:
|
||||||
if (arrayStarted) {
|
if (arrayStarted) {
|
||||||
return entitySet;
|
return entitySet;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VALUE_NUMBER_INT:
|
case VALUE_NUMBER_INT:
|
||||||
case VALUE_STRING:
|
case VALUE_STRING:
|
||||||
entitySet.addAnnotation(jp.getCurrentName(), jp.getValueAsString());
|
entitySet.addAnnotation(jp.getCurrentName(), jp.getValueAsString());
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,13 @@ import com.fasterxml.jackson.core.JsonParseException;
|
||||||
public class EntitySetImpl implements EntitySet, Iterator<Entity> {
|
public class EntitySetImpl implements EntitySet, Iterator<Entity> {
|
||||||
|
|
||||||
private String odataContext;
|
private String odataContext;
|
||||||
|
|
||||||
private Long odataCount;
|
private Long odataCount;
|
||||||
|
|
||||||
private String odataNextLink;
|
private String odataNextLink;
|
||||||
|
|
||||||
private String odataDeltaLink;
|
private String odataDeltaLink;
|
||||||
|
|
||||||
private List<Entity> entities = null;
|
private List<Entity> entities = null;
|
||||||
|
|
||||||
private PropertyCollectionBuilder propertyCollectionsBuilder;
|
private PropertyCollectionBuilder propertyCollectionsBuilder;
|
||||||
|
@ -91,7 +95,9 @@ public class EntitySetImpl implements EntitySet, Iterator<Entity> {
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
try {
|
try {
|
||||||
return propertyCollectionsBuilder.hasNext();
|
return propertyCollectionsBuilder.hasNext();
|
||||||
} catch (JsonParseException e) {} catch (IOException e) {}
|
} catch (JsonParseException e) {
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +110,8 @@ public class EntitySetImpl implements EntitySet, Iterator<Entity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {}
|
public void remove() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Entity> iterator() {
|
public Iterator<Entity> iterator() {
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Map;
|
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.Entity;
|
||||||
import org.apache.olingo.odata4.client.api.deserializer.EntitySet;
|
import org.apache.olingo.odata4.client.api.deserializer.EntitySet;
|
||||||
import org.apache.olingo.odata4.client.api.deserializer.Property;
|
import org.apache.olingo.odata4.client.api.deserializer.Property;
|
||||||
|
@ -36,36 +36,36 @@ import com.fasterxml.jackson.core.JsonParser;
|
||||||
public class JsonReader implements Reader {
|
public class JsonReader implements Reader {
|
||||||
|
|
||||||
@Override
|
@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
|
// or, for data binding, org.codehaus.jackson.mapper.MappingJsonFactory
|
||||||
try {
|
try {
|
||||||
JsonParser jp = jsonFactory.createParser(in);
|
JsonParser jp = jsonFactory.createParser(in);
|
||||||
EntitySetBuilder entitySet = new EntitySetBuilder(jp);
|
EntitySetBuilder entitySet = new EntitySetBuilder(jp);
|
||||||
return entitySet.buildEntitySet();
|
return entitySet.buildEntitySet();
|
||||||
} catch (JsonParseException e) {
|
} catch (JsonParseException e) {
|
||||||
throw new ConsumerException("JSON Parsing failed.", e);
|
throw new ClientException("JSON Parsing failed.", e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ConsumerException("JSON Parsing failed.", e);
|
throw new ClientException("JSON Parsing failed.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Entity readEntity(final InputStream in) throws ConsumerException {
|
public Entity readEntity(final InputStream in) throws ClientException {
|
||||||
Entity entity = null;
|
Entity entity = null;
|
||||||
|
|
||||||
JsonFactory jsonFactory = new JsonFactory();
|
final JsonFactory jsonFactory = new JsonFactory();
|
||||||
// or, for data binding, org.codehaus.jackson.mapper.MappingJsonFactory
|
// or, for data binding, org.codehaus.jackson.mapper.MappingJsonFactory
|
||||||
try {
|
try {
|
||||||
JsonParser jp = jsonFactory.createParser(in);
|
final JsonParser jp = jsonFactory.createParser(in);
|
||||||
PropertyCollectionBuilder builder = new PropertyCollectionBuilder(jp);
|
final PropertyCollectionBuilder builder = new PropertyCollectionBuilder(jp);
|
||||||
builder.parseNext();
|
builder.parseNext();
|
||||||
entity = builder.buildEntity();
|
entity = builder.buildEntity();
|
||||||
} catch (JsonParseException e) {
|
} catch (JsonParseException e) {
|
||||||
throw new ConsumerException("JSON Parsing failed.", e);
|
throw new ClientException("JSON Parsing failed.", e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ConsumerException("JSON Parsing failed.", e);
|
throw new ClientException("JSON Parsing failed.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
|
@ -77,10 +77,10 @@ public class JsonReader implements Reader {
|
||||||
* @see org.apache.olingo.core.consumer.Reader#parseProperty(java.io.InputStream)
|
* @see org.apache.olingo.core.consumer.Reader#parseProperty(java.io.InputStream)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Property readProperty(final InputStream in) throws ConsumerException {
|
public Property readProperty(final InputStream in) throws ClientException {
|
||||||
Entity entity = readEntity(in);
|
final Entity entity = readEntity(in);
|
||||||
|
|
||||||
Map<String, StructuralProperty> properties = entity.getStructuralProperties();
|
final Map<String, StructuralProperty> properties = entity.getStructuralProperties();
|
||||||
if (properties.size() == 1) {
|
if (properties.size() == 1) {
|
||||||
return properties.values().iterator().next();
|
return properties.values().iterator().next();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,9 @@ import org.apache.olingo.odata4.client.api.deserializer.NavigationProperty;
|
||||||
public class NavigationPropertyImpl implements NavigationProperty {
|
public class NavigationPropertyImpl implements NavigationProperty {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private String associationLink;
|
private String associationLink;
|
||||||
|
|
||||||
private String navigationLink;
|
private String navigationLink;
|
||||||
|
|
||||||
public NavigationPropertyImpl(final String name) {
|
public NavigationPropertyImpl(final String name) {
|
||||||
|
@ -51,8 +53,8 @@ public class NavigationPropertyImpl implements NavigationProperty {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLink(final String name, final String link) {
|
public void updateLink(final String name, final String link) {
|
||||||
String regexNavigationLink = ".*@odata.navigationLink$";
|
final String regexNavigationLink = ".*@odata.navigationLink$";
|
||||||
String regexAssociationLink = ".*@odata.associationLink$";
|
final String regexAssociationLink = ".*@odata.associationLink$";
|
||||||
if (name.matches(regexNavigationLink)) {
|
if (name.matches(regexNavigationLink)) {
|
||||||
navigationLink = link;
|
navigationLink = link;
|
||||||
} else if (name.matches(regexAssociationLink)) {
|
} else if (name.matches(regexAssociationLink)) {
|
||||||
|
@ -61,7 +63,7 @@ public class NavigationPropertyImpl implements NavigationProperty {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String parseName(final String nameToParse) {
|
private String parseName(final String nameToParse) {
|
||||||
String[] split = nameToParse.split("@");
|
final String[] split = nameToParse.split("@");
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
return split[0];
|
return split[0];
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -30,24 +30,29 @@ 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.StructuralProperty;
|
||||||
|
|
||||||
abstract class PropertyCollection {
|
abstract class PropertyCollection {
|
||||||
|
|
||||||
protected Map<String, AnnotationProperty> annotationProperties = new HashMap<String, AnnotationProperty>();
|
protected Map<String, AnnotationProperty> annotationProperties = new HashMap<String, AnnotationProperty>();
|
||||||
|
|
||||||
protected Map<String, NavigationProperty> navigationProperties = new HashMap<String, NavigationProperty>();
|
protected Map<String, NavigationProperty> navigationProperties = new HashMap<String, NavigationProperty>();
|
||||||
|
|
||||||
protected Map<String, StructuralProperty> structuralProperties = new HashMap<String, StructuralProperty>();
|
protected Map<String, StructuralProperty> structuralProperties = new HashMap<String, StructuralProperty>();
|
||||||
|
|
||||||
public PropertyCollection() {}
|
public PropertyCollection() {
|
||||||
|
}
|
||||||
|
|
||||||
protected PropertyCollection(final Map<String, AnnotationProperty> annotationProperties,
|
protected PropertyCollection(final Map<String, AnnotationProperty> annotationProperties,
|
||||||
final Map<String, NavigationProperty> navigationProperties,
|
final Map<String, NavigationProperty> navigationProperties,
|
||||||
final Map<String, StructuralProperty> structuralProperties) {
|
final Map<String, StructuralProperty> structuralProperties) {
|
||||||
|
|
||||||
this.annotationProperties = annotationProperties;
|
this.annotationProperties = annotationProperties;
|
||||||
this.navigationProperties = navigationProperties;
|
this.navigationProperties = navigationProperties;
|
||||||
this.structuralProperties = structuralProperties;
|
this.structuralProperties = structuralProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Property> getProperties() {
|
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(annotationProperties.values());
|
||||||
properties.addAll(navigationProperties.values());
|
properties.addAll(navigationProperties.values());
|
||||||
properties.addAll(structuralProperties.values());
|
properties.addAll(structuralProperties.values());
|
||||||
|
@ -73,11 +78,11 @@ abstract class PropertyCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property instanceof NavigationPropertyImpl) {
|
if (property instanceof NavigationPropertyImpl) {
|
||||||
NavigationPropertyImpl navProperty = (NavigationPropertyImpl) navigationProperties.get(property.getName());
|
final NavigationPropertyImpl navProperty = (NavigationPropertyImpl) navigationProperties.get(property.getName());
|
||||||
if (navProperty == null) {
|
if (navProperty == null) {
|
||||||
navigationProperties.put(property.getName(), (NavigationPropertyImpl) property);
|
navigationProperties.put(property.getName(), (NavigationPropertyImpl) property);
|
||||||
} else {
|
} else {
|
||||||
NavigationProperty temp = (NavigationProperty) property;
|
final NavigationProperty temp = (NavigationProperty) property;
|
||||||
navProperty.updateLink(temp);
|
navProperty.updateLink(temp);
|
||||||
}
|
}
|
||||||
} else if (property instanceof AnnotationPropertyImpl) {
|
} else if (property instanceof AnnotationPropertyImpl) {
|
||||||
|
|
|
@ -36,14 +36,19 @@ import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.core.JsonToken;
|
import com.fasterxml.jackson.core.JsonToken;
|
||||||
|
|
||||||
public class PropertyCollectionBuilder extends PropertyCollection {
|
public class PropertyCollectionBuilder extends PropertyCollection {
|
||||||
|
|
||||||
private JsonParser parser;
|
private JsonParser parser;
|
||||||
|
|
||||||
private EntitySetImpl enclosingEntitySet;
|
private EntitySetImpl enclosingEntitySet;
|
||||||
|
|
||||||
|
private PropertyCollectionBuilder next = null;
|
||||||
|
|
||||||
public PropertyCollectionBuilder(final JsonParser parser) {
|
public PropertyCollectionBuilder(final JsonParser parser) {
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PropertyCollectionBuilder() {};
|
private PropertyCollectionBuilder() {
|
||||||
|
}
|
||||||
|
|
||||||
public PropertyCollectionBuilder(final JsonParser jp, final EntitySetImpl entitySet) {
|
public PropertyCollectionBuilder(final JsonParser jp, final EntitySetImpl entitySet) {
|
||||||
this(jp);
|
this(jp);
|
||||||
|
@ -51,15 +56,15 @@ public class PropertyCollectionBuilder extends PropertyCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity buildEntity() {
|
public Entity buildEntity() {
|
||||||
Entity v = new EntityImpl(annotationProperties, navigationProperties, structuralProperties);
|
final Entity entity = new EntityImpl(annotationProperties, navigationProperties, structuralProperties);
|
||||||
resetProperties();
|
resetProperties();
|
||||||
return v;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComplexValue buildComplexValue() {
|
public ComplexValue buildComplexValue() {
|
||||||
ComplexValue v = new ComplexValueImpl(annotationProperties, navigationProperties, structuralProperties);
|
final ComplexValue value = new ComplexValueImpl(annotationProperties, navigationProperties, structuralProperties);
|
||||||
resetProperties();
|
resetProperties();
|
||||||
return v;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetProperties() {
|
private void resetProperties() {
|
||||||
|
@ -68,8 +73,6 @@ public class PropertyCollectionBuilder extends PropertyCollection {
|
||||||
structuralProperties = new HashMap<String, StructuralProperty>();
|
structuralProperties = new HashMap<String, StructuralProperty>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private PropertyCollectionBuilder next = null;
|
|
||||||
|
|
||||||
public boolean hasNext() throws JsonParseException, IOException {
|
public boolean hasNext() throws JsonParseException, IOException {
|
||||||
if (parser.isClosed()) {
|
if (parser.isClosed()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -92,6 +95,7 @@ public class PropertyCollectionBuilder extends PropertyCollection {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (JsonParseException e) {
|
} catch (JsonParseException e) {
|
||||||
|
// TODO: SLF4J Logging!
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -110,6 +114,7 @@ public class PropertyCollectionBuilder extends PropertyCollection {
|
||||||
*/
|
*/
|
||||||
private PropertyCollectionBuilder parseNextObject(final JsonParser jp, final PropertyCollectionBuilder builder)
|
private PropertyCollectionBuilder parseNextObject(final JsonParser jp, final PropertyCollectionBuilder builder)
|
||||||
throws JsonParseException, IOException {
|
throws JsonParseException, IOException {
|
||||||
|
|
||||||
boolean endReached = readToStartObjectOrEnd(jp);
|
boolean endReached = readToStartObjectOrEnd(jp);
|
||||||
if (endReached) {
|
if (endReached) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -120,11 +125,11 @@ public class PropertyCollectionBuilder extends PropertyCollection {
|
||||||
List<Value> values = null;
|
List<Value> values = null;
|
||||||
|
|
||||||
while (jp.nextToken() != null) {
|
while (jp.nextToken() != null) {
|
||||||
JsonToken token = jp.getCurrentToken();
|
final JsonToken token = jp.getCurrentToken();
|
||||||
switch (token) {
|
switch (token) {
|
||||||
case START_OBJECT:
|
case START_OBJECT:
|
||||||
if (currentFieldName != null) {
|
if (currentFieldName != null) {
|
||||||
ComplexValue cvp = parseNextObject(jp, new PropertyCollectionBuilder()).buildComplexValue();
|
final ComplexValue cvp = parseNextObject(jp, new PropertyCollectionBuilder()).buildComplexValue();
|
||||||
if (values == null) {
|
if (values == null) {
|
||||||
builder.addProperty(new StructuralPropertyImpl(currentFieldName, cvp));
|
builder.addProperty(new StructuralPropertyImpl(currentFieldName, cvp));
|
||||||
} else {
|
} else {
|
||||||
|
@ -176,7 +181,7 @@ public class PropertyCollectionBuilder extends PropertyCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean readToStartObjectOrEnd(final JsonParser jp) throws IOException, JsonParseException {
|
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();
|
JsonToken token = jp.getCurrentToken() == null ? jp.nextToken() : jp.getCurrentToken();
|
||||||
while (token != null && token != endToken) {
|
while (token != null && token != endToken) {
|
||||||
if (enclosingEntitySet != null) {
|
if (enclosingEntitySet != null) {
|
||||||
|
@ -188,6 +193,7 @@ public class PropertyCollectionBuilder extends PropertyCollection {
|
||||||
case VALUE_STRING:
|
case VALUE_STRING:
|
||||||
enclosingEntitySet.addAnnotation(jp.getCurrentName(), jp.getValueAsString());
|
enclosingEntitySet.addAnnotation(jp.getCurrentName(), jp.getValueAsString());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,9 @@ import org.apache.olingo.odata4.client.api.deserializer.Value;
|
||||||
public class StructuralPropertyImpl implements StructuralProperty {
|
public class StructuralPropertyImpl implements StructuralProperty {
|
||||||
|
|
||||||
private final List<Value> values;
|
private final List<Value> values;
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private final boolean containsCollection;
|
private final boolean containsCollection;
|
||||||
|
|
||||||
public StructuralPropertyImpl(final String name, final Value value) {
|
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) {
|
public StructuralPropertyImpl(final String name, final List<Value> values) {
|
||||||
// XXX: ugly -> refactore
|
// XXX: ugly -> refactor
|
||||||
this(name, true, values.toArray(new Value[0]));
|
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 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;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ODataConsumerTest {
|
public class ODataClientTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void before() {
|
public void before() {
|
||||||
ODataConsumer consumer = ODataConsumer.create();
|
ODataClient client = ODataClient.create();
|
||||||
assertNotNull(consumer);
|
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.Property;
|
||||||
import org.apache.olingo.odata4.client.api.deserializer.StructuralProperty;
|
import org.apache.olingo.odata4.client.api.deserializer.StructuralProperty;
|
||||||
import org.apache.olingo.odata4.client.api.deserializer.Value;
|
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.apache.olingo.odata4.client.core.testutil.StringHelper;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -55,7 +54,6 @@ public class JsonReaderPerformance {
|
||||||
// long duration = endTime - startTime;
|
// long duration = endTime - startTime;
|
||||||
// System.out.println("Duration: " + duration + " ms");
|
// System.out.println("Duration: " + duration + " ms");
|
||||||
// System.out.println("Duration per run: " + (duration / (float) runs) + " ms");
|
// System.out.println("Duration per run: " + (duration / (float) runs) + " ms");
|
||||||
|
|
||||||
testComplexProperty(complex);
|
testComplexProperty(complex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,6 @@ import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
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.ComplexValue;
|
||||||
import org.apache.olingo.odata4.client.api.deserializer.Entity;
|
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.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.Reader;
|
||||||
import org.apache.olingo.odata4.client.api.deserializer.StructuralProperty;
|
import org.apache.olingo.odata4.client.api.deserializer.StructuralProperty;
|
||||||
import org.apache.olingo.odata4.client.api.deserializer.Value;
|
import org.apache.olingo.odata4.client.api.deserializer.Value;
|
||||||
import org.apache.olingo.odata4.client.core.deserializer.JsonReader;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class JsonReaderTest {
|
public class JsonReaderTest {
|
||||||
|
@ -243,8 +240,8 @@ public class JsonReaderTest {
|
||||||
|
|
||||||
InputStream content = JsonReaderTest.class.getResourceAsStream("/setOfComplexProperties.json");
|
InputStream content = JsonReaderTest.class.getResourceAsStream("/setOfComplexProperties.json");
|
||||||
Property property = consumer.readProperty(content);
|
Property property = consumer.readProperty(content);
|
||||||
Assert.assertEquals("PhoneNumbers", property.getName());
|
assertEquals("PhoneNumbers", property.getName());
|
||||||
Assert.assertTrue(property instanceof StructuralProperty);
|
assertTrue(property instanceof StructuralProperty);
|
||||||
|
|
||||||
StructuralProperty structuralProperty = (StructuralProperty) property;
|
StructuralProperty structuralProperty = (StructuralProperty) property;
|
||||||
assertTrue(structuralProperty.containsCollection());
|
assertTrue(structuralProperty.containsCollection());
|
||||||
|
|
|
@ -26,9 +26,7 @@ import java.io.InputStreamReader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
/**
|
// TODO: remove this class in favor of StringUtils, IOUtils, ...
|
||||||
* @author SAP AG
|
|
||||||
*/
|
|
||||||
public class StringHelper {
|
public class StringHelper {
|
||||||
|
|
||||||
public static String inputStreamToString(final InputStream in, final boolean preserveLineBreaks) throws IOException {
|
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]).
|
* @return random upper case characters ([A-Z]).
|
||||||
*/
|
*/
|
||||||
public static String generateData(final int len) {
|
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++) {
|
for (int j = 0; j < len; j++) {
|
||||||
char c = (char) (Math.random() * 26 + 65);
|
final char c = (char) (Math.random() * 26 + 65);
|
||||||
b.append(c);
|
builder.append(c);
|
||||||
}
|
}
|
||||||
return b.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue