diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/debug/DebugSupport.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/debug/DebugSupport.java index 054c23a70..dd6bf43af 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/debug/DebugSupport.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/debug/DebugSupport.java @@ -20,7 +20,6 @@ package org.apache.olingo.server.api.debug; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ODataResponse; -import org.apache.olingo.server.api.OlingoExtension; /** * Register this interface to add debug support to your service. diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java index ed18f8d10..8fd533bfd 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java @@ -301,7 +301,8 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler { static void copyHeaders(ODataRequest odRequest, final HttpServletRequest req) { for (final Enumeration headerNames = req.getHeaderNames(); headerNames.hasMoreElements();) { final String headerName = (String) headerNames.nextElement(); - @SuppressWarnings("unchecked") // getHeaders() says it returns an Enumeration of String. + @SuppressWarnings("unchecked") + // getHeaders() says it returns an Enumeration of String. final List headerValues = Collections.list(req.getHeaders(headerName)); odRequest.addHeader(headerName, headerValues); } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java index f315734df..8f6b21371 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java @@ -51,18 +51,15 @@ public class ODataWritableContent implements ODataContent { private StreamContent streamContent; private static abstract class StreamContent { - protected ODataSerializer serializer; protected EntityIterator iterator; protected ServiceMetadata metadata; protected EdmEntityType entityType; protected EntityCollectionSerializerOptions options; - public StreamContent(EntityIterator iterator, EdmEntityType entityType, - ODataSerializer serializer, ServiceMetadata metadata, - EntityCollectionSerializerOptions options) { + public StreamContent(EntityIterator iterator, EdmEntityType entityType, ServiceMetadata metadata, + EntityCollectionSerializerOptions options) { this.iterator = iterator; this.entityType = entityType; - this.serializer = serializer; this.metadata = metadata; this.options = options; } @@ -74,7 +71,7 @@ public class ODataWritableContent implements ODataContent { writeEntity(iterator, out); } catch (SerializerException e) { final ODataContentWriteErrorCallback errorCallback = options.getODataContentWriteErrorCallback(); - if(errorCallback != null) { + if (errorCallback != null) { final WriteErrorContext errorContext = new WriteErrorContext(e); errorCallback.handleError(errorContext, Channels.newChannel(out)); } @@ -88,7 +85,7 @@ public class ODataWritableContent implements ODataContent { public StreamContentForJson(EntityIterator iterator, EdmEntityType entityType, ODataJsonSerializer jsonSerializer, ServiceMetadata metadata, EntityCollectionSerializerOptions options) { - super(iterator, entityType, jsonSerializer, metadata, options); + super(iterator, entityType, metadata, options); this.jsonSerializer = jsonSerializer; } @@ -98,7 +95,7 @@ public class ODataWritableContent implements ODataContent { jsonSerializer.entityCollectionIntoStream(metadata, entityType, entity, options, outputStream); outputStream.flush(); } catch (final IOException e) { - throw new ODataRuntimeException("Failed entity serialization"); + throw new ODataRuntimeException("Failed entity serialization", e); } } } @@ -109,7 +106,7 @@ public class ODataWritableContent implements ODataContent { public StreamContentForXml(EntityIterator iterator, EdmEntityType entityType, ODataXmlSerializer xmlSerializer, ServiceMetadata metadata, EntityCollectionSerializerOptions options) { - super(iterator, entityType, xmlSerializer, metadata, options); + super(iterator, entityType, metadata, options); this.xmlSerializer = xmlSerializer; } @@ -119,7 +116,7 @@ public class ODataWritableContent implements ODataContent { xmlSerializer.entityCollectionIntoStream(metadata, entityType, entity, options, outputStream); outputStream.flush(); } catch (final IOException e) { - throw new ODataRuntimeException("Failed entity serialization"); + throw new ODataRuntimeException("Failed entity serialization", e); } } } @@ -139,13 +136,14 @@ public class ODataWritableContent implements ODataContent { } public static ODataWritableContentBuilder with(EntityIterator iterator, EdmEntityType entityType, - ODataSerializer serializer, ServiceMetadata metadata, + ODataSerializer serializer, ServiceMetadata metadata, EntityCollectionSerializerOptions options) { return new ODataWritableContentBuilder(iterator, entityType, serializer, metadata, options); } public static class WriteErrorContext implements ODataContentWriteErrorContext { private ODataLibraryException exception; + public WriteErrorContext(ODataLibraryException exception) { this.exception = exception; } @@ -154,6 +152,7 @@ public class ODataWritableContent implements ODataContent { public Exception getException() { return exception; } + @Override public ODataLibraryException getODataLibraryException() { return exception; @@ -168,8 +167,8 @@ public class ODataWritableContent implements ODataContent { private EntityCollectionSerializerOptions options; public ODataWritableContentBuilder(EntityIterator entities, EdmEntityType entityType, - ODataSerializer serializer, - ServiceMetadata metadata, EntityCollectionSerializerOptions options) { + ODataSerializer serializer, + ServiceMetadata metadata, EntityCollectionSerializerOptions options) { this.entities = entities; this.entityType = entityType; this.serializer = serializer; @@ -178,17 +177,18 @@ public class ODataWritableContent implements ODataContent { } public ODataContent buildContent() { - if(serializer instanceof ODataJsonSerializer) { + if (serializer instanceof ODataJsonSerializer) { StreamContent input = new StreamContentForJson(entities, entityType, (ODataJsonSerializer) serializer, metadata, options); return new ODataWritableContent(input); - } else if(serializer instanceof ODataXmlSerializer) { + } else if (serializer instanceof ODataXmlSerializer) { StreamContentForXml input = new StreamContentForXml(entities, entityType, (ODataXmlSerializer) serializer, metadata, options); return new ODataWritableContent(input); } throw new ODataRuntimeException("No suitable serializer found"); } + public SerializerStreamResult build() { return SerializerStreamResultImpl.with().content(buildContent()).build(); } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java index 98c2930de..eaeef7f5b 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java @@ -6,9 +6,9 @@ * 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 @@ -70,17 +70,18 @@ public class DebugResponseHelperImpl implements DebugResponseHelper { ODataResponse response = new ODataResponse(); final String contentTypeString; final InputStream body; - if(requestedFormat == DebugFormat.DOWNLOAD || requestedFormat == DebugFormat.HTML) { + if (requestedFormat == DebugFormat.DOWNLOAD || requestedFormat == DebugFormat.HTML) { String title = debugInfo.getRequest() == null ? "V4 Service" : "V4 Service: " + debugInfo.getRequest().getRawODataPath(); body = wrapInHtml(parts, title); contentTypeString = ContentType.TEXT_HTML.toContentTypeString(); - } else { // for JSON and also default response handling + } else { + // for JSON and also default response handling body = wrapInJson(parts); contentTypeString = ContentType.APPLICATION_JSON.toContentTypeString(); } // for download add additional Content-Disposition header - if(requestedFormat == DebugFormat.DOWNLOAD) { + if (requestedFormat == DebugFormat.DOWNLOAD) { response.setHeader("Content-Disposition", "attachment; filename=OData-Response." + new Date().toString().replace(' ', '_').replace(':', '.') + ".html"); } @@ -163,11 +164,7 @@ public class DebugResponseHelperImpl implements DebugResponseHelper { return csb.getInputStream(); } finally { if (outputStream != null) { - try { - outputStream.close(); - } catch (IOException e) { - throw e; - } + outputStream.close(); } } } @@ -188,61 +185,61 @@ public class DebugResponseHelperImpl implements DebugResponseHelper { StringWriter writer = new StringWriter(); writer.append("\n") - .append("\n") - .append("\n") - .append("\n") - .append("") - .append(escapeHtml(title)) - .append("\n") - .append("\n") - .append("\n") - .append("\n"); + .append(" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n") + .append("\n") + .append("\n") + .append("\n") + .append("") + .append(escapeHtml(title)) + .append("\n") + .append("\n") + .append("\n") + .append("\n"); char count = '0'; for (final DebugTab part : parts) { writer.append("
\n") - .append("

") - .append(part.getName()) - .append("

\n") - .append("
\n") - .append("
\n"); + .append("

") + .append(part.getName()) + .append("

\n") + .append("
\n") + .append("
\n"); part.appendHtml(writer); writer.append("
\n"); } writer.append("\n") - .append("\n") - .close(); + .append("\n") + .close(); byte[] bytes = writer.toString().getBytes("UTF-8"); return new ByteArrayInputStream(bytes); } @@ -271,14 +268,14 @@ public class DebugResponseHelperImpl implements DebugResponseHelper { protected static void appendHtmlTable(final Writer writer, final Map entries) throws IOException { writer.append("\n\n") - .append("\n") - .append("\n\n"); + .append("\n") + .append("\n\n"); if (entries != null && !entries.isEmpty()) { for (final Map.Entry entry : entries.entrySet()) { writer.append("") - .append("\n"); + .append("\n"); } } writer.append("\n
NameValue
NameValue
").append(entry.getKey()).append("") - .append(escapeHtml(entry.getValue())) - .append("
") + .append(escapeHtml(entry.getValue())) + .append("
\n"); diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRuntime.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRuntime.java index 573764608..421405012 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRuntime.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRuntime.java @@ -33,6 +33,7 @@ import com.fasterxml.jackson.core.JsonGenerator; */ public class DebugTabRuntime implements DebugTab { + private static final int TO_MILLIS_DIVISOR = 1000; private final RuntimeNode rootNode; public DebugTabRuntime(final List runtimeInformation) { @@ -69,7 +70,7 @@ public class DebugTabRuntime implements DebugTab { if (node.timeStopped == 0) { gen.writeNullField("duration"); } else { - gen.writeStringField("duration", Long.toString((node.timeStopped - node.timeStarted) / 1000)); + gen.writeStringField("duration", Long.toString((node.timeStopped - node.timeStarted) / TO_MILLIS_DIVISOR)); gen.writeStringField("unit", "µs"); } @@ -96,7 +97,7 @@ public class DebugTabRuntime implements DebugTab { .append("").append(node.className).append(".") .append("").append(node.methodName).append("(…)") .append(""); - long time = node.timeStopped == 0 ? 0 : (node.timeStopped - node.timeStarted) / 1000; + long time = node.timeStopped == 0 ? 0 : (node.timeStopped - node.timeStarted) / TO_MILLIS_DIVISOR; writer.append("").append(time == 0 ? "unfinished" : Long.toString(time) + " µs") diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/FixedFormatDeserializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/FixedFormatDeserializerImpl.java index bc77e66de..5f561e56e 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/FixedFormatDeserializerImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/FixedFormatDeserializerImpl.java @@ -44,10 +44,12 @@ import org.apache.olingo.server.core.deserializer.json.ODataJsonDeserializer; public class FixedFormatDeserializerImpl implements FixedFormatDeserializer { + private static final int DEFAULT_BUFFER_SIZE = 128; + @Override public byte[] binary(final InputStream content) throws DeserializerException { ByteArrayOutputStream result = new ByteArrayOutputStream(); - byte[] buffer = new byte[128]; + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int count; try { while ((count = content.read(buffer)) > -1) { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReader.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReader.java index 1a79985cf..c209ade2c 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReader.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReader.java @@ -96,6 +96,7 @@ public class BatchLineReader { private void updateCurrentCharset(final String currentLine) { if (currentLine != null) { if (currentLine.startsWith(HttpHeader.CONTENT_TYPE)) { + //13 is content-type.length() + 1 for header value String clValue = currentLine.substring(13, currentLine.length() - 2).trim(); ContentType ct = ContentType.parse(clValue); if (ct != null) { @@ -134,14 +135,13 @@ public class BatchLineReader { } ByteBuffer innerBuffer = ByteBuffer.allocate(BUFFER_SIZE); - boolean foundLineEnd = false; // EOF will be considered as line ending + // EOF will be considered as line ending + boolean foundLineEnd = false; while (!foundLineEnd) { // Is buffer refill required? - if (limit == offset) { - if (fillBuffer() == EOF) { - foundLineEnd = true; - } + if (limit == offset && fillBuffer() == EOF) { + foundLineEnd = true; } if (!foundLineEnd) { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java index 1600ee6e2..38773deb0 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java @@ -38,7 +38,7 @@ public class HttpRequestStatusLine { private static final String HTTP_VERSION = "HTTP/1.1"; final private Line statusLine; - final String requestBaseUri; + final private String requestBaseUri; private HttpMethod method; private String httpVersion; @@ -60,9 +60,9 @@ public class HttpRequestStatusLine { private void parse() throws BatchDeserializerException { final String[] parts = statusLine.toString().split(" "); + //Status line consists of 3 parts: Method, URI and HTTP Version if (parts.length == 3) { method = parseMethod(parts[0]); - // uri = new ODataURI(parts[1], requestBaseUri, statusLine.getLineNumber(), header.getHeaders(HttpHeader.HOST)); parseUri(parts[1], requestBaseUri); httpVersion = parseHttpVersion(parts[2]); } else { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/prefer/PreferParser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/prefer/PreferParser.java index d142f09cf..ac3e8aece 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/prefer/PreferParser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/prefer/PreferParser.java @@ -50,14 +50,14 @@ import org.apache.olingo.server.api.prefer.Preferences.Preference; */ public class PreferParser { - private static final String token = "(?:[-!#$%&'*+.^_`|~]|\\w)+"; - private static final String quotedString = "(?:\"(?:[\\t !#-\\[\\]-~\\x80-\\xFF]|" + private static final String TOKEN = "(?:[-!#$%&'*+.^_`|~]|\\w)+"; + private static final String QUOTED_STRING = "(?:\"(?:[\\t !#-\\[\\]-~\\x80-\\xFF]|" + "(?:\\\\[\\t !-~\\x80-\\xFF]))*\")"; - private static final String namedValue = - "(" + token + ")(?:\\s*=\\s*(" + token + "|" + quotedString + "))?"; + private static final String NAMED_VALUE = + "(" + TOKEN + ")(?:\\s*=\\s*(" + TOKEN + "|" + QUOTED_STRING + "))?"; private static final Pattern PREFERENCE = Pattern.compile("\\s*(,\\s*)+|" - + "(?:" + namedValue + "((?:\\s*;\\s*(?:" + namedValue + ")?)*))"); - private static final Pattern PARAMETER = Pattern.compile("\\s*(;\\s*)+|(?:" + namedValue + ")"); + + "(?:" + NAMED_VALUE + "((?:\\s*;\\s*(?:" + NAMED_VALUE + ")?)*))"); + private static final Pattern PARAMETER = Pattern.compile("\\s*(;\\s*)+|(?:" + NAMED_VALUE + ")"); private PreferParser() { // Private constructor for utility classes diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/prefer/PreferencesImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/prefer/PreferencesImpl.java index 85a724dad..7997d57a7 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/prefer/PreferencesImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/prefer/PreferencesImpl.java @@ -33,7 +33,8 @@ import org.apache.olingo.server.api.prefer.Preferences; */ public class PreferencesImpl implements Preferences { - private static final String URL = "url"; // parameter name for odata.callback + //parameter name for odata.callback + private static final String URL = "url"; private final Map preferences; diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java index 0a78c19f5..2fd28169a 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java @@ -178,7 +178,7 @@ public class BatchResponseSerializer { */ private static class BodyBuilder { private static final Charset CHARSET_ISO_8859_1 = Charset.forName("iso-8859-1"); - private ByteBuffer buffer = ByteBuffer.allocate(8192); + private ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE); private boolean isClosed = false; public byte[] getContent() { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java index 1b225014c..3e03bb525 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java @@ -6,9 +6,9 @@ * 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 @@ -186,11 +186,10 @@ public class ODataJsonSerializer extends AbstractODataSerializer { return ODataWritableContent.with(entities, entityType, this, metadata, options).build(); } - public void entityCollectionIntoStream(final ServiceMetadata metadata, final EdmEntityType entityType, final EntityIterator entitySet, final EntityCollectionSerializerOptions options, final OutputStream outputStream) - throws SerializerException { + throws SerializerException { SerializerException cachedException; try { @@ -235,9 +234,9 @@ public class ODataJsonSerializer extends AbstractODataSerializer { JsonGenerator json = new JsonFactory().createGenerator(outputStream); writeEntity(metadata, entityType, entity, contextURL, options == null ? null : options.getExpand(), - options == null ? null : options.getSelect(), - options == null ? false : options.getWriteOnlyReferences(), - json); + options == null ? null : options.getSelect(), + options == null ? false : options.getWriteOnlyReferences(), + json); json.close(); outputStream.close(); @@ -277,26 +276,27 @@ public class ODataJsonSerializer extends AbstractODataSerializer { json.writeEndArray(); } - private boolean areKeyPredicateNamesSelected(SelectOption select, EdmEntityType type) { + private boolean areKeyPredicateNamesSelected(SelectOption select, EdmEntityType type) { if (select == null || ExpandSelectHelper.isAll(select)) { return true; } final Set selected = ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems()); - for (String key: type.getKeyPredicateNames()) { + for (String key : type.getKeyPredicateNames()) { if (!selected.contains(key)) { return false; } } return true; } - + public void writeEntity(final ServiceMetadata metadata, final EdmEntityType entityType, final Entity entity, final ContextURL contextURL, final ExpandOption expand, final SelectOption select, final boolean onlyReference, final JsonGenerator json) - throws IOException, SerializerException { + throws IOException, SerializerException { json.writeStartObject(); if (!isODataMetadataNone) { - if (contextURL != null) { // top-level entity + // top-level entity + if (contextURL != null) { writeContextURL(contextURL, json); writeMetadataETag(metadata, json); } @@ -355,7 +355,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer { } throw new SerializerException("Wrong base type", SerializerException.MessageKeys.WRONG_BASE_TYPE, derivedTypeName, baseType - .getFullQualifiedName().getFullQualifiedNameAsString()); + .getFullQualifiedName().getFullQualifiedNameAsString()); } protected EdmComplexType resolveComplexType(final ServiceMetadata metadata, final EdmComplexType baseType, @@ -379,22 +379,22 @@ public class ODataJsonSerializer extends AbstractODataSerializer { } throw new SerializerException("Wrong base type", SerializerException.MessageKeys.WRONG_BASE_TYPE, derivedTypeName, baseType - .getFullQualifiedName().getFullQualifiedNameAsString()); + .getFullQualifiedName().getFullQualifiedNameAsString()); } protected void writeProperties(final ServiceMetadata metadata, final EdmStructuredType type, final List properties, final SelectOption select, final JsonGenerator json) - throws IOException, SerializerException { + throws IOException, SerializerException { final boolean all = ExpandSelectHelper.isAll(select); final Set selected = all ? new HashSet() : - ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems()); + ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems()); for (final String propertyName : type.getPropertyNames()) { if (all || selected.contains(propertyName)) { final EdmProperty edmProperty = type.getStructuralProperty(propertyName); final Property property = findProperty(propertyName, properties); final Set> selectedPaths = all || edmProperty.isPrimitive() ? null : - ExpandSelectHelper.getSelectedPaths(select.getSelectItems(), propertyName); + ExpandSelectHelper.getSelectedPaths(select.getSelectItems(), propertyName); writeProperty(metadata, edmProperty, property, selectedPaths, json); } } @@ -406,36 +406,36 @@ public class ODataJsonSerializer extends AbstractODataSerializer { if (ExpandSelectHelper.hasExpand(expand)) { final boolean expandAll = ExpandSelectHelper.isExpandAll(expand); final Set expanded = expandAll ? new HashSet() : - ExpandSelectHelper.getExpandedPropertyNames(expand.getExpandItems()); + ExpandSelectHelper.getExpandedPropertyNames(expand.getExpandItems()); for (final String propertyName : type.getNavigationPropertyNames()) { if (expandAll || expanded.contains(propertyName)) { final EdmNavigationProperty property = type.getNavigationProperty(propertyName); final Link navigationLink = linked.getNavigationLink(property.getName()); final ExpandItem innerOptions = expandAll ? null : - ExpandSelectHelper.getExpandItem(expand.getExpandItems(), propertyName); + ExpandSelectHelper.getExpandItem(expand.getExpandItems(), propertyName); if (innerOptions != null && innerOptions.getLevelsOption() != null) { throw new SerializerException("Expand option $levels is not supported.", SerializerException.MessageKeys.NOT_IMPLEMENTED); } writeExpandedNavigationProperty(metadata, property, navigationLink, innerOptions == null ? null : innerOptions.getExpandOption(), - innerOptions == null ? null : innerOptions.getSelectOption(), - innerOptions == null ? null : innerOptions.getCountOption(), + innerOptions == null ? null : innerOptions.getSelectOption(), + innerOptions == null ? null : innerOptions.getCountOption(), innerOptions == null ? false : innerOptions.hasCountPath(), - innerOptions == null ? false : innerOptions.isRef(), + innerOptions == null ? false : innerOptions.isRef(), json); } } } } - + protected void writeExpandedNavigationProperty( final ServiceMetadata metadata, final EdmNavigationProperty property, final Link navigationLink, final ExpandOption innerExpand, final SelectOption innerSelect, final CountOption innerCount, final boolean writeOnlyCount, final boolean writeOnlyRef, final JsonGenerator json) throws IOException, SerializerException { - + if (property.isCollection()) { if (writeOnlyCount) { if (navigationLink == null || navigationLink.getInlineEntitySet() == null) { @@ -443,11 +443,11 @@ public class ODataJsonSerializer extends AbstractODataSerializer { } else { writeInlineCount(property.getName(), navigationLink.getInlineEntitySet().getCount(), json); } - } else { + } else { if (navigationLink == null || navigationLink.getInlineEntitySet() == null) { if (innerCount != null && innerCount.getValue()) { writeInlineCount(property.getName(), 0, json); - } + } json.writeFieldName(property.getName()); json.writeStartArray(); json.writeEndArray(); @@ -473,7 +473,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer { protected void writeProperty(final ServiceMetadata metadata, final EdmProperty edmProperty, final Property property, final Set> selectedPaths, final JsonGenerator json) - throws IOException, SerializerException { + throws IOException, SerializerException { json.writeFieldName(edmProperty.getName()); if (property == null || property.isNull()) { if (edmProperty.isNullable() == Boolean.FALSE) { @@ -494,7 +494,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer { private void writePropertyValue(final ServiceMetadata metadata, final EdmProperty edmProperty, final Property property, final Set> selectedPaths, final JsonGenerator json) - throws IOException, SerializerException { + throws IOException, SerializerException { final EdmType type = edmProperty.getType(); try { if (edmProperty.isPrimitive() @@ -529,7 +529,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer { private void writePrimitiveCollection(final EdmPrimitiveType type, final Property property, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final JsonGenerator json) - throws IOException, SerializerException { + throws IOException, SerializerException { json.writeStartArray(); for (Object value : property.asCollection()) { switch (property.getValueType()) { @@ -557,7 +557,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer { private void writeComplexCollection(final ServiceMetadata metadata, final EdmComplexType type, final Property property, final Set> selectedPaths, final JsonGenerator json) - throws IOException, SerializerException { + throws IOException, SerializerException { json.writeStartArray(); for (Object value : property.asCollection()) { switch (property.getValueType()) { @@ -575,7 +575,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer { private void writePrimitive(final EdmPrimitiveType type, final Property property, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final JsonGenerator json) - throws EdmPrimitiveTypeException, IOException, SerializerException { + throws EdmPrimitiveTypeException, IOException, SerializerException { if (property.isPrimitive()) { writePrimitiveValue(type, property.asPrimitive(), isNullable, maxLength, precision, scale, isUnicode, json); @@ -618,7 +618,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer { protected void writeComplexValue(final ServiceMetadata metadata, final Property complexProperty, final EdmComplexType type, final List properties, final Set> selectedPaths, final JsonGenerator json) - throws IOException, SerializerException { + throws IOException, SerializerException { json.writeStartObject(); final EdmComplexType resolvedType = resolveComplexType(metadata, @@ -633,7 +633,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer { if (selectedPaths == null || ExpandSelectHelper.isSelected(selectedPaths, propertyName)) { writeProperty(metadata, (EdmProperty) resolvedType.getProperty(propertyName), property, selectedPaths == null ? null : ExpandSelectHelper.getReducedSelectedPaths(selectedPaths, propertyName), - json); + json); } } json.writeEndObject(); @@ -667,10 +667,10 @@ public class ODataJsonSerializer extends AbstractODataSerializer { json.writeFieldName(Constants.VALUE); writePrimitive(type, property, options == null ? null : options.isNullable(), - options == null ? null : options.getMaxLength(), - options == null ? null : options.getPrecision(), - options == null ? null : options.getScale(), - options == null ? null : options.isUnicode(), json); + options == null ? null : options.getMaxLength(), + options == null ? null : options.getPrecision(), + options == null ? null : options.getScale(), + options == null ? null : options.isUnicode(), json); } json.writeEndObject(); @@ -710,16 +710,16 @@ public class ODataJsonSerializer extends AbstractODataSerializer { } final List values = property.isNull() ? Collections. emptyList() : property.asComplex().getValue(); - writeProperties(metadata, type, values, options == null ? null : options.getSelect(), json); - if (!property.isNull() && property.isComplex()) { - writeNavigationProperties(metadata, type, property.asComplex(), - options == null ? null : options.getExpand(), json); - } - json.writeEndObject(); + writeProperties(metadata, type, values, options == null ? null : options.getSelect(), json); + if (!property.isNull() && property.isComplex()) { + writeNavigationProperties(metadata, type, property.asComplex(), + options == null ? null : options.getExpand(), json); + } + json.writeEndObject(); - json.close(); - outputStream.close(); - return SerializerResultImpl.with().content(buffer.getInputStream()).build(); + json.close(); + outputStream.close(); + return SerializerResultImpl.with().content(buffer.getInputStream()).build(); } catch (final IOException e) { cachedException = new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION); @@ -745,10 +745,10 @@ public class ODataJsonSerializer extends AbstractODataSerializer { json.writeFieldName(Constants.VALUE); writePrimitiveCollection(type, property, options == null ? null : options.isNullable(), - options == null ? null : options.getMaxLength(), - options == null ? null : options.getPrecision(), - options == null ? null : options.getScale(), - options == null ? null : options.isUnicode(), json); + options == null ? null : options.getMaxLength(), + options == null ? null : options.getPrecision(), + options == null ? null : options.getScale(), + options == null ? null : options.isUnicode(), json); json.writeEndObject(); json.close(); @@ -825,7 +825,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer { @Override public SerializerResult referenceCollection(final ServiceMetadata metadata, final EdmEntitySet edmEntitySet, final AbstractEntityCollection entityCollection, final ReferenceCollectionSerializerOptions options) - throws SerializerException { + throws SerializerException { OutputStream outputStream = null; SerializerException cachedException = null; @@ -898,13 +898,13 @@ public class ODataJsonSerializer extends AbstractODataSerializer { throws IOException { if (count != null) { if (isIEEE754Compatible) { - json.writeStringField(propertyName+Constants.JSON_COUNT, String.valueOf(count)); + json.writeStringField(propertyName + Constants.JSON_COUNT, String.valueOf(count)); } else { - json.writeNumberField(propertyName+Constants.JSON_COUNT, count); + json.writeNumberField(propertyName + Constants.JSON_COUNT, count); } } - } - + } + void writeNextLink(final AbstractEntityCollection entitySet, final JsonGenerator json) throws IOException { if (entitySet.getNext() != null) { json.writeStringField(Constants.JSON_NEXT_LINK, entitySet.getNext().toASCIIString()); diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java index 682e47821..75f511577 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java @@ -6,9 +6,9 @@ * 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 @@ -58,8 +58,8 @@ public class ServiceDocumentJsonSerializer { if (!isODataMetadataNone) { final String metadataUri = (serviceRoot == null ? "" : - serviceRoot.endsWith("/") ? serviceRoot : (serviceRoot + "/")) - + Constants.METADATA; + serviceRoot.endsWith("/") ? serviceRoot : (serviceRoot + "/")) + + Constants.METADATA; gen.writeObjectField(Constants.JSON_CONTEXT, metadataUri); if (metadata != null @@ -73,9 +73,11 @@ public class ServiceDocumentJsonSerializer { gen.writeArrayFieldStart(Constants.VALUE); final EdmEntityContainer container = metadata.getEdm().getEntityContainer(); - writeEntitySets(gen, container); - writeFunctionImports(gen, container); - writeSingletons(gen, container); + if (container != null) { + writeEntitySets(gen, container); + writeFunctionImports(gen, container); + writeSingletons(gen, container); + } } private void writeEntitySets(final JsonGenerator gen, final EdmEntityContainer container) throws IOException { @@ -102,7 +104,7 @@ public class ServiceDocumentJsonSerializer { private void writeElement(final JsonGenerator gen, final String kind, final String reference, final String name, final String title) - throws IOException { + throws IOException { gen.writeStartObject(); gen.writeObjectField(Constants.JSON_NAME, name); if (title != null) { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java index c86781548..94ff63b2f 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java @@ -148,7 +148,7 @@ public class MetadataDocumentXmlSerializer { private static final String XML_CONTAINS_TARGET = "ContainsTarget"; private static final String XML_TERM_ATT = "Term"; private static final String XML_QUALIFIER_ATT = "Qualifier"; - private static final String XML_PROPERTY_Value = "PropertyValue"; + private static final String XML_PROPERTY_VALUE = "PropertyValue"; private static final String XML_BASE_TERM = "BaseTerm"; private static final String XML_APPLIES_TO = "AppliesTo"; @@ -455,7 +455,7 @@ public class MetadataDocumentXmlSerializer { writer.writeAttribute(XML_TYPE, getAliasedFullQualifiedName(type, false)); } for (EdmPropertyValue propValue : asRecord.getPropertyValues()) { - writer.writeStartElement(XML_PROPERTY_Value); + writer.writeStartElement(XML_PROPERTY_VALUE); writer.writeAttribute(XML_PROPERTY, propValue.getProperty()); appendExpression(writer, propValue.getValue()); appendAnnotations(writer, propValue); diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java index 835194506..72d93a92f 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java @@ -6,9 +6,9 @@ * 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 @@ -55,7 +55,7 @@ public class ServiceDocumentXmlSerializer { public void writeServiceDocument(final XMLStreamWriter writer) throws XMLStreamException { final String metadataUri = (serviceRoot == null ? "" : serviceRoot.endsWith("/") ? serviceRoot : (serviceRoot + "/")) - + Constants.METADATA; + + Constants.METADATA; writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0"); writer.writeStartElement(APP, "service", NS_APP); @@ -74,14 +74,16 @@ public class ServiceDocumentXmlSerializer { writer.writeStartElement(APP, "workspace", NS_APP); final EdmEntityContainer container = metadata.getEdm().getEntityContainer(); - writer.writeStartElement(ATOM, Constants.ATOM_ELEM_TITLE, NS_ATOM); - writer.writeCharacters(container.getFullQualifiedName().getFullQualifiedNameAsString()); - writer.writeEndElement(); + if (container != null) { + writer.writeStartElement(ATOM, Constants.ATOM_ELEM_TITLE, NS_ATOM); + writer.writeCharacters(container.getFullQualifiedName().getFullQualifiedNameAsString()); + writer.writeEndElement(); - writeEntitySets(writer, container); - writeFunctionImports(writer, container); - writeSingletons(writer, container); - writeServiceDocuments(writer); + writeEntitySets(writer, container); + writeFunctionImports(writer, container); + writeSingletons(writer, container); + writeServiceDocuments(writer); + } writer.writeEndElement(); // end workspace writer.writeEndElement(); // end service } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java index 7183bde2c..916307f39 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java @@ -6,9 +6,9 @@ * 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 @@ -58,8 +58,10 @@ public class UriInfoImpl implements UriInfo { private UriInfoKind kind; - private List entitySetNames = new ArrayList(); // for $entity - private EdmEntityType entityTypeCast; // for $entity + // for $entity + private List entitySetNames = new ArrayList(); + // for $entity + private EdmEntityType entityTypeCast; private UriResource lastResourcePart; private List pathParts = new ArrayList(); @@ -175,12 +177,12 @@ public class UriInfoImpl implements UriInfo { * or an option of this kind has been added before */ public UriInfoImpl setSystemQueryOption(final SystemQueryOption systemOption) { - final SystemQueryOptionKind kind = systemOption.getKind(); - if (systemQueryOptions.containsKey(kind)) { + final SystemQueryOptionKind systemQueryOptionKind = systemOption.getKind(); + if (systemQueryOptions.containsKey(systemQueryOptionKind)) { throw new ODataRuntimeException("Double System Query Option: " + systemOption.getName()); } - switch (kind) { + switch (systemQueryOptionKind) { case EXPAND: case FILTER: case FORMAT: @@ -193,7 +195,7 @@ public class UriInfoImpl implements UriInfo { case SKIPTOKEN: case TOP: case LEVELS: - systemQueryOptions.put(kind, systemOption); + systemQueryOptions.put(systemQueryOptionKind, systemOption); break; default: throw new ODataRuntimeException("Unsupported System Query Option: " + systemOption.getName()); diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceComplexPropertyImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceComplexPropertyImpl.java index 8e9d5995a..0de0ee825 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceComplexPropertyImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceComplexPropertyImpl.java @@ -45,7 +45,7 @@ public class UriResourceComplexPropertyImpl extends UriResourceTypedImpl impleme @Override public EdmComplexType getComplexTypeFilter() { - return (EdmComplexType) typeFilter; + return (EdmComplexType) getTypeFilter(); } @Override diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceImpl.java index 19aa6487f..e272b2a33 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceImpl.java @@ -6,9 +6,9 @@ * 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 @@ -25,7 +25,7 @@ import org.apache.olingo.server.api.uri.UriResourceKind; * Abstract class for resource-path elements in URI. */ public abstract class UriResourceImpl implements UriResource { - protected UriResourceKind kind; + private final UriResourceKind kind; public UriResourceImpl(final UriResourceKind kind) { this.kind = kind; diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceSingletonImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceSingletonImpl.java index e7ad966ee..c2f5b1545 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceSingletonImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceSingletonImpl.java @@ -40,7 +40,7 @@ public class UriResourceSingletonImpl extends UriResourceTypedImpl implements Ur @Override public EdmEntityType getEntityTypeFilter() { - return (EdmEntityType) typeFilter; + return (EdmEntityType) getTypeFilter(); } @Override diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceStartingTypeFilterImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceStartingTypeFilterImpl.java index 3671720e0..ff19e051c 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceStartingTypeFilterImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceStartingTypeFilterImpl.java @@ -19,7 +19,6 @@ package org.apache.olingo.server.core.uri; import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.server.api.uri.UriResourceKind; public class UriResourceStartingTypeFilterImpl extends UriResourceWithKeysImpl { @@ -32,11 +31,6 @@ public class UriResourceStartingTypeFilterImpl extends UriResourceWithKeysImpl { this.isCollection = isCollection; } - @Override - public UriResourceKind getKind() { - return kind; - } - @Override public EdmType getType() { return type; diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceTypedImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceTypedImpl.java index d44b9e6b3..be9cc1597 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceTypedImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceTypedImpl.java @@ -25,7 +25,7 @@ import org.apache.olingo.server.api.uri.UriResourcePartTyped; public abstract class UriResourceTypedImpl extends UriResourceImpl implements UriResourcePartTyped { - protected EdmType typeFilter = null; + private EdmType typeFilter = null; public UriResourceTypedImpl(final UriResourceKind kind) { super(kind); diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceWithKeysImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceWithKeysImpl.java index 352b8704d..370090c12 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceWithKeysImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceWithKeysImpl.java @@ -28,9 +28,9 @@ import org.apache.olingo.server.api.uri.UriResourcePartTyped; public abstract class UriResourceWithKeysImpl extends UriResourceImpl implements UriResourcePartTyped { - protected EdmType collectionTypeFilter = null; + private EdmType collectionTypeFilter = null; protected List keyPredicates = null; - protected EdmType entryTypeFilter = null; + private EdmType entryTypeFilter = null; public UriResourceWithKeysImpl(final UriResourceKind kind) { super(kind); diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ResourcePathParser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ResourcePathParser.java index 5c280c855..3cce2788b 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ResourcePathParser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ResourcePathParser.java @@ -316,7 +316,7 @@ public class ResourcePathParser { } private void requireTyped(final UriResource previous, final String forWhat) throws UriParserException { - if (previous == null || !(previous instanceof UriResourcePartTyped)) { + if (!(previous instanceof UriResourcePartTyped)) { throw new UriParserSemanticException("Path segment before '" + forWhat + "' is not typed.", UriParserSemanticException.MessageKeys.PREVIOUS_PART_NOT_TYPED, forWhat); } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/SearchParser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/SearchParser.java index a072327d5..8d046a58d 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/SearchParser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/SearchParser.java @@ -60,7 +60,8 @@ public class SearchParser { private SearchExpression processExprAnd(UriTokenizer tokenizer) throws SearchParserException { SearchExpression left = processTerm(tokenizer); - while (tokenizer.next(TokenKind.AndOperatorSearch)) { // Could be whitespace or whitespace-surrounded 'AND'. + while (tokenizer.next(TokenKind.AndOperatorSearch)) { + // Could be whitespace or whitespace-surrounded 'AND'. final SearchExpression right = processTerm(tokenizer); left = new SearchBinaryImpl(left, SearchBinaryOperatorKind.AND, right); } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/ExpandOptionImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/ExpandOptionImpl.java index 05ee26052..87e2b6c6a 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/ExpandOptionImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/ExpandOptionImpl.java @@ -28,7 +28,7 @@ import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind; public class ExpandOptionImpl extends SystemQueryOptionImpl implements ExpandOption { - List expandItems = new ArrayList(); + private final List expandItems = new ArrayList(); public ExpandOptionImpl() { setKind(SystemQueryOptionKind.EXPAND); @@ -42,5 +42,4 @@ public class ExpandOptionImpl extends SystemQueryOptionImpl implements ExpandOpt public List getExpandItems() { return Collections.unmodifiableList(expandItems); } - } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/OrderByItemImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/OrderByItemImpl.java index 633318d6f..ad57d6bb2 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/OrderByItemImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/OrderByItemImpl.java @@ -6,9 +6,9 @@ * 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 @@ -24,7 +24,8 @@ import org.apache.olingo.server.api.uri.queryoption.expression.Expression; public class OrderByItemImpl implements OrderByItem { private Expression expression; - private boolean descending = false; // default sort order is ascending + // default sort order is ascending + private boolean descending = false; @Override public boolean isDescending() { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/SelectItemImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/SelectItemImpl.java index 8ead48969..12472306e 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/SelectItemImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/SelectItemImpl.java @@ -55,11 +55,7 @@ public class SelectItemImpl implements SelectItem { @Override public boolean isAllOperationsInSchema() { - if (addOperationsInSchemaNameSpace == null) { - return false; - } else { - return true; - } + return addOperationsInSchemaNameSpace != null; } @Override diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/BinaryImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/BinaryImpl.java index 5f07b4948..7c3f65df6 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/BinaryImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/BinaryImpl.java @@ -62,9 +62,9 @@ public class BinaryImpl implements Binary { @Override public T accept(final ExpressionVisitor visitor) throws ExpressionVisitException, ODataApplicationException { - T left = this.left.accept(visitor); - T right = this.right.accept(visitor); - return visitor.visitBinaryOperator(operator, left, right); + T localLeft = this.left.accept(visitor); + T localRight = this.right.accept(visitor); + return visitor.visitBinaryOperator(operator, localLeft, localRight); } @Override diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/MethodImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/MethodImpl.java index 9a38781ae..126a6b22c 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/MethodImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/MethodImpl.java @@ -6,9 +6,9 @@ * 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 @@ -96,7 +96,8 @@ public class MethodImpl implements Method { case ROUND: case FLOOR: case CEILING: - kind = EdmPrimitiveTypeKind.Double; // Needs to be refined if Decimal must be distinguished from Double. + // Needs to be refined if Decimal must be distinguished from Double. + kind = EdmPrimitiveTypeKind.Double; break; case GEODISTANCE: case GEOLENGTH: diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java index 9c076b2ab..0946b600f 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java @@ -103,7 +103,7 @@ public class UriValidator { } } - private static Map OPTION_INDEX; + private static final Map OPTION_INDEX; static { Map temp = new EnumMap(SystemQueryOptionKind.class); diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerImplTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerImplTest.java index e1734c5e7..964ed2bdf 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerImplTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerImplTest.java @@ -38,7 +38,6 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.edm.provider.CsdlAbstractEdmProvider; import org.apache.olingo.commons.api.edm.provider.CsdlEntitySet; import org.apache.olingo.commons.api.ex.ODataException; -import org.apache.olingo.commons.api.format.AcceptType; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpMethod; diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java index 8ebf598bb..02453e6b6 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java @@ -37,7 +37,6 @@ import java.util.List; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.Entity; -import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.Link; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterTreeToText.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterTreeToText.java index a083c67ec..610b666bb 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterTreeToText.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterTreeToText.java @@ -23,13 +23,19 @@ import java.util.List; import org.apache.olingo.commons.api.edm.EdmEnumType; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.server.api.ODataApplicationException; -import org.apache.olingo.server.api.uri.UriInfoResource; import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourceLambdaAll; import org.apache.olingo.server.api.uri.UriResourceLambdaAny; import org.apache.olingo.server.api.uri.UriResourcePartTyped; import org.apache.olingo.server.api.uri.queryoption.FilterOption; -import org.apache.olingo.server.api.uri.queryoption.expression.*; +import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind; +import org.apache.olingo.server.api.uri.queryoption.expression.Expression; +import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; +import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitor; +import org.apache.olingo.server.api.uri.queryoption.expression.Literal; +import org.apache.olingo.server.api.uri.queryoption.expression.Member; +import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind; +import org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind; public class FilterTreeToText implements ExpressionVisitor {