You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2013/12/12 09:07:49 UTC
[3/3] git commit: [OLINGO-71] code cleanup
[OLINGO-71] code cleanup
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/2f2553ca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/2f2553ca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/2f2553ca
Branch: refs/heads/master
Commit: 2f2553ca7eaa6bd349c2f7b2fb9dfe9eedc342a9
Parents: d6d839b
Author: Stephan Klevenz <sk...@apache.org>
Authored: Thu Dec 12 09:05:26 2013 +0100
Committer: Stephan Klevenz <sk...@apache.org>
Committed: Thu Dec 12 09:05:26 2013 +0100
----------------------------------------------------------------------
.../odata2/api/data/DataSourceProcessor.java | 2 +-
.../olingo/odata2/api/data/ValueAccess.java | 18 +-
.../annotation/data/AnnotationInMemoryDs.java | 91 ++++---
.../annotation/data/AnnotationValueAccess.java | 27 +-
.../annotation/data/BeanPropertyAccess.java | 6 +-
.../odata2/core/annotation/data/DataStore.java | 78 +++---
.../annotation/edm/AnnotationEdmProvider.java | 123 +++++----
.../annotation/processor/ListsProcessor.java | 12 +-
.../core/annotation/util/AnnotationHelper.java | 264 ++++++++++---------
.../core/annotation/util/ClassHelper.java | 45 ++--
.../data/AnnotationsInMemoryDsTest.java | 19 +-
.../edm/AnnotationEdmProviderTest.java | 158 ++++++-----
.../odata2/core/annotation/model/Building.java | 2 +-
.../odata2/core/annotation/model/City.java | 3 +-
.../odata2/core/annotation/model/Location.java | 1 -
.../odata2/core/annotation/model/Photo.java | 14 +-
.../odata2/core/annotation/model/RefBase.java | 20 +-
.../core/annotation/model/ResourceHelper.java | 16 +-
.../odata2/core/annotation/model/Room.java | 8 +-
.../odata2/core/annotation/model/Team.java | 4 +-
.../odata2/ref/annotation/model/Building.java | 2 +-
.../odata2/ref/annotation/model/City.java | 2 +-
.../odata2/ref/annotation/model/Photo.java | 14 +-
.../odata2/ref/annotation/model/RefBase.java | 18 +-
.../ref/annotation/model/ResourceHelper.java | 23 +-
.../odata2/ref/annotation/model/Team.java | 4 +-
.../processor/AnnotationServiceFactory.java | 34 +--
.../api/annotation/edm/Documentation.java | 28 +-
.../api/annotation/edm/EdmComplexType.java | 1 +
.../annotation/edm/EdmConcurrencyControl.java | 8 +-
.../api/annotation/edm/EdmDocumentation.java | 27 +-
.../odata2/api/annotation/edm/EdmEntitySet.java | 1 +
.../api/annotation/edm/EdmEntityType.java | 3 +-
.../odata2/api/annotation/edm/EdmFacets.java | 5 +-
.../api/annotation/edm/EdmFunctionImport.java | 41 +--
.../edm/EdmFunctionImportParameter.java | 4 +-
.../annotation/edm/EdmMediaResourceContent.java | 9 +-
.../edm/EdmMediaResourceMimeType.java | 6 +-
.../annotation/edm/EdmMediaResourceSource.java | 8 +-
.../annotation/edm/EdmNavigationProperty.java | 7 +-
.../odata2/api/annotation/edm/EdmProperty.java | 6 +-
.../odata2/api/annotation/edm/EdmType.java | 6 +-
.../odata2/api/annotation/edm/Facets.java | 28 +-
.../api/annotation/edm/FunctionImport.java | 28 +-
.../odata2/api/annotation/edm/Parameter.java | 30 +--
.../odata2/api/annotation/edmx/HttpMethod.java | 28 +-
.../api/ODataDebugResponseWrapperCallback.java | 8 +-
.../api/ep/EntityProviderWriteProperties.java | 5 +-
.../odata2/api/uri/UriNotMatchingException.java | 2 +-
.../apache/olingo/odata2/api/uri/UriParser.java | 12 +-
.../api/uri/expression/OrderExpression.java | 2 +-
.../api/uri/expression/PropertyExpression.java | 2 +-
.../api/uri/expression/UnaryExpression.java | 2 +-
.../olingo/odata2/core/ODataRequestHandler.java | 2 +-
.../olingo/odata2/core/commons/XmlHelper.java | 3 +-
.../ep/producer/JsonEntryEntityProducer.java | 11 -
.../odata2/core/rest/ODataExceptionWrapper.java | 3 +-
.../odata2/core/rest/ODataRootLocator.java | 5 +-
.../odata2/core/rest/ODataSubLocator.java | 6 +-
.../olingo/odata2/core/rest/RestUtil.java | 4 +-
.../core/ODataRequestHandlerValidationTest.java | 2 +-
.../debug/ODataDebugResponseWrapperTest.java | 6 +-
.../producer/JsonEntryEntityProducerTest.java | 4 +-
.../core/rest/ODataExceptionMapperImplTest.java | 2 +-
.../fit/misc/ODataApplicationFactory.java | 2 -
.../odata2/fit/ref/EntryXmlReadOnlyTest.java | 4 +-
.../testutil/fit/FitStaticServiceFactory.java | 4 +-
.../odata2/testutil/helper/StringHelper.java | 2 +-
.../odata2/testutil/mock/EdmTestProvider.java | 4 +-
.../mock/TechnicalScenarioEdmProvider.java | 2 +-
.../odata2/testutil/server/TestServer.java | 2 +-
71 files changed, 698 insertions(+), 685 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/2f2553ca/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java b/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
index 2be5663..dc89970 100644
--- a/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
+++ b/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
@@ -32,7 +32,7 @@ public abstract class DataSourceProcessor extends ODataSingleProcessor {
protected final DataSource dataSource;
protected final ValueAccess valueAccess;
-
+
/**
* Initialize a {@link DataSourceProcessor} in combination with given {@link DataSource} (providing data objects)
* and {@link ValueAccess} (accessing values of data objects).
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/2f2553ca/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java b/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
index 685e1b6..633ca37 100644
--- a/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
+++ b/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
@@ -29,7 +29,7 @@ public interface ValueAccess {
/**
* Retrieves the value of an EDM property for the given data object.
- * @param data the Java data object
+ * @param data the Java data object
* @param property the requested {@link EdmProperty}
* @return the requested property value
*/
@@ -37,15 +37,15 @@ public interface ValueAccess {
/**
* Sets the value of an EDM property for the given data object.
- * @param data the Java data object
+ * @param data the Java data object
* @param property the {@link EdmProperty}
- * @param value the new value of the property
+ * @param value the new value of the property
*/
public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException;
/**
* Retrieves the Java type of an EDM property for the given data object.
- * @param data the Java data object
+ * @param data the Java data object
* @param property the requested {@link EdmProperty}
* @return the requested Java type
*/
@@ -53,17 +53,17 @@ public interface ValueAccess {
/**
* Retrieves the value defined by a mapping object for the given data object.
- * @param data the Java data object
- * @param mapping the requested {@link EdmMapping}
+ * @param data the Java data object
+ * @param mapping the requested {@link EdmMapping}
* @return the requested value
*/
public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException;
/**
* Sets the value defined by a mapping object for the given data object.
- * @param data the Java data object
- * @param mapping the {@link EdmMapping}
- * @param value the new value
+ * @param data the Java data object
+ * @param mapping the {@link EdmMapping}
+ * @param value the new value
*/
public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/2f2553ca/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
index 9a03455..564c2bf 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -4,13 +4,13 @@
* 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.
- *****************************************************************************
+ *****************************************************************************
*/
package org.apache.olingo.odata2.core.annotation.data;
@@ -34,9 +34,9 @@ import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
-import org.apache.olingo.odata2.core.annotation.util.ClassHelper;
import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper.AnnotatedNavInfo;
import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper.ODataAnnotationException;
+import org.apache.olingo.odata2.core.annotation.util.ClassHelper;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
public class AnnotationInMemoryDs implements DataSource {
@@ -45,15 +45,15 @@ public class AnnotationInMemoryDs implements DataSource {
private final Map<String, DataStore<Object>> dataStores = new HashMap<String, DataStore<Object>>();
private final boolean persistInMemory;
- public AnnotationInMemoryDs(String packageToScan) throws ODataException {
+ public AnnotationInMemoryDs(final String packageToScan) throws ODataException {
this(packageToScan, true);
}
-
- public AnnotationInMemoryDs(String packageToScan, boolean persistInMemory) throws ODataException {
+
+ public AnnotationInMemoryDs(final String packageToScan, final boolean persistInMemory) throws ODataException {
this.persistInMemory = persistInMemory;
List<Class<?>> foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
@Override
- public boolean isClassValid(Class<?> c) {
+ public boolean isClassValid(final Class<?> c) {
return null != c.getAnnotation(org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet.class);
}
});
@@ -62,7 +62,7 @@ public class AnnotationInMemoryDs implements DataSource {
}
@SuppressWarnings("unchecked")
- private void init(List<Class<?>> foundClasses) throws ODataException {
+ private void init(final List<Class<?>> foundClasses) throws ODataException {
try {
for (Class<?> clz : foundClasses) {
DataStore<Object> dhs = (DataStore<Object>) DataStore.createInMemory(clz, persistInMemory);
@@ -74,13 +74,13 @@ public class AnnotationInMemoryDs implements DataSource {
}
}
- public <T> DataStore<T> getDataStore(Class<T> clazz) {
+ public <T> DataStore<T> getDataStore(final Class<T> clazz) {
String entitySetName = ANNOTATION_HELPER.extractEntitySetName(clazz);
return (DataStore<T>) dataStores.get(entitySetName);
}
@Override
- public List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException,
+ public List<?> readData(final EdmEntitySet entitySet) throws ODataNotImplementedException,
ODataNotFoundException, EdmException, ODataApplicationException {
DataStore<Object> holder = getDataStore(entitySet);
@@ -92,7 +92,7 @@ public class AnnotationInMemoryDs implements DataSource {
}
@Override
- public Object readData(EdmEntitySet entitySet, Map<String, Object> keys)
+ public Object readData(final EdmEntitySet entitySet, final Map<String, Object> keys)
throws ODataNotFoundException, EdmException, ODataApplicationException {
DataStore<Object> store = getDataStore(entitySet);
@@ -110,14 +110,16 @@ public class AnnotationInMemoryDs implements DataSource {
}
@Override
- public Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
+ public Object readData(final EdmFunctionImport function, final Map<String, Object> parameters,
+ final Map<String, Object> keys)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
}
@Override
- public Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys)
+ public Object readRelatedData(final EdmEntitySet sourceEntitySet, final Object sourceData,
+ final EdmEntitySet targetEntitySet,
+ final Map<String, Object> targetKeys)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
DataStore<?> sourceStore = dataStores.get(sourceEntitySet.getName());
@@ -128,7 +130,7 @@ public class AnnotationInMemoryDs implements DataSource {
Field sourceField = navInfo.getFromField();
if (sourceField == null) {
throw new ODataRuntimeException("Missing source field for related data (sourceStore='" + sourceStore
- + "', targetStore='" + targetStore + "').");
+ + "', targetStore='" + targetStore + "').");
}
Object navigationInstance = getValue(sourceField, sourceData);
@@ -165,7 +167,7 @@ public class AnnotationInMemoryDs implements DataSource {
}
@Override
- public BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData)
+ public BinaryData readBinaryData(final EdmEntitySet entitySet, final Object mediaLinkEntryData)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
Object data = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceContent.class);
@@ -176,7 +178,7 @@ public class AnnotationInMemoryDs implements DataSource {
}
@Override
- public Object newDataObject(EdmEntitySet entitySet)
+ public Object newDataObject(final EdmEntitySet entitySet)
throws ODataNotImplementedException, EdmException, ODataApplicationException {
DataStore<Object> dataStore = getDataStore(entitySet);
@@ -188,7 +190,8 @@ public class AnnotationInMemoryDs implements DataSource {
}
@Override
- public void writeBinaryData(EdmEntitySet entitySet, Object mediaEntityInstance, BinaryData binaryData)
+ public void writeBinaryData(final EdmEntitySet entitySet, final Object mediaEntityInstance,
+ final BinaryData binaryData)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
try {
@@ -197,7 +200,7 @@ public class AnnotationInMemoryDs implements DataSource {
ANNOTATION_HELPER.setValueForAnnotatedField(
mediaEntityInstance, EdmMediaResourceMimeType.class, binaryData.getMimeType());
} catch (ODataAnnotationException e) {
- throw new ODataRuntimeException("Invalid media resource annotation at entity set '" + entitySet.getName()
+ throw new ODataRuntimeException("Invalid media resource annotation at entity set '" + entitySet.getName()
+ "' with message '" + e.getMessage() + "'.", e);
}
}
@@ -212,15 +215,15 @@ public class AnnotationInMemoryDs implements DataSource {
* @throws org.apache.olingo.odata2.api.edm.EdmException
* @throws org.apache.olingo.odata2.api.exception.ODataApplicationException
*/
- public Object updateData(EdmEntitySet entitySet, Object data)
- throws ODataNotImplementedException, EdmException, ODataApplicationException {
+ public Object updateData(final EdmEntitySet entitySet, final Object data)
+ throws ODataNotImplementedException, EdmException, ODataApplicationException {
DataStore<Object> dataStore = getDataStore(entitySet);
return dataStore.update(data);
}
@Override
- public void deleteData(EdmEntitySet entitySet, Map<String, Object> keys)
+ public void deleteData(final EdmEntitySet entitySet, final Map<String, Object> keys)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
DataStore<Object> dataStore = getDataStore(entitySet);
Object keyInstance = dataStore.createInstance();
@@ -229,7 +232,7 @@ public class AnnotationInMemoryDs implements DataSource {
}
@Override
- public void createData(EdmEntitySet entitySet, Object data)
+ public void createData(final EdmEntitySet entitySet, final Object data)
throws ODataNotImplementedException, EdmException, ODataApplicationException {
DataStore<Object> dataStore = getDataStore(entitySet);
@@ -237,15 +240,17 @@ public class AnnotationInMemoryDs implements DataSource {
}
@Override
- public void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys)
+ public void deleteRelation(final EdmEntitySet sourceEntitySet, final Object sourceData,
+ final EdmEntitySet targetEntitySet,
+ final Map<String, Object> targetKeys)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
}
@Override
- public void writeRelation(EdmEntitySet sourceEntitySet, Object sourceEntity, EdmEntitySet targetEntitySet,
- Map<String, Object> targetEntityValues)
+ public void writeRelation(final EdmEntitySet sourceEntitySet, final Object sourceEntity,
+ final EdmEntitySet targetEntitySet,
+ final Map<String, Object> targetEntityValues)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
// get common data
DataStore<Object> sourceStore = dataStores.get(sourceEntitySet.getName());
@@ -253,50 +258,50 @@ public class AnnotationInMemoryDs implements DataSource {
AnnotatedNavInfo commonNavInfo = ANNOTATION_HELPER.getCommonNavigationInfo(
sourceStore.getDataTypeClass(), targetStore.getDataTypeClass());
-
+
// get and validate source fields
Field sourceField = commonNavInfo.getFromField();
if (sourceField == null) {
throw new ODataRuntimeException("Missing source field for related data (sourceStore='" + sourceStore
- + "', targetStore='" + targetStore + "').");
+ + "', targetStore='" + targetStore + "').");
}
-
+
// get related target entity
Object targetEntity = targetStore.createInstance();
ANNOTATION_HELPER.setKeyFields(targetEntity, targetEntityValues);
targetEntity = targetStore.read(targetEntity);
-
+
// set at source
setValueAtNavigationField(sourceEntity, sourceField, targetEntity);
// set at target
Field targetField = commonNavInfo.getToField();
- if(targetField != null) {
+ if (targetField != null) {
setValueAtNavigationField(targetEntity, targetField, sourceEntity);
}
}
/**
* Set (Multiplicity != *) or add (Multiplicity == *) <code>value</code> at <code>field</code>
- * of <code>instance</code>.
+ * of <code>instance</code>.
*
* @param instance
* @param field
* @param value
* @throws EdmException
*/
- private void setValueAtNavigationField(Object instance, Field field, Object value)
+ private void setValueAtNavigationField(final Object instance, final Field field, final Object value)
throws EdmException {
Class<?> fieldTypeClass = field.getType();
if (Collection.class.isAssignableFrom(fieldTypeClass)) {
@SuppressWarnings("unchecked")
Collection<Object> collection = (Collection<Object>) ANNOTATION_HELPER.getValueForField(
instance, field.getName(), EdmNavigationProperty.class);
- if(collection == null) {
+ if (collection == null) {
collection = new ArrayList<Object>();
setValue(instance, field, collection);
}
collection.add(value);
- } else if(fieldTypeClass.isArray()) {
+ } else if (fieldTypeClass.isArray()) {
throw new ODataRuntimeException("Write relations for internal used arrays is not supported.");
} else {
setValue(instance, field, value);
@@ -309,11 +314,11 @@ public class AnnotationInMemoryDs implements DataSource {
* Never returns NULL.
*
* @param entitySet for which the corresponding DataStore is returned
- * @return a DataStore object
- * @throws EdmException
- * @throws ODataRuntimeException if no DataStore is found
+ * @return a DataStore object
+ * @throws EdmException
+ * @throws ODataRuntimeException if no DataStore is found
*/
- private DataStore<Object> getDataStore(EdmEntitySet entitySet) throws EdmException {
+ private DataStore<Object> getDataStore(final EdmEntitySet entitySet) throws EdmException {
final String name = entitySet.getName();
DataStore<Object> dataStore = dataStores.get(name);
if (dataStore == null) {
@@ -322,7 +327,7 @@ public class AnnotationInMemoryDs implements DataSource {
return dataStore;
}
- private Object getValue(Field field, Object instance) {
+ private Object getValue(final Field field, final Object instance) {
try {
boolean access = field.isAccessible();
field.setAccessible(true);
@@ -338,7 +343,7 @@ public class AnnotationInMemoryDs implements DataSource {
}
}
- private void setValue(Object instance, Field field, Object value) {
+ private void setValue(final Object instance, final Field field, final Object value) {
try {
boolean access = field.isAccessible();
field.setAccessible(true);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/2f2553ca/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
index 14183bf..5703295 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
@@ -33,13 +33,13 @@ public class AnnotationValueAccess implements ValueAccess {
/**
* Retrieves the value of an EDM property for the given data object.
- * @param data the Java data object
+ * @param data the Java data object
* @param property the requested {@link EdmProperty}
* @return the requested property value
*/
@Override
public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
- if(data == null) {
+ if (data == null) {
return null;
} else if (annotationHelper.isEdmAnnotated(data)) {
return annotationHelper.getValueForProperty(data, property.getName());
@@ -49,12 +49,12 @@ public class AnnotationValueAccess implements ValueAccess {
/**
* Sets the value of an EDM property for the given data object.
- * @param data the Java data object
+ * @param data the Java data object
* @param property the {@link EdmProperty}
- * @param value the new value of the property
+ * @param value the new value of the property
*/
@Override
- public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
+ public <T, V> void setPropertyValue(final T data, final EdmProperty property, final V value) throws ODataException {
if (annotationHelper.isEdmAnnotated(data)) {
annotationHelper.setValueForProperty(data, property.getName(), value);
} else {
@@ -64,10 +64,11 @@ public class AnnotationValueAccess implements ValueAccess {
/**
* Retrieves the Java type of an EDM property for the given data object.
- * @param data the Java data object
+ * @param data the Java data object
* @param property the requested {@link EdmProperty}
* @return the requested Java type
*/
+ @Override
public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
if (annotationHelper.isEdmAnnotated(data)) {
Class<?> fieldType = annotationHelper.getFieldTypeForProperty(data, property.getName());
@@ -81,10 +82,11 @@ public class AnnotationValueAccess implements ValueAccess {
/**
* Retrieves the value defined by a mapping object for the given data object.
- * @param data the Java data object
- * @param mapping the requested {@link EdmMapping}
+ * @param data the Java data object
+ * @param mapping the requested {@link EdmMapping}
* @return the requested value
*/
+ @Override
public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
if (mapping != null && mapping.getMediaResourceMimeTypeKey() != null) {
return annotationHelper.getValueForProperty(data, mapping.getMediaResourceMimeTypeKey());
@@ -94,11 +96,12 @@ public class AnnotationValueAccess implements ValueAccess {
/**
* Sets the value defined by a mapping object for the given data object.
- * @param data the Java data object
- * @param mapping the {@link EdmMapping}
- * @param value the new value
+ * @param data the Java data object
+ * @param mapping the {@link EdmMapping}
+ * @param value the new value
*/
- public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
+ @Override
+ public <T, V> void setMappingValue(final T data, final EdmMapping mapping, final V value) throws ODataException {
if (mapping != null && mapping.getMediaResourceMimeTypeKey() != null) {
annotationHelper.setValueForProperty(data, mapping.getMediaResourceMimeTypeKey(), value);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/2f2553ca/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
index be3baac..49794be 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
@@ -42,7 +42,7 @@ public class BeanPropertyAccess implements ValueAccess {
}
@Override
- public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
+ public <T, V> void setPropertyValue(final T data, final EdmProperty property, final V value) throws ODataException {
final String methodName = getSetterMethodName(getGetterMethodName(property));
if (methodName != null) {
setValue(data, methodName, value);
@@ -63,7 +63,7 @@ public class BeanPropertyAccess implements ValueAccess {
}
@Override
- public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
+ public <T, V> void setMappingValue(final T data, final EdmMapping mapping, final V value) throws ODataException {
if (mapping != null && mapping.getMimeType() != null) {
setValue(data, getSetterMethodName(mapping.getMimeType()), value);
}
@@ -77,7 +77,7 @@ public class BeanPropertyAccess implements ValueAccess {
}
private boolean isBooleanProperty(final EdmProperty property) throws EdmException {
- return property.isSimple()
+ return property.isSimple()
&& property.getType() == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance();
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/2f2553ca/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
index 42e54b4..beeac17 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
@@ -48,7 +48,8 @@ public class DataStore<T> {
private static final Map<Class<?>, DataStore<?>> c2ds = new HashMap<Class<?>, DataStore<?>>();
@SuppressWarnings("unchecked")
- static synchronized DataStore<?> getInstance(Class<?> clz, boolean createNewInstance) throws DataStoreException {
+ static synchronized DataStore<?> getInstance(final Class<?> clz, final boolean createNewInstance)
+ throws DataStoreException {
DataStore<?> ds = c2ds.get(clz);
if (createNewInstance || ds == null) {
ds = new DataStore<Object>((Class<Object>) clz);
@@ -59,22 +60,23 @@ public class DataStore<T> {
}
@SuppressWarnings("unchecked")
- public static <T> DataStore<T> createInMemory(Class<T> clazz) throws DataStoreException {
+ public static <T> DataStore<T> createInMemory(final Class<T> clazz) throws DataStoreException {
return (DataStore<T>) InMemoryDataStore.getInstance(clazz, true);
}
@SuppressWarnings("unchecked")
- public static <T> DataStore<T> createInMemory(Class<T> clazz, boolean keepExisting) throws DataStoreException {
+ public static <T> DataStore<T> createInMemory(final Class<T> clazz, final boolean keepExisting)
+ throws DataStoreException {
return (DataStore<T>) InMemoryDataStore.getInstance(clazz, !keepExisting);
}
- private DataStore(Map<KeyElement, T> wrapStore, Class<T> clz) throws DataStoreException {
+ private DataStore(final Map<KeyElement, T> wrapStore, final Class<T> clz) throws DataStoreException {
dataStore = Collections.synchronizedMap(wrapStore);
dataTypeClass = clz;
keyAccess = new KeyAccess(clz);
}
- private DataStore(Class<T> clz) throws DataStoreException {
+ private DataStore(final Class<T> clz) throws DataStoreException {
this(new HashMap<KeyElement, T>(), clz);
}
@@ -96,7 +98,7 @@ public class DataStore<T> {
}
}
- public T read(T obj) {
+ public T read(final T obj) {
KeyElement objKeys = getKeys(obj);
return dataStore.get(objKeys);
}
@@ -104,13 +106,13 @@ public class DataStore<T> {
public Collection<T> read() {
return Collections.unmodifiableCollection(dataStore.values());
}
-
- public T create(T object) throws DataStoreException {
+
+ public T create(final T object) throws DataStoreException {
KeyElement keyElement = getKeys(object);
return create(object, keyElement);
}
-
- private T create(T object, KeyElement keyElement) throws DataStoreException {
+
+ private T create(final T object, final KeyElement keyElement) throws DataStoreException {
synchronized (dataStore) {
if (keyElement.keyValuesMissing() || dataStore.get(keyElement) != null) {
KeyElement newKey = createSetAndGetKeys(object);
@@ -121,7 +123,7 @@ public class DataStore<T> {
return object;
}
- public T update(T object) {
+ public T update(final T object) {
KeyElement keyElement = getKeys(object);
synchronized (dataStore) {
dataStore.remove(keyElement);
@@ -130,7 +132,7 @@ public class DataStore<T> {
return object;
}
- public T delete(T object) {
+ public T delete(final T object) {
KeyElement keyElement = getKeys(object);
synchronized (dataStore) {
return dataStore.remove(keyElement);
@@ -141,26 +143,18 @@ public class DataStore<T> {
private int cachedHashCode = 42;
private final List<Object> keyValues;
- public KeyElement(int size) {
+ public KeyElement(final int size) {
keyValues = new ArrayList<Object>(size);
}
- public KeyElement() {
- this(3);
- }
-
- private void addValue(Object keyValue) {
+ private void addValue(final Object keyValue) {
keyValues.add(keyValue);
cachedHashCode = 89 * cachedHashCode + (keyValue != null ? keyValue.hashCode() : 0);
}
-
+
boolean keyValuesMissing() {
return keyValues.contains(null);
}
-
- boolean allKeysSet() {
- return !keyValuesMissing();
- }
@Override
public int hashCode() {
@@ -168,7 +162,7 @@ public class DataStore<T> {
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
@@ -184,23 +178,22 @@ public class DataStore<T> {
@Override
public String toString() {
- return "KeyElement{" + "cachedHashCode=" + cachedHashCode + ", keyValues=" + keyValues + '}';
+ return "KeyElement{" + "cachedHashCode=" + cachedHashCode + ", keyValues=" + keyValues + '}';
}
}
-
+
private class KeyAccess {
final List<Field> keyFields;
final AtomicInteger idCounter = new AtomicInteger(1);
-
- KeyAccess(Class<?> clazz) throws DataStoreException {
+ KeyAccess(final Class<?> clazz) throws DataStoreException {
keyFields = ANNOTATION_HELPER.getAnnotatedFields(clazz, EdmKey.class);
if (keyFields.isEmpty()) {
throw new DataStoreException("No EdmKey annotated fields found for class " + clazz);
}
}
-
- KeyElement getKeyValues(T object) {
+
+ KeyElement getKeyValues(final T object) {
KeyElement keyElement = new KeyElement(keyFields.size());
for (Field field : keyFields) {
Object keyValue = ClassHelper.getFieldValue(object, field);
@@ -209,17 +202,8 @@ public class DataStore<T> {
return keyElement;
}
-
- T createKeys(T object) throws DataStoreException {
- for (Field field : keyFields) {
- Object key = createKey(field);
- ClassHelper.setFieldValue(object, field, key);
- }
- return object;
- }
-
- KeyElement createSetAndGetKeys(T object) throws DataStoreException {
+ KeyElement createSetAndGetKeys(final T object) throws DataStoreException {
KeyElement keyElement = new KeyElement(keyFields.size());
for (Field field : keyFields) {
Object key = createKey(field);
@@ -230,8 +214,7 @@ public class DataStore<T> {
return keyElement;
}
-
- private Object createKey(Field field) {
+ private Object createKey(final Field field) {
Class<?> type = field.getType();
if (type == String.class) {
@@ -246,24 +229,23 @@ public class DataStore<T> {
+ "' is not supported (caused on field '" + field + "').");
}
}
-
- private KeyElement getKeys(T object) {
+
+ private KeyElement getKeys(final T object) {
return keyAccess.getKeyValues(object);
}
- private KeyElement createSetAndGetKeys(T object) throws DataStoreException {
+ private KeyElement createSetAndGetKeys(final T object) throws DataStoreException {
return keyAccess.createSetAndGetKeys(object);
}
-
public static class DataStoreException extends ODataApplicationException {
private static final long serialVersionUID = 42L;
- public DataStoreException(String message) {
+ public DataStoreException(final String message) {
this(message, null);
}
- public DataStoreException(String message, Throwable cause) {
+ public DataStoreException(final String message, final Throwable cause) {
super(message, Locale.ENGLISH, cause);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/2f2553ca/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index 5a462fb..e35e128 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -70,7 +70,7 @@ import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
/**
* Provider for the entity data model used in the reference scenario
- *
+ *
*/
public class AnnotationEdmProvider extends EdmProvider {
@@ -82,7 +82,7 @@ public class AnnotationEdmProvider extends EdmProvider {
private final Map<String, Schema> namespace2Schema = new HashMap<String, Schema>();
private EntityContainer defaultContainer;
- public AnnotationEdmProvider(Collection<Class<?>> annotatedClasses) {
+ public AnnotationEdmProvider(final Collection<Class<?>> annotatedClasses) {
this.annotatedClasses = new ArrayList<Class<?>>(annotatedClasses.size());
for (Class<?> aClass : annotatedClasses) {
@@ -94,10 +94,10 @@ public class AnnotationEdmProvider extends EdmProvider {
init();
}
- public AnnotationEdmProvider(String packageToScan) {
- this.annotatedClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
+ public AnnotationEdmProvider(final String packageToScan) {
+ annotatedClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
@Override
- public boolean isClassValid(Class<?> c) {
+ public boolean isClassValid(final Class<?> c) {
return ANNOTATION_HELPER.isEdmAnnotated(c);
}
});
@@ -115,7 +115,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
@Override
- public Association getAssociation(FullQualifiedName edmFQName) throws ODataException {
+ public Association getAssociation(final FullQualifiedName edmFQName) throws ODataException {
Schema schema = namespace2Schema.get(edmFQName.getNamespace());
if (schema != null) {
List<Association> associations = schema.getAssociations();
@@ -129,8 +129,8 @@ public class AnnotationEdmProvider extends EdmProvider {
}
@Override
- public AssociationSet getAssociationSet(String entityContainer, FullQualifiedName association,
- String sourceEntitySetName, String sourceEntitySetRole) throws ODataException {
+ public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association,
+ final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException {
EntityContainer container = name2Container.get(entityContainer);
if (container != null) {
List<AssociationSet> associations = container.getAssociationSets();
@@ -153,7 +153,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
@Override
- public ComplexType getComplexType(FullQualifiedName edmFQName) throws ODataException {
+ public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataException {
Schema schema = namespace2Schema.get(edmFQName.getNamespace());
if (schema != null) {
List<ComplexType> complexTypes = schema.getComplexTypes();
@@ -167,7 +167,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
@Override
- public EntityContainerInfo getEntityContainerInfo(String name) throws ODataException {
+ public EntityContainerInfo getEntityContainerInfo(final String name) throws ODataException {
EntityContainer container = name2Container.get(name);
if (container == null) {
// use default container (if set)
@@ -188,7 +188,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
@Override
- public EntitySet getEntitySet(String entityContainer, String name) throws ODataException {
+ public EntitySet getEntitySet(final String entityContainer, final String name) throws ODataException {
EntityContainer container = name2Container.get(entityContainer);
if (container != null) {
List<EntitySet> entitySets = container.getEntitySets();
@@ -203,7 +203,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
@Override
- public EntityType getEntityType(FullQualifiedName edmFQName) throws ODataException {
+ public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataException {
Schema schema = namespace2Schema.get(edmFQName.getNamespace());
if (schema != null) {
List<EntityType> complexTypes = schema.getEntityTypes();
@@ -217,7 +217,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
@Override
- public FunctionImport getFunctionImport(String entityContainer, String name) throws ODataException {
+ public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException {
EntityContainer container = name2Container.get(entityContainer);
if (container != null) {
List<FunctionImport> functionImports = container.getFunctionImports();
@@ -240,7 +240,7 @@ public class AnnotationEdmProvider extends EdmProvider {
//
private Map<String, SchemaBuilder> namespace2SchemaBuilder = new HashMap<String, SchemaBuilder>();
- private void updateSchema(Class<?> aClass) {
+ private void updateSchema(final Class<?> aClass) {
EdmEntityType et = aClass.getAnnotation(EdmEntityType.class);
if (et != null) {
updateSchema(aClass, et);
@@ -251,16 +251,16 @@ public class AnnotationEdmProvider extends EdmProvider {
}
}
- private void updateSchema(Class<?> aClass, EdmEntityType et) {
+ private void updateSchema(final Class<?> aClass, final EdmEntityType et) {
SchemaBuilder b = getSchemaBuilder(et.namespace(), aClass);
TypeBuilder typeBuilder = TypeBuilder.init(et, aClass);
b.addEntityType(typeBuilder.buildEntityType());
b.addAssociations(typeBuilder.buildAssociations());
}
- private SchemaBuilder getSchemaBuilder(String namespace, Class<?> aClass) {
+ private SchemaBuilder getSchemaBuilder(final String namespace, final Class<?> aClass) {
String usedNamespace = namespace;
- if(usedNamespace.isEmpty()) {
+ if (usedNamespace.isEmpty()) {
usedNamespace = ANNOTATION_HELPER.getCanonicalNamespace(aClass);
}
SchemaBuilder builder = namespace2SchemaBuilder.get(usedNamespace);
@@ -271,13 +271,13 @@ public class AnnotationEdmProvider extends EdmProvider {
return builder;
}
- private void updateSchema(Class<?> aClass, EdmComplexType et) {
+ private void updateSchema(final Class<?> aClass, final EdmComplexType et) {
SchemaBuilder b = getSchemaBuilder(et.namespace(), aClass);
TypeBuilder typeBuilder = TypeBuilder.init(et, aClass);
b.addComplexType(typeBuilder.buildComplexType());
}
- private void handleEntityContainer(Class<?> aClass) {
+ private void handleEntityContainer(final Class<?> aClass) {
EdmEntityType entityType = aClass.getAnnotation(EdmEntityType.class);
if (entityType != null) {
FullQualifiedName typeName = createFqnForEntityType(aClass, entityType);
@@ -294,12 +294,12 @@ public class AnnotationEdmProvider extends EdmProvider {
}
}
- private EntitySet createEntitySet(FullQualifiedName typeName, Class<?> entitySetClass) {
+ private EntitySet createEntitySet(final FullQualifiedName typeName, final Class<?> entitySetClass) {
String entitySetName = ANNOTATION_HELPER.extractEntitySetName(entitySetClass);
return new EntitySet().setName(entitySetName).setEntityType(typeName);
}
- private FullQualifiedName createFqnForEntityType(Class<?> annotatedClass, EdmEntityType entityType) {
+ private FullQualifiedName createFqnForEntityType(final Class<?> annotatedClass, final EdmEntityType entityType) {
return ANNOTATION_HELPER.extractEntityTypeFqn(annotatedClass);
}
@@ -339,24 +339,24 @@ public class AnnotationEdmProvider extends EdmProvider {
private final List<NavigationProperty> navProperties = new ArrayList<NavigationProperty>();
private final List<Association> associations = new ArrayList<Association>();
- public TypeBuilder(FullQualifiedName fqn) {
- this.namespace = fqn.getNamespace();
- this.name = fqn.getName();
+ public TypeBuilder(final FullQualifiedName fqn) {
+ namespace = fqn.getNamespace();
+ name = fqn.getName();
}
- public static TypeBuilder init(EdmEntityType entity, Class<?> aClass) {
+ public static TypeBuilder init(final EdmEntityType entity, final Class<?> aClass) {
return new TypeBuilder(ANNOTATION_HELPER.extractEntityTypeFqn(entity, aClass)).withClass(aClass);
}
- public static TypeBuilder init(EdmComplexType entity, Class<?> aClass) {
+ public static TypeBuilder init(final EdmComplexType entity, final Class<?> aClass) {
return new TypeBuilder(ANNOTATION_HELPER.extractComplexTypeFqn(entity, aClass)).withClass(aClass);
}
- private TypeBuilder withClass(Class<?> aClass) {
+ private TypeBuilder withClass(final Class<?> aClass) {
baseEntityType = createBaseEntityFqn(aClass);
if (Modifier.isAbstract(aClass.getModifiers())) {
- this.isAbstract = true;
+ isAbstract = true;
}
Field[] fields = aClass.getDeclaredFields();
@@ -385,22 +385,22 @@ public class AnnotationEdmProvider extends EdmProvider {
return this;
}
- public TypeBuilder addProperty(PropertyRef property) {
+ public TypeBuilder addProperty(final PropertyRef property) {
keyProperties.add(property);
return this;
}
- public TypeBuilder addProperty(Property property) {
+ public TypeBuilder addProperty(final Property property) {
properties.add(property);
return this;
}
- public TypeBuilder addNavigationProperty(NavigationProperty property) {
+ public TypeBuilder addNavigationProperty(final NavigationProperty property) {
navProperties.add(property);
return this;
}
- public TypeBuilder setAbstract(boolean isAbstract) {
+ public TypeBuilder setAbstract(final boolean isAbstract) {
this.isAbstract = isAbstract;
return this;
}
@@ -434,7 +434,7 @@ public class AnnotationEdmProvider extends EdmProvider {
return Collections.unmodifiableCollection(associations);
}
- private PropertyRef createKeyProperty(EdmProperty et, Field field) {
+ private PropertyRef createKeyProperty(final EdmProperty et, final Field field) {
PropertyRef keyProperty = new PropertyRef();
String entityName = et.name();
if (entityName.isEmpty()) {
@@ -443,7 +443,7 @@ public class AnnotationEdmProvider extends EdmProvider {
return keyProperty.setName(entityName);
}
- private Property createProperty(EdmProperty ep, Field field, String defaultNamespace) {
+ private Property createProperty(final EdmProperty ep, final Field field, final String defaultNamespace) {
if (isAnnotatedEntity(field.getType())) {
return createComplexProperty(field, defaultNamespace);
} else {
@@ -451,7 +451,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
}
- private Property createSimpleProperty(EdmProperty ep, Field field) {
+ private Property createSimpleProperty(final EdmProperty ep, final Field field) {
SimpleProperty sp = new SimpleProperty();
String entityName = ANNOTATION_HELPER.getPropertyName(field);
sp.setName(entityName);
@@ -465,7 +465,7 @@ public class AnnotationEdmProvider extends EdmProvider {
return sp;
}
- private Property createComplexProperty(Field field, String defaultNamespace) {
+ private Property createComplexProperty(final Field field, final String defaultNamespace) {
ComplexProperty cp = new ComplexProperty();
// settings from property
String entityName = ANNOTATION_HELPER.getPropertyName(field);
@@ -482,7 +482,8 @@ public class AnnotationEdmProvider extends EdmProvider {
return cp;
}
- private NavigationProperty createNavigationProperty(String namespace, EdmNavigationProperty enp, Field field) {
+ private NavigationProperty createNavigationProperty(final String namespace, final EdmNavigationProperty enp,
+ final Field field) {
NavigationProperty navProp = new NavigationProperty();
navProp.setName(ANNOTATION_HELPER.getPropertyName(field));
String fromRole = ANNOTATION_HELPER.extractFromRoleName(enp, field);
@@ -528,8 +529,8 @@ public class AnnotationEdmProvider extends EdmProvider {
// throw new UnsupportedOperationException("Not yet supported type '" + type + "'.");
// }
// }
-
- private EdmType getEdmType(Class<?> type) {
+
+ private EdmType getEdmType(final Class<?> type) {
if (type == String.class) {
return EdmType.STRING;
} else if (type == boolean.class || type == Boolean.class) {
@@ -561,8 +562,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
}
-
- private Class<?> checkForBaseEntityClass(Class<?> aClass) {
+ private Class<?> checkForBaseEntityClass(final Class<?> aClass) {
Class<?> superClass = aClass.getSuperclass();
if (superClass == Object.class) {
return null;
@@ -576,7 +576,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
}
- private FullQualifiedName createBaseEntityFqn(Class<?> aClass) {
+ private FullQualifiedName createBaseEntityFqn(final Class<?> aClass) {
Class<?> baseEntityClass = checkForBaseEntityClass(aClass);
if (baseEntityClass == null) {
return null;
@@ -584,7 +584,7 @@ public class AnnotationEdmProvider extends EdmProvider {
return ANNOTATION_HELPER.extractEntityTypeFqn(baseEntityClass);
}
- private Association createAssociation(Field field, NavigationProperty navProperty) {
+ private Association createAssociation(final Field field, final NavigationProperty navProperty) {
Association association = new Association();
EdmNavigationProperty navigation = field.getAnnotation(EdmNavigationProperty.class);
@@ -607,11 +607,11 @@ public class AnnotationEdmProvider extends EdmProvider {
return association;
}
- private String getCanonicalName(Field field) {
+ private String getCanonicalName(final Field field) {
return ANNOTATION_HELPER.getCanonicalName(field);
}
- private boolean isAnnotatedEntity(Class<?> clazz) {
+ private boolean isAnnotatedEntity(final Class<?> clazz) {
return ANNOTATION_HELPER.isEdmTypeAnnotated(clazz);
}
}
@@ -619,7 +619,7 @@ public class AnnotationEdmProvider extends EdmProvider {
static class SchemaBuilder {
final private String namespace;
- // private String alias;
+ // private String alias;
private final List<Using> usings = new ArrayList<Using>();
private final List<EntityType> entityTypes = new ArrayList<EntityType>();
private final List<ComplexType> complexTypes = new ArrayList<ComplexType>();
@@ -628,30 +628,30 @@ public class AnnotationEdmProvider extends EdmProvider {
private final List<AnnotationAttribute> annotationAttributes = new ArrayList<AnnotationAttribute>();
private final List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
- private SchemaBuilder(String namespace) {
+ private SchemaBuilder(final String namespace) {
this.namespace = namespace;
}
- public static SchemaBuilder init(String namespace) {
+ public static SchemaBuilder init(final String namespace) {
return new SchemaBuilder(namespace);
}
- public SchemaBuilder addEntityType(EntityType type) {
+ public SchemaBuilder addEntityType(final EntityType type) {
entityTypes.add(type);
return this;
}
- public SchemaBuilder addEntityContainer(EntityContainer container) {
+ public SchemaBuilder addEntityContainer(final EntityContainer container) {
entityContainers.add(container);
return this;
}
- public SchemaBuilder addComplexType(ComplexType createEntityType) {
+ public SchemaBuilder addComplexType(final ComplexType createEntityType) {
complexTypes.add(createEntityType);
return this;
}
- public void addAssociations(Collection<Association> associations) {
+ public void addAssociations(final Collection<Association> associations) {
for (Association association : associations) {
final String relationshipName = association.getName();
if (name2Associations.containsKey(relationshipName)) {
@@ -661,7 +661,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
}
- private Association mergeAssociations(Association associationOne, Association associationTwo) {
+ private Association mergeAssociations(final Association associationOne, final Association associationTwo) {
AssociationEnd oneEnd1 = associationOne.getEnd1();
AssociationEnd oneEnd2 = associationOne.getEnd2();
AssociationEnd twoEnd1 = associationTwo.getEnd1();
@@ -706,9 +706,9 @@ public class AnnotationEdmProvider extends EdmProvider {
private final List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
private final List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
- // private Documentation documentation;
+ // private Documentation documentation;
- private ContainerBuilder(String namespace, String containerName) {
+ private ContainerBuilder(final String namespace, final String containerName) {
this.namespace = namespace;
name = containerName;
}
@@ -717,21 +717,16 @@ public class AnnotationEdmProvider extends EdmProvider {
return namespace;
}
- public static ContainerBuilder init(String namespace, String containerName) {
+ public static ContainerBuilder init(final String namespace, final String containerName) {
return new ContainerBuilder(namespace, containerName);
}
- public ContainerBuilder setDefaultContainer(boolean isDefault) {
- defaultContainer = isDefault;
- return this;
- }
-
- public ContainerBuilder addEntitySet(EntitySet entitySet) {
+ public ContainerBuilder addEntitySet(final EntitySet entitySet) {
entitySets.add(entitySet);
return this;
}
- public void addAssociationSets(Collection<Association> associations) {
+ public void addAssociationSets(final Collection<Association> associations) {
for (Association association : associations) {
AssociationSet as = new AssociationSet();
as.setName(association.getName());
@@ -762,7 +757,7 @@ public class AnnotationEdmProvider extends EdmProvider {
return ec;
}
- private String getEntitySetName(AssociationEnd end) {
+ private String getEntitySetName(final AssociationEnd end) {
for (EntitySet entitySet : entitySets) {
if (entitySet.getEntityType().equals(end.getType())) {
return entitySet.getName();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/2f2553ca/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
index d002fad..d335d9c 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
@@ -996,7 +996,7 @@ public class ListsProcessor extends DataSourceProcessor {
} catch (final ODataNotFoundException e) {
relatedData = null;
}
-
+
if (relatedData == null) {
result.setEntryData(Collections.<String, Object> emptyMap());
} else {
@@ -1221,7 +1221,7 @@ public class ListsProcessor extends DataSourceProcessor {
for (final OrderExpression expression : orderBy.getOrders()) {
String first = evaluateExpression(entity1, expression.getExpression());
String second = evaluateExpression(entity2, expression.getExpression());
-
+
if (first != null && second != null) {
result = first.compareTo(second);
} else if (first == null && second != null) {
@@ -1233,7 +1233,7 @@ public class ListsProcessor extends DataSourceProcessor {
if (expression.getSortOrder() == SortOrder.desc) {
result = -result;
}
-
+
if (result != 0) {
break;
}
@@ -1498,7 +1498,7 @@ public class ListsProcessor extends DataSourceProcessor {
return dataObject;
}
- private void handleMimeType(Object data, EdmMapping mapping, Map<String, Object> valueMap)
+ private void handleMimeType(final Object data, final EdmMapping mapping, final Map<String, Object> valueMap)
throws ODataException {
final String mimeTypeName = mapping.getMimeType();
if (mimeTypeName != null) {
@@ -1585,11 +1585,11 @@ public class ListsProcessor extends DataSourceProcessor {
final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
if (type instanceof EdmEntityType && ((EdmEntityType) type).getKeyProperties().contains(property)) {
Object v = valueAccess.getPropertyValue(data, property);
- if(v != null) {
+ if (v != null) {
continue;
}
}
-
+
if (!merge || valueMap != null && valueMap.containsKey(propertyName)) {
final Object value = valueMap == null ? null : valueMap.get(propertyName);
if (property.isSimple()) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/2f2553ca/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
index e3ec0de..f2157a0 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
@@ -4,9 +4,9 @@
* 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.
@@ -52,9 +52,9 @@ public class AnnotationHelper {
*
* @param firstInstance
* @param secondInstance
- * @return
+ * @return
*/
- public boolean keyMatch(Object firstInstance, Object secondInstance) {
+ public boolean keyMatch(final Object firstInstance, final Object secondInstance) {
if (firstInstance == null || secondInstance == null) {
return false;
} else if (firstInstance.getClass() != secondInstance.getClass()) {
@@ -72,14 +72,14 @@ public class AnnotationHelper {
*
* @param instance
* @param keyName2Value
- * @return
+ * @return
*/
- public boolean keyMatch(Object instance, Map<String, Object> keyName2Value) {
+ public boolean keyMatch(final Object instance, final Map<String, Object> keyName2Value) {
Map<String, Object> instanceKeyFields = getValueForAnnotatedFields(instance, EdmKey.class);
return keyValuesMatch(instanceKeyFields, keyName2Value);
}
- private boolean keyValuesMatch(Map<String, Object> firstKeyValues, Map<String, Object> secondKeyValues) {
+ private boolean keyValuesMatch(final Map<String, Object> firstKeyValues, final Map<String, Object> secondKeyValues) {
if (firstKeyValues.size() != secondKeyValues.size()) {
return false;
} else {
@@ -94,8 +94,8 @@ public class AnnotationHelper {
return true;
}
}
-
- private boolean isEqual(Object firstKey, Object secondKey) {
+
+ private boolean isEqual(final Object firstKey, final Object secondKey) {
if (firstKey == null) {
if (secondKey == null) {
return true;
@@ -107,12 +107,12 @@ public class AnnotationHelper {
}
}
- public String extractEntitTypeName(EdmNavigationProperty enp, Class<?> fallbackClass) {
+ public String extractEntitTypeName(final EdmNavigationProperty enp, final Class<?> fallbackClass) {
Class<?> entityTypeClass = enp.toType();
return extractEntityTypeName(entityTypeClass == Object.class ? fallbackClass : entityTypeClass);
}
- public String extractEntitTypeName(EdmNavigationProperty enp, Field field) {
+ public String extractEntitTypeName(final EdmNavigationProperty enp, final Field field) {
Class<?> entityTypeClass = enp.toType();
if (entityTypeClass == Object.class) {
Class<?> toClass = field.getType();
@@ -126,23 +126,23 @@ public class AnnotationHelper {
/**
* Returns <code>NULL</code> if given class is not annotated. If annotated the set entity type name is returned and if
* no name is set the default name is generated from the simple class name.
- *
+ *
* @param annotatedClass
* @return
*/
- public String extractEntityTypeName(Class<?> annotatedClass) {
+ public String extractEntityTypeName(final Class<?> annotatedClass) {
return extractTypeName(annotatedClass, EdmEntityType.class);
}
/**
- * Returns <code>NULL</code> if given class is not annotated.
+ * Returns <code>NULL</code> if given class is not annotated.
* If annotated the entity set name is returned and if
* no name is set a default name is generated based on the simple class name.
- *
+ *
* @param annotatedClass
* @return
*/
- public String extractEntitySetName(Class<?> annotatedClass) {
+ public String extractEntitySetName(final Class<?> annotatedClass) {
if (annotatedClass == Object.class) {
return null;
}
@@ -157,57 +157,56 @@ public class AnnotationHelper {
}
return name;
}
-
- public FullQualifiedName extractEntityTypeFqn(EdmEntityType type, Class<?> annotatedClass) {
- if(type.namespace().isEmpty()) {
+ public FullQualifiedName extractEntityTypeFqn(final EdmEntityType type, final Class<?> annotatedClass) {
+ if (type.namespace().isEmpty()) {
return new FullQualifiedName(generateNamespace(annotatedClass), extractEntityTypeName(annotatedClass));
}
return new FullQualifiedName(type.namespace(), extractEntityTypeName(annotatedClass));
}
-
- public FullQualifiedName extractEntityTypeFqn(Class<?> annotatedClass) {
+
+ public FullQualifiedName extractEntityTypeFqn(final Class<?> annotatedClass) {
EdmEntityType type = annotatedClass.getAnnotation(EdmEntityType.class);
- if(type == null) {
+ if (type == null) {
return null;
}
return extractEntityTypeFqn(type, annotatedClass);
}
- public FullQualifiedName extractComplexTypeFqn(Class<?> annotatedClass) {
+ public FullQualifiedName extractComplexTypeFqn(final Class<?> annotatedClass) {
EdmComplexType type = annotatedClass.getAnnotation(EdmComplexType.class);
- if(type == null) {
+ if (type == null) {
return null;
}
return extractComplexTypeFqn(type, annotatedClass);
}
- public FullQualifiedName extractComplexTypeFqn(EdmComplexType type, Class<?> annotatedClass) {
- if(type.namespace().isEmpty()) {
+ public FullQualifiedName extractComplexTypeFqn(final EdmComplexType type, final Class<?> annotatedClass) {
+ if (type.namespace().isEmpty()) {
return new FullQualifiedName(generateNamespace(annotatedClass), extractComplexTypeName(annotatedClass));
}
return new FullQualifiedName(type.namespace(), extractComplexTypeName(annotatedClass));
}
- public String extractComplexTypeName(Class<?> annotatedClass) {
+ public String extractComplexTypeName(final Class<?> annotatedClass) {
return extractTypeName(annotatedClass, EdmComplexType.class);
}
-
- public String generateNamespace(Class<?> annotatedClass) {
+
+ public String generateNamespace(final Class<?> annotatedClass) {
String packageName = annotatedClass.getPackage().getName();
return packageName;
}
/**
- *
- *
+ *
+ *
* @param <T> must be EdmEntityType or EdmComplexType annotation
* @param annotatedClass
* @param typeAnnotation
* @return null if annotatedClass is not annotated or name set via annotation or generated via
* {@link #getCanonicalName(java.lang.Class)}
*/
- private <T extends Annotation> String extractTypeName(Class<?> annotatedClass, Class<T> typeAnnotation) {
+ private <T extends Annotation> String extractTypeName(final Class<?> annotatedClass, final Class<T> typeAnnotation) {
if (annotatedClass == Object.class) {
return null;
}
@@ -233,11 +232,11 @@ public class AnnotationHelper {
/**
* Get the set property name from an EdmProperty or EdmNavigationProperty annotation.
- *
+ *
* @param field
* @return
*/
- public String getPropertyNameFromAnnotation(Field field) {
+ public String getPropertyNameFromAnnotation(final Field field) {
EdmProperty property = field.getAnnotation(EdmProperty.class);
if (property == null) {
EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
@@ -250,7 +249,7 @@ public class AnnotationHelper {
return property.name();
}
- public String getPropertyName(Field field) {
+ public String getPropertyName(final Field field) {
String propertyName = getPropertyNameFromAnnotation(field);
if (propertyName.isEmpty()) {
propertyName = getCanonicalName(field);
@@ -258,11 +257,11 @@ public class AnnotationHelper {
return propertyName;
}
- public String extractFromRoleName(EdmNavigationProperty enp, Field field) {
+ public String extractFromRoleName(final EdmNavigationProperty enp, final Field field) {
return getCanonicalRole(field.getDeclaringClass());
}
- public String extractToRoleName(EdmNavigationProperty enp, Field field) {
+ public String extractToRoleName(final EdmNavigationProperty enp, final Field field) {
String role = enp.toRole();
if (role.isEmpty()) {
role = getCanonicalRole(
@@ -272,12 +271,12 @@ public class AnnotationHelper {
return role;
}
- public String getCanonicalRole(Class<?> fallbackClass) {
+ public String getCanonicalRole(final Class<?> fallbackClass) {
String toRole = extractEntityTypeName(fallbackClass);
return "r_" + toRole;
}
- public String extractRelationshipName(EdmNavigationProperty enp, Field field) {
+ public String extractRelationshipName(final EdmNavigationProperty enp, final Field field) {
String relationshipName = enp.association();
if (relationshipName.isEmpty()) {
final String fromRole = extractFromRoleName(enp, field);
@@ -291,7 +290,7 @@ public class AnnotationHelper {
return relationshipName;
}
- public EdmMultiplicity getMultiplicity(EdmNavigationProperty enp, Field field) {
+ public EdmMultiplicity getMultiplicity(final EdmNavigationProperty enp, final Field field) {
EdmMultiplicity multiplicity = mapMultiplicity(enp.toMultiplicity());
final boolean isCollectionType = field.getType().isArray() || Collection.class.isAssignableFrom(field.getType());
@@ -301,17 +300,16 @@ public class AnnotationHelper {
return multiplicity;
}
-
/**
* Set key fields based on values in map.
- * If an key field is not available or <code>NULL</code> in the map
+ * If an key field is not available or <code>NULL</code> in the map
* it will be not set as <code>NULL</code> at the instance object.
*
* @param instance
* @param keys
* @return
*/
- public <T> T setKeyFields(T instance, Map<String, Object> keys) {
+ public <T> T setKeyFields(final T instance, final Map<String, Object> keys) {
List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
for (Field field : fields) {
@@ -326,24 +324,23 @@ public class AnnotationHelper {
public static final class ODataAnnotationException extends ODataException {
private static final long serialVersionUID = 42L;
- public ODataAnnotationException(String message) {
+ public ODataAnnotationException(final String message) {
super(message);
}
- public ODataAnnotationException(String message, Exception cause) {
+ public ODataAnnotationException(final String message, final Exception cause) {
super(message, cause);
}
}
-
public class AnnotatedNavInfo {
private final Field fromField;
private final Field toField;
private final EdmNavigationProperty fromNavigation;
private final EdmNavigationProperty toNavigation;
- public AnnotatedNavInfo(Field fromField, Field toField, EdmNavigationProperty fromNavigation,
- EdmNavigationProperty toNavigation) {
+ public AnnotatedNavInfo(final Field fromField, final Field toField, final EdmNavigationProperty fromNavigation,
+ final EdmNavigationProperty toNavigation) {
this.fromField = fromField;
this.toField = toField;
this.fromNavigation = fromNavigation;
@@ -365,13 +362,13 @@ public class AnnotationHelper {
public EdmMultiplicity getToMultiplicity() {
return getMultiplicity(fromNavigation, fromField);
}
-
+
public boolean isBiDirectional() {
return toNavigation != null;
}
}
- public AnnotatedNavInfo getCommonNavigationInfo(Class<?> sourceClass, Class<?> targetClass) {
+ public AnnotatedNavInfo getCommonNavigationInfo(final Class<?> sourceClass, final Class<?> targetClass) {
List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
@@ -387,22 +384,23 @@ public class AnnotationHelper {
}
}
}
-
+
// if nothing was found assume none bi-directinal navigation
String targetEntityTypeName = extractEntityTypeName(targetClass);
for (Field sourceField : sourceFields) {
final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
final String navTargetEntityName = extractEntitTypeName(sourceNav, sourceField);
-
+
if (navTargetEntityName.equals(targetEntityTypeName)) {
return new AnnotatedNavInfo(sourceField, null, sourceNav, null);
}
}
-
+
return null;
}
- public Class<?> getFieldTypeForProperty(Object instance, String propertyName) throws ODataAnnotationException {
+ public Class<?> getFieldTypeForProperty(final Object instance, final String propertyName)
+ throws ODataAnnotationException {
if (instance == null) {
return null;
}
@@ -415,7 +413,7 @@ public class AnnotationHelper {
return field.getType();
}
- public Object getValueForProperty(Object instance, String propertyName) throws ODataAnnotationException {
+ public Object getValueForProperty(final Object instance, final String propertyName) throws ODataAnnotationException {
if (instance == null) {
return null;
}
@@ -428,7 +426,7 @@ public class AnnotationHelper {
return getFieldValue(instance, field);
}
- public void setValueForProperty(Object instance, String propertyName, Object propertyValue) {
+ public void setValueForProperty(final Object instance, final String propertyName, final Object propertyValue) {
if (instance != null) {
Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
if (field != null) {
@@ -437,8 +435,8 @@ public class AnnotationHelper {
}
}
- private Field getFieldForPropertyName(Object instance, String propertyName,
- Class<?> resultClass, boolean inherited) {
+ private Field getFieldForPropertyName(final Object instance, final String propertyName,
+ final Class<?> resultClass, final boolean inherited) {
if (instance == null) {
return null;
}
@@ -463,32 +461,33 @@ public class AnnotationHelper {
return null;
}
- public Object getValueForField(Object instance, String fieldName, Class<? extends Annotation> annotation) {
+ public Object getValueForField(final Object instance, final String fieldName,
+ final Class<? extends Annotation> annotation) {
if (instance == null) {
return null;
}
return getValueForField(instance, fieldName, instance.getClass(), annotation, true);
}
- public Object getValueForField(Object instance, Class<? extends Annotation> annotation) {
+ public Object getValueForField(final Object instance, final Class<? extends Annotation> annotation) {
if (instance == null) {
return null;
}
return getValueForField(instance, instance.getClass(), annotation, true);
}
- private Object getValueForField(Object instance, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
+ private Object getValueForField(final Object instance, final Class<?> resultClass,
+ final Class<? extends Annotation> annotation, final boolean inherited) {
return getValueForField(instance, null, resultClass, annotation, inherited);
}
- public Map<String, Object> getValueForAnnotatedFields(Object instance,
- Class<? extends Annotation> annotation) {
+ public Map<String, Object> getValueForAnnotatedFields(final Object instance,
+ final Class<? extends Annotation> annotation) {
return getValueForAnnotatedFields(instance, instance.getClass(), annotation, true);
}
- private Map<String, Object> getValueForAnnotatedFields(Object instance, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
+ private Map<String, Object> getValueForAnnotatedFields(final Object instance, final Class<?> resultClass,
+ final Class<? extends Annotation> annotation, final boolean inherited) {
if (instance == null) {
return null;
}
@@ -514,14 +513,15 @@ public class AnnotationHelper {
return fieldName2Value;
}
- public void setValueForAnnotatedField(Object instance, Class<? extends Annotation> annotation, Object value)
+ public void setValueForAnnotatedField(final Object instance, final Class<? extends Annotation> annotation,
+ final Object value)
throws ODataAnnotationException {
List<Field> fields = getAnnotatedFields(instance, annotation);
- if(fields.isEmpty()) {
+ if (fields.isEmpty()) {
throw new ODataAnnotationException("No field found for annotation '" + annotation
+ "' on instance '" + instance + "'.");
- } else if(fields.size() > 1) {
+ } else if (fields.size() > 1) {
throw new ODataAnnotationException("More then one field found for annotation '" + annotation
+ "' on instance '" + instance + "'.");
}
@@ -529,8 +529,8 @@ public class AnnotationHelper {
setFieldValue(instance, fields.get(0), value);
}
- public void setValuesToAnnotatedFields(Object instance,
- Class<? extends Annotation> annotation, Map<String, Object> fieldName2Value) {
+ public void setValuesToAnnotatedFields(final Object instance,
+ final Class<? extends Annotation> annotation, final Map<String, Object> fieldName2Value) {
List<Field> fields = getAnnotatedFields(instance, annotation);
// XXX: refactore
@@ -543,27 +543,27 @@ public class AnnotationHelper {
}
}
- public List<Field> getAnnotatedFields(Object instance, Class<? extends Annotation> annotation) {
+ public List<Field> getAnnotatedFields(final Object instance, final Class<? extends Annotation> annotation) {
if (instance == null) {
return null;
}
return getAnnotatedFields(instance.getClass(), annotation, true);
}
- public List<Field> getAnnotatedFields(Class<?> fieldClass, Class<? extends Annotation> annotation) {
+ public List<Field> getAnnotatedFields(final Class<?> fieldClass, final Class<? extends Annotation> annotation) {
return getAnnotatedFields(fieldClass, annotation, true);
}
/**
- *
+ *
* @param instance
* @param resultClass
* @param annotation
* @param inherited
* @return
*/
- private List<Field> getAnnotatedFields(Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
+ private List<Field> getAnnotatedFields(final Class<?> resultClass,
+ final Class<? extends Annotation> annotation, final boolean inherited) {
if (resultClass == null) {
return null;
}
@@ -586,8 +586,8 @@ public class AnnotationHelper {
return annotatedFields;
}
- private Object getValueForField(Object instance, String fieldName, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
+ private Object getValueForField(final Object instance, final String fieldName, final Class<?> resultClass,
+ final Class<? extends Annotation> annotation, final boolean inherited) {
if (instance == null) {
return null;
}
@@ -608,7 +608,7 @@ public class AnnotationHelper {
return null;
}
- private Object getFieldValue(Object instance, Field field) {
+ private Object getFieldValue(final Object instance, final Field field) {
try {
boolean access = field.isAccessible();
field.setAccessible(true);
@@ -622,7 +622,7 @@ public class AnnotationHelper {
}
}
- private void setFieldValue(Object instance, Field field, Object value) {
+ private void setFieldValue(final Object instance, final Field field, final Object value) {
try {
Object usedValue = value;
if (value != null
@@ -641,7 +641,7 @@ public class AnnotationHelper {
}
}
- public Object convert(Field field, String propertyValue) {
+ public Object convert(final Field field, final String propertyValue) {
Class<?> fieldClass = field.getType();
try {
EdmProperty property = field.getAnnotation(EdmProperty.class);
@@ -654,20 +654,20 @@ public class AnnotationHelper {
}
}
- public boolean isEdmAnnotated(Object object) {
+ public boolean isEdmAnnotated(final Object object) {
if (object == null) {
return false;
}
return isEdmAnnotated(object.getClass());
}
- public boolean isEdmTypeAnnotated(Class<?> clazz) {
+ public boolean isEdmTypeAnnotated(final Class<?> clazz) {
boolean isComplexEntity = clazz.getAnnotation(EdmComplexType.class) != null;
boolean isEntity = clazz.getAnnotation(EdmEntityType.class) != null;
return isComplexEntity || isEntity;
}
- public boolean isEdmAnnotated(Class<?> clazz) {
+ public boolean isEdmAnnotated(final Class<?> clazz) {
if (clazz == null) {
return false;
} else {
@@ -678,54 +678,76 @@ public class AnnotationHelper {
}
}
- public String getCanonicalName(Field field) {
+ public String getCanonicalName(final Field field) {
return firstCharToUpperCase(field.getName());
}
- public String getCanonicalName(Class<?> clazz) {
+ public String getCanonicalName(final Class<?> clazz) {
return firstCharToUpperCase(clazz.getSimpleName());
}
- private String firstCharToUpperCase(String content) {
+ private String firstCharToUpperCase(final String content) {
if (content == null || content.isEmpty()) {
return content;
}
return content.substring(0, 1).toUpperCase(Locale.ENGLISH) + content.substring(1);
}
- public EdmSimpleTypeKind mapTypeKind(org.apache.olingo.odata2.api.annotation.edm.EdmType type) {
+ public EdmSimpleTypeKind mapTypeKind(final org.apache.olingo.odata2.api.annotation.edm.EdmType type) {
switch (type) {
- case BINARY: return EdmSimpleTypeKind.Binary;
- case BOOLEAN: return EdmSimpleTypeKind.Boolean;
- case BYTE: return EdmSimpleTypeKind.Byte;
- case COMPLEX: return EdmSimpleTypeKind.Null;
- case DATE_TIME: return EdmSimpleTypeKind.DateTime;
- case DATE_TIME_OFFSET: return EdmSimpleTypeKind.DateTimeOffset;
- case DECIMAL: return EdmSimpleTypeKind.Decimal;
- case DOUBLE: return EdmSimpleTypeKind.Double;
- case GUID: return EdmSimpleTypeKind.Guid;
- case INT16: return EdmSimpleTypeKind.Int16;
- case INT32: return EdmSimpleTypeKind.Int32;
- case INT64: return EdmSimpleTypeKind.Int64;
- case NULL: return EdmSimpleTypeKind.Null;
- case SBYTE: return EdmSimpleTypeKind.SByte;
- case SINGLE: return EdmSimpleTypeKind.Single;
- case STRING: return EdmSimpleTypeKind.String;
- case TIME: return EdmSimpleTypeKind.Time;
- default: throw new ODataRuntimeException("Unknown type '" + type
- + "' for mapping to EdmSimpleTypeKind.");
- }
- }
-
- public EdmMultiplicity mapMultiplicity(Multiplicity multiplicity) {
+ case BINARY:
+ return EdmSimpleTypeKind.Binary;
+ case BOOLEAN:
+ return EdmSimpleTypeKind.Boolean;
+ case BYTE:
+ return EdmSimpleTypeKind.Byte;
+ case COMPLEX:
+ return EdmSimpleTypeKind.Null;
+ case DATE_TIME:
+ return EdmSimpleTypeKind.DateTime;
+ case DATE_TIME_OFFSET:
+ return EdmSimpleTypeKind.DateTimeOffset;
+ case DECIMAL:
+ return EdmSimpleTypeKind.Decimal;
+ case DOUBLE:
+ return EdmSimpleTypeKind.Double;
+ case GUID:
+ return EdmSimpleTypeKind.Guid;
+ case INT16:
+ return EdmSimpleTypeKind.Int16;
+ case INT32:
+ return EdmSimpleTypeKind.Int32;
+ case INT64:
+ return EdmSimpleTypeKind.Int64;
+ case NULL:
+ return EdmSimpleTypeKind.Null;
+ case SBYTE:
+ return EdmSimpleTypeKind.SByte;
+ case SINGLE:
+ return EdmSimpleTypeKind.Single;
+ case STRING:
+ return EdmSimpleTypeKind.String;
+ case TIME:
+ return EdmSimpleTypeKind.Time;
+ default:
+ throw new ODataRuntimeException("Unknown type '" + type
+ + "' for mapping to EdmSimpleTypeKind.");
+ }
+ }
+
+ public EdmMultiplicity mapMultiplicity(final Multiplicity multiplicity) {
switch (multiplicity) {
- case ZERO_OR_ONE: return EdmMultiplicity.ZERO_TO_ONE;
- case ONE: return EdmMultiplicity.ONE;
- case MANY: return EdmMultiplicity.MANY;
- default: throw new ODataRuntimeException("Unknown type '" + multiplicity + "' for mapping to EdmMultiplicity.");
+ case ZERO_OR_ONE:
+ return EdmMultiplicity.ZERO_TO_ONE;
+ case ONE:
+ return EdmMultiplicity.ONE;
+ case MANY:
+ return EdmMultiplicity.MANY;
+ default:
+ throw new ODataRuntimeException("Unknown type '" + multiplicity + "' for mapping to EdmMultiplicity.");
}
}
-
+
/**
*
*/
@@ -733,20 +755,20 @@ public class AnnotationHelper {
private static final long serialVersionUID = 42L;
- public EdmAnnotationException(String message) {
+ public EdmAnnotationException(final String message) {
super(message);
}
}
- public String getCanonicalNamespace(Class<?> aClass) {
+ public String getCanonicalNamespace(final Class<?> aClass) {
return generateNamespace(aClass);
}
- public String extractContainerName(Class<?> aClass) {
+ public String extractContainerName(final Class<?> aClass) {
EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
- if(entitySet != null) {
+ if (entitySet != null) {
String containerName = entitySet.container();
- if(!containerName.isEmpty()) {
+ if (!containerName.isEmpty()) {
return containerName;
}
}